Skip to content

Commit

Permalink
Add "…" indicator for display types with settings
Browse files Browse the repository at this point in the history
Fix #1529

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 19, 2023
1 parent 29b7fc3 commit 8f25e27
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions avogadro/qtgui/scenepluginmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace Avogadro::QtGui {

ScenePluginModel::ScenePluginModel(QObject* parent_)
: QAbstractItemModel(parent_)
{}
{
}

QModelIndex ScenePluginModel::parent(const QModelIndex&) const
{
Expand All @@ -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
Expand Down Expand Up @@ -67,14 +68,35 @@ 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<QObject*>(index_.internalPointer());
auto* item = qobject_cast<ScenePlugin*>(object);
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<Qt::Alignment::Int>(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:
Expand All @@ -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();
}
Expand Down Expand Up @@ -148,4 +172,4 @@ void ScenePluginModel::itemChanged()
}
}

} // namespace Avogadro
} // namespace Avogadro::QtGui

0 comments on commit 8f25e27

Please sign in to comment.