diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-08-04 21:54:25 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-08-04 21:54:25 +0200 |
commit | eec87db86a8a00db0a9145a3b17c53408f7b1f5b (patch) | |
tree | 9df591cc6fe52f3a84c15cdecbbf20959ab99f30 /application/pages | |
parent | 42a98c366129bba97464f7ac3771b547d6cae804 (diff) | |
download | MultiMC-eec87db86a8a00db0a9145a3b17c53408f7b1f5b.tar MultiMC-eec87db86a8a00db0a9145a3b17c53408f7b1f5b.tar.gz MultiMC-eec87db86a8a00db0a9145a3b17c53408f7b1f5b.tar.lz MultiMC-eec87db86a8a00db0a9145a3b17c53408f7b1f5b.tar.xz MultiMC-eec87db86a8a00db0a9145a3b17c53408f7b1f5b.zip |
GH-1635 add filter bar to mod list pages
Diffstat (limited to 'application/pages')
-rw-r--r-- | application/pages/ModFolderPage.cpp | 31 | ||||
-rw-r--r-- | application/pages/ModFolderPage.h | 7 | ||||
-rw-r--r-- | application/pages/ModFolderPage.ui | 70 |
3 files changed, 82 insertions, 26 deletions
diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp index b838ed10..3926fc46 100644 --- a/application/pages/ModFolderPage.cpp +++ b/application/pages/ModFolderPage.cpp @@ -43,11 +43,17 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, m_displayName = displayName; m_iconName = iconName; m_helpName = helpPage; - m_filter = "%1 (*.zip *.jar)"; - ui->modTreeView->setModel(m_mods.get()); + m_fileSelectionFilter = "%1 (*.zip *.jar)"; + m_filterModel = new QSortFilterProxyModel(this); + m_filterModel->setDynamicSortFilter(true); + m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_filterModel->setSourceModel(m_mods.get()); + m_filterModel->setFilterKeyColumn(-1); + ui->modTreeView->setModel(m_filterModel); ui->modTreeView->installEventFilter(this); auto smodel = ui->modTreeView->selectionModel(); connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged ); } void ModFolderPage::opened() @@ -60,6 +66,13 @@ void ModFolderPage::closed() m_mods->stopWatching(); } +void ModFolderPage::on_filterTextChanged(const QString& newContents) +{ + m_viewFilter = newContents; + m_filterModel->setFilterFixedString(m_viewFilter); +} + + CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id, QString iconName, QString displayName, QString helpPage, QWidget *parent) @@ -141,7 +154,7 @@ void ModFolderPage::on_addModBtn_clicked() tr("Select %1", "Select whatever type of files the page contains. Example: 'Loader Mods'") .arg(m_displayName), - m_filter.arg(m_displayName), MMC->settings()->get("CentralModsDir").toString(), + m_fileSelectionFilter.arg(m_displayName), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget()); if (!list.empty()) { @@ -159,7 +172,14 @@ void ModFolderPage::on_rmModBtn_clicked() if (!lastfirst(list, first, last)) return; - m_mods->deleteMods(first, last); + + QVector<int> toDelete; + for(int i = first; i <= last; i++) + { + auto index = m_filterModel->mapToSource(m_filterModel->index(i,0,QModelIndex())); + toDelete.append(index.row()); + } + m_mods->deleteMods(toDelete); } void ModFolderPage::on_viewModBtn_clicked() @@ -174,7 +194,8 @@ void ModFolderPage::modCurrent(const QModelIndex ¤t, const QModelIndex &pr ui->frame->clear(); return; } - int row = current.row(); + auto sourceCurrent = m_filterModel->mapToSource(current); + int row = sourceCurrent.row(); Mod &m = m_mods->operator[](row); ui->frame->updateWithMod(m); } diff --git a/application/pages/ModFolderPage.h b/application/pages/ModFolderPage.h index 23b2f67d..4102a1bb 100644 --- a/application/pages/ModFolderPage.h +++ b/application/pages/ModFolderPage.h @@ -39,7 +39,7 @@ public: void setFilter(const QString & filter) { - m_filter = filter; + m_fileSelectionFilter = filter; } virtual QString displayName() const override @@ -72,11 +72,13 @@ protected: private: Ui::ModFolderPage *ui; std::shared_ptr<ModList> m_mods; + QSortFilterProxyModel *m_filterModel; QString m_iconName; QString m_id; QString m_displayName; QString m_helpName; - QString m_filter; + QString m_fileSelectionFilter; + QString m_viewFilter; public slots: @@ -84,6 +86,7 @@ slots: private slots: + void on_filterTextChanged(const QString & newContents); void on_addModBtn_clicked(); void on_rmModBtn_clicked(); void on_viewModBtn_clicked(); diff --git a/application/pages/ModFolderPage.ui b/application/pages/ModFolderPage.ui index cf991e04..707987c7 100644 --- a/application/pages/ModFolderPage.ui +++ b/application/pages/ModFolderPage.ui @@ -29,27 +29,17 @@ <number>0</number> </property> <widget class="QWidget" name="tab"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <attribute name="title"> <string notr="true">Tab 1</string> </attribute> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="ModListView" name="modTreeView"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="acceptDrops"> - <bool>true</bool> - </property> - <property name="dragDropMode"> - <enum>QAbstractItemView::DropOnly</enum> - </property> - </widget> - </item> - <item row="0" column="1"> + <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0"> + <item row="0" column="2"> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QPushButton" name="addModBtn"> @@ -87,7 +77,7 @@ </item> </layout> </item> - <item row="1" column="0" colspan="2"> + <item row="1" column="0" colspan="3"> <widget class="MCModInfoFrame" name="frame"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> @@ -97,6 +87,40 @@ </property> </widget> </item> + <item row="0" column="0" colspan="2"> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="1" column="1"> + <widget class="QLineEdit" name="filterEdit"> + <property name="clearButtonEnabled"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="filterLabel"> + <property name="text"> + <string>Filter:</string> + </property> + </widget> + </item> + <item row="0" column="0" colspan="3"> + <widget class="ModListView" name="modTreeView"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="acceptDrops"> + <bool>true</bool> + </property> + <property name="dragDropMode"> + <enum>QAbstractItemView::DropOnly</enum> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> </widget> @@ -116,6 +140,14 @@ <container>1</container> </customwidget> </customwidgets> + <tabstops> + <tabstop>tabWidget</tabstop> + <tabstop>modTreeView</tabstop> + <tabstop>addModBtn</tabstop> + <tabstop>rmModBtn</tabstop> + <tabstop>viewModBtn</tabstop> + <tabstop>filterEdit</tabstop> + </tabstops> <resources/> <connections/> </ui> |