From 8d66f11d6dd9925268be24bd8586c3ea7d155afc Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 21 Jun 2019 12:00:00 -0700 Subject: [PATCH] always show expand icon on folders --- app/project/projectviewmodel.cpp | 18 ++++++++++++++++++ app/project/projectviewmodel.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/app/project/projectviewmodel.cpp b/app/project/projectviewmodel.cpp index d9094f972..7564b4cdd 100644 --- a/app/project/projectviewmodel.cpp +++ b/app/project/projectviewmodel.cpp @@ -141,3 +141,21 @@ QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation, return QAbstractItemModel::headerData(section, orientation, role); } + +bool ProjectViewModel::hasChildren(const QModelIndex &parent) const +{ + // Check if this is a valid index + if (parent.isValid()) { + Item* item = static_cast(parent.internalPointer()); + + // Check if this item is a kFolder type + // If it's a folder, we always return TRUE in order to always show the "expand triangle" icon, + // even when there are no "physical" children + if (item->type() == Item::kFolder) { + return true; + } + } + + // Otherwise, return default behavior + return QAbstractItemModel::hasChildren(parent); +} diff --git a/app/project/projectviewmodel.h b/app/project/projectviewmodel.h index 5bfb4223e..593a14194 100644 --- a/app/project/projectviewmodel.h +++ b/app/project/projectviewmodel.h @@ -24,6 +24,12 @@ public: kRate }; + /** + * @brief ProjectViewModel Constructor + * + * @param parent + * Parent object for memory handling + */ ProjectViewModel(QObject* parent); /** @@ -55,6 +61,7 @@ public: /** Optional Qt QAbstractItemModel overrides */ virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; private: Project* project_;