insilmaril@726
|
1 |
#include "vymview.h"
|
insilmaril@726
|
2 |
|
insilmaril@727
|
3 |
#include <iostream>
|
insilmaril@742
|
4 |
using namespace std;
|
insilmaril@727
|
5 |
|
insilmaril@804
|
6 |
#include "branchitem.h"
|
insilmaril@732
|
7 |
#include "mainwindow.h"
|
insilmaril@726
|
8 |
#include "mapeditor.h"
|
insilmaril@769
|
9 |
#include "treeeditor.h"
|
insilmaril@726
|
10 |
|
insilmaril@732
|
11 |
extern Main *mainWindow;
|
insilmaril@732
|
12 |
|
insilmaril@732
|
13 |
|
insilmaril@742
|
14 |
VymView::VymView(VymModel *m)
|
insilmaril@726
|
15 |
{
|
insilmaril@742
|
16 |
model=m;
|
insilmaril@742
|
17 |
|
insilmaril@726
|
18 |
// Create TreeView
|
insilmaril@769
|
19 |
treeEditor=new TreeEditor (model);
|
insilmaril@788
|
20 |
//treeEditor->setModel ((QAbstractItemModel*)model);
|
insilmaril@769
|
21 |
//treeEditor->setMinimumWidth (50);
|
insilmaril@761
|
22 |
|
insilmaril@788
|
23 |
treeEditor->setColumnWidth (0,150);
|
insilmaril@788
|
24 |
treeEditor->setAnimated (true);
|
insilmaril@726
|
25 |
|
insilmaril@804
|
26 |
// FIXME-2 use proxySelModel=treeEditor->selectionModel();
|
insilmaril@801
|
27 |
selModel=new QItemSelectionModel (model);
|
insilmaril@801
|
28 |
|
insilmaril@801
|
29 |
//model->setSelectionModel (proxySelModel);
|
insilmaril@728
|
30 |
model->setSelectionModel (selModel);
|
insilmaril@804
|
31 |
treeEditor->setSelectionModel (selModel);
|
insilmaril@727
|
32 |
|
insilmaril@726
|
33 |
// Create good old MapEditor
|
insilmaril@761
|
34 |
mapEditor=model->getMapEditor();
|
insilmaril@761
|
35 |
if (!mapEditor) mapEditor=new MapEditor (model);
|
insilmaril@772
|
36 |
|
insilmaril@801
|
37 |
// Connect selections
|
insilmaril@801
|
38 |
|
insilmaril@801
|
39 |
// Proxymodel changed
|
insilmaril@804
|
40 |
/*
|
insilmaril@801
|
41 |
connect (
|
insilmaril@801
|
42 |
proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@801
|
43 |
this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@804
|
44 |
*/
|
insilmaril@801
|
45 |
|
insilmaril@804
|
46 |
// Selection in Model changed
|
insilmaril@801
|
47 |
connect (
|
insilmaril@801
|
48 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@801
|
49 |
this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@801
|
50 |
|
insilmaril@804
|
51 |
// Tell MapEditor to update selection
|
insilmaril@801
|
52 |
connect (
|
insilmaril@801
|
53 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@801
|
54 |
mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@801
|
55 |
|
insilmaril@804
|
56 |
// FIXME-2 testing, if that reenables updating selbox during animation
|
insilmaril@804
|
57 |
connect (
|
insilmaril@804
|
58 |
model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@804
|
59 |
mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@804
|
60 |
|
insilmaril@801
|
61 |
// Connect data changed signals
|
insilmaril@753
|
62 |
connect (
|
insilmaril@753
|
63 |
model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
|
insilmaril@761
|
64 |
mapEditor,SLOT (updateData(const QModelIndex &) ) );
|
insilmaril@726
|
65 |
|
insilmaril@800
|
66 |
connect (
|
insilmaril@800
|
67 |
model, SIGNAL (sortFilterChanged (const QString &)),
|
insilmaril@800
|
68 |
treeEditor, SLOT (setSortFilter (const QString &) ) );
|
insilmaril@800
|
69 |
|
insilmaril@746
|
70 |
connect (
|
insilmaril@753
|
71 |
model, SIGNAL (noteHasChanged(QModelIndex) ),
|
insilmaril@753
|
72 |
mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
|
insilmaril@746
|
73 |
|
insilmaril@763
|
74 |
connect (
|
insilmaril@763
|
75 |
model, SIGNAL (expandAll() ),
|
insilmaril@763
|
76 |
this, SLOT (expandAll () ) );
|
insilmaril@763
|
77 |
|
insilmaril@763
|
78 |
connect (
|
insilmaril@804
|
79 |
model, SIGNAL (expandOneLevel() ),
|
insilmaril@804
|
80 |
this, SLOT (expandOneLevel() ) );
|
insilmaril@804
|
81 |
|
insilmaril@804
|
82 |
connect (
|
insilmaril@804
|
83 |
model, SIGNAL (collapseOneLevel() ),
|
insilmaril@804
|
84 |
this, SLOT (collapseOneLevel() ) );
|
insilmaril@804
|
85 |
|
insilmaril@804
|
86 |
connect (
|
insilmaril@763
|
87 |
model, SIGNAL (showSelection() ),
|
insilmaril@763
|
88 |
this, SLOT (showSelection() ) );
|
insilmaril@763
|
89 |
|
insilmaril@726
|
90 |
|
insilmaril@761
|
91 |
mapEditor->setAntiAlias (mainWindow->isAliased());
|
insilmaril@761
|
92 |
mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
|
insilmaril@726
|
93 |
|
insilmaril@769
|
94 |
addWidget (treeEditor);
|
insilmaril@761
|
95 |
addWidget (mapEditor);
|
insilmaril@726
|
96 |
|
insilmaril@726
|
97 |
// Set geometry
|
insilmaril@761
|
98 |
QList <int> widths;
|
insilmaril@788
|
99 |
widths<<200;
|
insilmaril@761
|
100 |
widths<<600;
|
insilmaril@761
|
101 |
setSizes(widths);
|
insilmaril@726
|
102 |
}
|
insilmaril@726
|
103 |
|
insilmaril@772
|
104 |
VymView::~VymView()
|
insilmaril@772
|
105 |
{
|
insilmaril@772
|
106 |
//cout << "Destructor VymView\n";
|
insilmaril@772
|
107 |
}
|
insilmaril@772
|
108 |
|
insilmaril@772
|
109 |
VymModel* VymView::getModel()
|
insilmaril@772
|
110 |
{
|
insilmaril@772
|
111 |
return model;
|
insilmaril@772
|
112 |
}
|
insilmaril@772
|
113 |
|
insilmaril@772
|
114 |
MapEditor* VymView::getMapEditor()
|
insilmaril@772
|
115 |
{
|
insilmaril@772
|
116 |
return mapEditor;
|
insilmaril@772
|
117 |
}
|
insilmaril@772
|
118 |
|
insilmaril@769
|
119 |
void VymView::initFocus()
|
insilmaril@769
|
120 |
{
|
insilmaril@769
|
121 |
mapEditor->setFocus();
|
insilmaril@769
|
122 |
}
|
insilmaril@769
|
123 |
|
insilmaril@746
|
124 |
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
|
insilmaril@727
|
125 |
{
|
insilmaril@746
|
126 |
// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
|
insilmaril@777
|
127 |
mainWindow->changeSelection (model,newsel,oldsel); // FIXME-5 maybe connect VymModel <-> MainWindow directly?
|
insilmaril@777
|
128 |
// would require to also get current model in mainWindow
|
insilmaril@804
|
129 |
|
insilmaril@804
|
130 |
cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
|
insilmaril@804
|
131 |
|
insilmaril@804
|
132 |
if (newsel.indexes().count()>0)
|
insilmaril@804
|
133 |
{
|
insilmaril@804
|
134 |
|
insilmaril@804
|
135 |
/* FIXME-2 use proxymodel
|
insilmaril@804
|
136 |
proxySelModel->select (
|
insilmaril@804
|
137 |
treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
|
insilmaril@804
|
138 |
QItemSelectionModel::ClearAndSelect );
|
insilmaril@804
|
139 |
*/
|
insilmaril@804
|
140 |
QModelIndex ix=newsel.indexes().first();
|
insilmaril@804
|
141 |
selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
|
insilmaril@804
|
142 |
treeEditor->setCurrentIndex (ix);
|
insilmaril@804
|
143 |
showSelection();
|
insilmaril@804
|
144 |
}
|
insilmaril@801
|
145 |
}
|
insilmaril@777
|
146 |
|
insilmaril@801
|
147 |
void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
|
insilmaril@801
|
148 |
{
|
insilmaril@801
|
149 |
// Notify mainwindow to update satellites, but map selection to
|
insilmaril@801
|
150 |
// original model first
|
insilmaril@801
|
151 |
|
insilmaril@804
|
152 |
cout << "VV::changeProxySelection newsel.count="<<newsel.indexes().count()<<endl;
|
insilmaril@804
|
153 |
if (!newsel.indexes().isEmpty())
|
insilmaril@804
|
154 |
{
|
insilmaril@804
|
155 |
/* FIXME-2 need to set current, too
|
insilmaril@804
|
156 |
*/
|
insilmaril@804
|
157 |
proxySelModel->setCurrentIndex (
|
insilmaril@804
|
158 |
newsel.indexes().first(),
|
insilmaril@804
|
159 |
QItemSelectionModel::ClearAndSelect );
|
insilmaril@804
|
160 |
treeEditor->setCurrentIndex (newsel.indexes().first() );
|
insilmaril@804
|
161 |
}
|
insilmaril@804
|
162 |
|
insilmaril@801
|
163 |
// Re-emit but map selection first
|
insilmaril@804
|
164 |
selModel->select (
|
insilmaril@804
|
165 |
treeEditor->getProxyModel()->mapSelectionToSource (newsel),
|
insilmaril@802
|
166 |
QItemSelectionModel::ClearAndSelect );
|
insilmaril@804
|
167 |
|
insilmaril@803
|
168 |
showSelection();
|
insilmaril@727
|
169 |
}
|
insilmaril@727
|
170 |
|
insilmaril@763
|
171 |
void VymView::expandAll()
|
insilmaril@763
|
172 |
{
|
insilmaril@769
|
173 |
treeEditor->expandAll();
|
insilmaril@763
|
174 |
}
|
insilmaril@763
|
175 |
|
insilmaril@804
|
176 |
void VymView::expandOneLevel()
|
insilmaril@804
|
177 |
{
|
insilmaril@804
|
178 |
int level=999999;
|
insilmaril@804
|
179 |
int d;
|
insilmaril@804
|
180 |
BranchItem *cur=NULL;
|
insilmaril@804
|
181 |
BranchItem *prev=NULL;
|
insilmaril@804
|
182 |
QModelIndex pix;
|
insilmaril@804
|
183 |
|
insilmaril@804
|
184 |
// Find level to expand
|
insilmaril@804
|
185 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
186 |
while (cur)
|
insilmaril@804
|
187 |
{
|
insilmaril@804
|
188 |
// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
|
insilmaril@804
|
189 |
pix=model->index (cur);
|
insilmaril@804
|
190 |
d=cur->depth();
|
insilmaril@804
|
191 |
if (!treeEditor->isExpanded(pix) && d < level)
|
insilmaril@804
|
192 |
level=d;
|
insilmaril@804
|
193 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
194 |
}
|
insilmaril@804
|
195 |
|
insilmaril@804
|
196 |
// Expand all to level
|
insilmaril@804
|
197 |
cur=NULL;
|
insilmaril@804
|
198 |
prev=NULL;
|
insilmaril@804
|
199 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
200 |
while (cur)
|
insilmaril@804
|
201 |
{
|
insilmaril@804
|
202 |
// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
|
insilmaril@804
|
203 |
pix=model->index (cur);
|
insilmaril@804
|
204 |
d=cur->depth();
|
insilmaril@804
|
205 |
if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
|
insilmaril@804
|
206 |
treeEditor->setExpanded(pix,true);
|
insilmaril@804
|
207 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
208 |
}
|
insilmaril@804
|
209 |
/* FIXME-3 optimize expanding by using flat version of next
|
insilmaril@804
|
210 |
model->nextBranch(cur,prev,false);
|
insilmaril@804
|
211 |
while (cur)
|
insilmaril@804
|
212 |
{
|
insilmaril@804
|
213 |
cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
|
insilmaril@804
|
214 |
;
|
insilmaril@804
|
215 |
model->nextBranch(cur,prev,false);
|
insilmaril@804
|
216 |
}
|
insilmaril@804
|
217 |
*/
|
insilmaril@804
|
218 |
}
|
insilmaril@804
|
219 |
|
insilmaril@804
|
220 |
void VymView::collapseOneLevel()
|
insilmaril@804
|
221 |
{
|
insilmaril@804
|
222 |
int level=-1;
|
insilmaril@804
|
223 |
int d;
|
insilmaril@804
|
224 |
BranchItem *cur=NULL;
|
insilmaril@804
|
225 |
BranchItem *prev=NULL;
|
insilmaril@804
|
226 |
QModelIndex pix;
|
insilmaril@804
|
227 |
|
insilmaril@804
|
228 |
// Find level to collapse
|
insilmaril@804
|
229 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
230 |
while (cur)
|
insilmaril@804
|
231 |
{
|
insilmaril@804
|
232 |
// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
|
insilmaril@804
|
233 |
pix=model->index (cur);
|
insilmaril@804
|
234 |
d=cur->depth();
|
insilmaril@804
|
235 |
if (treeEditor->isExpanded(pix) && d > level)
|
insilmaril@804
|
236 |
level=d;
|
insilmaril@804
|
237 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
238 |
}
|
insilmaril@804
|
239 |
|
insilmaril@804
|
240 |
// collapse all to level
|
insilmaril@804
|
241 |
cur=NULL;
|
insilmaril@804
|
242 |
prev=NULL;
|
insilmaril@804
|
243 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
244 |
while (cur)
|
insilmaril@804
|
245 |
{
|
insilmaril@804
|
246 |
// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
|
insilmaril@804
|
247 |
pix=model->index (cur);
|
insilmaril@804
|
248 |
d=cur->depth();
|
insilmaril@804
|
249 |
if (treeEditor->isExpanded(pix) && d >= level)
|
insilmaril@804
|
250 |
treeEditor->setExpanded(pix,false);
|
insilmaril@804
|
251 |
model->nextBranch(cur,prev);
|
insilmaril@804
|
252 |
}
|
insilmaril@804
|
253 |
}
|
insilmaril@804
|
254 |
|
insilmaril@763
|
255 |
void VymView::showSelection()
|
insilmaril@763
|
256 |
{
|
insilmaril@772
|
257 |
QModelIndex ix=model->getSelectedIndex();
|
insilmaril@772
|
258 |
treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
|
insilmaril@772
|
259 |
mapEditor->scrollTo ( ix);
|
insilmaril@763
|
260 |
}
|
insilmaril@763
|
261 |
|