blob: e2e411cd3c6a93040f5157d7258bbd9713f969b9 (
plain)
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
|
#include "lsscenemodel.h"
#include "lsglobals.h"
LSSceneModel::LSSceneModel(LYTLayout *layout, QObject *parent) :
QAbstractItemModel(parent)
{
m_layout = layout;
m_paneIcons[LYTPane::PaneType] = LSGlobals::getIcon("pane");
m_paneIcons[LYTPane::PictureType] = LSGlobals::getIcon("picture");
m_paneIcons[LYTPane::TextBoxType] = LSGlobals::getIcon("textbox");
m_paneIcons[LYTPane::WindowType] = LSGlobals::getIcon("window");
m_paneIcons[LYTPane::BoundingType] = LSGlobals::getIcon("bounding");
}
QModelIndex LSSceneModel::index(int row, int column, const QModelIndex &parent) const {
if (!hasIndex(row, column, parent))
return QModelIndex();
if (!parent.isValid())
return createIndex(row, column, m_layout->rootPane);
// what's the parent..?
LYTPane *parentPane = (LYTPane*)parent.internalPointer();
LYTPane *pane = parentPane->children.at(row);
return createIndex(row, column, pane);
}
QModelIndex LSSceneModel::parent(const QModelIndex &child) const {
if (!child.isValid())
return QModelIndex();
LYTPane *childPane = (LYTPane*)child.internalPointer();
LYTPane *parentPane = childPane->parent;
if (parentPane) {
LYTPane *parentParentPane = parentPane->parent;
int index = parentParentPane ? parentParentPane->children.indexOf(parentPane) : 0;
return createIndex(index, 0, parentPane);
} else {
return QModelIndex();
}
}
int LSSceneModel::rowCount(const QModelIndex &parent) const {
if (!parent.isValid()) {
return 1; // the root pane
}
LYTPane *parentPane = (LYTPane*)parent.internalPointer();
return parentPane->children.count();
}
int LSSceneModel::columnCount(const QModelIndex &parent) const {
(void)parent;
return 1;
}
QVariant LSSceneModel::data(const QModelIndex &index, int role) const {
LYTPane *pane = (LYTPane*)index.internalPointer();
if (pane) {
switch (role) {
case Qt::DisplayRole:
return pane->name;
case Qt::DecorationRole:
return m_paneIcons[pane->type()];
}
}
return QVariant();
}
Qt::ItemFlags LSSceneModel::flags(const QModelIndex &index) const {
Qt::ItemFlags flag;
flag = Qt::ItemIsEnabled | Qt::ItemIsSelectable |
Qt::ItemIsDropEnabled | Qt::ItemIsEditable;
if (index.isValid() && index.parent().isValid())
flag |= Qt::ItemIsDragEnabled;
return flag;
}
Qt::DropActions LSSceneModel::supportedDropActions() const {
return Qt::CopyAction | Qt::MoveAction;
}
|