summaryrefslogtreecommitdiff
path: root/lsscenemodel.cpp
blob: a5b6a23404d8a034c9d2873240e297cca1d5eee7 (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
#include "lsscenemodel.h"

LSSceneModel::LSSceneModel(LYTLayout *layout, QObject *parent) :
	QAbstractItemModel(parent)
{
	m_layout = layout;
}


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 {
	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;
		}
	}
	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;
}