Support 'hidden' plugins

Plugins can be hidden in the "About Plugins" view by default. Users can
still make them all visible, but the default view can be made less noisy
by hiding plugins that only exist as a base for other plugins.
Plugins that can not run on the current platform are hidden by default
as well.

Change-Id: Iaf2f751c4ea4b3afc605bbbea6611eea042e62c7
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2017-01-04 06:23:32 +01:00
parent b29513aa5b
commit 284fa63be2
8 changed files with 91 additions and 11 deletions

View File

@@ -82,6 +82,7 @@ enum Columns { NameColumn, LoadedColumn, VersionColumn, VendorColumn, };
enum IconIndex { OkIcon, ErrorIcon, NotLoadedIcon };
static const int SortRole = Qt::UserRole + 1;
static const int HiddenByDefaultRole = Qt::UserRole + 2;
static const QIcon &icon(IconIndex icon)
{
@@ -114,6 +115,8 @@ public:
QVariant data(int column, int role) const
{
if (role == HiddenByDefaultRole)
return m_spec->isHiddenByDefault() || !m_spec->isAvailableForHostPlatform();
switch (column) {
case NameColumn:
if (role == Qt::DisplayRole)
@@ -223,6 +226,8 @@ public:
QVariant data(int column, int role) const
{
if (role == HiddenByDefaultRole)
return false;
if (column == NameColumn) {
if (role == Qt::DisplayRole || role == SortRole)
return m_name;
@@ -285,6 +290,40 @@ public:
PluginView *m_view; // Not owned.
};
class PluginFilterModel : public CategorySortFilterModel
{
public:
PluginFilterModel(QObject *parent = 0) : CategorySortFilterModel(parent) {}
void setShowHidden(bool show)
{
if (show == m_showHidden)
return;
m_showHidden = show;
invalidateFilter();
}
bool isShowingHidden() const
{
return m_showHidden;
}
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
{
if (CategorySortFilterModel::filterAcceptsRow(source_row, source_parent)) {
if (m_showHidden)
return true;
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
return !sourceModel()->data(index, HiddenByDefaultRole).toBool();
}
return false;
}
private:
bool m_showHidden = true;
};
} // Internal
using namespace ExtensionSystem::Internal;
@@ -312,7 +351,7 @@ PluginView::PluginView(QWidget *parent)
m_model = new TreeModel<TreeItem, CollectionItem, PluginItem>(this);
m_model->setHeader({ tr("Name"), tr("Load"), tr("Version"), tr("Vendor") });
m_sortModel = new CategorySortFilterModel(this);
m_sortModel = new PluginFilterModel(this);
m_sortModel->setSourceModel(m_model);
m_sortModel->setSortRole(SortRole);
m_sortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -360,6 +399,17 @@ void PluginView::setFilter(const QString &filter)
m_categoryView->expandAll();
}
void PluginView::setShowHidden(bool showHidden)
{
m_sortModel->setShowHidden(showHidden);
m_categoryView->expandAll();
}
bool PluginView::isShowingHidden() const
{
return m_sortModel->isShowingHidden();
}
PluginSpec *PluginView::pluginForIndex(const QModelIndex &index) const
{
const QModelIndex &sourceIndex = m_sortModel->mapToSource(index);