Skip to content

Commit

Permalink
Plugins dialog: make sure that we can see the check boxes and icons.
Browse files Browse the repository at this point in the history
This is part of our work on issue #2285.
  • Loading branch information
agarny committed Feb 12, 2020
1 parent dbc87b3 commit 683f9df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
45 changes: 43 additions & 2 deletions src/pluginitemmodel.cpp
Expand Up @@ -121,6 +121,24 @@ QModelIndex PluginItem::modelIndex() const

//==============================================================================

bool PluginItem::hasCheckBox() const
{
// Return whether we have a check box

return mHasCheckBox;
}

//==============================================================================

void PluginItem::setHasCheckBox(bool pHasCheckBox)
{
// Specify whether we have a check box

mHasCheckBox = pHasCheckBox;
}

//==============================================================================

bool PluginItem::isCheckable() const
{
// Return whether we are checkable
Expand Down Expand Up @@ -157,6 +175,15 @@ void PluginItem::setCheckState(Qt::CheckState pCheckState)

//==============================================================================

QIcon PluginItem::icon() const
{
// Return our icon

return mIcon;
}

//==============================================================================

QString PluginItem::name() const
{
// Return our name
Expand Down Expand Up @@ -275,8 +302,22 @@ QVariant PluginItemModel::data(const QModelIndex &pIndex, int pRole) const
{
// Return the data for the given index

if (pIndex.isValid() && (pRole == Qt::DisplayRole)) {
return static_cast<PluginItem *>(pIndex.internalPointer())->name();
if (pIndex.isValid()) {
if (pRole == Qt::DisplayRole) {
return static_cast<PluginItem *>(pIndex.internalPointer())->name();
}

if (pRole == Qt::CheckStateRole) {
PluginItem *item = static_cast<PluginItem *>(pIndex.internalPointer());

if (item->hasCheckBox()) {
return static_cast<PluginItem *>(pIndex.internalPointer())->checkState();
}
}

if (pRole == Qt::DecorationRole) {
return static_cast<PluginItem *>(pIndex.internalPointer())->icon();
}
}

return {};
Expand Down
7 changes: 6 additions & 1 deletion src/pluginitemmodel.h
Expand Up @@ -57,12 +57,16 @@ class PluginItem

QModelIndex modelIndex() const;

bool hasCheckBox() const;
void setHasCheckBox(bool pHasCheckBox);

bool isCheckable() const;
void setCheckable(bool pCheckable);

Qt::CheckState checkState() const;
void setCheckState(Qt::CheckState pCheckState);

QIcon icon() const;
QString name() const;

void insert(int pIndex, PluginItem *pItem);
Expand All @@ -74,7 +78,8 @@ class PluginItem
PluginItem *mParent = nullptr;
QVector<PluginItem *> mChildren;

bool mCheckable = true;
bool mHasCheckBox = false;
bool mCheckable = false;
Qt::CheckState mCheckState;

QIcon mIcon;
Expand Down
4 changes: 3 additions & 1 deletion src/pluginsdialog.cpp
Expand Up @@ -154,11 +154,13 @@ PluginsDialog::PluginsDialog(PluginManager *pPluginManager,
plugin->name());

// Only selectable plugins and plugins that are of the right type are
// checkable
// checkable though all plugins should have a check box
// Note: the latter is only so that everything gets nicely aligned...

PluginInfo *pluginInfo = plugin->info();

if (pluginInfo != nullptr) {
pluginItem->setHasCheckBox(true);
pluginItem->setCheckable(pluginInfo->isSelectable());

if (pluginItem->isCheckable()) {
Expand Down

0 comments on commit 683f9df

Please sign in to comment.