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;
}
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
{
return 3;

View File

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

View File

@ -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 &current, 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);
}

View File

@ -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();

View File

@ -29,27 +29,17 @@
<number>0</number>
</property>
<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">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<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">
<attribute name="title">
<string notr="true">Tab 1</string>
</attribute>
<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>