Added categories filter
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include "ModFilterWidget.h"
|
||||
#include <qcheckbox.h>
|
||||
#include <qcombobox.h>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QListWidget>
|
||||
#include <algorithm>
|
||||
#include "BaseVersionList.h"
|
||||
#include "meta/Index.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
@ -76,6 +78,8 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extendedSuppo
|
||||
connect(ui->alphaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
|
||||
connect(ui->unknownCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged);
|
||||
|
||||
connect(ui->categoriesList, &QListWidget::itemClicked, this, &ModFilterWidget::onCategoryClicked);
|
||||
|
||||
setHidden(true);
|
||||
loadVersionList();
|
||||
prepareBasicFilter();
|
||||
@ -238,4 +242,33 @@ void ModFilterWidget::onVersionFilterTextChanged(QString version)
|
||||
emit filterChanged();
|
||||
}
|
||||
|
||||
#include "ModFilterWidget.moc"
|
||||
void ModFilterWidget::setCategories(QList<ModPlatform::Category> categories)
|
||||
{
|
||||
ui->categoriesList->clear();
|
||||
m_categories = categories;
|
||||
for (auto cat : categories) {
|
||||
auto item = new QListWidgetItem(cat.name, ui->categoriesList);
|
||||
item->setFlags(item->flags() & (~Qt::ItemIsUserCheckable));
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
ui->categoriesList->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ModFilterWidget::onCategoryClicked(QListWidgetItem* item)
|
||||
{
|
||||
if (item)
|
||||
item->setCheckState(item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
|
||||
m_filter->categoryIds.clear();
|
||||
for (auto i = 0; i < ui->categoriesList->count(); i++) {
|
||||
auto item = ui->categoriesList->item(i);
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
auto c = std::find_if(m_categories.cbegin(), m_categories.cend(), [item](auto v) { return v.name == item->text(); });
|
||||
if (c != m_categories.cend())
|
||||
m_filter->categoryIds << c->id;
|
||||
}
|
||||
}
|
||||
m_filter_changed = true;
|
||||
emit filterChanged();
|
||||
};
|
||||
|
||||
#include "ModFilterWidget.moc"
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QList>
|
||||
#include <QListWidgetItem>
|
||||
#include <QTabWidget>
|
||||
|
||||
#include "Version.h"
|
||||
@ -26,11 +28,12 @@ class ModFilterWidget : public QTabWidget {
|
||||
ModPlatform::ModLoaderTypes loaders;
|
||||
QString side;
|
||||
bool hideInstalled;
|
||||
QStringList categoryIds;
|
||||
|
||||
bool operator==(const Filter& other) const
|
||||
{
|
||||
return hideInstalled == other.hideInstalled && side == other.side && loaders == other.loaders && versions == other.versions &&
|
||||
releases == other.releases;
|
||||
releases == other.releases && categoryIds == other.categoryIds;
|
||||
}
|
||||
bool operator!=(const Filter& other) const { return !(*this == other); }
|
||||
};
|
||||
@ -45,6 +48,9 @@ class ModFilterWidget : public QTabWidget {
|
||||
void filterChanged();
|
||||
void filterUnchanged();
|
||||
|
||||
public slots:
|
||||
void setCategories(QList<ModPlatform::Category>);
|
||||
|
||||
private:
|
||||
ModFilterWidget(MinecraftInstance* instance, bool extendedSupport, QWidget* parent = nullptr);
|
||||
|
||||
@ -59,6 +65,7 @@ class ModFilterWidget : public QTabWidget {
|
||||
void onSideFilterChanged();
|
||||
void onHideInstalledFilterChanged();
|
||||
void onIncludeSnapshotsChanged();
|
||||
void onCategoryClicked(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
Ui::ModFilterWidget* ui;
|
||||
@ -69,4 +76,6 @@ class ModFilterWidget : public QTabWidget {
|
||||
|
||||
Meta::VersionList::Ptr m_version_list;
|
||||
VersionProxyModel* m_versions_proxy = nullptr;
|
||||
|
||||
QList<ModPlatform::Category> m_categories;
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>460</width>
|
||||
<height>127</height>
|
||||
<height>132</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -145,6 +145,44 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="CategoryPage">
|
||||
<attribute name="title">
|
||||
<string>Categories</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QListWidget" name="categoriesList">
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerItem</enum>
|
||||
</property>
|
||||
<property name="flow">
|
||||
<enum>QListView::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::ListMode</enum>
|
||||
</property>
|
||||
<property name="modelColumn">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="ModPage">
|
||||
<attribute name="title">
|
||||
<string>Others</string>
|
||||
|
Reference in New Issue
Block a user