mirror of
https://github.com/ModOrganizer2/modorganizer.git
synced 2026-07-27 13:58:24 -07:00
three modes for separators, save state
renamed enumerators
This commit is contained in:
+22
-6
@@ -2,6 +2,7 @@
|
||||
#include "ui_mainwindow.h"
|
||||
#include "categories.h"
|
||||
#include "categoriesdialog.h"
|
||||
#include "settings.h"
|
||||
#include <utility.h>
|
||||
|
||||
using namespace MOBase;
|
||||
@@ -157,7 +158,7 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory)
|
||||
[&]{ onOptionsChanged(); });
|
||||
|
||||
connect(
|
||||
ui->filtersSeparators, &QCheckBox::toggled,
|
||||
ui->filtersSeparators, qOverload<int>(&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("<Contains %1>").arg(ModInfo::getContentTypeName(i)),
|
||||
i, ModListSortProxy::TYPE_CONTENT);
|
||||
i, ModListSortProxy::TypeContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +217,7 @@ void FilterList::addCategoryCriteria(QTreeWidgetItem *root, const std::set<int>
|
||||
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<ModListSortProxy::SeparatorsMode>(
|
||||
ui->filtersSeparators->currentData().toInt());
|
||||
|
||||
emit optionsChanged(mode, separators);
|
||||
}
|
||||
|
||||
+6
-1
@@ -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<ModListSortProxy::Criteria>& criteria);
|
||||
void clearSelection();
|
||||
void refresh();
|
||||
|
||||
signals:
|
||||
void criteriaChanged(std::vector<ModListSortProxy::Criteria> criteria);
|
||||
void optionsChanged(ModListSortProxy::FilterMode mode, bool separators);
|
||||
void optionsChanged(
|
||||
ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep);
|
||||
|
||||
private:
|
||||
class CriteriaItem;
|
||||
|
||||
+10
-6
@@ -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<ModListSortProxy::Criteria>
|
||||
} 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<ModListSortProxy::Criteria>
|
||||
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)
|
||||
|
||||
+2
-1
@@ -515,7 +515,8 @@ private slots:
|
||||
void deselectFilters();
|
||||
void refreshFilters();
|
||||
void onFiltersCriteria(const std::vector<ModListSortProxy::Criteria>& filters);
|
||||
void onFiltersOptions(ModListSortProxy::FilterMode mode, bool separators);
|
||||
void onFiltersOptions(
|
||||
ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep);
|
||||
|
||||
void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
|
||||
|
||||
|
||||
+16
-5
@@ -153,6 +153,18 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="filtersAnd">
|
||||
<property name="toolTip">
|
||||
@@ -177,12 +189,11 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="filtersSeparators">
|
||||
<widget class="QComboBox" name="filtersSeparators">
|
||||
<property name="toolTip">
|
||||
<string>Include separators</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Separators</string>
|
||||
<string>Filter: only show the separators that match the current filters
|
||||
Show: always show separators
|
||||
Hide: never show separators</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
+40
-25
@@ -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<ModInfo::EFlag> &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;
|
||||
|
||||
+16
-9
@@ -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>& 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<Criteria> m_PreChangeCriteria;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user