insilmaril@726
|
1 |
#include "vymview.h"
|
insilmaril@726
|
2 |
|
insilmaril@727
|
3 |
#include <iostream>
|
insilmaril@742
|
4 |
using namespace std;
|
insilmaril@727
|
5 |
|
insilmaril@732
|
6 |
#include "mainwindow.h"
|
insilmaril@726
|
7 |
#include "mapeditor.h"
|
insilmaril@726
|
8 |
|
insilmaril@732
|
9 |
extern Main *mainWindow;
|
insilmaril@732
|
10 |
|
insilmaril@732
|
11 |
|
insilmaril@742
|
12 |
VymView::VymView(VymModel *m)
|
insilmaril@726
|
13 |
{
|
insilmaril@742
|
14 |
model=m;
|
insilmaril@742
|
15 |
|
insilmaril@726
|
16 |
// Create TreeView
|
insilmaril@727
|
17 |
treeview=new QTreeView;
|
insilmaril@726
|
18 |
treeview->setModel ((QAbstractItemModel*)model);
|
insilmaril@726
|
19 |
treeview->setMinimumWidth (350);
|
insilmaril@726
|
20 |
treeview->setColumnWidth (0,350);
|
insilmaril@726
|
21 |
|
insilmaril@727
|
22 |
selModel=treeview->selectionModel();
|
insilmaril@728
|
23 |
model->setSelectionModel (selModel);
|
insilmaril@727
|
24 |
connect (
|
insilmaril@727
|
25 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@727
|
26 |
this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@727
|
27 |
|
insilmaril@726
|
28 |
// Create good old MapEditor
|
insilmaril@726
|
29 |
MapEditor* me=model->getMapEditor();
|
insilmaril@726
|
30 |
if (!me) me=new MapEditor (model);
|
insilmaril@728
|
31 |
connect (
|
insilmaril@728
|
32 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@728
|
33 |
me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@729
|
34 |
connect (
|
insilmaril@729
|
35 |
selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)),
|
insilmaril@729
|
36 |
me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
|
insilmaril@726
|
37 |
|
insilmaril@746
|
38 |
// VymModel may want to update selection or other data, e.g. during animation
|
insilmaril@728
|
39 |
connect (
|
insilmaril@728
|
40 |
model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@728
|
41 |
me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@745
|
42 |
connect (
|
insilmaril@745
|
43 |
model, SIGNAL (newChildObject(QModelIndex) ),
|
insilmaril@745
|
44 |
this,SLOT (updateChilds (QModelIndex) ) );
|
insilmaril@746
|
45 |
connect (
|
insilmaril@746
|
46 |
model, SIGNAL (contentHasChanged(QModelIndex) ),
|
insilmaril@746
|
47 |
mainWindow, SLOT (updateContent(QModelIndex) ) );
|
insilmaril@746
|
48 |
|
insilmaril@726
|
49 |
|
insilmaril@746
|
50 |
//me->viewport()->setFocus(); //FIXME-3 needed?
|
insilmaril@732
|
51 |
me->setAntiAlias (mainWindow->isAliased());
|
insilmaril@732
|
52 |
me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
|
insilmaril@726
|
53 |
|
insilmaril@726
|
54 |
addWidget (treeview);
|
insilmaril@726
|
55 |
addWidget (me);
|
insilmaril@726
|
56 |
|
insilmaril@726
|
57 |
// Set geometry
|
insilmaril@726
|
58 |
QList <int> sizes;
|
insilmaril@735
|
59 |
sizes.append (120);
|
insilmaril@726
|
60 |
sizes.append (600);
|
insilmaril@726
|
61 |
setSizes (sizes);
|
insilmaril@726
|
62 |
}
|
insilmaril@726
|
63 |
|
insilmaril@726
|
64 |
QItemSelectionModel* VymView::selectionModel()
|
insilmaril@726
|
65 |
{
|
insilmaril@728
|
66 |
if (treeview)
|
insilmaril@728
|
67 |
return selModel;
|
insilmaril@728
|
68 |
else
|
insilmaril@728
|
69 |
std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
|
insilmaril@726
|
70 |
return NULL;
|
insilmaril@726
|
71 |
}
|
insilmaril@726
|
72 |
|
insilmaril@726
|
73 |
|
insilmaril@745
|
74 |
void VymView::updateChilds (QModelIndex ix)
|
insilmaril@745
|
75 |
{
|
insilmaril@745
|
76 |
treeview->setExpanded (ix,true);
|
insilmaril@745
|
77 |
}
|
insilmaril@745
|
78 |
|
insilmaril@746
|
79 |
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
|
insilmaril@727
|
80 |
{
|
insilmaril@746
|
81 |
/*
|
insilmaril@746
|
82 |
cout <<"VymView::changeSelection (";
|
insilmaril@746
|
83 |
if (!newsel.indexes().isEmpty() )
|
insilmaril@746
|
84 |
cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
85 |
cout << " <- ";
|
insilmaril@746
|
86 |
if (!oldsel.indexes().isEmpty() )
|
insilmaril@746
|
87 |
cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
88 |
cout << ")\n";
|
insilmaril@746
|
89 |
*/
|
insilmaril@727
|
90 |
|
insilmaril@746
|
91 |
// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
|
insilmaril@746
|
92 |
mainWindow->changeSelection (model,newsel,oldsel); // FIXME-3 maybe connect VymModel <-> MainWindow directly?
|
insilmaril@727
|
93 |
}
|
insilmaril@727
|
94 |
|