Menu

[2edc72]: / vymview.cpp  Maximize  Restore  History

Download this file

260 lines (206 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "vymview.h"
#include "branchitem.h"
#include "mainwindow.h"
#include "mapeditor.h"
#include "treedelegate.h"
#include "treeeditor.h"
extern Main *mainWindow;
VymView::VymView(VymModel *m)
{
model=m;
// Create TreeView
treeEditor=new TreeEditor (model);
//treeEditor->setModel ((QAbstractItemModel*)model);
//treeEditor->setMinimumWidth (50);
treeEditor->setColumnWidth (0,150);
treeEditor->setAnimated (true);
selModel=new QItemSelectionModel (model);
model->setSelectionModel (selModel);
treeEditor->setSelectionModel (selModel);
TreeDelegate *delegate=new TreeDelegate (this);
treeEditor->setItemDelegate (delegate);
// Create good old MapEditor
mapEditor=model->getMapEditor();
if (!mapEditor) mapEditor=new MapEditor (model);
// Create Layout
QVBoxLayout* mainLayout = new QVBoxLayout (this);
QSplitter *splitter= new QSplitter (this);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
splitter->setSizePolicy(sizePolicy);
mainLayout->addWidget (splitter);
// Connect selections
// Selection in Model changed
connect (
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
// Needed to update selbox during animation
connect (
model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
// Connect data changed signals
connect (
model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
mapEditor,SLOT (updateData(const QModelIndex &) ) );
connect (
model, SIGNAL (updateQueries (VymModel*)),
mainWindow,SLOT (updateQueries(VymModel*) ) );
connect (
model, SIGNAL (noteHasChanged(QModelIndex) ),
mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
connect (
model, SIGNAL (expandAll() ),
this, SLOT (expandAll () ) );
connect (
model, SIGNAL (expandOneLevel() ),
this, SLOT (expandOneLevel() ) );
connect (
model, SIGNAL (collapseOneLevel() ),
this, SLOT (collapseOneLevel() ) );
connect (
model, SIGNAL (collapseUnselected() ),
this, SLOT (collapseUnselected() ) );
connect (
model, SIGNAL (showSelection() ),
this, SLOT (showSelection() ) );
connect (
model, SIGNAL (updateLayout() ),
mapEditor, SLOT (autoLayout() ) );
mapEditor->setAntiAlias (mainWindow->isAliased());
mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
splitter->addWidget (treeEditor);
splitter->addWidget (mapEditor);
// Set geometry
QList <int> widths;
widths<<200;
widths<<600;
splitter->setSizes(widths);
}
VymView::~VymView()
{
//cout << "Destructor VymView\n";
}
VymModel* VymView::getModel()
{
return model;
}
MapEditor* VymView::getMapEditor()
{
return mapEditor;
}
TreeEditor* VymView::getTreeEditor()
{
return treeEditor;
}
void VymView::initFocus()
{
mapEditor->setFocus();
}
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
{
//qDebug() << "VV::changeSelection newsel.count="<<newsel.indexes().count();
mainWindow->changeSelection (model,newsel,oldsel);
mapEditor->updateSelection (newsel,oldsel);
if (newsel.indexes().count()>0)
{
QModelIndex ix=newsel.indexes().first();
selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
treeEditor->setCurrentIndex (ix);
showSelection();
}
}
void VymView::expandAll()
{
treeEditor->expandAll();
}
void VymView::expandOneLevel()
{
int level=999999;
int d;
BranchItem *cur=NULL;
BranchItem *prev=NULL;
QModelIndex pix;
// Find level to expand
model->nextBranch(cur,prev);
while (cur)
{
pix=model->index (cur);
d=cur->depth();
if (!treeEditor->isExpanded(pix) && d < level)
level=d;
model->nextBranch(cur,prev);
}
// Expand all to level
cur=NULL;
prev=NULL;
model->nextBranch(cur,prev);
while (cur)
{
pix=model->index (cur);
d=cur->depth();
if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
treeEditor->setExpanded(pix,true);
model->nextBranch(cur,prev);
}
}
void VymView::collapseOneLevel()
{
int level=-1;
int d;
BranchItem *cur=NULL;
BranchItem *prev=NULL;
QModelIndex pix;
// Find level to collapse
model->nextBranch(cur,prev);
while (cur)
{
pix=model->index (cur);
d=cur->depth();
if (treeEditor->isExpanded(pix) && d > level)
level=d;
model->nextBranch(cur,prev);
}
// collapse all to level
cur=NULL;
prev=NULL;
model->nextBranch(cur,prev);
while (cur)
{
pix=model->index (cur);
d=cur->depth();
if (treeEditor->isExpanded(pix) && d >= level)
treeEditor->setExpanded(pix,false);
model->nextBranch(cur,prev);
}
}
void VymView::collapseUnselected()
{
BranchItem *cur=NULL;
BranchItem *prev=NULL;
QModelIndex pix;
// Find level to collapse
TreeItem *selti=model->getSelectedItem();
if (!selti) return;
int level=selti->depth();
// collapse all to level
model->nextBranch(cur,prev);
while (cur)
{
pix=model->index (cur);
if (treeEditor->isExpanded(pix) && level <= cur->depth())
treeEditor->setExpanded(pix,false);
model->nextBranch(cur,prev);
}
}
void VymView::showSelection()
{
QModelIndex ix=model->getSelectedIndex();
treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
mapEditor->scrollTo ( ix);
}
void VymView::toggleTreeEditor()
{
if (treeEditor->isVisible() )
treeEditor->hide();
else
treeEditor->show();
}