Connected filters

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2023-10-21 18:28:33 +03:00
parent 4850434c67
commit 9e85297f7a
23 changed files with 214 additions and 152 deletions

View File

@ -84,7 +84,7 @@ CheckComboBox::CheckComboBox(QWidget* parent) : QComboBox(parent), m_separator("
this->installEventFilter(this);
}
void CheckComboBox::setModel(QAbstractItemModel* new_model)
void CheckComboBox::setSourceModel(QAbstractItemModel* new_model)
{
auto proxy = new CheckComboModel(this);
proxy->setSourceModel(new_model);

View File

@ -28,7 +28,7 @@ class CheckComboBox : public QComboBox {
explicit CheckComboBox(QWidget* parent = nullptr);
virtual ~CheckComboBox() = default;
virtual void hidePopup() override;
void hidePopup() override;
QString defaultText() const;
void setDefaultText(const QString& text);
@ -41,7 +41,7 @@ class CheckComboBox : public QComboBox {
QStringList checkedItems() const;
virtual void setModel(QAbstractItemModel* model) override;
void setSourceModel(QAbstractItemModel* model);
public slots:
void setCheckedItems(const QStringList& items);

View File

@ -9,9 +9,9 @@
#include "Application.h"
#include "minecraft/PackProfile.h"
unique_qobject_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* instance, QWidget* parent)
unique_qobject_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* instance, bool extendedSupport, QWidget* parent)
{
return unique_qobject_ptr<ModFilterWidget>(new ModFilterWidget(instance, parent));
return unique_qobject_ptr<ModFilterWidget>(new ModFilterWidget(instance, extendedSupport, parent));
}
class VersionBasicModel : public QIdentityProxyModel {
@ -28,23 +28,33 @@ class VersionBasicModel : public QIdentityProxyModel {
}
};
ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, QWidget* parent)
ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extendedSupport, QWidget* parent)
: QTabWidget(parent), ui(new Ui::ModFilterWidget), m_instance(instance), m_filter(new Filter())
{
ui->setupUi(this);
m_versions_proxy = new VersionProxyModel(this);
m_versions_proxy->setFilter(BaseVersionList::TypeRole, new RegexpFilter("(release)", false));
auto proxy = new VersionBasicModel(this);
proxy->setSourceModel(m_versions_proxy);
ui->versionsCb->setModel(proxy);
ui->versionsCb->setSeparator("| ");
m_versions_proxy->setFilter(BaseVersionList::TypeRole, new RegexpFilter("(release)", false));
if (!extendedSupport) {
ui->versionsSimpleCb->setModel(proxy);
ui->versionsCb->hide();
ui->snapshotsCb->hide();
ui->envBox->hide();
} else {
ui->versionsCb->setSourceModel(proxy);
ui->versionsCb->setSeparator("| ");
ui->versionsSimpleCb->hide();
}
ui->versionsCb->setStyleSheet("combobox-popup: 0;");
ui->versionsSimpleCb->setStyleSheet("combobox-popup: 0;");
connect(ui->snapshotsCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onIncludeSnapshotsChanged);
connect(ui->versionsCb, &QComboBox::currentIndexChanged, this, &ModFilterWidget::onVersionFilterChanged);
connect(ui->versionsSimpleCb, &QComboBox::currentTextChanged, this, &ModFilterWidget::onVersionFilterTextChanged);
connect(ui->neoForgeCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged);
connect(ui->forgeCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged);
@ -61,6 +71,11 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, QWidget* parent)
connect(ui->hide_installed, &QCheckBox::stateChanged, this, &ModFilterWidget::onHideInstalledFilterChanged);
connect(ui->releaseCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
connect(ui->betaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
connect(ui->alphaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
connect(ui->unknownCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
setHidden(true);
loadVersionList();
prepareBasicFilter();
@ -196,4 +211,31 @@ void ModFilterWidget::onHideInstalledFilterChanged()
emit filterUnchanged();
}
void ModFilterWidget::onReleaseFilterChanged()
{
std::list<ModPlatform::IndexedVersionType> releases;
if (ui->releaseCb->isChecked())
releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Release));
if (ui->betaCb->isChecked())
releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Beta));
if (ui->alphaCb->isChecked())
releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Alpha));
if (ui->unknownCb->isChecked())
releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Unknown));
m_filter_changed = releases != m_filter->releases;
m_filter->releases = releases;
if (m_filter_changed)
emit filterChanged();
else
emit filterUnchanged();
}
void ModFilterWidget::onVersionFilterTextChanged(QString version)
{
m_filter->versions.clear();
m_filter->versions.push_front(version);
m_filter_changed = true;
emit filterChanged();
}
#include "ModFilterWidget.moc"

View File

@ -22,41 +22,44 @@ class ModFilterWidget : public QTabWidget {
public:
struct Filter {
std::list<Version> versions;
std::list<ModPlatform::IndexedVersionType> releases;
ModPlatform::ModLoaderTypes loaders;
QString side;
bool hideInstalled;
bool operator==(const Filter& other) const
{
return hideInstalled == other.hideInstalled && side == other.side && loaders == other.loaders && versions == other.versions;
return hideInstalled == other.hideInstalled && side == other.side && loaders == other.loaders && versions == other.versions &&
releases == other.releases;
}
bool operator!=(const Filter& other) const { return !(*this == other); }
};
static unique_qobject_ptr<ModFilterWidget> create(MinecraftInstance* instance, QWidget* parent = nullptr);
static unique_qobject_ptr<ModFilterWidget> create(MinecraftInstance* instance, bool extendedSupport, QWidget* parent = nullptr);
virtual ~ModFilterWidget();
auto getFilter() -> std::shared_ptr<Filter>;
auto changed() const -> bool { return m_filter_changed; }
signals:
void filterChanged();
void filterUnchanged();
private:
ModFilterWidget(MinecraftInstance* instance, QWidget* parent = nullptr);
ModFilterWidget(MinecraftInstance* instance, bool extendedSupport, QWidget* parent = nullptr);
void loadVersionList();
void prepareBasicFilter();
private slots:
void onVersionFilterChanged();
void onVersionFilterTextChanged(QString version);
void onReleaseFilterChanged();
void onLoadersFilterChanged();
void onSideFilterChanged();
void onHideInstalledFilterChanged();
void onIncludeSnapshotsChanged();
public:
signals:
void filterChanged();
void filterUnchanged();
private:
Ui::ModFilterWidget* ui;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>460</width>
<height>127</height>
</rect>
</property>
@ -17,13 +17,20 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="VersionPage">
<attribute name="title">
<string>Minecraft versions</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QCheckBox" name="snapshotsCb">
<property name="text">
<string>Include Snapshots</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="CheckComboBox" name="versionsCb">
<property name="sizePolicy">
@ -40,12 +47,8 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="snapshotsCb">
<property name="text">
<string>Include Snapshots</string>
</property>
</widget>
<item row="2" column="0">
<widget class="QComboBox" name="versionsSimpleCb"/>
</item>
</layout>
</widget>