insilmaril@726
|
1 |
#include "vymview.h"
|
insilmaril@726
|
2 |
|
insilmaril@727
|
3 |
#include <iostream>
|
insilmaril@742
|
4 |
using namespace std;
|
insilmaril@727
|
5 |
|
insilmaril@763
|
6 |
#include "linkablemapobj.h"
|
insilmaril@732
|
7 |
#include "mainwindow.h"
|
insilmaril@726
|
8 |
#include "mapeditor.h"
|
insilmaril@726
|
9 |
|
insilmaril@732
|
10 |
extern Main *mainWindow;
|
insilmaril@732
|
11 |
|
insilmaril@732
|
12 |
|
insilmaril@742
|
13 |
VymView::VymView(VymModel *m)
|
insilmaril@726
|
14 |
{
|
insilmaril@742
|
15 |
model=m;
|
insilmaril@742
|
16 |
|
insilmaril@726
|
17 |
// Create TreeView
|
insilmaril@727
|
18 |
treeview=new QTreeView;
|
insilmaril@726
|
19 |
treeview->setModel ((QAbstractItemModel*)model);
|
insilmaril@759
|
20 |
//treeview->setMinimumWidth (50);
|
insilmaril@761
|
21 |
|
insilmaril@726
|
22 |
treeview->setColumnWidth (0,350);
|
insilmaril@726
|
23 |
|
insilmaril@727
|
24 |
selModel=treeview->selectionModel();
|
insilmaril@728
|
25 |
model->setSelectionModel (selModel);
|
insilmaril@727
|
26 |
connect (
|
insilmaril@727
|
27 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@727
|
28 |
this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@727
|
29 |
|
insilmaril@726
|
30 |
// Create good old MapEditor
|
insilmaril@761
|
31 |
mapEditor=model->getMapEditor();
|
insilmaril@761
|
32 |
if (!mapEditor) mapEditor=new MapEditor (model);
|
insilmaril@728
|
33 |
connect (
|
insilmaril@728
|
34 |
selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@761
|
35 |
mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@753
|
36 |
/*
|
insilmaril@729
|
37 |
connect (
|
insilmaril@729
|
38 |
selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)),
|
insilmaril@729
|
39 |
me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
|
insilmaril@753
|
40 |
*/
|
insilmaril@753
|
41 |
/*
|
insilmaril@753
|
42 |
*/
|
insilmaril@753
|
43 |
connect (
|
insilmaril@753
|
44 |
model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
|
insilmaril@761
|
45 |
mapEditor,SLOT (updateData(const QModelIndex &) ) );
|
insilmaril@726
|
46 |
|
insilmaril@746
|
47 |
// VymModel may want to update selection or other data, e.g. during animation
|
insilmaril@728
|
48 |
connect (
|
insilmaril@728
|
49 |
model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
|
insilmaril@761
|
50 |
mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
|
insilmaril@761
|
51 |
|
insilmaril@761
|
52 |
/*
|
insilmaril@745
|
53 |
connect (
|
insilmaril@745
|
54 |
model, SIGNAL (newChildObject(QModelIndex) ),
|
insilmaril@745
|
55 |
this,SLOT (updateChilds (QModelIndex) ) );
|
insilmaril@761
|
56 |
*/
|
insilmaril@761
|
57 |
|
insilmaril@746
|
58 |
connect (
|
insilmaril@753
|
59 |
model, SIGNAL (noteHasChanged(QModelIndex) ),
|
insilmaril@753
|
60 |
mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
|
insilmaril@746
|
61 |
|
insilmaril@763
|
62 |
connect (
|
insilmaril@763
|
63 |
model, SIGNAL (expandAll() ),
|
insilmaril@763
|
64 |
this, SLOT (expandAll () ) );
|
insilmaril@763
|
65 |
|
insilmaril@763
|
66 |
connect (
|
insilmaril@763
|
67 |
model, SIGNAL (showSelection() ),
|
insilmaril@763
|
68 |
this, SLOT (showSelection() ) );
|
insilmaril@763
|
69 |
|
insilmaril@726
|
70 |
|
insilmaril@761
|
71 |
//mapEditor->viewport()->setFocus(); //FIXmapEditor-3 needed?
|
insilmaril@761
|
72 |
mapEditor->setAntiAlias (mainWindow->isAliased());
|
insilmaril@761
|
73 |
mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
|
insilmaril@726
|
74 |
|
insilmaril@726
|
75 |
addWidget (treeview);
|
insilmaril@761
|
76 |
addWidget (mapEditor);
|
insilmaril@726
|
77 |
|
insilmaril@726
|
78 |
// Set geometry
|
insilmaril@761
|
79 |
QList <int> widths;
|
insilmaril@761
|
80 |
widths<<120;
|
insilmaril@761
|
81 |
widths<<600;
|
insilmaril@761
|
82 |
setSizes(widths);
|
insilmaril@726
|
83 |
}
|
insilmaril@726
|
84 |
|
insilmaril@726
|
85 |
QItemSelectionModel* VymView::selectionModel()
|
insilmaril@726
|
86 |
{
|
insilmaril@728
|
87 |
if (treeview)
|
insilmaril@728
|
88 |
return selModel;
|
insilmaril@728
|
89 |
else
|
insilmaril@728
|
90 |
std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
|
insilmaril@726
|
91 |
return NULL;
|
insilmaril@726
|
92 |
}
|
insilmaril@726
|
93 |
|
insilmaril@726
|
94 |
|
insilmaril@761
|
95 |
void VymView::updateChilds (QModelIndex ix) //FIXME-4 not needed?
|
insilmaril@745
|
96 |
{
|
insilmaril@761
|
97 |
cout << "VV::updateChilds \n";
|
insilmaril@761
|
98 |
//treeview->setExpanded (ix,true); // This is expensive...
|
insilmaril@745
|
99 |
}
|
insilmaril@745
|
100 |
|
insilmaril@746
|
101 |
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
|
insilmaril@727
|
102 |
{
|
insilmaril@746
|
103 |
/*
|
insilmaril@746
|
104 |
cout <<"VymView::changeSelection (";
|
insilmaril@746
|
105 |
if (!newsel.indexes().isEmpty() )
|
insilmaril@746
|
106 |
cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
107 |
cout << " <- ";
|
insilmaril@746
|
108 |
if (!oldsel.indexes().isEmpty() )
|
insilmaril@746
|
109 |
cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
110 |
cout << ")\n";
|
insilmaril@746
|
111 |
*/
|
insilmaril@727
|
112 |
|
insilmaril@746
|
113 |
// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
|
insilmaril@746
|
114 |
mainWindow->changeSelection (model,newsel,oldsel); // FIXME-3 maybe connect VymModel <-> MainWindow directly?
|
insilmaril@727
|
115 |
}
|
insilmaril@727
|
116 |
|
insilmaril@763
|
117 |
void VymView::expandAll()
|
insilmaril@763
|
118 |
{
|
insilmaril@763
|
119 |
treeview->expandAll();
|
insilmaril@763
|
120 |
}
|
insilmaril@763
|
121 |
|
insilmaril@763
|
122 |
void VymView::showSelection()
|
insilmaril@763
|
123 |
{
|
insilmaril@763
|
124 |
treeview->scrollTo(
|
insilmaril@763
|
125 |
model->getSelectedIndex(),
|
insilmaril@763
|
126 |
//QAbstractItemView::PositionAtCenter
|
insilmaril@763
|
127 |
QAbstractItemView::EnsureVisible
|
insilmaril@763
|
128 |
);
|
insilmaril@763
|
129 |
|
insilmaril@763
|
130 |
LinkableMapObj* lmo=model->getSelectedLMO();
|
insilmaril@763
|
131 |
if (lmo)
|
insilmaril@763
|
132 |
mapEditor->ensureVisible(lmo->getBBox() );
|
insilmaril@763
|
133 |
}
|
insilmaril@763
|
134 |
|