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/filterlist.cpp | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/filterlist.cpp (limited to 'src/filterlist.cpp') 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(); + } +} -- 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/filterlist.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/filterlist.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 ed14d5510d932362f8e232496b824729e096d3cf Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 02:20:18 -0500 Subject: implemented not flag moved stuff to CriteriaItem fixed jumbled names in getSpecialCategoryName() --- src/categories.cpp | 16 ++++---- src/filterlist.cpp | 102 +++++++++++++++++++++++++++++++++-------------- src/filterlist.h | 2 + src/modlistsortproxy.cpp | 23 +++++++++-- 4 files changed, 102 insertions(+), 41 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 082b4fbc..b75efefa 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -327,14 +327,14 @@ QString CategoryFactory::getSpecialCategoryName(int type) const 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 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 {}; } } diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 9e5437b3..31783c88 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -5,9 +5,60 @@ #include using namespace MOBase; +using CriteriaType = ModListSortProxy::CriteriaType; +using Criteria = ModListSortProxy::Criteria; + +class FilterList::CriteriaItem : public QTreeWidgetItem +{ +public: + CriteriaItem(FilterList* list, QString name, CriteriaType type, int id) + : QTreeWidgetItem({name}), m_list(list), m_widget(nullptr), m_checkbox(nullptr) + { + setData(0, Qt::ToolTipRole, name); + setData(0, TypeRole, type); + setData(0, IDRole, id); + + m_widget = new QWidget; + m_widget->setStyleSheet("background-color: rgba(0,0,0,0)"); + + auto* ly = new QVBoxLayout(m_widget); + ly->setAlignment(Qt::AlignCenter); + ly->setContentsMargins(0, 0, 0, 0); + + m_checkbox = new QCheckBox; + QObject::connect(m_checkbox, &QCheckBox::toggled, [&]{ m_list->onSelection(); }); + ly->addWidget(m_checkbox); + } + + QWidget* widget() + { + return m_widget; + } + + CriteriaType type() const + { + return static_cast(data(0, TypeRole).toInt()); + } + + int id() const + { + return data(0, IDRole).toInt(); + } + + bool inverse() const + { + return m_checkbox->isChecked(); + } + +private: + const int IDRole = Qt::UserRole; + const int TypeRole = Qt::UserRole + 1; + + FilterList* m_list; + QWidget* m_widget; + QCheckBox* m_checkbox; +}; -const int CategoryIDRole = Qt::UserRole; -const int CategoryTypeRole = Qt::UserRole + 1; FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) : ui(ui), m_factory(factory) @@ -42,13 +93,9 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) QTreeWidgetItem* FilterList::addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, - ModListSortProxy::CriteriaType type) + CriteriaType type) { - QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name)); - - item->setData(0, Qt::ToolTipRole, name); - item->setData(0, CategoryIDRole, categoryID); - item->setData(0, CategoryTypeRole, type); + auto* item = new CriteriaItem(this, name, type, categoryID); if (root != nullptr) { root->addChild(item); @@ -56,18 +103,7 @@ QTreeWidgetItem* FilterList::addCriteriaItem( 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); + ui->filters->setItemWidget(item, 1, item->widget()); return item; } @@ -163,7 +199,14 @@ 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, CategoryIDRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { + const auto* item = dynamic_cast( + ui->filters->topLevelItem(i)); + + if (!item) { + continue; + } + + if (item->id() == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { ui->filters->setCurrentItem(ui->filters->topLevelItem(i)); break; } @@ -178,18 +221,17 @@ void FilterList::clearSelection() void FilterList::onSelection() { const QModelIndexList indices = ui->filters->selectionModel()->selectedRows(); - std::vector criteria; + std::vector criteria; for (auto* item: ui->filters->selectedItems()) { - const auto type = static_cast( - item->data(0, CategoryTypeRole).toInt()); - - const int id = item->data(0, CategoryIDRole).toInt(); - - auto* cb = static_cast(ui->filters->itemWidget(item, 1)); - const bool inverse = cb->isChecked(); + const auto* ci = dynamic_cast(item); + if (!ci) { + continue; + } - criteria.push_back({type, id, inverse}); + criteria.push_back({ + ci->type(), ci->id(), ci->inverse() + }); } ui->filtersClear->setEnabled(!criteria.empty()); diff --git a/src/filterlist.h b/src/filterlist.h index 418989e7..72fe3b5f 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -23,6 +23,8 @@ signals: void optionsChanged(ModListSortProxy::FilterMode mode, bool separators); private: + class CriteriaItem; + Ui::MainWindow* ui; CategoryFactory& m_factory; diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 646401b9..3bb02c0f 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -305,18 +305,35 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const bool ModListSortProxy::criteriaMatchesMod( ModInfo::Ptr info, bool enabled, const Criteria& c) const { + bool b = false; + switch (c.type) { case TYPE_SPECIAL: // fall-through case TYPE_CATEGORY: - return categoryMatchesMod(info, enabled, c.id); + { + b = categoryMatchesMod(info, enabled, c.id); + break; + } case TYPE_CONTENT: - return contentMatchesMod(info, enabled, c.id); + { + b = contentMatchesMod(info, enabled, c.id); + break; + } default: - return false; + { + log::error("bad criteria type {}", c.type); + break; + } } + + if (c.inverse) { + b = !b; + } + + return b; } bool ModListSortProxy::categoryMatchesMod( -- cgit v1.3.1 From f463c5494362a0fa75c581e59192e2640ec10f7e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 03:02:11 -0500 Subject: added context menu items so set/unset inverted flag --- src/filterlist.cpp | 33 +++++++++++++++++++++++++++++++-- src/filterlist.h | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 31783c88..8f297af6 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -50,6 +50,11 @@ public: return m_checkbox->isChecked(); } + void setInverted(bool b) + { + m_checkbox->setChecked(b); + } + private: const int IDRole = Qt::UserRole; const int TypeRole = Qt::UserRole + 1; @@ -223,7 +228,7 @@ void FilterList::onSelection() const QModelIndexList indices = ui->filters->selectionModel()->selectedRows(); std::vector criteria; - for (auto* item: ui->filters->selectedItems()) { + for (auto* item : ui->filters->selectedItems()) { const auto* ci = dynamic_cast(item); if (!ci) { continue; @@ -242,8 +247,11 @@ void FilterList::onSelection() void FilterList::onContextMenu(const QPoint &pos) { QMenu menu; + menu.addAction(tr("Deselect filters"), [&]{ clearSelection(); }); + menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); + menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); + menu.addSeparator(); menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); }); - menu.addAction(tr("Deselect filter"), [&]{ clearSelection(); }); menu.exec(ui->filters->viewport()->mapToGlobal(pos)); } @@ -257,6 +265,27 @@ void FilterList::editCategories() } } +void FilterList::toggleInverted(bool b) +{ + bool changed = false; + + for (auto* item : ui->filters->selectedItems()) { + auto* ci = dynamic_cast(item); + if (!ci) { + continue; + } + + if (ci->inverse() != b) { + ci->setInverted(b); + changed = true; + } + } + + if (changed) { + onSelection(); + } +} + void FilterList::onCriteriaChanged() { const auto mode = ui->filtersAnd->isChecked() ? diff --git a/src/filterlist.h b/src/filterlist.h index 72fe3b5f..1fd0942a 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -33,6 +33,7 @@ private: void onCriteriaChanged(); void editCategories(); + void toggleInverted(bool b); QTreeWidgetItem* addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, -- 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/filterlist.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 f080e2e25d05eb639cc4168d3c6905041f4dc564 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 03:39:12 -0500 Subject: always enable clear filter button, made it so it also removes not flags removed "deselect filters" context menu, redundant disable not flag menu items without selection --- src/filterlist.cpp | 30 ++++++++++++++++++++++++------ src/filterlist.h | 3 ++- src/mainwindow.ui | 6 ------ 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 36cdacd0..66a9aed0 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -78,7 +78,7 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) connect( ui->filtersClear, &QPushButton::clicked, - [&]{ clearSelection(); }); + [&]{ clear(); }); connect( ui->filtersAnd, &QCheckBox::toggled, @@ -241,20 +241,23 @@ void FilterList::onSelection() }); } - ui->filtersClear->setEnabled(!criteria.empty()); - emit criteriaChanged(criteria); } void FilterList::onContextMenu(const QPoint &pos) { QMenu menu; - menu.addAction(tr("Deselect filters"), [&]{ clearSelection(); }); - menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); - menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); + + QAction* set = menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); + QAction* unset = menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); menu.addSeparator(); menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); }); + if (ui->filters->selectedItems().empty()) { + set->setEnabled(false); + unset->setEnabled(false); + } + menu.exec(ui->filters->viewport()->mapToGlobal(pos)); } @@ -267,6 +270,21 @@ void FilterList::editCategories() } } +void FilterList::clear() +{ + const auto count = ui->filters->topLevelItemCount(); + for (int i=0; i(ui->filters->topLevelItem(i)); + if (!ci) { + continue; + } + + ci->setInverted(false); + } + + clearSelection(); +} + void FilterList::toggleInverted(bool b) { bool changed = false; diff --git a/src/filterlist.h b/src/filterlist.h index 1fd0942a..e98f81a9 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -32,8 +32,9 @@ private: void onSelection(); void onCriteriaChanged(); - void editCategories(); + void clear(); void toggleInverted(bool b); + void editCategories(); QTreeWidgetItem* addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 6c35d239..5206d797 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -114,9 +114,6 @@ - - false - 0 @@ -132,9 +129,6 @@ Clear - - true - -- 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/filterlist.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 7f4fce35f97f262c36e4c00dad55c1b078cf3758 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 05:23:22 -0500 Subject: fixed separators option being used even without filters changed filter list to use tristate items without selection --- src/filterlist.cpp | 232 ++++++++++++++++++++++++++++------------------- src/filterlist.h | 8 +- src/mainwindow.ui | 64 +++++++------ src/modlistsortproxy.cpp | 26 +++++- src/modlistsortproxy.h | 3 +- 5 files changed, 204 insertions(+), 129 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 81f8b670..0dee8544 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -11,28 +11,23 @@ using Criteria = ModListSortProxy::Criteria; class FilterList::CriteriaItem : public QTreeWidgetItem { public: - CriteriaItem(FilterList* list, QString name, CriteriaType type, int id) - : QTreeWidgetItem({name}), m_list(list), m_widget(nullptr), m_checkbox(nullptr) + enum States : int { - setData(0, Qt::ToolTipRole, name); - setData(0, TypeRole, type); - setData(0, IDRole, id); - - m_widget = new QWidget; - m_widget->setStyleSheet("background-color: rgba(0,0,0,0)"); + FirstState = 0, - auto* ly = new QVBoxLayout(m_widget); - ly->setAlignment(Qt::AlignCenter); - ly->setContentsMargins(0, 0, 0, 0); + Inactive = FirstState, + Active, + Inverted, - m_checkbox = new QCheckBox; - QObject::connect(m_checkbox, &QCheckBox::toggled, [&]{ m_list->onSelection(); }); - ly->addWidget(m_checkbox); - } + LastState = Inverted + }; - QWidget* widget() + CriteriaItem(FilterList* list, QString name, CriteriaType type, int id) + : QTreeWidgetItem({"", name}), m_list(list), m_state(Inactive) { - return m_widget; + setData(0, Qt::ToolTipRole, name); + setData(0, TypeRole, type); + setData(0, IDRole, id); } CriteriaType type() const @@ -45,14 +40,37 @@ public: return data(0, IDRole).toInt(); } - bool inverse() const + States state() const + { + return m_state; + } + + void setState(States s) { - return m_checkbox->isChecked(); + if (m_state != s) { + m_state = s; + updateState(); + } } - void setInverted(bool b) + void nextState() { - m_checkbox->setChecked(b); + m_state = static_cast(m_state + 1); + if (m_state > LastState) { + m_state = FirstState; + } + + updateState(); + } + + void previousState() + { + m_state = static_cast(m_state - 1); + if (m_state < FirstState) { + m_state = LastState; + } + + updateState(); } private: @@ -60,40 +78,91 @@ private: const int TypeRole = Qt::UserRole + 1; FilterList* m_list; - QWidget* m_widget; - QCheckBox* m_checkbox; + States m_state; + + void updateState() + { + QString s; + + switch (m_state) + { + case Inactive: + { + break; + } + + case Active: + { + // U+2713 CHECK MARK + s = QString::fromUtf8("\xe2\x9c\x93"); + break; + } + + case Inverted: + { + s = tr("Not"); + break; + } + } + + setText(0, s); + } +}; + + +class ClickFilter : public QObject +{ +public: + ClickFilter(std::function f) + : m_f(std::move(f)) + { + } + + bool eventFilter(QObject* o, QEvent* e) override + { + if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) { + if (m_f) { + return m_f(static_cast(e)); + } + } + + return QObject::eventFilter(o, e);; + } + +private: + std::function m_f; }; FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) : ui(ui), m_factory(factory) { - connect( - ui->filters, &QTreeWidget::customContextMenuRequested, - [&](auto&& pos){ onContextMenu(pos); }); + ui->filters->viewport()->installEventFilter( + new ClickFilter([&](auto* e){ return onClick(e); })); connect( - ui->filters, &QTreeWidget::itemSelectionChanged, - [&]{ onSelection(); }); + ui->filtersClear, &QPushButton::clicked, + [&]{ clearSelection(); }); connect( - ui->filtersClear, &QPushButton::clicked, - [&]{ clear(); }); + ui->filtersEdit, &QPushButton::clicked, + [&]{ editCategories(); }); connect( ui->filtersAnd, &QCheckBox::toggled, - [&]{ onCriteriaChanged(); }); + [&]{ onOptionsChanged(); }); connect( ui->filtersOr, &QCheckBox::toggled, - [&]{ onCriteriaChanged(); }); + [&]{ onOptionsChanged(); }); connect( ui->filtersSeparators, &QCheckBox::toggled, - [&]{ onCriteriaChanged(); }); + [&]{ onOptionsChanged(); }); - ui->filters->header()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->filters->header()->resizeSection(1, 50); + ui->filters->header()->setMinimumSectionSize(0); + ui->filters->header()->setSectionResizeMode(0, QHeaderView::Fixed); + ui->filters->header()->resizeSection(0, 30); ui->categoriesSplitter->setCollapsible(0, false); ui->categoriesSplitter->setCollapsible(1, false); } @@ -110,7 +179,7 @@ QTreeWidgetItem* FilterList::addCriteriaItem( ui->filters->addTopLevelItem(item); } - ui->filters->setItemWidget(item, 1, item->widget()); + item->setTextAlignment(0, Qt::AlignCenter); return item; } @@ -224,91 +293,72 @@ void FilterList::setSelection(const std::vector& criteria) void FilterList::clearSelection() { - ui->filters->clearSelection(); -} - -void FilterList::onSelection() -{ - const QModelIndexList indices = ui->filters->selectionModel()->selectedRows(); - std::vector criteria; - - for (auto* item : ui->filters->selectedItems()) { - const auto* ci = dynamic_cast(item); + for (int i=0; ifilters->topLevelItemCount(); ++i) { + auto* ci = dynamic_cast(ui->filters->topLevelItem(i)); if (!ci) { continue; } - criteria.push_back({ - ci->type(), ci->id(), ci->inverse() - }); + ci->setState(CriteriaItem::Inactive); } - emit criteriaChanged(criteria); + checkCriteria(); } -void FilterList::onContextMenu(const QPoint &pos) +bool FilterList::onClick(QMouseEvent* e) { - QMenu menu; + auto* item = ui->filters->itemAt(e->pos()); + if (!item) { + return false; + } - QAction* set = menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); - QAction* unset = menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); - menu.addSeparator(); - menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); }); + auto* ci = dynamic_cast(item); + if (!ci) { + return false; + } - if (ui->filters->selectedItems().empty()) { - set->setEnabled(false); - unset->setEnabled(false); + if (e->button() == Qt::LeftButton) { + ci->nextState(); + } else if (e->button() == Qt::RightButton) { + ci->previousState(); + } else { + return false; } - menu.exec(ui->filters->viewport()->mapToGlobal(pos)); + checkCriteria(); + return true; } -void FilterList::editCategories() +void FilterList::checkCriteria() { - CategoriesDialog dialog(qApp->activeWindow()); - - if (dialog.exec() == QDialog::Accepted) { - dialog.commitChanges(); - } -} + std::vector criteria; -void FilterList::clear() -{ - const auto count = ui->filters->topLevelItemCount(); - for (int i=0; i(ui->filters->topLevelItem(i)); + for (int i=0; ifilters->topLevelItemCount(); ++i) { + const auto* ci = dynamic_cast(ui->filters->topLevelItem(i)); if (!ci) { continue; } - ci->setInverted(false); + if (ci->state() != CriteriaItem::Inactive) { + criteria.push_back({ + ci->type(), ci->id(), (ci->state() == CriteriaItem::Inverted) + }); + } } - clearSelection(); + emit criteriaChanged(criteria); } -void FilterList::toggleInverted(bool b) +void FilterList::editCategories() { - bool changed = false; - - for (auto* item : ui->filters->selectedItems()) { - auto* ci = dynamic_cast(item); - if (!ci) { - continue; - } - - if (ci->inverse() != b) { - ci->setInverted(b); - changed = true; - } - } + CategoriesDialog dialog(qApp->activeWindow()); - if (changed) { - onSelection(); + if (dialog.exec() == QDialog::Accepted) { + dialog.commitChanges(); } } -void FilterList::onCriteriaChanged() +void FilterList::onOptionsChanged() { const auto mode = ui->filtersAnd->isChecked() ? ModListSortProxy::FILTER_AND : ModListSortProxy::FILTER_OR; diff --git a/src/filterlist.h b/src/filterlist.h index 52b90ea7..fac1d683 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -28,13 +28,11 @@ private: Ui::MainWindow* ui; CategoryFactory& m_factory; - void onContextMenu(const QPoint &pos); - void onSelection(); - void onCriteriaChanged(); + bool onClick(QMouseEvent* e); + void onOptionsChanged(); - void clear(); - void toggleInverted(bool b); void editCategories(); + void checkCriteria(); QTreeWidgetItem* addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 5206d797..1a64dfdd 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -76,59 +76,69 @@ 0 - - Qt::CustomContextMenu - - QAbstractItemView::ExtendedSelection + QAbstractItemView::NoSelection 0 + + false + true - false + true - true + false - true - - false - Category + - Invert + Category - - - - 0 - 0 - - - - - 0 - 25 - - - - Clear - + + + + 0 + + + 2 + + + 0 + + + 0 + + + + + Clear + + + + + + + Edit... + + + + diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 36dcae59..e6bed49c 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -269,12 +269,12 @@ bool ModListSortProxy::hasConflictFlag(const std::vector &flags) bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const { - if (info->hasFlag(ModInfo::FLAG_SEPARATOR) && !m_FilterSeparators) { + if (!optionsMatchMod(info, enabled)) { return false; } for (auto&& c : m_Criteria) { - if (!criteriaMatchesMod(info, enabled, c)) { + if (!criteriaMatchMod(info, enabled, c)) { return false; } } @@ -284,12 +284,12 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const { - if (info->hasFlag(ModInfo::FLAG_SEPARATOR) && !m_FilterSeparators) { + if (!optionsMatchMod(info, enabled)) { return false; } for (auto&& c : m_Criteria) { - if (criteriaMatchesMod(info, enabled, c)) { + if (criteriaMatchMod(info, enabled, c)) { return true; } } @@ -302,7 +302,23 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const return true; } -bool ModListSortProxy::criteriaMatchesMod( +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; +} + +bool ModListSortProxy::criteriaMatchMod( ModInfo::Ptr info, bool enabled, const Criteria& c) const { bool b = false; diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h index 5aeaccce..9b533492 100644 --- a/src/modlistsortproxy.h +++ b/src/modlistsortproxy.h @@ -157,7 +157,8 @@ private: std::vector m_PreChangeCriteria; - bool criteriaMatchesMod(ModInfo::Ptr info, bool enabled, const Criteria& c) const; + bool optionsMatchMod(ModInfo::Ptr info, bool enabled) const; + bool criteriaMatchMod(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 d2073ef2bd62527034864fd0cacd5537aff33218 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 05:37:34 -0500 Subject: made all categories positive fixed context menu sometimes appearing --- src/categories.cpp | 16 ++++++++-------- src/categories.h | 8 ++++---- src/filterlist.cpp | 10 +++++----- src/mainwindow.ui | 3 +++ src/modlistsortproxy.cpp | 29 ++++++++++++++++------------- 5 files changed, 36 insertions(+), 30 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 1bd56f7f..5c9a4d55 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -324,15 +324,15 @@ QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const { switch (type) { - case Checked: return QObject::tr(""); - case UpdateAvailable: return QObject::tr(""); - case HasNoCategory: return QObject::tr(""); + case Checked: return QObject::tr(""); + case UpdateAvailable: return QObject::tr(""); + case HasCategory: 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(""); + case Endorsed: return QObject::tr(""); + case Backup: return QObject::tr(""); + case Managed: return QObject::tr(""); + case HasGameData: return QObject::tr(""); + case HasNexusID: return QObject::tr(""); default: return {}; } } diff --git a/src/categories.h b/src/categories.h index 296e7711..02695e4d 100644 --- a/src/categories.h +++ b/src/categories.h @@ -41,13 +41,13 @@ public: { Checked = 10000, UpdateAvailable, - HasNoCategory, + HasCategory, Conflict, - NotEndorsed, + Endorsed, Backup, Managed, - NoGameData, - NoNexusID + HasGameData, + HasNexusID }; public: diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 0dee8544..b65f0f4a 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -11,7 +11,7 @@ using Criteria = ModListSortProxy::Criteria; class FilterList::CriteriaItem : public QTreeWidgetItem { public: - enum States : int + enum States { FirstState = 0, @@ -234,11 +234,11 @@ void FilterList::refresh() addSpecialCriteria(F::UpdateAvailable); addSpecialCriteria(F::Backup); addSpecialCriteria(F::Managed); - addSpecialCriteria(F::HasNoCategory); + addSpecialCriteria(F::HasCategory); addSpecialCriteria(F::Conflict); - addSpecialCriteria(F::NotEndorsed); - addSpecialCriteria(F::NoNexusID); - addSpecialCriteria(F::NoGameData); + addSpecialCriteria(F::Endorsed); + addSpecialCriteria(F::HasNexusID); + addSpecialCriteria(F::HasGameData); addContentCriteria(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 1a64dfdd..92a41c67 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -76,6 +76,9 @@ 0 + + Qt::NoContextMenu + QAbstractItemView::NoSelection diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index e6bed49c..fd3dbc9e 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -371,9 +371,9 @@ bool ModListSortProxy::categoryMatchesMod( break; } - case CategoryFactory::HasNoCategory: + case CategoryFactory::HasCategory: { - b = (info->getCategories().size() == 0); + b = !info->getCategories().empty(); break; } @@ -383,10 +383,9 @@ bool ModListSortProxy::categoryMatchesMod( break; } - case CategoryFactory::NotEndorsed: + case CategoryFactory::Endorsed: { - ModInfo::EEndorsedState state = info->endorsedState(); - b = (state != ModInfo::ENDORSED_TRUE); + b = (info->endorsedState() == ModInfo::ENDORSED_TRUE); break; } @@ -402,20 +401,24 @@ bool ModListSortProxy::categoryMatchesMod( break; } - case CategoryFactory::NoGameData: + case CategoryFactory::HasGameData: { - b = (info->hasFlag(ModInfo::FLAG_INVALID)); + b = !info->hasFlag(ModInfo::FLAG_INVALID); break; } - case CategoryFactory::NoNexusID: + case CategoryFactory::HasNexusID: { - b = ( - info->getNexusID() == -1 && - !info->hasFlag(ModInfo::FLAG_FOREIGN) && - !info->hasFlag(ModInfo::FLAG_BACKUP) && - !info->hasFlag(ModInfo::FLAG_OVERWRITE)); + // never show these + if ( + info->hasFlag(ModInfo::FLAG_FOREIGN) || + info->hasFlag(ModInfo::FLAG_BACKUP) || + info->hasFlag(ModInfo::FLAG_OVERWRITE)) + { + return false; + } + b = (info->getNexusID() > 0); break; } -- 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/filterlist.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 From 2de015815c279dbf965c04c50376a4d39e28f92b Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 2 Dec 2019 15:34:29 -0500 Subject: added "tracked on nexus" filter --- src/categories.cpp | 1 + src/categories.h | 3 ++- src/filterlist.cpp | 1 + src/modlistsortproxy.cpp | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/filterlist.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 5c9a4d55..3e005079 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -333,6 +333,7 @@ QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const case Managed: return QObject::tr(""); case HasGameData: return QObject::tr(""); case HasNexusID: return QObject::tr(""); + case Tracked: return QObject::tr(""); default: return {}; } } diff --git a/src/categories.h b/src/categories.h index 02695e4d..6b27c6a7 100644 --- a/src/categories.h +++ b/src/categories.h @@ -47,7 +47,8 @@ public: Backup, Managed, HasGameData, - HasNexusID + HasNexusID, + Tracked }; public: diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 05bff2dd..0a5d0414 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -252,6 +252,7 @@ void FilterList::refresh() addSpecialCriteria(F::HasCategory); addSpecialCriteria(F::Conflict); addSpecialCriteria(F::Endorsed); + addSpecialCriteria(F::Tracked); addSpecialCriteria(F::HasNexusID); addSpecialCriteria(F::HasGameData); diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 7ac98f66..64d5de42 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -404,6 +404,12 @@ bool ModListSortProxy::categoryMatchesMod( break; } + case CategoryFactory::Tracked: + { + b = (info->trackedState() == ModInfo::TRACKED_TRUE); + break; + } + default: { b = (info->categorySet(category)); -- cgit v1.3.1 From e263d3049acd7e296ad87f2ac91318b37bf33f2f Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 4 Dec 2019 11:43:36 -0500 Subject: keyboard nav for filter list, alternating row colors --- src/filterlist.cpp | 96 ++++++++++++++++++++++++++++++++++++------------------ src/filterlist.h | 3 +- src/mainwindow.ui | 6 ++++ 3 files changed, 72 insertions(+), 33 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 0a5d0414..b345d21d 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -111,51 +111,88 @@ private: }; -class ClickFilter : public QObject +class CriteriaItemFilter : public QObject { public: - ClickFilter(std::function f) - : m_f(std::move(f)) + using Callback = std::function; + + CriteriaItemFilter(QTreeWidget* tree, Callback f) + : QObject(tree), m_tree(tree), m_f(std::move(f)) { } bool eventFilter(QObject* o, QEvent* e) override { - if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) { - if (m_f) { - return m_f(static_cast(e)); + // careful: this filter is installed on both the tree and the viewport + // + // no check is currently necessary because mouse events originate from the + // viewport only and keyboard events from the tree only + + if (m_f) { + if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) { + if (handleMouse(static_cast(e))) { + return true; + } + } else if (e->type() == QEvent::KeyPress) { + if (handleKeyboard(static_cast(e))) { + return true; + } } } - return QObject::eventFilter(o, e);; + return QObject::eventFilter(o, e); } private: - std::function m_f; + QTreeWidget* m_tree; + Callback m_f; + + bool handleMouse(QMouseEvent* e) + { + auto* item = m_tree->itemAt(e->pos()); + if (!item) { + return false; + } + + m_tree->setCurrentItem(item); + + const auto dir = (e->button() == Qt::LeftButton ? 1 : - 1); + + return m_f(item, dir); + } + + bool handleKeyboard(QKeyEvent* e) + { + if (e->key() == Qt::Key_Space) { + auto* item = m_tree->currentItem(); + if (!item) { + return false; + } + + const auto shiftPressed = (e->modifiers() & Qt::ShiftModifier); + const auto dir = (shiftPressed ? -1 : 1); + + return m_f(item, dir); + } + + return false; + } }; FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) : ui(ui), m_factory(factory) { - ui->filters->viewport()->installEventFilter( - new ClickFilter([&](auto* e){ return onClick(e); })); + auto* eventFilter = new CriteriaItemFilter( + ui->filters, [&](auto* item, int dir){ return cycleItem(item, dir); }); - connect( - ui->filtersClear, &QPushButton::clicked, - [&]{ clearSelection(); }); + ui->filters->installEventFilter(eventFilter); + ui->filters->viewport()->installEventFilter(eventFilter); - connect( - ui->filtersEdit, &QPushButton::clicked, - [&]{ editCategories(); }); - - connect( - ui->filtersAnd, &QCheckBox::toggled, - [&]{ onOptionsChanged(); }); - - connect( - ui->filtersOr, &QCheckBox::toggled, - [&]{ onOptionsChanged(); }); + connect(ui->filtersClear, &QPushButton::clicked, [&]{ clearSelection(); }); + connect(ui->filtersEdit, &QPushButton::clicked, [&]{ editCategories(); }); + connect(ui->filtersAnd, &QCheckBox::toggled, [&]{ onOptionsChanged(); }); + connect(ui->filtersOr, &QCheckBox::toggled, [&]{ onOptionsChanged(); }); connect( ui->filtersSeparators, qOverload(&QComboBox::currentIndexChanged), @@ -321,21 +358,16 @@ void FilterList::clearSelection() checkCriteria(); } -bool FilterList::onClick(QMouseEvent* e) +bool FilterList::cycleItem(QTreeWidgetItem* item, int direction) { - auto* item = ui->filters->itemAt(e->pos()); - if (!item) { - return false; - } - auto* ci = dynamic_cast(item); if (!ci) { return false; } - if (e->button() == Qt::LeftButton) { + if (direction > 0) { ci->nextState(); - } else if (e->button() == Qt::RightButton) { + } else if (direction < 0) { ci->previousState(); } else { return false; diff --git a/src/filterlist.h b/src/filterlist.h index 671462d4..72cbe8bf 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -34,10 +34,12 @@ private: CategoryFactory& m_factory; bool onClick(QMouseEvent* e); + void onItemActivated(QTreeWidgetItem* item); void onOptionsChanged(); void editCategories(); void checkCriteria(); + bool cycleItem(QTreeWidgetItem* item, int direction); QTreeWidgetItem* addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, @@ -47,7 +49,6 @@ private: void addCategoryCriteria( QTreeWidgetItem *root, const std::set &categoriesUsed, int targetID); void addSpecialCriteria(int type); - }; #endif // MODORGANIZER_CATEGORIESLIST_INCLUDED diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 0520db84..309e9f62 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -79,6 +79,9 @@ Qt::NoContextMenu + + true + QAbstractItemView::NoSelection @@ -91,6 +94,9 @@ true + + true + true -- cgit v1.3.1 From 2001f2675782ffe8f987daaed099ce3ee3a57a1c Mon Sep 17 00:00:00 2001 From: Silarn Date: Tue, 10 Dec 2019 15:25:31 -0600 Subject: Rework filter labels to separate bracket from translation --- src/categories.cpp | 22 +-- src/filterlist.cpp | 3 +- src/organizer_en.ts | 486 ++++++++++++++++++++++++++-------------------------- 3 files changed, 257 insertions(+), 254 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 3e005079..bb37483b 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -322,20 +322,22 @@ QString CategoryFactory::getCategoryName(unsigned int index) const QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const { + QString label; switch (type) { - case Checked: return QObject::tr(""); - case UpdateAvailable: return QObject::tr(""); - case HasCategory: return QObject::tr(""); - case Conflict: return QObject::tr(""); - case Endorsed: return QObject::tr(""); - case Backup: return QObject::tr(""); - case Managed: return QObject::tr(""); - case HasGameData: return QObject::tr(""); - case HasNexusID: return QObject::tr(""); - case Tracked: return QObject::tr(""); + case Checked: label = QObject::tr("Active"); break; + case UpdateAvailable: label = QObject::tr("Update available"); break; + case HasCategory: label = QObject::tr("Has category"); break; + case Conflict: label = QObject::tr("Conflicted"); break; + case Endorsed: label = QObject::tr("Endorsed"); break; + case Backup: label = QObject::tr("Has backup"); break; + case Managed: label = QObject::tr("Managed"); break; + case HasGameData: label = QObject::tr("Has valid game data"); break; + case HasNexusID: label = QObject::tr("Has Nexus ID"); break; + case Tracked: label = QObject::tr("Tracked on Nexus"); break; default: return {}; } + return QString("<%1>").arg(label); } QString CategoryFactory::getCategoryNameByID(int id) const diff --git a/src/filterlist.cpp b/src/filterlist.cpp index b345d21d..6a85bcaa 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -239,8 +239,9 @@ QTreeWidgetItem* FilterList::addCriteriaItem( void FilterList::addContentCriteria() { for (unsigned i = 0; i < ModInfo::NUM_CONTENT_TYPES; ++i) { + QString filterName = tr("Contains %1").arg(ModInfo::getContentTypeName(i)); addCriteriaItem( - nullptr, tr("").arg(ModInfo::getContentTypeName(i)), + nullptr, QString("<%1>").arg(filterName), i, ModListSortProxy::TypeContent); } } diff --git a/src/organizer_en.ts b/src/organizer_en.ts index d462f1b6..ca82a996 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -1387,8 +1387,8 @@ Right now the only case I know of where this needs to be overwritten is for the - - <Contains %1> + + Contains %1 @@ -1862,7 +1862,7 @@ p, li { white-space: pre-wrap; } - + Create Backup @@ -2038,8 +2038,8 @@ p, li { white-space: pre-wrap; } - - + + Refresh @@ -2324,7 +2324,7 @@ p, li { white-space: pre-wrap; } - + Endorse Mod Organizer @@ -2445,8 +2445,8 @@ Error: %1 - - + + Endorse @@ -2571,645 +2571,645 @@ Error: %1 - + Notice: Your current MO version (%1) is lower than the previously used one (%2). The GUI may not downgrade gracefully, so you may experience oddities. However, there should be no serious issues. - + Choose Mod - + Mod Archive - + Start Tutorial? - + You're about to start a tutorial. For technical reasons it's not possible to end the tutorial early. Continue? - + failed to change origin name: %1 - + failed to move "%1" from mod "%2" to "%3": %4 - + failed to rename mod: %1 - + Overwrite? - + This will replace the existing mod "%1". Continue? - + failed to remove mod "%1" - - - + + + failed to rename "%1" to "%2" - - - - + + + + Confirm - + Remove the following mods?<br><ul>%1</ul> - + failed to remove mod: %1 - - + + Failed - + Installation file no longer exists - + Mods installed with old versions of MO can't be reinstalled in this way. - + Failed to create backup. - + Endorsing multiple mods will take a while. Please wait... - + Unendorsing multiple mods will take a while. Please wait... - + Failed to display overwrite dialog: %1 - + Opening Nexus Links - + You are trying to open %1 links to Nexus Mods. Are you sure you want to do this? - + Nexus ID for this mod is unknown - + Opening Web Pages - + You are trying to open %1 Web Pages. Are you sure you want to do this? - + <table cellspacing="5"><tr><th>Type</th><th>All</th><th>Visible</th><tr><td>Enabled mods:&emsp;</td><td align=right>%1 / %2</td><td align=right>%3 / %4</td></tr><tr><td>Unmanaged/DLCs:&emsp;</td><td align=right>%5</td><td align=right>%6</td></tr><tr><td>Mod backups:&emsp;</td><td align=right>%7</td><td align=right>%8</td></tr><tr><td>Separators:&emsp;</td><td align=right>%9</td><td align=right>%10</td></tr></table> - + <table cellspacing="6"><tr><th>Type</th><th>Active </th><th>Total</th></tr><tr><td>All plugins:</td><td align=right>%1 </td><td align=right>%2</td></tr><tr><td>ESMs:</td><td align=right>%3 </td><td align=right>%4</td></tr><tr><td>ESPs:</td><td align=right>%7 </td><td align=right>%8</td></tr><tr><td>ESMs+ESPs:</td><td align=right>%9 </td><td align=right>%10</td></tr><tr><td>ESLs:</td><td align=right>%5 </td><td align=right>%6</td></tr></table> - - - + + + Create Mod... - + This will create an empty mod. Please enter a name: - - + + A mod with this name already exists - + Create Separator... - + This will create a new separator. Please enter a name: - + A separator with this name already exists - + This will move all files from overwrite into a new, regular mod. Please enter a name: - + Move successful. - - + + Are you sure? - + About to recursively delete: - + Continue? - + The versioning scheme decides which version is considered newer than another. This function will guess the versioning scheme under the assumption that the installed version is outdated. - + Sorry - + I don't know a versioning scheme where %1 is newer than %2. - + Really enable all visible mods? - + Really disable all visible mods? - + Export to csv - + CSV (Comma Separated Values) is a format that can be imported in programs like Excel to create a spreadsheet. You can also use online editors and converters instead. - + Select what mods you want export: - + All installed mods - + Only active (checked) mods from your current profile - + All currently visible mods in the mod list - + Choose what Columns to export: - + Mod_Priority - + Mod_Name - + Notes_column - + Mod_Status - + Primary_Category - + Nexus_ID - + Mod_Nexus_URL - + Mod_Version - + Install_Date - + Download_File_Name - + export failed: %1 - + Open Game folder - + Open MyGames folder - + Open INIs folder - + Open Instance folder - + Open Mods folder - + Open Profile folder - + Open Downloads folder - + Open MO2 Install folder - + Open MO2 Plugins folder - + Open MO2 Stylesheets folder - + Open MO2 Logs folder - + Install Mod... - + Create empty mod - + Create Separator - + Enable all visible - + Disable all visible - + Check for updates - + Export to csv... - - + + Send to - - + + Top - - + + Bottom - - + + Priority... - + Separator... - + All Mods - + Sync to Mods... - + Move content to Mod... - + Clear Overwrite... - - + + Open in Explorer - + Restore Backup - + Remove Backup... - - + + Change Categories - - + + Primary Category - + Rename Separator... - + Remove Separator... - + Select Color... - + Reset Color - + Change versioning scheme - + Force-check updates - + Un-ignore update - + Ignore update - - + + Enable selected - - + + Disable selected - + Rename Mod... - + Reinstall Mod - + Remove Mod... - + Un-Endorse - + Won't endorse - + Endorsement state unknown - + Start tracking - + Stop tracking - + Tracked state unknown - + Ignore missing data - + Mark as converted/working - + Visit on Nexus - + Visit on %1 - + Information... - - + + Exception: - - + + Unknown exception - + %1 more - + Are you sure you want to remove the following %n save(s)?<br><ul>%1</ul><br>Removed saves will be sent to the Recycle Bin. @@ -3217,12 +3217,12 @@ You can also use online editors and converters instead. - + Enable Mods... - + Delete %n save(s) @@ -3230,335 +3230,335 @@ You can also use online editors and converters instead. - + Restart Mod Organizer - + Mod Organizer must restart to finish configuration changes - + Restart - + Continue - + Some things might be weird. - + Can't change download directory while downloads are in progress! - + failed to write to file %1 - + %1 written - + Enter Name - + Enter a name for the executable - + Not an executable - + This is not a recognized executable. - - + + Replace file? - + There already is a hidden version of this file. Replace it? - - + + File operation failed - - + + Failed to remove "%1". Maybe you lack the required file permissions? - + There already is a visible version of this file. Replace it? - - + + Set Priority - + Set the priority of the selected plugins - + Update available - + &Execute - + Execute with &VFS - + &Open - + Open with &VFS - + &Add as Executable - + Preview - + Un-Hide - + Hide - + Write To File... - + Do you want to endorse Mod Organizer on %1 now? - + Abstain from Endorsing Mod Organizer - + Are you sure you want to abstain from endorsing Mod Organizer 2? You will have to visit the mod page on the %1 Nexus site to change your mind. - + Thank you for endorsing MO2! :) - + Please reconsider endorsing MO2 on Nexus! - + Thank you! - + Thank you for your endorsement! - + Mod ID %1 no longer seems to be available on Nexus. - + Request to Nexus failed: %1 - - + + failed to read %1: %2 - + Error - + failed to extract %1 (errorcode %2) - + Extract BSA - + This archive contains invalid hashes. Some files may be broken. - + Extract... - + This will restart MO, continue? - + <Multiple> - + Remove '%1' from the toolbar - + Enable all - + Disable all - + Unlock load order - + Lock load order - + Open Origin in Explorer - + Open Origin Info... - + Backup of load order created - + Choose backup to restore - + No Backups - + There are no backups to restore - - + + Restore failed - - + + Failed to restore the backup. Errorcode: %1 - + Backup of mod list created - + A file with the same name has already been downloaded. What would you like to do? - + Overwrite - + Rename new file - + Ignore file - + Set the priority of the selected mods @@ -5611,62 +5611,62 @@ p, li { white-space: pre-wrap; } - + invalid category index: %1 - - - <Active> - - - <Update available> + Active - <Has category> + Update available - <Conflicted> + Has category - <Endorsed> + Conflicted - <Has backup> + Endorsed - <Managed> + Has backup - <Has valid game data> + Managed - <Has Nexus ID> + Has valid game data - <Tracked on Nexus> + Has Nexus ID + + + + + Tracked on Nexus - + invalid category id: %1 @@ -6115,7 +6115,7 @@ If the folder was still in use, restart MO and try again. - + <Manage...> -- cgit v1.3.1 From c3c1183308dbe00a14b8cf5e3c58e92bd9edfaf6 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 12 Dec 2019 14:47:35 -0500 Subject: fixed alt colors in saves list for dark.qss translated some sanity checks warnings fixed filter list not refreshing selection correctly --- src/filterlist.cpp | 38 +++++++++++++++++++------------------- src/filterlist.h | 1 + src/organizer_en.ts | 17 +++++++++++++++++ src/sanitychecks.cpp | 21 ++++++++++++++------- src/stylesheets/dark.qss | 2 +- 5 files changed, 52 insertions(+), 27 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 6a85bcaa..69aca4c5 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -275,10 +275,7 @@ void FilterList::addSpecialCriteria(int type) void FilterList::refresh() { - QStringList selectedItems; - for (QTreeWidgetItem *item : ui->filters->selectedItems()) { - selectedItems.append(item->text(0)); - } + const auto oldSelection = selectedCriteria(); ui->filters->clear(); @@ -315,33 +312,30 @@ void FilterList::refresh() } addCategoryCriteria(nullptr, categoriesUsed, 0); - - for (const QString &item : selectedItems) { - QList matches = ui->filters->findItems( - item, Qt::MatchFixedString | Qt::MatchRecursive); - - if (matches.size() > 0) { - matches.at(0)->setSelected(true); - } - } + setSelection(oldSelection); } void FilterList::setSelection(const std::vector& criteria) { for (int i = 0; i < ui->filters->topLevelItemCount(); ++i) { - const auto* item = dynamic_cast( - ui->filters->topLevelItem(i)); - + auto* item = dynamic_cast(ui->filters->topLevelItem(i)); if (!item) { continue; } + bool found = false; + for (auto&& c : criteria) { if (item->type() == c.type && item->id() == c.id) { - ui->filters->setCurrentItem(ui->filters->topLevelItem(i)); + item->setState(c.inverse ? CriteriaItem::Inverted : CriteriaItem::Active); + found = true; break; } } + + if (!found) { + item->setState(CriteriaItem::Inactive); + } } } @@ -378,7 +372,7 @@ bool FilterList::cycleItem(QTreeWidgetItem* item, int direction) return true; } -void FilterList::checkCriteria() +std::vector FilterList::selectedCriteria() const { std::vector criteria; @@ -395,7 +389,12 @@ void FilterList::checkCriteria() } } - emit criteriaChanged(criteria); + return criteria; +} + +void FilterList::checkCriteria() +{ + emit criteriaChanged(selectedCriteria()); } void FilterList::editCategories() @@ -404,6 +403,7 @@ void FilterList::editCategories() if (dialog.exec() == QDialog::Accepted) { dialog.commitChanges(); + refresh(); } } diff --git a/src/filterlist.h b/src/filterlist.h index 72cbe8bf..b0ebc9a4 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -39,6 +39,7 @@ private: void editCategories(); void checkCriteria(); + std::vector selectedCriteria() const; bool cycleItem(QTreeWidgetItem* item, int direction); QTreeWidgetItem* addCriteriaItem( diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 95854200..6101c8e7 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -6754,6 +6754,23 @@ You can restart Mod Organizer as administrator and try launching the program aga Exit Now + + + '%1': file is blocked (%2) + '%1': file is blocked ('%2') + + + + + '%1' seems to be missing, an antivirus may have deleted it + + + + + %1 is loaded. This program is known to cause issues with Mod Organizer, such as freezing or blank windows. Consider uninstalling it. + %1 is loaded. This program is known to cause issues with Mod Organizer, such as freezing or blank windows. Consider uninstalling it. (%2) + + QueryOverwriteDialog diff --git a/src/sanitychecks.cpp b/src/sanitychecks.cpp index 330735ed..bdf762d9 100644 --- a/src/sanitychecks.cpp +++ b/src/sanitychecks.cpp @@ -110,7 +110,11 @@ bool isFileBlocked(const QFileInfo& fi) } // file is blocked - log::warn("'{}': file is blocked, zone id is {}", path, toString(z)); + log::warn("{}", QObject::tr( + "'%1': file is blocked (%2)") + .arg(path) + .arg(toString(z))); + return true; } @@ -199,9 +203,9 @@ int checkMissingFiles() const QFileInfo file(dir + "/" + name); if (!file.exists()) { - log::warn( - "'{}' seems to be missing, an antivirus may have deleted it", - file.absoluteFilePath()); + log::warn("{}", QObject::tr( + "'%1' seems to be missing, an antivirus may have deleted it") + .arg(file.absoluteFilePath())); ++n; } @@ -231,10 +235,13 @@ int checkIncompatibleModule(const env::Module& m) for (auto&& p : names) { if (file.fileName().compare(p.first, Qt::CaseInsensitive) == 0) { - log::warn( - "{} is loaded. This program is known to cause issues with " + log::warn("{}", QObject::tr( + "%1 is loaded. This program is known to cause issues with " "Mod Organizer, such as freezing or blank windows. Consider " - "uninstalling it. ({})", p.second, file.absoluteFilePath()); + "uninstalling it.") + .arg(p.second)); + + log::warn("{}", file.absoluteFilePath()); ++n; } diff --git a/src/stylesheets/dark.qss b/src/stylesheets/dark.qss index 9d11109d..91f808bc 100644 --- a/src/stylesheets/dark.qss +++ b/src/stylesheets/dark.qss @@ -349,7 +349,7 @@ QToolButton:hover padding-bottom: 2px; } -QTreeView +QTreeView, QListView { color: #E9E6E4; background-color: #3F4041; -- cgit v1.3.1