summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-09-30 19:57:54 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-09-30 19:57:54 +0200
commit7786a75feef8f012e9a403bb83319f2d306fe3df (patch)
tree39f62fa28bc166dab4bb4d6c14b9db470ac9e28f
parent04c8409bf5eb41475064c0dbb69f431e43917593 (diff)
Make filter work and reorganize layout with QSplitters.
-rw-r--r--src/settingsdialog.ui271
-rw-r--r--src/settingsdialogplugins.cpp61
-rw-r--r--src/settingsdialogplugins.h9
3 files changed, 205 insertions, 136 deletions
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index 67df1ec9..05a648de 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>586</width>
- <height>491</height>
+ <width>820</width>
+ <height>652</height>
</rect>
</property>
<property name="windowTitle">
@@ -1038,130 +1038,172 @@
<attribute name="title">
<string>Plugins</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_9" stretch="0,0,0">
+ <layout class="QVBoxLayout" name="verticalLayout_9">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_9">
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_15">
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="handleWidth">
+ <number>2</number>
+ </property>
+ <widget class="QWidget" name="" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>4</verstretch>
+ </sizepolicy>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
- <widget class="QTreeWidget" name="pluginsList">
- <column>
- <property name="text">
- <string notr="true">1</string>
- </property>
- </column>
+ <widget class="QSplitter" name="splitter_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="handleWidth">
+ <number>2</number>
+ </property>
+ <widget class="QWidget" name="" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_15">
+ <item>
+ <widget class="QTreeWidget" name="pluginsList">
+ <column>
+ <property name="text">
+ <string notr="true">1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLineEdit" name="pluginFilterEdit">
+ <property name="placeholderText">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_7" stretch="0,1">
+ <item>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_13">
+ <property name="text">
+ <string>Author:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="authorLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_15">
+ <property name="text">
+ <string>Version:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="versionLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="descriptionLabel">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_14">
+ <property name="text">
+ <string>Description:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTreeWidget" name="pluginSettingsList">
+ <property name="indentation">
+ <number>0</number>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <property name="itemsExpandable">
+ <bool>false</bool>
+ </property>
+ <property name="expandsOnDoubleClick">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="headerDefaultSectionSize">
+ <number>170</number>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Key</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Value</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
</widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_4">
- <item>
- <widget class="QLineEdit" name="pluginFilterEdit">
- <property name="placeholderText">
- <string/>
- </property>
- </widget>
- </item>
- </layout>
- </item>
</layout>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_7" stretch="0,1">
- <item>
- <layout class="QFormLayout" name="formLayout_2">
- <item row="0" column="0">
- <widget class="QLabel" name="label_13">
- <property name="text">
- <string>Author:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLabel" name="authorLabel">
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_15">
- <property name="text">
- <string>Version:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLabel" name="versionLabel">
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_14">
- <property name="text">
- <string>Description:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLabel" name="descriptionLabel">
- <property name="text">
- <string/>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
+ </widget>
+ <widget class="QWidget" name="verticalWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>1</verstretch>
+ </sizepolicy>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_16">
<item>
- <widget class="QTreeWidget" name="pluginSettingsList">
- <property name="indentation">
- <number>0</number>
- </property>
- <property name="rootIsDecorated">
- <bool>false</bool>
- </property>
- <property name="itemsExpandable">
- <bool>false</bool>
- </property>
- <property name="expandsOnDoubleClick">
- <bool>false</bool>
+ <widget class="QLabel" name="label_18">
+ <property name="text">
+ <string>Blacklisted Plugins (use &lt;del&gt; to remove):</string>
</property>
- <attribute name="headerVisible">
- <bool>false</bool>
- </attribute>
- <attribute name="headerDefaultSectionSize">
- <number>170</number>
- </attribute>
- <column>
- <property name="text">
- <string>Key</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Value</string>
- </property>
- </column>
</widget>
</item>
+ <item>
+ <widget class="QListWidget" name="pluginBlacklist"/>
+ </item>
</layout>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QLabel" name="label_18">
- <property name="text">
- <string>Blacklisted Plugins (use &lt;del&gt; to remove):</string>
- </property>
+ </widget>
</widget>
</item>
- <item>
- <widget class="QListWidget" name="pluginBlacklist"/>
- </item>
</layout>
</widget>
<widget class="QWidget" name="workaroundTab">
@@ -1625,7 +1667,6 @@ programs you are intentionally running.</string>
<tabstop>steamUserEdit</tabstop>
<tabstop>steamPassEdit</tabstop>
<tabstop>pluginSettingsList</tabstop>
- <tabstop>pluginBlacklist</tabstop>
<tabstop>appIDEdit</tabstop>
<tabstop>mechanismBox</tabstop>
<tabstop>hideUncheckedBox</tabstop>
diff --git a/src/settingsdialogplugins.cpp b/src/settingsdialogplugins.cpp
index e13f727e..75344ecf 100644
--- a/src/settingsdialogplugins.cpp
+++ b/src/settingsdialogplugins.cpp
@@ -8,16 +8,39 @@
using MOBase::IPlugin;
PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginContainer* pluginContainer, SettingsDialog& d)
- : SettingsTab(s, d)
+ : SettingsTab(s, d), m_pluginContainer(pluginContainer)
{
ui->pluginSettingsList->setStyleSheet("QTreeWidget::item {padding-right: 10px;}");
+ populatePluginList();
+
+ // display plugin blacklist
+ for (const QString &pluginName : settings().plugins().blacklist()) {
+ ui->pluginBlacklist->addItem(pluginName);
+ }
+
+ m_filter.setEdit(ui->pluginFilterEdit);
+
+ QObject::connect(
+ ui->pluginsList, &QTreeWidget::currentItemChanged,
+ [&](auto* current, auto* previous) { on_pluginsList_currentItemChanged(current, previous); });
+
+ QShortcut *delShortcut = new QShortcut(
+ QKeySequence(Qt::Key_Delete), ui->pluginBlacklist);
+ QObject::connect(delShortcut, &QShortcut::activated, &dialog(), [&] { deleteBlacklistItem(); });
+ QObject::connect(&m_filter, &MOBase::FilterWidget::changed, [&] { populatePluginList(); });
+}
+
+void PluginsSettingsTab::populatePluginList()
+{
+ ui->pluginsList->clear();
+
// Create top-level tree widget:
- QStringList pluginInterfaces = pluginContainer->pluginInterfaces();
+ QStringList pluginInterfaces = m_pluginContainer->pluginInterfaces();
pluginInterfaces.sort(Qt::CaseInsensitive);
std::map<QString, QTreeWidgetItem*> topItems;
for (QString interfaceName : pluginInterfaces) {
- auto *item = new QTreeWidgetItem(ui->pluginsList, { interfaceName });
+ auto* item = new QTreeWidgetItem(ui->pluginsList, { interfaceName });
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
auto font = item->font(0);
font.setBold(true);
@@ -29,11 +52,17 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginContainer* pluginConta
// display plugin settings
QSet<QString> handledNames;
- for (IPlugin *plugin : settings().plugins().plugins()) {
- if (handledNames.contains(plugin->name()))
+ for (IPlugin* plugin : settings().plugins().plugins()) {
+ if (handledNames.contains(plugin->name())) {
continue;
+ }
+ if (!m_filter.matches([plugin](const QRegularExpression& regex) {
+ return regex.match(plugin->localizedName()).hasMatch();
+ })) {
+ continue;
+ }
QTreeWidgetItem* listItem = new QTreeWidgetItem(
- topItems.at(pluginContainer->topImplementedInterface(plugin)));
+ topItems.at(m_pluginContainer->topImplementedInterface(plugin)));
listItem->setData(0, Qt::DisplayRole, plugin->localizedName());
listItem->setData(0, ROLE_PLUGIN, QVariant::fromValue((void*)plugin));
listItem->setData(0, ROLE_SETTINGS, settings().plugins().settings(plugin->name()));
@@ -46,23 +75,13 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginContainer* pluginConta
handledNames.insert(plugin->name());
}
- ui->pluginsList->sortByColumn(0, Qt::AscendingOrder);
-
- // display plugin blacklist
- for (const QString &pluginName : settings().plugins().blacklist()) {
- ui->pluginBlacklist->addItem(pluginName);
+ for (auto& [k, item] : topItems) {
+ if (item->childCount() == 0) {
+ item->setHidden(true);
+ }
}
- m_filter.setEdit(ui->pluginFilterEdit);
- m_filter.setList(ui->pluginsList);
-
- QObject::connect(
- ui->pluginsList, &QTreeWidget::currentItemChanged,
- [&](auto* current, auto* previous) { on_pluginsList_currentItemChanged(current, previous); });
-
- QShortcut *delShortcut = new QShortcut(
- QKeySequence(Qt::Key_Delete), ui->pluginBlacklist);
- QObject::connect(delShortcut, &QShortcut::activated, &dialog(), [&]{ deleteBlacklistItem(); });
+ ui->pluginsList->sortByColumn(0, Qt::AscendingOrder);
}
IPlugin* PluginsSettingsTab::plugin(QTreeWidgetItem* pluginItem) const
diff --git a/src/settingsdialogplugins.h b/src/settingsdialogplugins.h
index e284b271..a09c34f1 100644
--- a/src/settingsdialogplugins.h
+++ b/src/settingsdialogplugins.h
@@ -19,6 +19,13 @@ private:
void deleteBlacklistItem();
void storeSettings(QTreeWidgetItem *pluginItem);
+private slots:
+ /**
+ * @brief Clear and repopulate the plugin list.
+ *
+ */
+ void populatePluginList();
+
/**
* @brief Retrieve the plugin associated to the given item in the list.
*
@@ -31,6 +38,8 @@ private:
private:
+ PluginContainer* m_pluginContainer;
+
MOBase::FilterWidget m_filter;
};