From 8f25e274db4ce3e2d55b6e6b38d13a262551816c Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 18 Dec 2023 19:22:25 -0500 Subject: [PATCH] =?UTF-8?q?Add=20"=E2=80=A6"=20indicator=20for=20display?= =?UTF-8?q?=20types=20with=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #1529 Signed-off-by: Geoff Hutchison --- avogadro/qtgui/scenepluginmodel.cpp | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/avogadro/qtgui/scenepluginmodel.cpp b/avogadro/qtgui/scenepluginmodel.cpp index 46e6580591..789fa918f4 100644 --- a/avogadro/qtgui/scenepluginmodel.cpp +++ b/avogadro/qtgui/scenepluginmodel.cpp @@ -11,7 +11,8 @@ namespace Avogadro::QtGui { ScenePluginModel::ScenePluginModel(QObject* parent_) : QAbstractItemModel(parent_) -{} +{ +} QModelIndex ScenePluginModel::parent(const QModelIndex&) const { @@ -28,7 +29,7 @@ int ScenePluginModel::rowCount(const QModelIndex& parent_) const int ScenePluginModel::columnCount(const QModelIndex&) const { - return 1; + return 2; } Qt::ItemFlags ScenePluginModel::flags(const QModelIndex& index_) const @@ -67,7 +68,7 @@ bool ScenePluginModel::setData(const QModelIndex& index_, const QVariant& value, QVariant ScenePluginModel::data(const QModelIndex& index_, int role) const { - if (!index_.isValid() || index_.column() > 1) + if (!index_.isValid() || index_.column() > 2) return QVariant(); auto* object = static_cast(index_.internalPointer()); @@ -75,6 +76,27 @@ QVariant ScenePluginModel::data(const QModelIndex& index_, int role) const if (!item) return QVariant(); + // Simple lambda to convert QFlags to variant as in Qt 6 this needs help. + auto toVariant = [&](auto flags) { + return static_cast(flags); + }; + + // check if setupWidget() returns something + if (index_.column() == 1) { + switch (role) { + case Qt::DisplayRole: + case Qt::EditRole: + return (item->setupWidget() != nullptr) ? "…" : " "; + case Qt::ToolTipRole: + case Qt::WhatsThisRole: + return tr("Settings"); + case Qt::TextAlignmentRole: + return toVariant(Qt::AlignLeft | Qt::AlignVCenter); + default: + return QVariant(); + } + } + if (index_.column() == 0) { switch (role) { case Qt::DisplayRole: @@ -88,6 +110,8 @@ QVariant ScenePluginModel::data(const QModelIndex& index_, int role) const case Qt::ToolTipRole: case Qt::WhatsThisRole: return item->description(); + case Qt::TextAlignmentRole: + return toVariant(Qt::AlignLeft); default: return QVariant(); } @@ -148,4 +172,4 @@ void ScenePluginModel::itemChanged() } } -} // namespace Avogadro +} // namespace Avogadro::QtGui