Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "…" indicator for display types with settings #1541

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading