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
53 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
54 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
56 // FIXME-2 testing, if that reenables updating selbox during animation
58 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
59 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
61 // Connect data changed signals
63 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
64 mapEditor,SLOT (updateData(const QModelIndex &) ) );
67 model, SIGNAL (sortFilterChanged (const QString &)),
68 treeEditor, SLOT (setSortFilter (const QString &) ) );
71 model, SIGNAL (noteHasChanged(QModelIndex) ),
72 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
75 model, SIGNAL (expandAll() ),
76 this, SLOT (expandAll () ) );
79 model, SIGNAL (expandOneLevel() ),
80 this, SLOT (expandOneLevel() ) );
83 model, SIGNAL (collapseOneLevel() ),
84 this, SLOT (collapseOneLevel() ) );
87 model, SIGNAL (showSelection() ),
88 this, SLOT (showSelection() ) );
91 mapEditor->setAntiAlias (mainWindow->isAliased());
92 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
94 addWidget (treeEditor);
95 addWidget (mapEditor);
106 //cout << "Destructor VymView\n";
109 VymModel* VymView::getModel()
114 MapEditor* VymView::getMapEditor()
119 void VymView::initFocus()
121 mapEditor->setFocus();
124 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
126 // Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
127 mainWindow->changeSelection (model,newsel,oldsel); // FIXME-5 maybe connect VymModel <-> MainWindow directly?
128 // would require to also get current model in mainWindow
130 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
132 if (newsel.indexes().count()>0)
135 /* FIXME-2 use proxymodel
136 proxySelModel->select (
137 treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
138 QItemSelectionModel::ClearAndSelect );
140 QModelIndex ix=newsel.indexes().first();
141 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
142 treeEditor->setCurrentIndex (ix);
147 void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
149 // Notify mainwindow to update satellites, but map selection to
150 // original model first
152 //cout << "VV::changeProxySelection newsel.count="<<newsel.indexes().count()<<endl;
153 if (!newsel.indexes().isEmpty())
155 /* FIXME-2 need to set current, too
157 proxySelModel->setCurrentIndex (
158 newsel.indexes().first(),
159 QItemSelectionModel::ClearAndSelect );
160 treeEditor->setCurrentIndex (newsel.indexes().first() );
163 // Re-emit but map selection first
165 treeEditor->getProxyModel()->mapSelectionToSource (newsel),
166 QItemSelectionModel::ClearAndSelect );
171 void VymView::expandAll()
173 treeEditor->expandAll();
176 void VymView::expandOneLevel()
180 BranchItem *cur=NULL;
181 BranchItem *prev=NULL;
184 // Find level to expand
185 model->nextBranch(cur,prev);
188 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
189 pix=model->index (cur);
191 if (!treeEditor->isExpanded(pix) && d < level)
193 model->nextBranch(cur,prev);
196 // Expand all to level
199 model->nextBranch(cur,prev);
202 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
203 pix=model->index (cur);
205 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
206 treeEditor->setExpanded(pix,true);
207 model->nextBranch(cur,prev);
209 /* FIXME-3 optimize expanding by using flat version of next
210 model->nextBranch(cur,prev,false);
213 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
215 model->nextBranch(cur,prev,false);
220 void VymView::collapseOneLevel()
224 BranchItem *cur=NULL;
225 BranchItem *prev=NULL;
228 // Find level to collapse
229 model->nextBranch(cur,prev);
232 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
233 pix=model->index (cur);
235 if (treeEditor->isExpanded(pix) && d > level)
237 model->nextBranch(cur,prev);
240 // collapse all to level
243 model->nextBranch(cur,prev);
246 // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
247 pix=model->index (cur);
249 if (treeEditor->isExpanded(pix) && d >= level)
250 treeEditor->setExpanded(pix,false);
251 model->nextBranch(cur,prev);
255 void VymView::showSelection()
257 QModelIndex ix=model->getSelectedIndex();
258 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
259 mapEditor->scrollTo ( ix);