summaryrefslogtreecommitdiff
path: root/src/libs/extensionsystem
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-01-04 06:23:32 +0100
committerEike Ziller <eike.ziller@qt.io>2017-01-09 12:25:08 +0000
commit284fa63be2b2af4d16926bc7cc17ca30cf0b5e39 (patch)
tree2bc8424f485c8ec84a6836d4d7d09153714f3f92 /src/libs/extensionsystem
parentb29513aa5b63c3abfef79e928bc803f471663eb4 (diff)
downloadqt-creator-284fa63be2b2af4d16926bc7cc17ca30cf0b5e39.tar.gz
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>
Diffstat (limited to 'src/libs/extensionsystem')
-rw-r--r--src/libs/extensionsystem/pluginspec.cpp12
-rw-r--r--src/libs/extensionsystem/pluginspec.h1
-rw-r--r--src/libs/extensionsystem/pluginspec_p.h1
-rw-r--r--src/libs/extensionsystem/pluginview.cpp52
-rw-r--r--src/libs/extensionsystem/pluginview.h7
5 files changed, 70 insertions, 3 deletions
diff --git a/src/libs/extensionsystem/pluginspec.cpp b/src/libs/extensionsystem/pluginspec.cpp
index 61e2fb0451..c839b8ea3f 100644
--- a/src/libs/extensionsystem/pluginspec.cpp
+++ b/src/libs/extensionsystem/pluginspec.cpp
@@ -277,6 +277,11 @@ bool PluginSpec::isRequired() const
return d->required;
}
+bool PluginSpec::isHiddenByDefault() const
+{
+ return d->hiddenByDefault;
+}
+
/*!
Returns whether the plugin has its experimental flag set.
*/
@@ -482,6 +487,7 @@ namespace {
const char PLUGIN_VERSION[] = "Version";
const char PLUGIN_COMPATVERSION[] = "CompatVersion";
const char PLUGIN_REQUIRED[] = "Required";
+ const char PLUGIN_HIDDEN_BY_DEFAULT[] = "HiddenByDefault";
const char PLUGIN_EXPERIMENTAL[] = "Experimental";
const char PLUGIN_DISABLED_BY_DEFAULT[] = "DisabledByDefault";
const char VENDOR[] = "Vendor";
@@ -692,6 +698,12 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &metaData)
required = value.toBool(false);
qCDebug(pluginLog) << "required =" << required;
+ value = pluginInfo.value(QLatin1String(PLUGIN_HIDDEN_BY_DEFAULT));
+ if (!value.isUndefined() && !value.isBool())
+ return reportError(msgValueIsNotABool(PLUGIN_HIDDEN_BY_DEFAULT));
+ hiddenByDefault = value.toBool(false);
+ qCDebug(pluginLog) << "hiddenByDefault =" << hiddenByDefault;
+
value = pluginInfo.value(QLatin1String(PLUGIN_EXPERIMENTAL));
if (!value.isUndefined() && !value.isBool())
return reportError(msgValueIsNotABool(PLUGIN_EXPERIMENTAL));
diff --git a/src/libs/extensionsystem/pluginspec.h b/src/libs/extensionsystem/pluginspec.h
index 68c6fdd315..64725c8e9f 100644
--- a/src/libs/extensionsystem/pluginspec.h
+++ b/src/libs/extensionsystem/pluginspec.h
@@ -95,6 +95,7 @@ public:
QRegExp platformSpecification() const;
bool isAvailableForHostPlatform() const;
bool isRequired() const;
+ bool isHiddenByDefault() const;
bool isExperimental() const;
bool isEnabledByDefault() const;
bool isEnabledBySettings() const;
diff --git a/src/libs/extensionsystem/pluginspec_p.h b/src/libs/extensionsystem/pluginspec_p.h
index f4685e5e2a..86790da8ec 100644
--- a/src/libs/extensionsystem/pluginspec_p.h
+++ b/src/libs/extensionsystem/pluginspec_p.h
@@ -71,6 +71,7 @@ public:
QString version;
QString compatVersion;
bool required = false;
+ bool hiddenByDefault = false;
bool experimental = false;
bool enabledByDefault = true;
QString vendor;
diff --git a/src/libs/extensionsystem/pluginview.cpp b/src/libs/extensionsystem/pluginview.cpp
index 4ce87cd602..042e666c6a 100644
--- a/src/libs/extensionsystem/pluginview.cpp
+++ b/src/libs/extensionsystem/pluginview.cpp
@@ -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);
diff --git a/src/libs/extensionsystem/pluginview.h b/src/libs/extensionsystem/pluginview.h
index 50fe7482e0..44ca2e2b12 100644
--- a/src/libs/extensionsystem/pluginview.h
+++ b/src/libs/extensionsystem/pluginview.h
@@ -45,8 +45,9 @@ class PluginManager;
class PluginSpec;
namespace Internal {
-class PluginItem;
class CollectionItem;
+class PluginFilterModel;
+class PluginItem;
} // Internal
class EXTENSIONSYSTEM_EXPORT PluginView : public QWidget
@@ -59,6 +60,8 @@ public:
PluginSpec *currentPlugin() const;
void setFilter(const QString &filter);
+ void setShowHidden(bool showHidden);
+ bool isShowingHidden() const;
signals:
void currentPluginChanged(ExtensionSystem::PluginSpec *spec);
@@ -72,7 +75,7 @@ private:
Utils::TreeView *m_categoryView;
Utils::TreeModel<Utils::TreeItem, Internal::CollectionItem, Internal::PluginItem> *m_model;
- QSortFilterProxyModel *m_sortModel;
+ Internal::PluginFilterModel *m_sortModel;
friend class Internal::CollectionItem;
friend class Internal::PluginItem;