vymview.cpp
author insilmaril
Mon Mar 15 15:32:37 2010 +0000 (2010-03-15)
changeset 836 62d621e3e550
parent 825 1ad892c1a709
child 837 5ecd0462f76b
permissions -rw-r--r--
Fix for animation of branches using relPos
insilmaril@726
     1
#include "vymview.h"
insilmaril@726
     2
insilmaril@804
     3
#include "branchitem.h"
insilmaril@732
     4
#include "mainwindow.h"
insilmaril@726
     5
#include "mapeditor.h"
insilmaril@769
     6
#include "treeeditor.h"
insilmaril@726
     7
insilmaril@732
     8
extern Main *mainWindow;
insilmaril@732
     9
insilmaril@732
    10
insilmaril@742
    11
VymView::VymView(VymModel *m)
insilmaril@726
    12
{
insilmaril@742
    13
	model=m;
insilmaril@742
    14
insilmaril@726
    15
	// Create TreeView
insilmaril@769
    16
	treeEditor=new TreeEditor (model);
insilmaril@788
    17
	//treeEditor->setModel ((QAbstractItemModel*)model);
insilmaril@769
    18
	//treeEditor->setMinimumWidth (50);
insilmaril@761
    19
insilmaril@788
    20
	treeEditor->setColumnWidth (0,150);
insilmaril@788
    21
	treeEditor->setAnimated (true);
insilmaril@726
    22
insilmaril@801
    23
	selModel=new QItemSelectionModel (model);
insilmaril@801
    24
insilmaril@728
    25
	model->setSelectionModel (selModel);
insilmaril@804
    26
	treeEditor->setSelectionModel (selModel);
insilmaril@727
    27
insilmaril@726
    28
	// Create good old MapEditor
insilmaril@761
    29
	mapEditor=model->getMapEditor();
insilmaril@761
    30
	if (!mapEditor) mapEditor=new MapEditor (model);
insilmaril@772
    31
insilmaril@808
    32
	// Create Layout 
insilmaril@829
    33
	QVBoxLayout* mainLayout = new QVBoxLayout (this); //FIXME-4 not needed
insilmaril@829
    34
	QSplitter *splitter= new QSplitter (this);
insilmaril@808
    35
insilmaril@808
    36
	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
insilmaril@808
    37
    splitter->setSizePolicy(sizePolicy);
insilmaril@808
    38
	mainLayout->addWidget (splitter);
insilmaril@808
    39
insilmaril@801
    40
	// Connect selections
insilmaril@801
    41
insilmaril@804
    42
		// Selection in Model changed	
insilmaril@801
    43
		connect (
insilmaril@801
    44
			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@801
    45
			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@801
    46
insilmaril@804
    47
		// Tell MapEditor to update selection
insilmaril@807
    48
		/* FIXME-3 done implicit here in VymView
insilmaril@801
    49
		connect (
insilmaril@801
    50
			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@801
    51
			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@807
    52
			*/
insilmaril@801
    53
insilmaril@823
    54
		// Needed to update selbox during animation
insilmaril@804
    55
		connect (
insilmaril@804
    56
			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@804
    57
			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@804
    58
insilmaril@801
    59
	// Connect data changed signals	
insilmaril@753
    60
	connect (
insilmaril@753
    61
		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@761
    62
		mapEditor,SLOT (updateData(const QModelIndex &) ) );
insilmaril@726
    63
insilmaril@800
    64
	connect (
insilmaril@800
    65
		model, SIGNAL (sortFilterChanged (const QString &)),
insilmaril@800
    66
		treeEditor, SLOT (setSortFilter (const QString &) ) );
insilmaril@800
    67
insilmaril@746
    68
	connect (
insilmaril@753
    69
		model, SIGNAL (noteHasChanged(QModelIndex) ),
insilmaril@753
    70
		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
insilmaril@746
    71
		
insilmaril@763
    72
	connect (
insilmaril@763
    73
		model, SIGNAL (expandAll() ),
insilmaril@763
    74
		this, SLOT (expandAll () ) );
insilmaril@763
    75
		
insilmaril@763
    76
	connect (
insilmaril@804
    77
		model, SIGNAL (expandOneLevel() ),
insilmaril@804
    78
		this, SLOT (expandOneLevel() ) );
insilmaril@804
    79
		
insilmaril@804
    80
	connect (
insilmaril@804
    81
		model, SIGNAL (collapseOneLevel() ),
insilmaril@804
    82
		this, SLOT (collapseOneLevel() ) );
insilmaril@804
    83
		
insilmaril@804
    84
	connect (
insilmaril@763
    85
		model, SIGNAL (showSelection() ),
insilmaril@763
    86
		this, SLOT (showSelection() ) );
insilmaril@763
    87
		
insilmaril@761
    88
	mapEditor->setAntiAlias (mainWindow->isAliased());
insilmaril@761
    89
	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
insilmaril@726
    90
insilmaril@808
    91
	splitter->addWidget (treeEditor);
insilmaril@808
    92
	splitter->addWidget (mapEditor);
insilmaril@726
    93
insilmaril@726
    94
	// Set geometry
insilmaril@761
    95
	QList <int> widths;
insilmaril@788
    96
	widths<<200;
insilmaril@761
    97
	widths<<600;
insilmaril@808
    98
	splitter->setSizes(widths);
insilmaril@726
    99
}
insilmaril@726
   100
insilmaril@772
   101
VymView::~VymView()
insilmaril@772
   102
{
insilmaril@772
   103
	//cout << "Destructor VymView\n";
insilmaril@772
   104
}
insilmaril@772
   105
insilmaril@772
   106
VymModel* VymView::getModel()
insilmaril@772
   107
{
insilmaril@772
   108
	return model;
insilmaril@772
   109
}
insilmaril@772
   110
insilmaril@772
   111
MapEditor* VymView::getMapEditor()
insilmaril@772
   112
{
insilmaril@772
   113
	return mapEditor;
insilmaril@772
   114
}
insilmaril@772
   115
insilmaril@769
   116
void VymView::initFocus()
insilmaril@769
   117
{
insilmaril@769
   118
	mapEditor->setFocus();
insilmaril@769
   119
}
insilmaril@769
   120
insilmaril@807
   121
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)	
insilmaril@727
   122
{
insilmaril@807
   123
	//cout << "VV::changeSelection   newsel.count="<<newsel.indexes().count()<<endl;
insilmaril@804
   124
insilmaril@807
   125
	mainWindow->changeSelection (model,newsel,oldsel);	
insilmaril@807
   126
	mapEditor->updateSelection (newsel,oldsel);
insilmaril@804
   127
insilmaril@804
   128
	if (newsel.indexes().count()>0)
insilmaril@804
   129
	{
insilmaril@804
   130
insilmaril@807
   131
		
insilmaril@804
   132
		QModelIndex ix=newsel.indexes().first();
insilmaril@804
   133
		selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect  );
insilmaril@804
   134
		treeEditor->setCurrentIndex (ix);
insilmaril@804
   135
		showSelection();
insilmaril@807
   136
		
insilmaril@804
   137
	}
insilmaril@801
   138
}
insilmaril@777
   139
insilmaril@763
   140
void VymView::expandAll()
insilmaril@763
   141
{
insilmaril@769
   142
	treeEditor->expandAll();
insilmaril@763
   143
}
insilmaril@763
   144
insilmaril@804
   145
void VymView::expandOneLevel()
insilmaril@804
   146
{
insilmaril@804
   147
	int level=999999;
insilmaril@804
   148
	int d;
insilmaril@804
   149
	BranchItem *cur=NULL;
insilmaril@804
   150
	BranchItem *prev=NULL;
insilmaril@804
   151
	QModelIndex pix;
insilmaril@804
   152
insilmaril@804
   153
	// Find level to expand
insilmaril@804
   154
	model->nextBranch(cur,prev);
insilmaril@804
   155
	while (cur) 
insilmaril@804
   156
	{
insilmaril@804
   157
		pix=model->index (cur);
insilmaril@804
   158
		d=cur->depth();
insilmaril@804
   159
		if (!treeEditor->isExpanded(pix) && d < level)
insilmaril@804
   160
			level=d;
insilmaril@804
   161
		model->nextBranch(cur,prev);	
insilmaril@804
   162
	}
insilmaril@804
   163
insilmaril@804
   164
	// Expand all to level
insilmaril@804
   165
	cur=NULL;
insilmaril@804
   166
	prev=NULL;
insilmaril@804
   167
	model->nextBranch(cur,prev);
insilmaril@804
   168
	while (cur) 
insilmaril@804
   169
	{
insilmaril@804
   170
		pix=model->index (cur);
insilmaril@804
   171
		d=cur->depth();
insilmaril@804
   172
		if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
insilmaril@804
   173
			treeEditor->setExpanded(pix,true);
insilmaril@804
   174
		model->nextBranch(cur,prev);	
insilmaril@804
   175
	}
insilmaril@804
   176
	/* FIXME-3 optimize expanding by using flat version of next
insilmaril@804
   177
	model->nextBranch(cur,prev,false);
insilmaril@804
   178
	while (cur) 
insilmaril@804
   179
	{
insilmaril@804
   180
		cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
insilmaril@804
   181
;
insilmaril@804
   182
		model->nextBranch(cur,prev,false);	
insilmaril@804
   183
	}
insilmaril@804
   184
	*/
insilmaril@804
   185
}
insilmaril@804
   186
insilmaril@804
   187
void VymView::collapseOneLevel()
insilmaril@804
   188
{
insilmaril@804
   189
	int level=-1;
insilmaril@804
   190
	int d;
insilmaril@804
   191
	BranchItem *cur=NULL;
insilmaril@804
   192
	BranchItem *prev=NULL;
insilmaril@804
   193
	QModelIndex pix;
insilmaril@804
   194
insilmaril@804
   195
	// Find level to collapse
insilmaril@804
   196
	model->nextBranch(cur,prev);
insilmaril@804
   197
	while (cur) 
insilmaril@804
   198
	{
insilmaril@804
   199
		pix=model->index (cur);
insilmaril@804
   200
		d=cur->depth();
insilmaril@804
   201
		if (treeEditor->isExpanded(pix) && d > level)
insilmaril@804
   202
			level=d;
insilmaril@804
   203
		model->nextBranch(cur,prev);	
insilmaril@804
   204
	}
insilmaril@804
   205
insilmaril@804
   206
	// collapse all to level
insilmaril@804
   207
	cur=NULL;
insilmaril@804
   208
	prev=NULL;
insilmaril@804
   209
	model->nextBranch(cur,prev);
insilmaril@804
   210
	while (cur) 
insilmaril@804
   211
	{
insilmaril@804
   212
		pix=model->index (cur);
insilmaril@804
   213
		d=cur->depth();
insilmaril@804
   214
		if (treeEditor->isExpanded(pix) && d >= level)
insilmaril@804
   215
			treeEditor->setExpanded(pix,false);
insilmaril@804
   216
		model->nextBranch(cur,prev);	
insilmaril@804
   217
	}
insilmaril@804
   218
}
insilmaril@804
   219
insilmaril@763
   220
void VymView::showSelection()
insilmaril@763
   221
{
insilmaril@772
   222
	QModelIndex ix=model->getSelectedIndex();
insilmaril@772
   223
	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
insilmaril@807
   224
	mapEditor->scrollTo ( ix);	// FIXME-3 also called from MapEditor::updateSelection...
insilmaril@763
   225
}
insilmaril@763
   226
insilmaril@823
   227
void VymView::toggleTreeEditor()
insilmaril@823
   228
{
insilmaril@823
   229
	if (treeEditor->isVisible() )
insilmaril@823
   230
		treeEditor->hide();
insilmaril@823
   231
	else
insilmaril@823
   232
		treeEditor->show();
insilmaril@823
   233
}
insilmaril@823
   234
insilmaril@823
   235