From d5e38fca6b3a8c7bf90c5a3d8ec779752a22c61d Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Wed, 27 Nov 2019 17:05:20 -0500
Subject: added not filter, not functional yet fixed no mods being displayed
for OR with no conditions
---
src/mainwindow.cpp | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'src/mainwindow.cpp')
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index e134d64a..21606fa9 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -6552,6 +6552,11 @@ void MainWindow::on_categoriesOrBtn_toggled(bool checked)
}
}
+void MainWindow::on_categoriesNotBtn_toggled(bool checked)
+{
+ m_ModListSortProxy->setFilterNot(checked);
+}
+
void MainWindow::on_managedArchiveLabel_linkHovered(const QString&)
{
QToolTip::showText(QCursor::pos(),
--
cgit v1.3.1
From 17452071c9b72a48498e7578d65b9b52729f914f Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Wed, 27 Nov 2019 17:30:30 -0500
Subject: added separators filter changed notendorsed filter to include
anything else than true
---
src/mainwindow.cpp | 5 +++++
src/mainwindow.h | 1 +
src/mainwindow.ui | 7 +++++++
src/modlistsortproxy.cpp | 20 ++++++++++++++++++--
src/modlistsortproxy.h | 2 ++
5 files changed, 33 insertions(+), 2 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 21606fa9..d5636ab9 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -6557,6 +6557,11 @@ void MainWindow::on_categoriesNotBtn_toggled(bool checked)
m_ModListSortProxy->setFilterNot(checked);
}
+void MainWindow::on_categoriesSeparators_toggled(bool checked)
+{
+ m_ModListSortProxy->setFilterSeparators(checked);
+}
+
void MainWindow::on_managedArchiveLabel_linkHovered(const QString&)
{
QToolTip::showText(QCursor::pos(),
diff --git a/src/mainwindow.h b/src/mainwindow.h
index cbf45635..c99c724b 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -660,6 +660,7 @@ private slots: // ui slots
void on_categoriesAndBtn_toggled(bool checked);
void on_categoriesOrBtn_toggled(bool checked);
void on_categoriesNotBtn_toggled(bool checked);
+ void on_categoriesSeparators_toggled(bool checked);
void on_managedArchiveLabel_linkHovered(const QString &link);
void storeSettings();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index cd9cbc4b..9648a586 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -159,6 +159,13 @@
+ -
+
+
+ Separators
+
+
+
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index 0984d415..ddae675c 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -39,6 +39,7 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent)
, m_FilterActive(false)
, m_FilterMode(FILTER_AND)
, m_FilterNot(false)
+ , m_FilterSeparators(false)
{
setDynamicSortFilter(true); // this seems to work without dynamicsortfilter
// but I don't know why. This should be necessary
@@ -278,6 +279,10 @@ bool ModListSortProxy::hasConflictFlag(const std::vector &flags)
bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const
{
for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
+ if (info->hasFlag(ModInfo::FLAG_SEPARATOR) && !m_FilterSeparators) {
+ return false;
+ }
+
if (!categoryMatchesMod(info, enabled, *iter)) {
return false;
}
@@ -295,6 +300,10 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons
bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
{
for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
+ if (info->hasFlag(ModInfo::FLAG_SEPARATOR) && !m_FilterSeparators) {
+ return false;
+ }
+
if (categoryMatchesMod(info, enabled, *iter)) {
return true;
}
@@ -332,7 +341,7 @@ bool ModListSortProxy::categoryMatchesMod(
case CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED:
{
ModInfo::EEndorsedState state = info->endorsedState();
- return ((state == ModInfo::ENDORSED_FALSE) || (state == ModInfo::ENDORSED_NEVER));
+ return (state != ModInfo::ENDORSED_TRUE);
}
case CategoryFactory::CATEGORY_SPECIAL_BACKUP:
@@ -353,7 +362,6 @@ bool ModListSortProxy::categoryMatchesMod(
info->getNexusID() == -1 &&
!info->hasFlag(ModInfo::FLAG_FOREIGN) &&
!info->hasFlag(ModInfo::FLAG_BACKUP) &&
- !info->hasFlag(ModInfo::FLAG_SEPARATOR) &&
!info->hasFlag(ModInfo::FLAG_OVERWRITE));
}
@@ -480,6 +488,14 @@ void ModListSortProxy::setFilterNot(bool b)
}
}
+void ModListSortProxy::setFilterSeparators(bool b)
+{
+ if (b != m_FilterSeparators) {
+ m_FilterSeparators = b;
+ this->invalidate();
+ }
+}
+
bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) const
{
if (m_Profile == nullptr) {
diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h
index 17888ae6..2ebfbcf0 100644
--- a/src/modlistsortproxy.h
+++ b/src/modlistsortproxy.h
@@ -86,6 +86,7 @@ public:
void setFilterMode(FilterMode mode);
void setFilterNot(bool b);
+ void setFilterSeparators(bool b);
/**
* @brief tests if the specified index has child nodes
@@ -139,6 +140,7 @@ private:
bool m_FilterActive;
FilterMode m_FilterMode;
bool m_FilterNot;
+ bool m_FilterSeparators;
std::vector m_PreChangeFilters;
--
cgit v1.3.1
From 4bbdbb000fd5051fe80b5dca21dda60910284333 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Wed, 27 Nov 2019 19:14:37 -0500
Subject: split filter list
---
src/CMakeLists.txt | 3 +
src/filterlist.cpp | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/filterlist.h | 42 ++++++++++++
src/mainwindow.cpp | 177 ++++---------------------------------------------
src/mainwindow.h | 12 +---
5 files changed, 249 insertions(+), 174 deletions(-)
create mode 100644 src/filterlist.cpp
create mode 100644 src/filterlist.h
(limited to 'src/mainwindow.cpp')
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e3a42409..a46908ef 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -144,6 +144,7 @@ SET(organizer_SRCS
uilocker.cpp
loot.cpp
lootdialog.cpp
+ filterlist.cpp
shared/windows_error.cpp
shared/error_report.cpp
@@ -268,6 +269,7 @@ SET(organizer_HDRS
loot.h
lootdialog.h
json.h
+ filterlist.h
shared/windows_error.h
shared/error_report.h
@@ -320,6 +322,7 @@ SET(organizer_RCS
source_group(src REGULAR_EXPRESSION ".*\\.(h|cpp|ui)")
set(application
+ filterlist
iuserinterface
main
mainwindow
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
new file mode 100644
index 00000000..8ef4b62d
--- /dev/null
+++ b/src/filterlist.cpp
@@ -0,0 +1,189 @@
+#include "filterlist.h"
+#include "ui_mainwindow.h"
+#include "categories.h"
+#include "categoriesdialog.h"
+#include
+
+using namespace MOBase;
+
+FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
+ : ui(ui), m_factory(factory)
+{
+ QObject::connect(
+ ui->categoriesList, &QTreeWidget::customContextMenuRequested,
+ [&](auto&& pos){ onContextMenu(pos); });
+
+ QObject::connect(
+ ui->categoriesList, &QTreeWidget::itemSelectionChanged,
+ [&]{ onSelection(); });
+}
+
+QTreeWidgetItem* FilterList::addFilterItem(
+ QTreeWidgetItem *root, const QString &name, int categoryID,
+ ModListSortProxy::FilterType type)
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
+ item->setData(0, Qt::ToolTipRole, name);
+ item->setData(0, Qt::UserRole, categoryID);
+ item->setData(0, Qt::UserRole + 1, type);
+ if (root != nullptr) {
+ root->addChild(item);
+ } else {
+ ui->categoriesList->addTopLevelItem(item);
+ }
+ return item;
+}
+
+void FilterList::addContentFilters()
+{
+ for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) {
+ addFilterItem(nullptr, tr("").arg(ModInfo::getContentTypeName(i)), i, ModListSortProxy::TYPE_CONTENT);
+ }
+}
+
+void FilterList::addCategoryFilters(QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID)
+{
+ for (unsigned int i = 1;
+ i < static_cast(m_factory.numCategories()); ++i) {
+ if ((m_factory.getParentID(i) == targetID)) {
+ int categoryID = m_factory.getCategoryID(i);
+ if (categoriesUsed.find(categoryID) != categoriesUsed.end()) {
+ QTreeWidgetItem *item =
+ addFilterItem(root, m_factory.getCategoryName(i),
+ categoryID, ModListSortProxy::TYPE_CATEGORY);
+ if (m_factory.hasChildren(i)) {
+ addCategoryFilters(item, categoriesUsed, categoryID);
+ }
+ }
+ }
+ }
+}
+
+void FilterList::refresh()
+{
+ QItemSelection currentSelection = ui->modList->selectionModel()->selection();
+
+ QVariant currentIndexName = ui->modList->currentIndex().data();
+ ui->modList->setCurrentIndex(QModelIndex());
+
+ QStringList selectedItems;
+ for (QTreeWidgetItem *item : ui->categoriesList->selectedItems()) {
+ selectedItems.append(item->text(0));
+ }
+
+ ui->categoriesList->clear();
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CHECKED, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNCHECKED, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_BACKUP, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_MANAGED, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNMANAGED, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CONFLICT, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NONEXUSID, ModListSortProxy::TYPE_SPECIAL);
+ addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA, ModListSortProxy::TYPE_SPECIAL);
+
+ addContentFilters();
+ std::set categoriesUsed;
+ for (unsigned int modIdx = 0; modIdx < ModInfo::getNumMods(); ++modIdx) {
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIdx);
+ for (int categoryID : modInfo->getCategories()) {
+ int currentID = categoryID;
+ std::set cycleTest;
+ // also add parents so they show up in the tree
+ while (currentID != 0) {
+ categoriesUsed.insert(currentID);
+ if (!cycleTest.insert(currentID).second) {
+ log::warn("cycle in categories: {}", SetJoin(cycleTest, ", "));
+ break;
+ }
+ currentID = m_factory.getParentID(m_factory.getCategoryIndex(currentID));
+ }
+ }
+ }
+
+ addCategoryFilters(nullptr, categoriesUsed, 0);
+
+ for (const QString &item : selectedItems) {
+ QList matches = ui->categoriesList->findItems(item, Qt::MatchFixedString | Qt::MatchRecursive);
+ if (matches.size() > 0) {
+ matches.at(0)->setSelected(true);
+ }
+ }
+ ui->modList->selectionModel()->select(currentSelection, QItemSelectionModel::Select);
+ QModelIndexList matchList;
+ if (currentIndexName.isValid()) {
+ matchList = ui->modList->model()->match(ui->modList->model()->index(0, 0), Qt::DisplayRole, currentIndexName);
+ }
+
+ if (matchList.size() > 0) {
+ ui->modList->setCurrentIndex(matchList.at(0));
+ }
+}
+
+void FilterList::setSelection(std::vector categories)
+{
+ for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) {
+ if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
+ ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i));
+ break;
+ }
+ }
+}
+
+void FilterList::clearSelection()
+{
+ ui->categoriesList->clearSelection();
+}
+
+void FilterList::onSelection()
+{
+ QModelIndexList indices = ui->categoriesList->selectionModel()->selectedRows();
+ std::vector categories;
+ std::vector content;
+ for (const QModelIndex &index : indices) {
+ int filterType = index.data(Qt::UserRole + 1).toInt();
+ if ((filterType == ModListSortProxy::TYPE_CATEGORY)
+ || (filterType == ModListSortProxy::TYPE_SPECIAL)) {
+ int categoryId = index.data(Qt::UserRole).toInt();
+ if (categoryId != CategoryFactory::CATEGORY_NONE) {
+ categories.push_back(categoryId);
+ }
+ } else if (filterType == ModListSortProxy::TYPE_CONTENT) {
+ int contentId = index.data(Qt::UserRole).toInt();
+ content.push_back(contentId);
+ }
+ }
+
+ emit changed(categories, content);
+
+ ui->clickBlankButton->setEnabled(categories.size() > 0 || content.size() >0);
+
+ if (indices.count() == 0) {
+ ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
+ } else if (indices.count() > 1) {
+ ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
+ } else {
+ ui->currentCategoryLabel->setText(QString("(%1)").arg(indices.first().data().toString()));
+ }
+ ui->modList->reset();
+}
+
+void FilterList::onContextMenu(const QPoint &pos)
+{
+ QMenu menu;
+ menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); });
+ menu.addAction(tr("Deselect filter"), [&]{ clearSelection(); });
+
+ menu.exec(ui->categoriesList->viewport()->mapToGlobal(pos));
+}
+
+void FilterList::editCategories()
+{
+ CategoriesDialog dialog(qApp->activeWindow());
+
+ if (dialog.exec() == QDialog::Accepted) {
+ dialog.commitChanges();
+ }
+}
diff --git a/src/filterlist.h b/src/filterlist.h
new file mode 100644
index 00000000..ca74021a
--- /dev/null
+++ b/src/filterlist.h
@@ -0,0 +1,42 @@
+#ifndef MODORGANIZER_CATEGORIESLIST_INCLUDED
+#define MODORGANIZER_CATEGORIESLIST_INCLUDED
+
+#include "modlistsortproxy.h"
+#include
+
+namespace Ui { class MainWindow; };
+class CategoryFactory;
+
+class FilterList : public QObject
+{
+ Q_OBJECT;
+
+public:
+ FilterList(Ui::MainWindow* ui, CategoryFactory& factory);
+
+ void setSelection(std::vector categories);
+ void clearSelection();
+ void refresh();
+
+signals:
+ void changed(std::vector categories, std::vector content);
+
+private:
+ Ui::MainWindow* ui;
+ CategoryFactory& m_factory;
+
+ void onContextMenu(const QPoint &pos);
+ void onSelection();
+
+ void editCategories();
+
+ QTreeWidgetItem* addFilterItem(
+ QTreeWidgetItem *root, const QString &name, int categoryID,
+ ModListSortProxy::FilterType type);
+
+ void addContentFilters();
+ void addCategoryFilters(
+ QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID);
+};
+
+#endif // MODORGANIZER_CATEGORIESLIST_INCLUDED
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index d5636ab9..b63f9211 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -75,6 +75,7 @@ along with Mod Organizer. If not, see .
#include "appconfig.h"
#include "eventfilter.h"
#include "statusbar.h"
+#include "filterlist.h"
#include
#include
#include
@@ -260,6 +261,11 @@ MainWindow::MainWindow(Settings &settings
languageChange(settings.interface().language());
m_CategoryFactory.loadCategories();
+ m_Filters.reset(new FilterList(ui, m_CategoryFactory));
+ connect(m_Filters.get(), &FilterList::changed, [&](auto&& cats, auto&& content) {
+ m_ModListSortProxy->setCategoryFilter(cats);
+ m_ModListSortProxy->setContentFilter(content);
+ });
ui->logList->setCore(m_OrganizerCore);
@@ -1223,7 +1229,7 @@ void MainWindow::showEvent(QShowEvent *event)
if (!m_WasVisible) {
readSettings();
- refreshFilters();
+ m_Filters->refresh();
// this needs to be connected here instead of in the constructor because the
// actual changing of the stylesheet is done by MOApplication, which
@@ -2646,108 +2652,6 @@ void MainWindow::fileMoved(const QString &filePath, const QString &oldOriginName
}
}
-QTreeWidgetItem *MainWindow::addFilterItem(QTreeWidgetItem *root, const QString &name, int categoryID, ModListSortProxy::FilterType type)
-{
- QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
- item->setData(0, Qt::ToolTipRole, name);
- item->setData(0, Qt::UserRole, categoryID);
- item->setData(0, Qt::UserRole + 1, type);
- if (root != nullptr) {
- root->addChild(item);
- } else {
- ui->categoriesList->addTopLevelItem(item);
- }
- return item;
-}
-
-void MainWindow::addContentFilters()
-{
- for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) {
- addFilterItem(nullptr, tr("").arg(ModInfo::getContentTypeName(i)), i, ModListSortProxy::TYPE_CONTENT);
- }
-}
-
-void MainWindow::addCategoryFilters(QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID)
-{
- for (unsigned int i = 1;
- i < static_cast(m_CategoryFactory.numCategories()); ++i) {
- if ((m_CategoryFactory.getParentID(i) == targetID)) {
- int categoryID = m_CategoryFactory.getCategoryID(i);
- if (categoriesUsed.find(categoryID) != categoriesUsed.end()) {
- QTreeWidgetItem *item =
- addFilterItem(root, m_CategoryFactory.getCategoryName(i),
- categoryID, ModListSortProxy::TYPE_CATEGORY);
- if (m_CategoryFactory.hasChildren(i)) {
- addCategoryFilters(item, categoriesUsed, categoryID);
- }
- }
- }
- }
-}
-
-void MainWindow::refreshFilters()
-{
- QItemSelection currentSelection = ui->modList->selectionModel()->selection();
-
- QVariant currentIndexName = ui->modList->currentIndex().data();
- ui->modList->setCurrentIndex(QModelIndex());
-
- QStringList selectedItems;
- for (QTreeWidgetItem *item : ui->categoriesList->selectedItems()) {
- selectedItems.append(item->text(0));
- }
-
- ui->categoriesList->clear();
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CHECKED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNCHECKED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_BACKUP, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_MANAGED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNMANAGED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CONFLICT, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NONEXUSID, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA, ModListSortProxy::TYPE_SPECIAL);
-
- addContentFilters();
- std::set categoriesUsed;
- for (unsigned int modIdx = 0; modIdx < ModInfo::getNumMods(); ++modIdx) {
- ModInfo::Ptr modInfo = ModInfo::getByIndex(modIdx);
- for (int categoryID : modInfo->getCategories()) {
- int currentID = categoryID;
- std::set cycleTest;
- // also add parents so they show up in the tree
- while (currentID != 0) {
- categoriesUsed.insert(currentID);
- if (!cycleTest.insert(currentID).second) {
- log::warn("cycle in categories: {}", SetJoin(cycleTest, ", "));
- break;
- }
- currentID = m_CategoryFactory.getParentID(m_CategoryFactory.getCategoryIndex(currentID));
- }
- }
- }
-
- addCategoryFilters(nullptr, categoriesUsed, 0);
-
- for (const QString &item : selectedItems) {
- QList matches = ui->categoriesList->findItems(item, Qt::MatchFixedString | Qt::MatchRecursive);
- if (matches.size() > 0) {
- matches.at(0)->setSelected(true);
- }
- }
- ui->modList->selectionModel()->select(currentSelection, QItemSelectionModel::Select);
- QModelIndexList matchList;
- if (currentIndexName.isValid()) {
- matchList = ui->modList->model()->match(ui->modList->model()->index(0, 0), Qt::DisplayRole, currentIndexName);
- }
-
- if (matchList.size() > 0) {
- ui->modList->setCurrentIndex(matchList.at(0));
- }
-}
-
void MainWindow::renameMod_clicked()
{
@@ -4121,7 +4025,7 @@ void MainWindow::addRemoveCategories_MenuHandler() {
m_OrganizerCore.modList()->notifyChange(m_ContextRow);
}
- refreshFilters();
+ m_Filters->refresh();
}
void MainWindow::replaceCategories_MenuHandler() {
@@ -4165,7 +4069,7 @@ void MainWindow::replaceCategories_MenuHandler() {
m_OrganizerCore.modList()->notifyChange(m_ContextRow);
}
- refreshFilters();
+ m_Filters->refresh();
}
void MainWindow::saveArchiveList()
@@ -4217,12 +4121,7 @@ void MainWindow::checkModsForUpdates()
if (updatesAvailable || checkingModsForUpdate) {
m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE));
- for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) {
- if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
- ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i));
- break;
- }
- }
+ m_Filters->setSelection({CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE});
}
}
@@ -4848,40 +4747,6 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos)
}
-void MainWindow::on_categoriesList_itemSelectionChanged()
-{
- QModelIndexList indices = ui->categoriesList->selectionModel()->selectedRows();
- std::vector categories;
- std::vector content;
- for (const QModelIndex &index : indices) {
- int filterType = index.data(Qt::UserRole + 1).toInt();
- if ((filterType == ModListSortProxy::TYPE_CATEGORY)
- || (filterType == ModListSortProxy::TYPE_SPECIAL)) {
- int categoryId = index.data(Qt::UserRole).toInt();
- if (categoryId != CategoryFactory::CATEGORY_NONE) {
- categories.push_back(categoryId);
- }
- } else if (filterType == ModListSortProxy::TYPE_CONTENT) {
- int contentId = index.data(Qt::UserRole).toInt();
- content.push_back(contentId);
- }
- }
-
- m_ModListSortProxy->setCategoryFilter(categories);
- m_ModListSortProxy->setContentFilter(content);
- ui->clickBlankButton->setEnabled(categories.size() > 0 || content.size() >0);
-
- if (indices.count() == 0) {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
- } else if (indices.count() > 1) {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
- } else {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(indices.first().data().toString()));
- }
- ui->modList->reset();
-}
-
-
void MainWindow::deleteSavegame_clicked()
{
SaveGameInfo const *info = m_OrganizerCore.managedGame()->feature();
@@ -5071,7 +4936,7 @@ void MainWindow::on_actionSettings_triggered()
instManager->setDownloadDirectory(settings.paths().downloads());
fixCategories();
- refreshFilters();
+ m_Filters->refresh();
if (settings.paths().profiles() != oldProfilesDirectory) {
refreshProfiles();
@@ -6213,27 +6078,9 @@ void MainWindow::on_displayCategoriesBtn_toggled(bool checked)
setCategoryListVisible(checked);
}
-void MainWindow::editCategories()
-{
- CategoriesDialog dialog(this);
-
- if (dialog.exec() == QDialog::Accepted) {
- dialog.commitChanges();
- }
-}
-
void MainWindow::deselectFilters()
{
- ui->categoriesList->clearSelection();
-}
-
-void MainWindow::on_categoriesList_customContextMenuRequested(const QPoint &pos)
-{
- QMenu menu;
- menu.addAction(tr("Edit Categories..."), this, SLOT(editCategories()));
- menu.addAction(tr("Deselect filter"), this, SLOT(deselectFilters()));
-
- menu.exec(ui->categoriesList->viewport()->mapToGlobal(pos));
+ m_Filters->clearSelection();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index c99c724b..04ba7a35 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -39,6 +39,7 @@ along with Mod Organizer. If not, see .
class Executable;
class CategoryFactory;
class OrganizerCore;
+class FilterList;
class PluginListSortProxy;
namespace BSA { class Archive; }
@@ -235,8 +236,6 @@ private:
void writeDataToFile(QFile &file, const QString &directory, const MOShared::DirectoryEntry &directoryEntry);
- void refreshFilters();
-
/**
* Sets category selections from menu; for multiple mods, this will only apply
* the changes made in the menu (which is the delta between the current menu selection and the reference mod)
@@ -266,10 +265,6 @@ private:
size_t checkForProblems();
- QTreeWidgetItem *addFilterItem(QTreeWidgetItem *root, const QString &name, int categoryID, ModListSortProxy::FilterType type);
- void addContentFilters();
- void addCategoryFilters(QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID);
-
void setCategoryListVisible(bool visible);
void displaySaveGameInfo(QListWidgetItem *newItem);
@@ -327,6 +322,8 @@ private:
MOBase::TutorialControl m_Tutorial;
+ std::unique_ptr m_Filters;
+
int m_OldProfileIndex;
std::vector m_ModNameList; // the mod-list to go with the directory structure
@@ -515,7 +512,6 @@ private slots:
void onRequestsChanged(const APIStats& stats, const APIUserAccount& user);
- void editCategories();
void deselectFilters();
void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
@@ -630,7 +626,6 @@ private slots: // ui slots
void on_clearFiltersButton_clicked();
void on_btnRefreshData_clicked();
void on_btnRefreshDownloads_clicked();
- void on_categoriesList_customContextMenuRequested(const QPoint &pos);
void on_conflictsCheckBox_toggled(bool checked);
void on_showArchiveDataCheckBox_toggled(bool checked);
void on_dataTree_customContextMenuRequested(const QPoint &pos);
@@ -647,7 +642,6 @@ private slots: // ui slots
void on_espList_customContextMenuRequested(const QPoint &pos);
void on_displayCategoriesBtn_toggled(bool checked);
void on_groupCombo_currentIndexChanged(int index);
- void on_categoriesList_itemSelectionChanged();
void on_linkButton_pressed();
void on_showHiddenBox_toggled(bool checked);
void on_bsaList_itemChanged(QTreeWidgetItem *item, int column);
--
cgit v1.3.1
From 93318a1474031035da5e61ad199171cad5803c2f Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Fri, 29 Nov 2019 23:50:33 -0500
Subject: moved all remaining filter stuff to FilterList renamed some widgets
---
src/categories.cpp | 34 ++++++++++++++
src/categories.h | 2 +
src/filterlist.cpp | 135 +++++++++++++++++++++++++++++++----------------------
src/filterlist.h | 6 ++-
src/mainwindow.cpp | 107 +++++++++++++++++++++++++++++-------------
src/mainwindow.h | 7 ++-
src/mainwindow.ui | 12 ++---
7 files changed, 204 insertions(+), 99 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/categories.cpp b/src/categories.cpp
index 12b18998..082b4fbc 100644
--- a/src/categories.cpp
+++ b/src/categories.cpp
@@ -320,6 +320,40 @@ QString CategoryFactory::getCategoryName(unsigned int index) const
return m_Categories[index].m_Name;
}
+QString CategoryFactory::getSpecialCategoryName(int type) const
+{
+ switch (type)
+ {
+ case CATEGORY_SPECIAL_CHECKED: return QObject::tr("");
+ case CATEGORY_SPECIAL_UNCHECKED: return QObject::tr("");
+ case CATEGORY_SPECIAL_UPDATEAVAILABLE: return QObject::tr("");
+ case CATEGORY_SPECIAL_NOCATEGORY: return QObject::tr("");
+ case CATEGORY_SPECIAL_CONFLICT: return QObject::tr("");
+ case CATEGORY_SPECIAL_NOTENDORSED: return QObject::tr("");
+ case CATEGORY_SPECIAL_BACKUP: return QObject::tr("");
+ case CATEGORY_SPECIAL_MANAGED: return QObject::tr("");
+ case CATEGORY_SPECIAL_UNMANAGED: return QObject::tr("");
+ case CATEGORY_SPECIAL_NOGAMEDATA: return QObject::tr("");
+ case CATEGORY_SPECIAL_NONEXUSID: return QObject::tr("");
+ default: return {};
+ }
+}
+
+QString CategoryFactory::getCategoryNameByID(int id) const
+{
+ auto itor = m_IDMap.find(id);
+
+ if (itor == m_IDMap.end()) {
+ return getSpecialCategoryName(id);
+ } else {
+ const auto index = itor->second;
+ if (index >= m_Categories.size()) {
+ return {};
+ }
+
+ return m_Categories[index].m_Name;
+ }
+}
int CategoryFactory::getCategoryID(unsigned int index) const
{
diff --git a/src/categories.h b/src/categories.h
index 67fee3e7..2041ce1f 100644
--- a/src/categories.h
+++ b/src/categories.h
@@ -144,6 +144,8 @@ public:
* @return QString name of the category
**/
QString getCategoryName(unsigned int index) const;
+ QString getSpecialCategoryName(int type) const;
+ QString getCategoryNameByID(int id) const;
/**
* @brief look up the id of a category by its index
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
index 8ef4b62d..5562736d 100644
--- a/src/filterlist.cpp
+++ b/src/filterlist.cpp
@@ -9,13 +9,33 @@ using namespace MOBase;
FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
: ui(ui), m_factory(factory)
{
- QObject::connect(
- ui->categoriesList, &QTreeWidget::customContextMenuRequested,
+ connect(
+ ui->filters, &QTreeWidget::customContextMenuRequested,
[&](auto&& pos){ onContextMenu(pos); });
- QObject::connect(
- ui->categoriesList, &QTreeWidget::itemSelectionChanged,
+ connect(
+ ui->filters, &QTreeWidget::itemSelectionChanged,
[&]{ onSelection(); });
+
+ connect(
+ ui->filtersClear, &QPushButton::clicked,
+ [&]{ clearSelection(); });
+
+ connect(
+ ui->filtersAnd, &QCheckBox::toggled,
+ [&]{ onCriteriaChanged(); });
+
+ connect(
+ ui->filtersOr, &QCheckBox::toggled,
+ [&]{ onCriteriaChanged(); });
+
+ connect(
+ ui->filtersNot, &QCheckBox::toggled,
+ [&]{ onCriteriaChanged(); });
+
+ connect(
+ ui->filtersSeparators, &QCheckBox::toggled,
+ [&]{ onCriteriaChanged(); });
}
QTreeWidgetItem* FilterList::addFilterItem(
@@ -29,7 +49,7 @@ QTreeWidgetItem* FilterList::addFilterItem(
if (root != nullptr) {
root->addChild(item);
} else {
- ui->categoriesList->addTopLevelItem(item);
+ ui->filters->addTopLevelItem(item);
}
return item;
}
@@ -37,7 +57,9 @@ QTreeWidgetItem* FilterList::addFilterItem(
void FilterList::addContentFilters()
{
for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) {
- addFilterItem(nullptr, tr("").arg(ModInfo::getContentTypeName(i)), i, ModListSortProxy::TYPE_CONTENT);
+ addFilterItem(
+ nullptr, tr("").arg(ModInfo::getContentTypeName(i)),
+ i, ModListSortProxy::TYPE_CONTENT);
}
}
@@ -59,32 +81,37 @@ void FilterList::addCategoryFilters(QTreeWidgetItem *root, const std::set &
}
}
-void FilterList::refresh()
+void FilterList::addSpecialFilterItem(int type)
{
- QItemSelection currentSelection = ui->modList->selectionModel()->selection();
-
- QVariant currentIndexName = ui->modList->currentIndex().data();
- ui->modList->setCurrentIndex(QModelIndex());
+ addFilterItem(
+ nullptr, m_factory.getSpecialCategoryName(type),
+ type, ModListSortProxy::TYPE_SPECIAL);
+}
+void FilterList::refresh()
+{
QStringList selectedItems;
- for (QTreeWidgetItem *item : ui->categoriesList->selectedItems()) {
+ for (QTreeWidgetItem *item : ui->filters->selectedItems()) {
selectedItems.append(item->text(0));
}
- ui->categoriesList->clear();
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CHECKED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNCHECKED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_BACKUP, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_MANAGED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_UNMANAGED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_CONFLICT, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NONEXUSID, ModListSortProxy::TYPE_SPECIAL);
- addFilterItem(nullptr, tr(""), CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA, ModListSortProxy::TYPE_SPECIAL);
+ ui->filters->clear();
+
+ using F = CategoryFactory;
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_CHECKED);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_UNCHECKED);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_UPDATEAVAILABLE);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_BACKUP);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_MANAGED);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_UNMANAGED);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_NOCATEGORY);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_CONFLICT);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_NOTENDORSED);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_NONEXUSID);
+ addSpecialFilterItem(F::CATEGORY_SPECIAL_NOGAMEDATA);
addContentFilters();
+
std::set categoriesUsed;
for (unsigned int modIdx = 0; modIdx < ModInfo::getNumMods(); ++modIdx) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIdx);
@@ -106,27 +133,20 @@ void FilterList::refresh()
addCategoryFilters(nullptr, categoriesUsed, 0);
for (const QString &item : selectedItems) {
- QList matches = ui->categoriesList->findItems(item, Qt::MatchFixedString | Qt::MatchRecursive);
+ QList matches = ui->filters->findItems(
+ item, Qt::MatchFixedString | Qt::MatchRecursive);
+
if (matches.size() > 0) {
matches.at(0)->setSelected(true);
}
}
- ui->modList->selectionModel()->select(currentSelection, QItemSelectionModel::Select);
- QModelIndexList matchList;
- if (currentIndexName.isValid()) {
- matchList = ui->modList->model()->match(ui->modList->model()->index(0, 0), Qt::DisplayRole, currentIndexName);
- }
-
- if (matchList.size() > 0) {
- ui->modList->setCurrentIndex(matchList.at(0));
- }
}
void FilterList::setSelection(std::vector categories)
{
- for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) {
- if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
- ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i));
+ for (int i = 0; i < ui->filters->topLevelItemCount(); ++i) {
+ if (ui->filters->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
+ ui->filters->setCurrentItem(ui->filters->topLevelItem(i));
break;
}
}
@@ -134,40 +154,32 @@ void FilterList::setSelection(std::vector categories)
void FilterList::clearSelection()
{
- ui->categoriesList->clearSelection();
+ ui->filters->clearSelection();
}
void FilterList::onSelection()
{
- QModelIndexList indices = ui->categoriesList->selectionModel()->selectedRows();
+ QModelIndexList indices = ui->filters->selectionModel()->selectedRows();
std::vector categories;
std::vector content;
+
for (const QModelIndex &index : indices) {
- int filterType = index.data(Qt::UserRole + 1).toInt();
- if ((filterType == ModListSortProxy::TYPE_CATEGORY)
- || (filterType == ModListSortProxy::TYPE_SPECIAL)) {
- int categoryId = index.data(Qt::UserRole).toInt();
+ const int filterType = index.data(Qt::UserRole + 1).toInt();
+
+ if ((filterType == ModListSortProxy::TYPE_CATEGORY) || (filterType == ModListSortProxy::TYPE_SPECIAL)) {
+ const int categoryId = index.data(Qt::UserRole).toInt();
if (categoryId != CategoryFactory::CATEGORY_NONE) {
categories.push_back(categoryId);
}
} else if (filterType == ModListSortProxy::TYPE_CONTENT) {
- int contentId = index.data(Qt::UserRole).toInt();
+ const int contentId = index.data(Qt::UserRole).toInt();
content.push_back(contentId);
}
}
- emit changed(categories, content);
-
- ui->clickBlankButton->setEnabled(categories.size() > 0 || content.size() >0);
+ ui->filtersClear->setEnabled(categories.size() > 0 || content.size() >0);
- if (indices.count() == 0) {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
- } else if (indices.count() > 1) {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(tr("")));
- } else {
- ui->currentCategoryLabel->setText(QString("(%1)").arg(indices.first().data().toString()));
- }
- ui->modList->reset();
+ emit filtersChanged(categories, content);
}
void FilterList::onContextMenu(const QPoint &pos)
@@ -176,7 +188,7 @@ void FilterList::onContextMenu(const QPoint &pos)
menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); });
menu.addAction(tr("Deselect filter"), [&]{ clearSelection(); });
- menu.exec(ui->categoriesList->viewport()->mapToGlobal(pos));
+ menu.exec(ui->filters->viewport()->mapToGlobal(pos));
}
void FilterList::editCategories()
@@ -187,3 +199,14 @@ void FilterList::editCategories()
dialog.commitChanges();
}
}
+
+void FilterList::onCriteriaChanged()
+{
+ const auto mode = ui->filtersAnd->isChecked() ?
+ ModListSortProxy::FILTER_AND : ModListSortProxy::FILTER_OR;
+
+ const bool inverse = ui->filtersNot->isChecked();
+ const bool separators = ui->filtersSeparators->isChecked();
+
+ emit criteriaChanged(mode, inverse, separators);
+}
diff --git a/src/filterlist.h b/src/filterlist.h
index ca74021a..85982392 100644
--- a/src/filterlist.h
+++ b/src/filterlist.h
@@ -19,7 +19,8 @@ public:
void refresh();
signals:
- void changed(std::vector categories, std::vector content);
+ void filtersChanged(std::vector categories, std::vector content);
+ void criteriaChanged(ModListSortProxy::FilterMode mode, bool inverse, bool separators);
private:
Ui::MainWindow* ui;
@@ -27,6 +28,7 @@ private:
void onContextMenu(const QPoint &pos);
void onSelection();
+ void onCriteriaChanged();
void editCategories();
@@ -37,6 +39,8 @@ private:
void addContentFilters();
void addCategoryFilters(
QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID);
+ void addSpecialFilterItem(int type);
+
};
#endif // MODORGANIZER_CATEGORIESLIST_INCLUDED
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b63f9211..1319d906 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -262,10 +262,14 @@ MainWindow::MainWindow(Settings &settings
m_CategoryFactory.loadCategories();
m_Filters.reset(new FilterList(ui, m_CategoryFactory));
- connect(m_Filters.get(), &FilterList::changed, [&](auto&& cats, auto&& content) {
- m_ModListSortProxy->setCategoryFilter(cats);
- m_ModListSortProxy->setContentFilter(content);
- });
+
+ connect(
+ m_Filters.get(), &FilterList::filtersChanged,
+ [&](auto&& cats, auto&& content) { onFilters(cats, content); });
+
+ connect(
+ m_Filters.get(), &FilterList::criteriaChanged,
+ [&](auto mode, bool inv, bool sep) { onFiltersCriteria(mode, inv, sep); });
ui->logList->setCore(m_OrganizerCore);
@@ -1229,7 +1233,7 @@ void MainWindow::showEvent(QShowEvent *event)
if (!m_WasVisible) {
readSettings();
- m_Filters->refresh();
+ refreshFilters();
// this needs to be connected here instead of in the constructor because the
// actual changing of the stylesheet is done by MOApplication, which
@@ -4025,7 +4029,7 @@ void MainWindow::addRemoveCategories_MenuHandler() {
m_OrganizerCore.modList()->notifyChange(m_ContextRow);
}
- m_Filters->refresh();
+ refreshFilters();
}
void MainWindow::replaceCategories_MenuHandler() {
@@ -4069,7 +4073,7 @@ void MainWindow::replaceCategories_MenuHandler() {
m_OrganizerCore.modList()->notifyChange(m_ContextRow);
}
- m_Filters->refresh();
+ refreshFilters();
}
void MainWindow::saveArchiveList()
@@ -4936,7 +4940,7 @@ void MainWindow::on_actionSettings_triggered()
instManager->setDownloadDirectory(settings.paths().downloads());
fixCategories();
- m_Filters->refresh();
+ refreshFilters();
if (settings.paths().profiles() != oldProfilesDirectory) {
refreshProfiles();
@@ -6083,6 +6087,69 @@ void MainWindow::deselectFilters()
m_Filters->clearSelection();
}
+void MainWindow::refreshFilters()
+{
+ QItemSelection currentSelection = ui->modList->selectionModel()->selection();
+
+ QVariant currentIndexName = ui->modList->currentIndex().data();
+ ui->modList->setCurrentIndex(QModelIndex());
+
+ m_Filters->refresh();
+
+ ui->modList->selectionModel()->select(currentSelection, QItemSelectionModel::Select);
+
+ QModelIndexList matchList;
+ if (currentIndexName.isValid()) {
+ matchList = ui->modList->model()->match(
+ ui->modList->model()->index(0, 0),
+ Qt::DisplayRole,
+ currentIndexName);
+ }
+
+ if (matchList.size() > 0) {
+ ui->modList->setCurrentIndex(matchList.at(0));
+ }
+}
+
+void MainWindow::onFilters(
+ const std::vector& categories, const std::vector& content)
+{
+ m_ModListSortProxy->setCategoryFilter(categories);
+ m_ModListSortProxy->setContentFilter(content);
+
+ QString label = "?";
+
+ if ((categories.size() + content.size()) > 1) {
+ label = tr("");
+ } else if (!categories.empty()) {
+ const int c = categories[0];
+ label = m_CategoryFactory.getCategoryNameByID(c);
+ if (label.isEmpty()) {
+ log::error("category '{}' not found", c);
+ }
+ } else if (!content.empty()) {
+ const int c = content[0];
+ try {
+ label = ModInfo::getContentTypeName(c);
+ }
+ catch(std::exception&) {
+ log::error("content filter '{}' not found", c);
+ }
+ } else {
+ label = "";
+ }
+
+ ui->currentCategoryLabel->setText(label);
+ ui->modList->reset();
+}
+
+void MainWindow::onFiltersCriteria(
+ ModListSortProxy::FilterMode mode, bool inverse, bool separators)
+{
+ m_ModListSortProxy->setFilterMode(mode);
+ m_ModListSortProxy->setFilterNot(inverse);
+ m_ModListSortProxy->setFilterSeparators(separators);
+}
void MainWindow::updateESPLock(bool locked)
{
@@ -6385,30 +6452,6 @@ void MainWindow::on_restoreModsButton_clicked()
}
}
-void MainWindow::on_categoriesAndBtn_toggled(bool checked)
-{
- if (checked) {
- m_ModListSortProxy->setFilterMode(ModListSortProxy::FILTER_AND);
- }
-}
-
-void MainWindow::on_categoriesOrBtn_toggled(bool checked)
-{
- if (checked) {
- m_ModListSortProxy->setFilterMode(ModListSortProxy::FILTER_OR);
- }
-}
-
-void MainWindow::on_categoriesNotBtn_toggled(bool checked)
-{
- m_ModListSortProxy->setFilterNot(checked);
-}
-
-void MainWindow::on_categoriesSeparators_toggled(bool checked)
-{
- m_ModListSortProxy->setFilterSeparators(checked);
-}
-
void MainWindow::on_managedArchiveLabel_linkHovered(const QString&)
{
QToolTip::showText(QCursor::pos(),
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 04ba7a35..9837378b 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -513,6 +513,9 @@ private slots:
void onRequestsChanged(const APIStats& stats, const APIUserAccount& user);
void deselectFilters();
+ void refreshFilters();
+ void onFilters(const std::vector& categories, const std::vector& content);
+ void onFiltersCriteria(ModListSortProxy::FilterMode mode, bool inverse, bool separators);
void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
@@ -651,10 +654,6 @@ private slots: // ui slots
void on_restoreButton_clicked();
void on_restoreModsButton_clicked();
void on_saveModsButton_clicked();
- void on_categoriesAndBtn_toggled(bool checked);
- void on_categoriesOrBtn_toggled(bool checked);
- void on_categoriesNotBtn_toggled(bool checked);
- void on_categoriesSeparators_toggled(bool checked);
void on_managedArchiveLabel_linkHovered(const QString &link);
void storeSettings();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 7e11c70e..ed35f783 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -66,7 +66,7 @@
1
-
-
+
120
@@ -96,7 +96,7 @@
-
-
+
false
@@ -130,7 +130,7 @@
-
-
+
Display mods that match all selected categories.
@@ -143,7 +143,7 @@
-
-
+
Display mods that match at least one of the selected categories
@@ -153,7 +153,7 @@
-
-
+
Invert each selected category
@@ -163,7 +163,7 @@
-
-
+
Include separators
--
cgit v1.3.1
From e99dfe153c62f914ada0605430305fca81a332a9 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 30 Nov 2019 01:53:09 -0500
Subject: renamed filters to criteria merged categories and content, they can
be distinguished using the type added a not flag for criteria, not used yet
---
src/filterlist.cpp | 116 +++++++++++++++++++++++++--------------------
src/filterlist.h | 14 +++---
src/mainwindow.cpp | 50 +++++++++-----------
src/mainwindow.h | 4 +-
src/mainwindow.ui | 38 +++++++--------
src/modlistsortproxy.cpp | 120 +++++++++++++++++------------------------------
src/modlistsortproxy.h | 42 +++++++++++------
7 files changed, 182 insertions(+), 202 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
index 5562736d..9e5437b3 100644
--- a/src/filterlist.cpp
+++ b/src/filterlist.cpp
@@ -6,6 +6,9 @@
using namespace MOBase;
+const int CategoryIDRole = Qt::UserRole;
+const int CategoryTypeRole = Qt::UserRole + 1;
+
FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
: ui(ui), m_factory(factory)
{
@@ -29,61 +32,76 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
ui->filtersOr, &QCheckBox::toggled,
[&]{ onCriteriaChanged(); });
- connect(
- ui->filtersNot, &QCheckBox::toggled,
- [&]{ onCriteriaChanged(); });
-
connect(
ui->filtersSeparators, &QCheckBox::toggled,
[&]{ onCriteriaChanged(); });
+
+ ui->filters->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ ui->filters->header()->resizeSection(1, 50);
}
-QTreeWidgetItem* FilterList::addFilterItem(
+QTreeWidgetItem* FilterList::addCriteriaItem(
QTreeWidgetItem *root, const QString &name, int categoryID,
- ModListSortProxy::FilterType type)
+ ModListSortProxy::CriteriaType type)
{
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
+
item->setData(0, Qt::ToolTipRole, name);
- item->setData(0, Qt::UserRole, categoryID);
- item->setData(0, Qt::UserRole + 1, type);
+ item->setData(0, CategoryIDRole, categoryID);
+ item->setData(0, CategoryTypeRole, type);
+
if (root != nullptr) {
root->addChild(item);
} else {
ui->filters->addTopLevelItem(item);
}
+
+ auto* w = new QWidget;
+ w->setStyleSheet("background-color: rgba(0,0,0,0)");
+
+ auto* ly = new QVBoxLayout(w);
+ ly->setAlignment(Qt::AlignCenter);
+ ly->setContentsMargins(0, 0, 0, 0);
+
+ auto* cb = new QCheckBox;
+ connect(cb, &QCheckBox::toggled, [&]{ onSelection(); });
+ ly->addWidget(cb);
+
+ ui->filters->setItemWidget(item, 1, w);
+
return item;
}
-void FilterList::addContentFilters()
+void FilterList::addContentCriteria()
{
for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) {
- addFilterItem(
+ addCriteriaItem(
nullptr, tr("").arg(ModInfo::getContentTypeName(i)),
i, ModListSortProxy::TYPE_CONTENT);
}
}
-void FilterList::addCategoryFilters(QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID)
+void FilterList::addCategoryCriteria(QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID)
{
- for (unsigned int i = 1;
- i < static_cast(m_factory.numCategories()); ++i) {
- if ((m_factory.getParentID(i) == targetID)) {
+ const auto count = static_cast(m_factory.numCategories());
+ for (unsigned int i = 1; i < count; ++i) {
+ if (m_factory.getParentID(i) == targetID) {
int categoryID = m_factory.getCategoryID(i);
if (categoriesUsed.find(categoryID) != categoriesUsed.end()) {
QTreeWidgetItem *item =
- addFilterItem(root, m_factory.getCategoryName(i),
+ addCriteriaItem(root, m_factory.getCategoryName(i),
categoryID, ModListSortProxy::TYPE_CATEGORY);
if (m_factory.hasChildren(i)) {
- addCategoryFilters(item, categoriesUsed, categoryID);
+ addCategoryCriteria(item, categoriesUsed, categoryID);
}
}
}
}
}
-void FilterList::addSpecialFilterItem(int type)
+void FilterList::addSpecialCriteria(int type)
{
- addFilterItem(
+ addCriteriaItem(
nullptr, m_factory.getSpecialCategoryName(type),
type, ModListSortProxy::TYPE_SPECIAL);
}
@@ -98,19 +116,19 @@ void FilterList::refresh()
ui->filters->clear();
using F = CategoryFactory;
- addSpecialFilterItem(F::CATEGORY_SPECIAL_CHECKED);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_UNCHECKED);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_UPDATEAVAILABLE);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_BACKUP);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_MANAGED);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_UNMANAGED);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_NOCATEGORY);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_CONFLICT);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_NOTENDORSED);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_NONEXUSID);
- addSpecialFilterItem(F::CATEGORY_SPECIAL_NOGAMEDATA);
-
- addContentFilters();
+ addSpecialCriteria(F::CATEGORY_SPECIAL_CHECKED);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_UNCHECKED);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_UPDATEAVAILABLE);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_BACKUP);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_MANAGED);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_UNMANAGED);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_NOCATEGORY);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_CONFLICT);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_NOTENDORSED);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_NONEXUSID);
+ addSpecialCriteria(F::CATEGORY_SPECIAL_NOGAMEDATA);
+
+ addContentCriteria();
std::set categoriesUsed;
for (unsigned int modIdx = 0; modIdx < ModInfo::getNumMods(); ++modIdx) {
@@ -130,7 +148,7 @@ void FilterList::refresh()
}
}
- addCategoryFilters(nullptr, categoriesUsed, 0);
+ addCategoryCriteria(nullptr, categoriesUsed, 0);
for (const QString &item : selectedItems) {
QList matches = ui->filters->findItems(
@@ -145,7 +163,7 @@ void FilterList::refresh()
void FilterList::setSelection(std::vector categories)
{
for (int i = 0; i < ui->filters->topLevelItemCount(); ++i) {
- if (ui->filters->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
+ if (ui->filters->topLevelItem(i)->data(0, CategoryIDRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
ui->filters->setCurrentItem(ui->filters->topLevelItem(i));
break;
}
@@ -159,27 +177,24 @@ void FilterList::clearSelection()
void FilterList::onSelection()
{
- QModelIndexList indices = ui->filters->selectionModel()->selectedRows();
- std::vector categories;
- std::vector content;
+ const QModelIndexList indices = ui->filters->selectionModel()->selectedRows();
+ std::vector criteria;
- for (const QModelIndex &index : indices) {
- const int filterType = index.data(Qt::UserRole + 1).toInt();
+ for (auto* item: ui->filters->selectedItems()) {
+ const auto type = static_cast(
+ item->data(0, CategoryTypeRole).toInt());
- if ((filterType == ModListSortProxy::TYPE_CATEGORY) || (filterType == ModListSortProxy::TYPE_SPECIAL)) {
- const int categoryId = index.data(Qt::UserRole).toInt();
- if (categoryId != CategoryFactory::CATEGORY_NONE) {
- categories.push_back(categoryId);
- }
- } else if (filterType == ModListSortProxy::TYPE_CONTENT) {
- const int contentId = index.data(Qt::UserRole).toInt();
- content.push_back(contentId);
- }
+ const int id = item->data(0, CategoryIDRole).toInt();
+
+ auto* cb = static_cast(ui->filters->itemWidget(item, 1));
+ const bool inverse = cb->isChecked();
+
+ criteria.push_back({type, id, inverse});
}
- ui->filtersClear->setEnabled(categories.size() > 0 || content.size() >0);
+ ui->filtersClear->setEnabled(!criteria.empty());
- emit filtersChanged(categories, content);
+ emit criteriaChanged(criteria);
}
void FilterList::onContextMenu(const QPoint &pos)
@@ -205,8 +220,7 @@ void FilterList::onCriteriaChanged()
const auto mode = ui->filtersAnd->isChecked() ?
ModListSortProxy::FILTER_AND : ModListSortProxy::FILTER_OR;
- const bool inverse = ui->filtersNot->isChecked();
const bool separators = ui->filtersSeparators->isChecked();
- emit criteriaChanged(mode, inverse, separators);
+ emit optionsChanged(mode, separators);
}
diff --git a/src/filterlist.h b/src/filterlist.h
index 85982392..418989e7 100644
--- a/src/filterlist.h
+++ b/src/filterlist.h
@@ -19,8 +19,8 @@ public:
void refresh();
signals:
- void filtersChanged(std::vector categories, std::vector content);
- void criteriaChanged(ModListSortProxy::FilterMode mode, bool inverse, bool separators);
+ void criteriaChanged(std::vector criteria);
+ void optionsChanged(ModListSortProxy::FilterMode mode, bool separators);
private:
Ui::MainWindow* ui;
@@ -32,14 +32,14 @@ private:
void editCategories();
- QTreeWidgetItem* addFilterItem(
+ QTreeWidgetItem* addCriteriaItem(
QTreeWidgetItem *root, const QString &name, int categoryID,
- ModListSortProxy::FilterType type);
+ ModListSortProxy::CriteriaType type);
- void addContentFilters();
- void addCategoryFilters(
+ void addContentCriteria();
+ void addCategoryCriteria(
QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID);
- void addSpecialFilterItem(int type);
+ void addSpecialCriteria(int type);
};
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 1319d906..03d61bc6 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -264,12 +264,12 @@ MainWindow::MainWindow(Settings &settings
m_Filters.reset(new FilterList(ui, m_CategoryFactory));
connect(
- m_Filters.get(), &FilterList::filtersChanged,
- [&](auto&& cats, auto&& content) { onFilters(cats, content); });
+ m_Filters.get(), &FilterList::criteriaChanged,
+ [&](auto&& v) { onFiltersCriteria(v); });
connect(
- m_Filters.get(), &FilterList::criteriaChanged,
- [&](auto mode, bool inv, bool sep) { onFiltersCriteria(mode, inv, sep); });
+ m_Filters.get(), &FilterList::optionsChanged,
+ [&](auto mode, bool sep) { onFiltersOptions(mode, sep); });
ui->logList->setCore(m_OrganizerCore);
@@ -4124,7 +4124,12 @@ void MainWindow::checkModsForUpdates()
}
if (updatesAvailable || checkingModsForUpdate) {
- m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE));
+ m_ModListSortProxy->setCriteria({{
+ ModListSortProxy::TYPE_SPECIAL,
+ CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE,
+ false}
+ });
+
m_Filters->setSelection({CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE});
}
}
@@ -6111,44 +6116,31 @@ void MainWindow::refreshFilters()
}
}
-void MainWindow::onFilters(
- const std::vector& categories, const std::vector& content)
+void MainWindow::onFiltersCriteria(const std::vector& criteria)
{
- m_ModListSortProxy->setCategoryFilter(categories);
- m_ModListSortProxy->setContentFilter(content);
+ m_ModListSortProxy->setCriteria(criteria);
QString label = "?";
- if ((categories.size() + content.size()) > 1) {
- label = tr("");
- } else if (!categories.empty()) {
- const int c = categories[0];
- label = m_CategoryFactory.getCategoryNameByID(c);
+ if (criteria.empty()) {
+ label = "";
+ } else if (criteria.size() == 1) {
+ const auto& c = criteria[0];
+ label = m_CategoryFactory.getCategoryNameByID(c.id);
if (label.isEmpty()) {
- log::error("category '{}' not found", c);
- }
- } else if (!content.empty()) {
- const int c = content[0];
- try {
- label = ModInfo::getContentTypeName(c);
- }
- catch(std::exception&) {
- log::error("content filter '{}' not found", c);
+ log::error("category '{}' not found", c.id);
}
} else {
- label = "";
+ label = tr("");
}
ui->currentCategoryLabel->setText(label);
ui->modList->reset();
}
-void MainWindow::onFiltersCriteria(
- ModListSortProxy::FilterMode mode, bool inverse, bool separators)
+void MainWindow::onFiltersOptions(ModListSortProxy::FilterMode mode, bool separators)
{
- m_ModListSortProxy->setFilterMode(mode);
- m_ModListSortProxy->setFilterNot(inverse);
- m_ModListSortProxy->setFilterSeparators(separators);
+ m_ModListSortProxy->setOptions(mode, separators);
}
void MainWindow::updateESPLock(bool locked)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9837378b..0b559300 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -514,8 +514,8 @@ private slots:
void deselectFilters();
void refreshFilters();
- void onFilters(const std::vector& categories, const std::vector& content);
- void onFiltersCriteria(ModListSortProxy::FilterMode mode, bool inverse, bool separators);
+ void onFiltersCriteria(const std::vector& filters);
+ void onFiltersOptions(ModListSortProxy::FilterMode mode, bool separators);
void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index ed35f783..7cc7dca4 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -85,12 +85,26 @@
true
+
+ false
+
+ true
+
+
+ true
+
+
false
- 1
+ Category
+
+
+
+
+ Invert
@@ -152,16 +166,6 @@
- -
-
-
- Invert each selected category
-
-
- Not
-
-
-
-
@@ -351,9 +355,6 @@ p, li { white-space: pre-wrap; }
Qt::CustomContextMenu
-
- List of available mods.
-
This is a list of installed mods. Use the checkboxes to activate/deactivate mods and drag & drop mods to change their "installation" orders.
@@ -448,14 +449,7 @@ p, li { white-space: pre-wrap; }
-
-
-
-
- 8
- true
-
-
-
+
-
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index d2a5e258..646401b9 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -38,7 +38,6 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent)
, m_Profile(profile)
, m_FilterActive(false)
, m_FilterMode(FILTER_AND)
- , m_FilterNot(false)
, m_FilterSeparators(false)
{
setDynamicSortFilter(true); // this seems to work without dynamicsortfilter
@@ -52,26 +51,20 @@ void ModListSortProxy::setProfile(Profile *profile)
void ModListSortProxy::updateFilterActive()
{
- m_FilterActive = ((m_CategoryFilter.size() > 0)
- || (m_ContentFilter.size() > 0)
- || !m_CurrentFilter.isEmpty());
+ m_FilterActive = (!m_Criteria.empty() || !m_Filter.isEmpty());
emit filterActive(m_FilterActive);
}
-void ModListSortProxy::setCategoryFilter(const std::vector &categories)
+void ModListSortProxy::setCriteria(const std::vector& criteria)
{
- //avoid refreshing the filter unless we are checking all mods for update.
- if (categories != m_CategoryFilter || (!categories.empty() && categories.at(0) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)) {
- m_CategoryFilter = categories;
- updateFilterActive();
- invalidate();
- }
-}
-
-void ModListSortProxy::setContentFilter(const std::vector &content)
-{
- if (content != m_ContentFilter) {
- m_ContentFilter = content;
+ // avoid refreshing the filter unless we are checking all mods for update.
+ const bool changed = (criteria != m_Criteria);
+ const bool isForUpdates = (
+ !criteria.empty() &&
+ criteria[0].id == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE);
+
+ if (changed || isForUpdates) {
+ m_Criteria = criteria;
updateFilterActive();
invalidate();
}
@@ -248,12 +241,10 @@ bool ModListSortProxy::lessThan(const QModelIndex &left,
return lt;
}
-void ModListSortProxy::updateFilter(const QString &filter)
+void ModListSortProxy::updateFilter(const QString& filter)
{
- m_CurrentFilter = filter;
+ m_Filter = filter;
updateFilterActive();
- // using invalidateFilter here should be enough but that crashes the application? WTF?
- // invalidateFilter();
invalidate();
}
@@ -282,14 +273,8 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons
return false;
}
- for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
- if (!categoryMatchesMod(info, enabled, *iter)) {
- return false;
- }
- }
-
- foreach (int content, m_ContentFilter) {
- if (!contentMatchesMod(info, enabled, content)) {
+ for (auto&& c : m_Criteria) {
+ if (!criteriaMatchesMod(info, enabled, c)) {
return false;
}
}
@@ -303,29 +288,35 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
return false;
}
- for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
- if (categoryMatchesMod(info, enabled, *iter)) {
+ for (auto&& c : m_Criteria) {
+ if (criteriaMatchesMod(info, enabled, c)) {
return true;
}
}
- if (!m_CategoryFilter.empty()) {
+ if (!m_Criteria.empty()) {
// nothing matched
return false;
}
- foreach (int content, m_ContentFilter) {
- if (contentMatchesMod(info, enabled, content)) {
- return true;
- }
- }
+ return true;
+}
- if (!m_ContentFilter.empty()) {
- // nothing matched
- return false;
- }
+bool ModListSortProxy::criteriaMatchesMod(
+ ModInfo::Ptr info, bool enabled, const Criteria& c) const
+{
+ switch (c.type)
+ {
+ case TYPE_SPECIAL: // fall-through
+ case TYPE_CATEGORY:
+ return categoryMatchesMod(info, enabled, c.id);
- return true;
+ case TYPE_CONTENT:
+ return contentMatchesMod(info, enabled, c.id);
+
+ default:
+ return false;
+ }
}
bool ModListSortProxy::categoryMatchesMod(
@@ -414,29 +405,19 @@ bool ModListSortProxy::categoryMatchesMod(
}
}
- if (m_FilterNot) {
- b = !b;
- }
-
return b;
}
bool ModListSortProxy::contentMatchesMod(ModInfo::Ptr info, bool enabled, int content) const
{
- bool b = info->hasContent(static_cast(content));
-
- if (m_FilterNot) {
- b = !b;
- }
-
- return b;
+ return info->hasContent(static_cast(content));
}
bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
{
- if (!m_CurrentFilter.isEmpty()) {
+ if (!m_Filter.isEmpty()) {
bool display = false;
- QString filterCopy = QString(m_CurrentFilter);
+ QString filterCopy = QString(m_Filter);
filterCopy.replace("||", ";").replace("OR", ";").replace("|", ";");
QStringList ORList = filterCopy.split(";", QString::SkipEmptyParts);
@@ -527,26 +508,11 @@ void ModListSortProxy::setColumnVisible(int column, bool visible)
m_EnabledColumns[column] = visible;
}
-void ModListSortProxy::setFilterMode(ModListSortProxy::FilterMode mode)
+void ModListSortProxy::setOptions(ModListSortProxy::FilterMode mode, bool separators)
{
- if (m_FilterMode != mode) {
+ if (m_FilterMode != mode || separators != m_FilterSeparators) {
m_FilterMode = mode;
- this->invalidate();
- }
-}
-
-void ModListSortProxy::setFilterNot(bool b)
-{
- if (b != m_FilterNot) {
- m_FilterNot = b;
- this->invalidate();
- }
-}
-
-void ModListSortProxy::setFilterSeparators(bool b)
-{
- if (b != m_FilterSeparators) {
- m_FilterSeparators = b;
+ m_FilterSeparators = separators;
this->invalidate();
}
}
@@ -623,8 +589,8 @@ void ModListSortProxy::aboutToChangeData()
// (at least with some Qt versions)
// this may be related to the fact that the item being edited may disappear from the view as a
// result of the edit
- m_PreChangeFilters = categoryFilter();
- setCategoryFilter(std::vector());
+ m_PreChangeCriteria = m_Criteria;
+ setCriteria({});
}
void ModListSortProxy::postDataChanged()
@@ -633,8 +599,8 @@ void ModListSortProxy::postDataChanged()
// or at least the view continues to think it's being edited. As a result no new editor can be
// opened
QTimer::singleShot(10, [this] () {
- setCategoryFilter(m_PreChangeFilters);
- m_PreChangeFilters.clear();
+ setCriteria(m_PreChangeCriteria);
+ m_PreChangeCriteria.clear();
});
}
diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h
index 2ebfbcf0..5aeaccce 100644
--- a/src/modlistsortproxy.h
+++ b/src/modlistsortproxy.h
@@ -37,22 +37,38 @@ public:
FILTER_OR
};
- enum FilterType {
+ enum CriteriaType {
TYPE_SPECIAL,
TYPE_CATEGORY,
TYPE_CONTENT
};
+ struct Criteria
+ {
+ CriteriaType type;
+ int id;
+ bool inverse;
+
+ bool operator==(const Criteria& other) const
+ {
+ return
+ (type == other.type) &&
+ (id == other.id) &&
+ (inverse == other.inverse);
+ }
+
+ bool operator!=(const Criteria& other) const
+ {
+ return !(*this == other);
+ }
+ };
+
public:
explicit ModListSortProxy(Profile *profile, QObject *parent = 0);
void setProfile(Profile *profile);
- void setCategoryFilter(const std::vector &categories);
- std::vector categoryFilter() const { return m_CategoryFilter; }
-
- void setContentFilter(const std::vector &content);
virtual Qt::ItemFlags flags(const QModelIndex &modelIndex) const;
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
@@ -84,9 +100,8 @@ public:
*/
bool isFilterActive() const { return m_FilterActive; }
- void setFilterMode(FilterMode mode);
- void setFilterNot(bool b);
- void setFilterSeparators(bool b);
+ void setCriteria(const std::vector& criteria);
+ void setOptions(FilterMode mode, bool separators);
/**
* @brief tests if the specified index has child nodes
@@ -131,19 +146,18 @@ private slots:
void postDataChanged();
private:
- Profile *m_Profile;
- std::vector m_CategoryFilter;
- std::vector m_ContentFilter;
+ Profile* m_Profile;
+ std::vector m_Criteria;
+ QString m_Filter;
std::bitset m_EnabledColumns;
- QString m_CurrentFilter;
bool m_FilterActive;
FilterMode m_FilterMode;
- bool m_FilterNot;
bool m_FilterSeparators;
- std::vector m_PreChangeFilters;
+ std::vector m_PreChangeCriteria;
+ bool criteriaMatchesMod(ModInfo::Ptr info, bool enabled, const Criteria& c) const;
bool categoryMatchesMod(ModInfo::Ptr info, bool enabled, int category) const;
bool contentMatchesMod(ModInfo::Ptr info, bool enabled, int content) const;
};
--
cgit v1.3.1
From a38d1723bffcd20bc7011c0fe635636b936aa78b Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 30 Nov 2019 03:21:23 -0500
Subject: removed redundant categories now that there's a not filter disabled
collapsing for filter, there's already a button to hide it
---
src/categories.cpp | 24 +++++++++++-------------
src/categories.h | 31 +++++++++++++------------------
src/filterlist.cpp | 28 +++++++++++++++-------------
src/mainwindow.cpp | 4 ++--
src/mainwindow.ui | 3 +++
src/modlistsortproxy.cpp | 32 ++++++++++----------------------
6 files changed, 54 insertions(+), 68 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/categories.cpp b/src/categories.cpp
index b75efefa..1bd56f7f 100644
--- a/src/categories.cpp
+++ b/src/categories.cpp
@@ -320,21 +320,19 @@ QString CategoryFactory::getCategoryName(unsigned int index) const
return m_Categories[index].m_Name;
}
-QString CategoryFactory::getSpecialCategoryName(int type) const
+QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const
{
switch (type)
{
- case CATEGORY_SPECIAL_CHECKED: return QObject::tr("");
- case CATEGORY_SPECIAL_UNCHECKED: return QObject::tr("");
- case CATEGORY_SPECIAL_UPDATEAVAILABLE: return QObject::tr("");
- case CATEGORY_SPECIAL_NOCATEGORY: return QObject::tr("");
- case CATEGORY_SPECIAL_CONFLICT: return QObject::tr("");
- case CATEGORY_SPECIAL_NOTENDORSED: return QObject::tr("");
- case CATEGORY_SPECIAL_BACKUP: return QObject::tr("");
- case CATEGORY_SPECIAL_MANAGED: return QObject::tr("");
- case CATEGORY_SPECIAL_UNMANAGED: return QObject::tr("");
- case CATEGORY_SPECIAL_NOGAMEDATA: return QObject::tr("");
- case CATEGORY_SPECIAL_NONEXUSID: return QObject::tr("");
+ case Checked: return QObject::tr("");
+ case UpdateAvailable: return QObject::tr("");
+ case HasNoCategory: return QObject::tr("");
+ case Conflict: return QObject::tr("");
+ case NotEndorsed: return QObject::tr("");
+ case Backup: return QObject::tr("");
+ case Managed: return QObject::tr("");
+ case NoGameData: return QObject::tr("");
+ case NoNexusID: return QObject::tr("");
default: return {};
}
}
@@ -344,7 +342,7 @@ QString CategoryFactory::getCategoryNameByID(int id) const
auto itor = m_IDMap.find(id);
if (itor == m_IDMap.end()) {
- return getSpecialCategoryName(id);
+ return getSpecialCategoryName(static_cast(id));
} else {
const auto index = itor->second;
if (index >= m_Categories.size()) {
diff --git a/src/categories.h b/src/categories.h
index 2041ce1f..296e7711 100644
--- a/src/categories.h
+++ b/src/categories.h
@@ -37,25 +37,20 @@ class CategoryFactory {
friend class CategoriesDialog;
public:
-
- static const int CATEGORY_NONE = 0;
-
- static const int CATEGORY_SPECIAL_FIRST = 10000;
- static const int CATEGORY_SPECIAL_CHECKED = CATEGORY_SPECIAL_FIRST;
- static const int CATEGORY_SPECIAL_UNCHECKED = 10001;
- static const int CATEGORY_SPECIAL_UPDATEAVAILABLE = 10002;
- static const int CATEGORY_SPECIAL_NOCATEGORY = 10003;
- static const int CATEGORY_SPECIAL_CONFLICT = 10004;
- static const int CATEGORY_SPECIAL_NOTENDORSED = 10005;
- static const int CATEGORY_SPECIAL_BACKUP = 10006;
- static const int CATEGORY_SPECIAL_MANAGED = 10007;
- static const int CATEGORY_SPECIAL_UNMANAGED = 10008;
- static const int CATEGORY_SPECIAL_NOGAMEDATA = 10009;
- static const int CATEGORY_SPECIAL_NONEXUSID = 10010;
-
+ enum SpecialCategories
+ {
+ Checked = 10000,
+ UpdateAvailable,
+ HasNoCategory,
+ Conflict,
+ NotEndorsed,
+ Backup,
+ Managed,
+ NoGameData,
+ NoNexusID
+ };
public:
-
struct Category {
Category(int sortValue, int id, const QString &name, const std::vector &nexusIDs, int parentID)
: m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false),
@@ -144,7 +139,7 @@ public:
* @return QString name of the category
**/
QString getCategoryName(unsigned int index) const;
- QString getSpecialCategoryName(int type) const;
+ QString getSpecialCategoryName(SpecialCategories type) const;
QString getCategoryNameByID(int id) const;
/**
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
index 8f297af6..36cdacd0 100644
--- a/src/filterlist.cpp
+++ b/src/filterlist.cpp
@@ -94,6 +94,8 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
ui->filters->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->filters->header()->resizeSection(1, 50);
+ ui->categoriesSplitter->setCollapsible(0, false);
+ ui->categoriesSplitter->setCollapsible(1, false);
}
QTreeWidgetItem* FilterList::addCriteriaItem(
@@ -142,8 +144,10 @@ void FilterList::addCategoryCriteria(QTreeWidgetItem *root, const std::set
void FilterList::addSpecialCriteria(int type)
{
+ const auto sc = static_cast(type);
+
addCriteriaItem(
- nullptr, m_factory.getSpecialCategoryName(type),
+ nullptr, m_factory.getSpecialCategoryName(sc),
type, ModListSortProxy::TYPE_SPECIAL);
}
@@ -157,17 +161,15 @@ void FilterList::refresh()
ui->filters->clear();
using F = CategoryFactory;
- addSpecialCriteria(F::CATEGORY_SPECIAL_CHECKED);
- addSpecialCriteria(F::CATEGORY_SPECIAL_UNCHECKED);
- addSpecialCriteria(F::CATEGORY_SPECIAL_UPDATEAVAILABLE);
- addSpecialCriteria(F::CATEGORY_SPECIAL_BACKUP);
- addSpecialCriteria(F::CATEGORY_SPECIAL_MANAGED);
- addSpecialCriteria(F::CATEGORY_SPECIAL_UNMANAGED);
- addSpecialCriteria(F::CATEGORY_SPECIAL_NOCATEGORY);
- addSpecialCriteria(F::CATEGORY_SPECIAL_CONFLICT);
- addSpecialCriteria(F::CATEGORY_SPECIAL_NOTENDORSED);
- addSpecialCriteria(F::CATEGORY_SPECIAL_NONEXUSID);
- addSpecialCriteria(F::CATEGORY_SPECIAL_NOGAMEDATA);
+ addSpecialCriteria(F::Checked);
+ addSpecialCriteria(F::UpdateAvailable);
+ addSpecialCriteria(F::Backup);
+ addSpecialCriteria(F::Managed);
+ addSpecialCriteria(F::HasNoCategory);
+ addSpecialCriteria(F::Conflict);
+ addSpecialCriteria(F::NotEndorsed);
+ addSpecialCriteria(F::NoNexusID);
+ addSpecialCriteria(F::NoGameData);
addContentCriteria();
@@ -211,7 +213,7 @@ void FilterList::setSelection(std::vector categories)
continue;
}
- if (item->id() == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) {
+ if (item->id() == CategoryFactory::UpdateAvailable) {
ui->filters->setCurrentItem(ui->filters->topLevelItem(i));
break;
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 03d61bc6..0ad57803 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4126,11 +4126,11 @@ void MainWindow::checkModsForUpdates()
if (updatesAvailable || checkingModsForUpdate) {
m_ModListSortProxy->setCriteria({{
ModListSortProxy::TYPE_SPECIAL,
- CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE,
+ CategoryFactory::UpdateAvailable,
false}
});
- m_Filters->setSelection({CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE});
+ m_Filters->setSelection({CategoryFactory::UpdateAvailable});
}
}
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 7cc7dca4..6c35d239 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -39,6 +39,9 @@
Qt::Horizontal
+
+ false
+
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index 3bb02c0f..36dcae59 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -61,7 +61,7 @@ void ModListSortProxy::setCriteria(const std::vector& criteria)
const bool changed = (criteria != m_Criteria);
const bool isForUpdates = (
!criteria.empty() &&
- criteria[0].id == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE);
+ criteria[0].id == CategoryFactory::UpdateAvailable);
if (changed || isForUpdates) {
m_Criteria = criteria;
@@ -343,68 +343,56 @@ bool ModListSortProxy::categoryMatchesMod(
switch (category)
{
- case CategoryFactory::CATEGORY_SPECIAL_CHECKED:
+ case CategoryFactory::Checked:
{
b = (enabled || info->alwaysEnabled());
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_UNCHECKED:
- {
- b = (!enabled && !info->alwaysEnabled());
- break;
- }
-
- case CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE:
+ case CategoryFactory::UpdateAvailable:
{
b = (info->updateAvailable() || info->downgradeAvailable());
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY:
+ case CategoryFactory::HasNoCategory:
{
b = (info->getCategories().size() == 0);
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_CONFLICT:
+ case CategoryFactory::Conflict:
{
b = (hasConflictFlag(info->getFlags()));
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED:
+ case CategoryFactory::NotEndorsed:
{
ModInfo::EEndorsedState state = info->endorsedState();
b = (state != ModInfo::ENDORSED_TRUE);
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_BACKUP:
+ case CategoryFactory::Backup:
{
b = (info->hasFlag(ModInfo::FLAG_BACKUP));
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_MANAGED:
+ case CategoryFactory::Managed:
{
b = (!info->hasFlag(ModInfo::FLAG_FOREIGN));
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_UNMANAGED:
- {
- b = (info->hasFlag(ModInfo::FLAG_FOREIGN));
- break;
- }
-
- case CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA:
+ case CategoryFactory::NoGameData:
{
b = (info->hasFlag(ModInfo::FLAG_INVALID));
break;
}
- case CategoryFactory::CATEGORY_SPECIAL_NONEXUSID:
+ case CategoryFactory::NoNexusID:
{
b = (
info->getNexusID() == -1 &&
--
cgit v1.3.1
From 507d29a0fc0765f0f8de49795eb100a258970d01 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 30 Nov 2019 03:29:54 -0500
Subject: fixed bad label for content categories
---
src/mainwindow.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0ad57803..420242ad 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -6126,9 +6126,15 @@ void MainWindow::onFiltersCriteria(const std::vector
label = "";
} else if (criteria.size() == 1) {
const auto& c = criteria[0];
- label = m_CategoryFactory.getCategoryNameByID(c.id);
+
+ if (c.type == ModListSortProxy::TYPE_CONTENT) {
+ label = ModInfo::getContentTypeName(c.id);
+ } else {
+ label = m_CategoryFactory.getCategoryNameByID(c.id);
+ }
+
if (label.isEmpty()) {
- log::error("category '{}' not found", c.id);
+ log::error("category {}:{} not found", c.type, c.id);
}
} else {
label = tr("");
--
cgit v1.3.1
From 38d56ef8310674bc5a2f8b304ee17a6b7e1c5798 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 30 Nov 2019 04:04:40 -0500
Subject: fixed setting selection when checking for updates
---
src/filterlist.cpp | 10 ++++++----
src/filterlist.h | 2 +-
src/mainwindow.cpp | 6 +++++-
3 files changed, 12 insertions(+), 6 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
index 66a9aed0..81f8b670 100644
--- a/src/filterlist.cpp
+++ b/src/filterlist.cpp
@@ -203,7 +203,7 @@ void FilterList::refresh()
}
}
-void FilterList::setSelection(std::vector categories)
+void FilterList::setSelection(const std::vector& criteria)
{
for (int i = 0; i < ui->filters->topLevelItemCount(); ++i) {
const auto* item = dynamic_cast(
@@ -213,9 +213,11 @@ void FilterList::setSelection(std::vector categories)
continue;
}
- if (item->id() == CategoryFactory::UpdateAvailable) {
- ui->filters->setCurrentItem(ui->filters->topLevelItem(i));
- break;
+ for (auto&& c : criteria) {
+ if (item->type() == c.type && item->id() == c.id) {
+ ui->filters->setCurrentItem(ui->filters->topLevelItem(i));
+ break;
+ }
}
}
}
diff --git a/src/filterlist.h b/src/filterlist.h
index e98f81a9..52b90ea7 100644
--- a/src/filterlist.h
+++ b/src/filterlist.h
@@ -14,7 +14,7 @@ class FilterList : public QObject
public:
FilterList(Ui::MainWindow* ui, CategoryFactory& factory);
- void setSelection(std::vector categories);
+ void setSelection(const std::vector& criteria);
void clearSelection();
void refresh();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 420242ad..096ea076 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4130,7 +4130,11 @@ void MainWindow::checkModsForUpdates()
false}
});
- m_Filters->setSelection({CategoryFactory::UpdateAvailable});
+ m_Filters->setSelection({{
+ ModListSortProxy::TYPE_SPECIAL,
+ CategoryFactory::UpdateAvailable,
+ false
+ }});
}
}
--
cgit v1.3.1
From 3c25117fe163f7fab7afa22ba171ea2d41112f23 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Mon, 2 Dec 2019 10:41:52 -0500
Subject: three modes for separators, save state renamed enumerators
---
src/filterlist.cpp | 28 ++++++++++++++++-----
src/filterlist.h | 7 +++++-
src/mainwindow.cpp | 16 +++++++-----
src/mainwindow.h | 3 ++-
src/mainwindow.ui | 21 ++++++++++++----
src/modlistsortproxy.cpp | 65 +++++++++++++++++++++++++++++-------------------
src/modlistsortproxy.h | 25 ++++++++++++-------
7 files changed, 112 insertions(+), 53 deletions(-)
(limited to 'src/mainwindow.cpp')
diff --git a/src/filterlist.cpp b/src/filterlist.cpp
index b65f0f4a..05bff2dd 100644
--- a/src/filterlist.cpp
+++ b/src/filterlist.cpp
@@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include "categories.h"
#include "categoriesdialog.h"
+#include "settings.h"
#include
using namespace MOBase;
@@ -157,7 +158,7 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
[&]{ onOptionsChanged(); });
connect(
- ui->filtersSeparators, &QCheckBox::toggled,
+ ui->filtersSeparators, qOverload(&QComboBox::currentIndexChanged),
[&]{ onOptionsChanged(); });
ui->filters->header()->setMinimumSectionSize(0);
@@ -165,6 +166,20 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
ui->filters->header()->resizeSection(0, 30);
ui->categoriesSplitter->setCollapsible(0, false);
ui->categoriesSplitter->setCollapsible(1, false);
+
+ ui->filtersSeparators->addItem(tr("Filter separators"), ModListSortProxy::SeparatorFilter);
+ ui->filtersSeparators->addItem(tr("Show separators"), ModListSortProxy::SeparatorShow);
+ ui->filtersSeparators->addItem(tr("Hide separators"), ModListSortProxy::SeparatorHide);
+}
+
+void FilterList::restoreState(const Settings& s)
+{
+ s.widgets().restoreIndex(ui->filtersSeparators);
+}
+
+void FilterList::saveState(Settings& s) const
+{
+ s.widgets().saveIndex(ui->filtersSeparators);
}
QTreeWidgetItem* FilterList::addCriteriaItem(
@@ -189,7 +204,7 @@ void FilterList::addContentCriteria()
for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) {
addCriteriaItem(
nullptr, tr("").arg(ModInfo::getContentTypeName(i)),
- i, ModListSortProxy::TYPE_CONTENT);
+ i, ModListSortProxy::TypeContent);
}
}
@@ -202,7 +217,7 @@ void FilterList::addCategoryCriteria(QTreeWidgetItem *root, const std::set
if (categoriesUsed.find(categoryID) != categoriesUsed.end()) {
QTreeWidgetItem *item =
addCriteriaItem(root, m_factory.getCategoryName(i),
- categoryID, ModListSortProxy::TYPE_CATEGORY);
+ categoryID, ModListSortProxy::TypeCategory);
if (m_factory.hasChildren(i)) {
addCategoryCriteria(item, categoriesUsed, categoryID);
}
@@ -217,7 +232,7 @@ void FilterList::addSpecialCriteria(int type)
addCriteriaItem(
nullptr, m_factory.getSpecialCategoryName(sc),
- type, ModListSortProxy::TYPE_SPECIAL);
+ type, ModListSortProxy::TypeSpecial);
}
void FilterList::refresh()
@@ -361,9 +376,10 @@ void FilterList::editCategories()
void FilterList::onOptionsChanged()
{
const auto mode = ui->filtersAnd->isChecked() ?
- ModListSortProxy::FILTER_AND : ModListSortProxy::FILTER_OR;
+ ModListSortProxy::FilterAnd: ModListSortProxy::FilterOr;
- const bool separators = ui->filtersSeparators->isChecked();
+ const auto separators = static_cast(
+ ui->filtersSeparators->currentData().toInt());
emit optionsChanged(mode, separators);
}
diff --git a/src/filterlist.h b/src/filterlist.h
index fac1d683..671462d4 100644
--- a/src/filterlist.h
+++ b/src/filterlist.h
@@ -6,6 +6,7 @@
namespace Ui { class MainWindow; };
class CategoryFactory;
+class Settings;
class FilterList : public QObject
{
@@ -14,13 +15,17 @@ class FilterList : public QObject
public:
FilterList(Ui::MainWindow* ui, CategoryFactory& factory);
+ void restoreState(const Settings& s);
+ void saveState(Settings& s) const;
+
void setSelection(const std::vector& criteria);
void clearSelection();
void refresh();
signals:
void criteriaChanged(std::vector criteria);
- void optionsChanged(ModListSortProxy::FilterMode mode, bool separators);
+ void optionsChanged(
+ ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep);
private:
class CriteriaItem;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 096ea076..b5af9aa5 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -269,7 +269,7 @@ MainWindow::MainWindow(Settings &settings
connect(
m_Filters.get(), &FilterList::optionsChanged,
- [&](auto mode, bool sep) { onFiltersOptions(mode, sep); });
+ [&](auto&& mode, auto&& sep) { onFiltersOptions(mode, sep); });
ui->logList->setCore(m_OrganizerCore);
@@ -2205,6 +2205,7 @@ void MainWindow::readSettings()
}
s.widgets().restoreIndex(ui->groupCombo);
+ m_Filters->restoreState(s);
{
s.geometry().restoreVisibility(ui->categoriesGroup, false);
@@ -2283,6 +2284,8 @@ void MainWindow::storeSettings()
s.widgets().saveIndex(ui->groupCombo);
s.widgets().saveIndex(ui->executablesListBox);
+
+ m_Filters->saveState(s);
}
QWidget* MainWindow::qtWidget()
@@ -4125,13 +4128,13 @@ void MainWindow::checkModsForUpdates()
if (updatesAvailable || checkingModsForUpdate) {
m_ModListSortProxy->setCriteria({{
- ModListSortProxy::TYPE_SPECIAL,
+ ModListSortProxy::TypeSpecial,
CategoryFactory::UpdateAvailable,
false}
});
m_Filters->setSelection({{
- ModListSortProxy::TYPE_SPECIAL,
+ ModListSortProxy::TypeSpecial,
CategoryFactory::UpdateAvailable,
false
}});
@@ -6131,7 +6134,7 @@ void MainWindow::onFiltersCriteria(const std::vector
} else if (criteria.size() == 1) {
const auto& c = criteria[0];
- if (c.type == ModListSortProxy::TYPE_CONTENT) {
+ if (c.type == ModListSortProxy::TypeContent) {
label = ModInfo::getContentTypeName(c.id);
} else {
label = m_CategoryFactory.getCategoryNameByID(c.id);
@@ -6148,9 +6151,10 @@ void MainWindow::onFiltersCriteria(const std::vector
ui->modList->reset();
}
-void MainWindow::onFiltersOptions(ModListSortProxy::FilterMode mode, bool separators)
+void MainWindow::onFiltersOptions(
+ ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep)
{
- m_ModListSortProxy->setOptions(mode, separators);
+ m_ModListSortProxy->setOptions(mode, sep);
}
void MainWindow::updateESPLock(bool locked)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 0b559300..69aee073 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -515,7 +515,8 @@ private slots:
void deselectFilters();
void refreshFilters();
void onFiltersCriteria(const std::vector& filters);
- void onFiltersOptions(ModListSortProxy::FilterMode mode, bool separators);
+ void onFiltersOptions(
+ ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep);
void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 92a41c67..85be22b3 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -153,6 +153,18 @@
+
+ 0
+
+
+ 2
+
+
+ 0
+
+
+ 0
+
-
@@ -177,12 +189,11 @@
-
-
+
- Include separators
-
-
- Separators
+ Filter: only show the separators that match the current filters
+Show: always show separators
+Hide: never show separators
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index fd3dbc9e..7ac98f66 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -37,8 +37,8 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent)
: QSortFilterProxyModel(parent)
, m_Profile(profile)
, m_FilterActive(false)
- , m_FilterMode(FILTER_AND)
- , m_FilterSeparators(false)
+ , m_FilterMode(FilterAnd)
+ , m_FilterSeparators(SeparatorFilter)
{
setDynamicSortFilter(true); // this seems to work without dynamicsortfilter
// but I don't know why. This should be necessary
@@ -269,10 +269,6 @@ bool ModListSortProxy::hasConflictFlag(const std::vector &flags)
bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const
{
- if (!optionsMatchMod(info, enabled)) {
- return false;
- }
-
for (auto&& c : m_Criteria) {
if (!criteriaMatchMod(info, enabled, c)) {
return false;
@@ -284,10 +280,6 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons
bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
{
- if (!optionsMatchMod(info, enabled)) {
- return false;
- }
-
for (auto&& c : m_Criteria) {
if (criteriaMatchMod(info, enabled, c)) {
return true;
@@ -304,16 +296,6 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
bool ModListSortProxy::optionsMatchMod(ModInfo::Ptr info, bool) const
{
- // don't check options if there are no filters selected
- if (!m_FilterActive) {
- return true;
- }
-
- if (!m_FilterSeparators) {
- if (info->hasFlag(ModInfo::FLAG_SEPARATOR)) {
- return false;
- }
- }
return true;
}
@@ -325,14 +307,14 @@ bool ModListSortProxy::criteriaMatchMod(
switch (c.type)
{
- case TYPE_SPECIAL: // fall-through
- case TYPE_CATEGORY:
+ case TypeSpecial: // fall-through
+ case TypeCategory:
{
b = categoryMatchesMod(info, enabled, c.id);
break;
}
- case TYPE_CONTENT:
+ case TypeContent:
{
b = contentMatchesMod(info, enabled, c.id);
break;
@@ -439,6 +421,37 @@ bool ModListSortProxy::contentMatchesMod(ModInfo::Ptr info, bool enabled, int co
bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
{
+ // don't check if there are no filters selected
+ if (!m_FilterActive) {
+ return true;
+ }
+
+
+ // special case for separators
+ if (info->hasFlag(ModInfo::FLAG_SEPARATOR)) {
+ switch (m_FilterSeparators)
+ {
+ case SeparatorFilter:
+ {
+ // filter normally
+ break;
+ }
+
+ case SeparatorShow:
+ {
+ // force visible
+ return true;
+ }
+
+ case SeparatorHide:
+ {
+ // force hide
+ return false;
+ }
+ }
+ }
+
+
if (!m_Filter.isEmpty()) {
bool display = false;
QString filterCopy = QString(m_Filter);
@@ -519,7 +532,8 @@ bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
}
}//if (!m_CurrentFilter.isEmpty())
- if (m_FilterMode == FILTER_AND) {
+
+ if (m_FilterMode == FilterAnd) {
return filterMatchesModAnd(info, enabled);
}
else {
@@ -532,7 +546,8 @@ void ModListSortProxy::setColumnVisible(int column, bool visible)
m_EnabledColumns[column] = visible;
}
-void ModListSortProxy::setOptions(ModListSortProxy::FilterMode mode, bool separators)
+void ModListSortProxy::setOptions(
+ ModListSortProxy::FilterMode mode, SeparatorsMode separators)
{
if (m_FilterMode != mode || separators != m_FilterSeparators) {
m_FilterMode = mode;
diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h
index 9b533492..46356fe9 100644
--- a/src/modlistsortproxy.h
+++ b/src/modlistsortproxy.h
@@ -31,16 +31,23 @@ class ModListSortProxy : public QSortFilterProxyModel
Q_OBJECT
public:
-
- enum FilterMode {
- FILTER_AND,
- FILTER_OR
+ enum FilterMode
+ {
+ FilterAnd,
+ FilterOr
};
enum CriteriaType {
- TYPE_SPECIAL,
- TYPE_CATEGORY,
- TYPE_CONTENT
+ TypeSpecial,
+ TypeCategory,
+ TypeContent
+ };
+
+ enum SeparatorsMode
+ {
+ SeparatorFilter,
+ SeparatorShow,
+ SeparatorHide
};
struct Criteria
@@ -101,7 +108,7 @@ public:
bool isFilterActive() const { return m_FilterActive; }
void setCriteria(const std::vector& criteria);
- void setOptions(FilterMode mode, bool separators);
+ void setOptions(FilterMode mode, SeparatorsMode separators);
/**
* @brief tests if the specified index has child nodes
@@ -153,7 +160,7 @@ private:
bool m_FilterActive;
FilterMode m_FilterMode;
- bool m_FilterSeparators;
+ SeparatorsMode m_FilterSeparators;
std::vector m_PreChangeCriteria;
--
cgit v1.3.1