diff options
Diffstat (limited to 'lsscenemodel.cpp')
-rw-r--r-- | lsscenemodel.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
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; } |