rework: make the filter as a tabbed widget in the dialog itself
Still needs a clear indication that the filter only applies after you click the search button...
This commit is contained in:
@ -91,9 +91,14 @@ void ListModel::refresh()
|
||||
performPaginatedSearch();
|
||||
}
|
||||
|
||||
void ListModel::searchWithTerm(const QString& term, const int sort)
|
||||
void ListModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed)
|
||||
{
|
||||
if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; }
|
||||
if (currentSearchTerm == term
|
||||
&& currentSearchTerm.isNull() == term.isNull()
|
||||
&& currentSort == sort
|
||||
&& !filter_changed)
|
||||
{ return; }
|
||||
|
||||
currentSearchTerm = term;
|
||||
currentSort = sort;
|
||||
|
||||
|
@ -35,7 +35,7 @@ class ListModel : public QAbstractListModel {
|
||||
/* Ask the API for more information */
|
||||
void fetchMore(const QModelIndex& parent) override;
|
||||
void refresh();
|
||||
void searchWithTerm(const QString& term, const int sort);
|
||||
void searchWithTerm(const QString& term, const int sort, const bool filter_changed);
|
||||
void requestModVersions(const ModPlatform::IndexedPack& current);
|
||||
|
||||
virtual void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) = 0;
|
||||
|
@ -13,7 +13,7 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
|
||||
, m_instance(instance)
|
||||
, ui(new Ui::ModPage)
|
||||
, dialog(dialog)
|
||||
, filter_dialog(static_cast<MinecraftInstance*>(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this)
|
||||
, filter_widget(static_cast<MinecraftInstance*>(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this)
|
||||
, api(api)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -24,7 +24,10 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
|
||||
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||
|
||||
m_filter = filter_dialog.getFilter();
|
||||
ui->gridLayout_3->addWidget(&filter_widget, 0, 0, 1, ui->gridLayout_3->columnCount());
|
||||
|
||||
filter_widget.setInstance(static_cast<MinecraftInstance*>(m_instance));
|
||||
m_filter = filter_widget.getFilter();
|
||||
}
|
||||
|
||||
ModPage::~ModPage()
|
||||
@ -59,21 +62,22 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
|
||||
|
||||
void ModPage::filterMods()
|
||||
{
|
||||
auto ret = filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
|
||||
m_filter = filter_dialog.getFilter();
|
||||
|
||||
if(ret == QDialog::DialogCode::Accepted){
|
||||
listModel->refresh();
|
||||
|
||||
int prev_count = ui->versionSelectionBox->count();
|
||||
ui->versionSelectionBox->clear();
|
||||
updateModVersions(prev_count);
|
||||
}
|
||||
filter_widget.setHidden(!filter_widget.isHidden());
|
||||
}
|
||||
|
||||
void ModPage::triggerSearch()
|
||||
{
|
||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
|
||||
auto changed = filter_widget.changed();
|
||||
m_filter = filter_widget.getFilter();
|
||||
|
||||
if(changed){
|
||||
ui->packView->clearSelection();
|
||||
ui->packDescription->clear();
|
||||
ui->versionSelectionBox->clear();
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex(), changed);
|
||||
}
|
||||
|
||||
void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include "Application.h"
|
||||
#include "modplatform/ModAPI.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui/dialogs/FilterModsDialog.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/pages/modplatform/ModModel.h"
|
||||
#include "ui/widgets/ModFilterWidget.h"
|
||||
|
||||
class ModDownloadDialog;
|
||||
|
||||
@ -40,7 +40,7 @@ class ModPage : public QWidget, public BasePage {
|
||||
virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0;
|
||||
|
||||
auto apiProvider() const -> const ModAPI* { return api.get(); };
|
||||
auto getFilter() const -> const std::shared_ptr<FilterModsDialog::Filter> { return m_filter; }
|
||||
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
||||
|
||||
auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
|
||||
void updateModVersions(int prev_count = -1);
|
||||
@ -64,8 +64,8 @@ class ModPage : public QWidget, public BasePage {
|
||||
Ui::ModPage* ui = nullptr;
|
||||
ModDownloadDialog* dialog = nullptr;
|
||||
|
||||
FilterModsDialog filter_dialog;
|
||||
std::shared_ptr<FilterModsDialog::Filter> m_filter;
|
||||
ModFilterWidget filter_widget;
|
||||
std::shared_ptr<ModFilterWidget::Filter> m_filter;
|
||||
|
||||
ModPlatform::ListModel* listModel = nullptr;
|
||||
ModPlatform::IndexedPack current;
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="1" column="0" colspan="4">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="2">
|
||||
<widget class="QTextBrowser" name="packDescription">
|
||||
@ -41,7 +41,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="searchButton">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
@ -55,7 +55,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="2" column="0" colspan="4">
|
||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0">
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="versionSelectionBox"/>
|
||||
@ -80,15 +80,22 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="modFilterButton">
|
||||
<property name="text">
|
||||
<string>Filter options</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="modFilterButton">
|
||||
<property name="text">
|
||||
<string>Filter options</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
@ -67,25 +67,6 @@ auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min
|
||||
return ver.mcVersion.contains(mineVer);
|
||||
}
|
||||
|
||||
// We override this so that it refreshes correctly, otherwise it would show
|
||||
// invalid mods on the mod list, because the API would return mods for the
|
||||
// wrong mod loader :(
|
||||
void FlameModPage::filterMods()
|
||||
{
|
||||
auto ret = filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
|
||||
m_filter = filter_dialog.getFilter();
|
||||
|
||||
if(ret == QDialog::DialogCode::Accepted){
|
||||
// CF API can't handle well this
|
||||
if(!m_filter->versions.empty())
|
||||
listModel->refresh();
|
||||
|
||||
int prev_count = ui->versionSelectionBox->count();
|
||||
ui->versionSelectionBox->clear();
|
||||
updateModVersions(prev_count);
|
||||
}
|
||||
}
|
||||
|
||||
// I don't know why, but doing this on the parent class makes it so that
|
||||
// other mod providers start loading before being selected, at least with
|
||||
// my Qt, so we need to implement this in every derived class...
|
||||
|
@ -56,7 +56,5 @@ class FlameModPage : public ModPage {
|
||||
|
||||
auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override;
|
||||
|
||||
void filterMods() override;
|
||||
|
||||
auto shouldDisplay() const -> bool override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user