GH-1635 add filter bar to mod list pages

This commit is contained in:
Petr Mrázek 2016-08-04 21:54:25 +02:00
parent 42a98c3661
commit eec87db86a
5 changed files with 96 additions and 26 deletions

View File

@ -199,6 +199,17 @@ bool ModList::deleteMods(int first, int last)
return true; return true;
} }
bool ModList::deleteMods(const QVector<int> &indexes)
{
for (auto i: indexes)
{
Mod &m = mods[i];
m.destroy();
}
emit changed();
return true;
}
int ModList::columnCount(const QModelIndex &parent) const int ModList::columnCount(const QModelIndex &parent) const
{ {
return 3; return 3;

View File

@ -89,6 +89,9 @@ public:
/// Deletes all the selected mods /// Deletes all the selected mods
virtual bool deleteMods(int first, int last); virtual bool deleteMods(int first, int last);
/// Deletes all the selected mods
virtual bool deleteMods(const QVector<int> &indexes);
void startWatching(); void startWatching();
void stopWatching(); void stopWatching();

View File

@ -43,11 +43,17 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods,
m_displayName = displayName; m_displayName = displayName;
m_iconName = iconName; m_iconName = iconName;
m_helpName = helpPage; m_helpName = helpPage;
m_filter = "%1 (*.zip *.jar)"; m_fileSelectionFilter = "%1 (*.zip *.jar)";
ui->modTreeView->setModel(m_mods.get()); 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); ui->modTreeView->installEventFilter(this);
auto smodel = ui->modTreeView->selectionModel(); auto smodel = ui->modTreeView->selectionModel();
connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent);
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged );
} }
void ModFolderPage::opened() void ModFolderPage::opened()
@ -60,6 +66,13 @@ void ModFolderPage::closed()
m_mods->stopWatching(); 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, CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods,
QString id, QString iconName, QString displayName, QString id, QString iconName, QString displayName,
QString helpPage, QWidget *parent) QString helpPage, QWidget *parent)
@ -141,7 +154,7 @@ void ModFolderPage::on_addModBtn_clicked()
tr("Select %1", tr("Select %1",
"Select whatever type of files the page contains. Example: 'Loader Mods'") "Select whatever type of files the page contains. Example: 'Loader Mods'")
.arg(m_displayName), .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()); this->parentWidget());
if (!list.empty()) if (!list.empty())
{ {
@ -159,7 +172,14 @@ void ModFolderPage::on_rmModBtn_clicked()
if (!lastfirst(list, first, last)) if (!lastfirst(list, first, last))
return; 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() void ModFolderPage::on_viewModBtn_clicked()
@ -174,7 +194,8 @@ void ModFolderPage::modCurrent(const QModelIndex &current, const QModelIndex &pr
ui->frame->clear(); ui->frame->clear();
return; return;
} }
int row = current.row(); auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
Mod &m = m_mods->operator[](row); Mod &m = m_mods->operator[](row);
ui->frame->updateWithMod(m); ui->frame->updateWithMod(m);
} }

View File

@ -39,7 +39,7 @@ public:
void setFilter(const QString & filter) void setFilter(const QString & filter)
{ {
m_filter = filter; m_fileSelectionFilter = filter;
} }
virtual QString displayName() const override virtual QString displayName() const override
@ -72,11 +72,13 @@ protected:
private: private:
Ui::ModFolderPage *ui; Ui::ModFolderPage *ui;
std::shared_ptr<ModList> m_mods; std::shared_ptr<ModList> m_mods;
QSortFilterProxyModel *m_filterModel;
QString m_iconName; QString m_iconName;
QString m_id; QString m_id;
QString m_displayName; QString m_displayName;
QString m_helpName; QString m_helpName;
QString m_filter; QString m_fileSelectionFilter;
QString m_viewFilter;
public public
slots: slots:
@ -84,6 +86,7 @@ slots:
private private
slots: slots:
void on_filterTextChanged(const QString & newContents);
void on_addModBtn_clicked(); void on_addModBtn_clicked();
void on_rmModBtn_clicked(); void on_rmModBtn_clicked();
void on_viewModBtn_clicked(); void on_viewModBtn_clicked();

View File

@ -29,27 +29,17 @@
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<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"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="acceptDrops"> <attribute name="title">
<bool>true</bool> <string notr="true">Tab 1</string>
</property> </attribute>
<property name="dragDropMode"> <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0">
<enum>QAbstractItemView::DropOnly</enum> <item row="0" column="2">
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QPushButton" name="addModBtn"> <widget class="QPushButton" name="addModBtn">
@ -87,7 +77,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="3">
<widget class="MCModInfoFrame" name="frame"> <widget class="MCModInfoFrame" name="frame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum"> <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
@ -97,6 +87,40 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</widget> </widget>
@ -116,6 +140,14 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>modTreeView</tabstop>
<tabstop>addModBtn</tabstop>
<tabstop>rmModBtn</tabstop>
<tabstop>viewModBtn</tabstop>
<tabstop>filterEdit</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>