6 #include "branchitem.h"
7 #include "mainwindow.h"
9 #include "treeeditor.h"
11 extern Main *mainWindow;
14 VymView::VymView(VymModel *m)
19 treeEditor=new TreeEditor (model);
20 //treeEditor->setModel ((QAbstractItemModel*)model);
21 //treeEditor->setMinimumWidth (50);
23 treeEditor->setColumnWidth (0,150);
24 treeEditor->setAnimated (true);
26 // FIXME-2 use proxySelModel=treeEditor->selectionModel();
27 selModel=new QItemSelectionModel (model);
29 //model->setSelectionModel (proxySelModel);
30 model->setSelectionModel (selModel);
31 treeEditor->setSelectionModel (selModel);
33 // Create good old MapEditor
34 mapEditor=model->getMapEditor();
35 if (!mapEditor) mapEditor=new MapEditor (model);
42 proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
43 this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
46 // Selection in Model changed
48 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
49 this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
51 // Tell MapEditor to update selection
52 /* FIXME-3 done implicit here in VymView
54 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
55 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
58 // FIXME-2 testing, if that reenables updating selbox during animation
60 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
61 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
63 // Connect data changed signals
65 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
66 mapEditor,SLOT (updateData(const QModelIndex &) ) );
69 model, SIGNAL (sortFilterChanged (const QString &)),
70 treeEditor, SLOT (setSortFilter (const QString &) ) );
73 model, SIGNAL (noteHasChanged(QModelIndex) ),
74 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
77 model, SIGNAL (expandAll() ),
78 this, SLOT (expandAll () ) );
81 model, SIGNAL (expandOneLevel() ),
82 this, SLOT (expandOneLevel() ) );
85 model, SIGNAL (collapseOneLevel() ),
86 this, SLOT (collapseOneLevel() ) );
89 model, SIGNAL (showSelection() ),
90 this, SLOT (showSelection() ) );
93 mapEditor->setAntiAlias (mainWindow->isAliased());
94 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
96 addWidget (treeEditor);
97 addWidget (mapEditor);
108 //cout << "Destructor VymView\n";
111 VymModel* VymView::getModel()
116 MapEditor* VymView::getMapEditor()
121 void VymView::initFocus()
123 mapEditor->setFocus();
126 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
128 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
130 mainWindow->changeSelection (model,newsel,oldsel);
131 mapEditor->updateSelection (newsel,oldsel);
133 if (newsel.indexes().count()>0)
136 /* FIXME-2 use proxymodel
137 proxySelModel->select (
138 treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
139 QItemSelectionModel::ClearAndSelect );
142 QModelIndex ix=newsel.indexes().first();
143 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
144 treeEditor->setCurrentIndex (ix);
150 void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
152 // Notify mainwindow to update satellites, but map selection to
153 // original model first
155 //cout << "VV::changeProxySelection newsel.count="<<newsel.indexes().count()<<endl;
156 if (!newsel.indexes().isEmpty())
158 /* FIXME-2 need to set current, too
160 proxySelModel->setCurrentIndex (
161 newsel.indexes().first(),
162 QItemSelectionModel::ClearAndSelect );
163 treeEditor->setCurrentIndex (newsel.indexes().first() );
166 // Re-emit but map selection first
168 treeEditor->getProxyModel()->mapSelectionToSource (newsel),
169 QItemSelectionModel::ClearAndSelect );
174 void VymView::expandAll()
176 treeEditor->expandAll();
179 void VymView::expandOneLevel()
183 BranchItem *cur=NULL;
184 BranchItem *prev=NULL;
187 // Find level to expand
188 model->nextBranch(cur,prev);
191 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
192 pix=model->index (cur);
194 if (!treeEditor->isExpanded(pix) && d < level)
196 model->nextBranch(cur,prev);
199 // Expand all to level
202 model->nextBranch(cur,prev);
205 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
206 pix=model->index (cur);
208 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
209 treeEditor->setExpanded(pix,true);
210 model->nextBranch(cur,prev);
212 /* FIXME-3 optimize expanding by using flat version of next
213 model->nextBranch(cur,prev,false);
216 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
218 model->nextBranch(cur,prev,false);
223 void VymView::collapseOneLevel()
227 BranchItem *cur=NULL;
228 BranchItem *prev=NULL;
231 // Find level to collapse
232 model->nextBranch(cur,prev);
235 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
236 pix=model->index (cur);
238 if (treeEditor->isExpanded(pix) && d > level)
240 model->nextBranch(cur,prev);
243 // collapse all to level
246 model->nextBranch(cur,prev);
249 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
250 pix=model->index (cur);
252 if (treeEditor->isExpanded(pix) && d >= level)
253 treeEditor->setExpanded(pix,false);
254 model->nextBranch(cur,prev);
258 void VymView::showSelection()
260 QModelIndex ix=model->getSelectedIndex();
261 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
262 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...