summaryrefslogtreecommitdiff
path: root/lsscenemodel.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-08-05 17:35:52 +0200
committerTreeki <treeki@gmail.com>2012-08-05 17:35:52 +0200
commit3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c (patch)
tree2f6a0303927dbb2b16205e74034255cb70a7d1d4 /lsscenemodel.cpp
parentcee09c07899dfec32672e7e2d175972530a7dfd4 (diff)
downloadLayoutStudio-3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c.tar.gz
LayoutStudio-3b2fb505d58f28f0ce9b4de121f12fc924c1ec0c.zip
getting further... basic read-only Scene Graph model/widget
Diffstat (limited to '')
-rw-r--r--lsscenemodel.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/lsscenemodel.cpp b/lsscenemodel.cpp
new file mode 100644
index 0000000..7450368
--- /dev/null
+++ b/lsscenemodel.cpp
@@ -0,0 +1,60 @@
+#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();
+}