From a55b7493b1bd54e9d1231fa18300e0f882700fe3 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 18 Aug 2012 04:29:13 +0200 Subject: made pane visibility part of the scene graph tree --- lsscenemodel.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lsscenemodel.cpp') diff --git a/lsscenemodel.cpp b/lsscenemodel.cpp index acb059c..1e55cdd 100644 --- a/lsscenemodel.cpp +++ b/lsscenemodel.cpp @@ -1,8 +1,8 @@ #include "lsscenemodel.h" #include "lsglobals.h" -LSSceneModel::LSSceneModel(LYTLayout *layout, QObject *parent) : - QAbstractItemModel(parent) +LSSceneModel::LSSceneModel(LYTLayout *layout, bool exposeVisibility, QObject *parent) : + QAbstractItemModel(parent), m_exposesVisibility(exposeVisibility) { m_layout = layout; @@ -72,19 +72,41 @@ QVariant LSSceneModel::data(const QModelIndex &index, int role) const { case Qt::DecorationRole: return m_paneIcons[pane->type()]; } + + if (m_exposesVisibility && role == Qt::CheckStateRole) { + return pane->visible ? Qt::Checked : Qt::Unchecked; + } } return QVariant(); } +bool LSSceneModel::setData(const QModelIndex &index, const QVariant &value, int role) { + if (m_exposesVisibility && role == Qt::CheckStateRole) { + LYTPane *pane = (LYTPane*)index.internalPointer(); + + bool newVisible = value.toBool(); + if (pane->visible != newVisible) { + pane->visible = newVisible; + emit dataChanged(index, index); + emit paneVisibilityChanged(); + } + } + + return false; +} + Qt::ItemFlags LSSceneModel::flags(const QModelIndex &index) const { Qt::ItemFlags flag; flag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | - Qt::ItemIsDropEnabled | Qt::ItemIsEditable; + Qt::ItemIsDropEnabled; if (index.isValid() && index.parent().isValid()) flag |= Qt::ItemIsDragEnabled; + if (m_exposesVisibility) + flag |= Qt::ItemIsUserCheckable; + return flag; } -- cgit v1.2.3