From e53905329a7a204ad0ad41600a9fb3040b942991 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 11 Jan 2021 18:55:15 +0100 Subject: Allow collapsible separator in descending priority. --- src/modlistview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modlistview.cpp') diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 8827733b..1926a3f4 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -683,8 +683,8 @@ void ModListView::updateGroupByProxy() nextProxy = m_byNexusIdProxy; } else if (m_core->settings().interface().collapsibleSeparators() - && m_sortProxy->sortColumn() == ModList::COL_PRIORITY - && m_sortProxy->sortOrder() == Qt::AscendingOrder) { + && m_sortProxy->sortColumn() == ModList::COL_PRIORITY) { + m_byPriorityProxy->setSortOrder(m_sortProxy->sortOrder()); nextProxy = m_byPriorityProxy; } -- cgit v1.3.1 From 08520822eb91c065a0893da0e2e9d11574450208 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 11 Jan 2021 19:15:39 +0100 Subject: Fix drop in separator and create mod in separator in descending priority. --- src/modlistbypriorityproxy.cpp | 3 --- src/modlistsortproxy.cpp | 4 ++-- src/modlistview.cpp | 5 +++++ src/modlistview.h | 3 ++- src/modlistviewactions.cpp | 31 +++++++++++++++++++++---------- 5 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src/modlistview.cpp') diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index e6728942..eca7108c 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -104,9 +104,6 @@ void ModListByPriorityProxy::buildTree() std::make_move_iterator(backups.begin()), std::make_move_iterator(backups.end())); } - // we do not really care about their position in the root - // as long as those are not in a separator - endResetModel(); } diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 0682b9c3..bc28490f 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -620,7 +620,7 @@ bool ModListSortProxy::canDropMimeData(const QMimeData* data, Qt::DropAction act // in the regular model, when dropping between rows, the row-value passed to // the sourceModel is inconsistent between ascending and descending ordering. // This should fix that - if (sortOrder() == Qt::DescendingOrder) { + if (sortOrder() == Qt::DescendingOrder && row != -1) { --row; } @@ -645,7 +645,7 @@ bool ModListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction action // in the regular model, when dropping between rows, the row-value passed to // the sourceModel is inconsistent between ascending and descending ordering. // This should fix that - if (sortOrder() == Qt::DescendingOrder) { + if (sortOrder() == Qt::DescendingOrder && row != -1) { --row; } diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 1926a3f4..88c588f6 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -209,6 +209,11 @@ int ModListView::sortColumn() const return m_sortProxy ? m_sortProxy->sortColumn() : -1; } +Qt::SortOrder ModListView::sortOrder() const +{ + return m_sortProxy ? m_sortProxy->sortOrder() : Qt::AscendingOrder; +} + ModListView::GroupByMode ModListView::groupByMode() const { if (m_sortProxy == nullptr) { diff --git a/src/modlistview.h b/src/modlistview.h index 53c71458..13f868c6 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -61,9 +61,10 @@ public: // bool hasCollapsibleSeparators() const; - // the column by which the mod list is currently sorted + // the column/order by which the mod list is currently sorted // int sortColumn() const; + Qt::SortOrder sortOrder() const; // the current group mode // diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index cc50f009..09142026 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -103,22 +103,33 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const auto info = ModInfo::getByIndex(mIndex); newPriority = m_core.currentProfile()->getModPriority(mIndex); if (info->isSeparator()) { + + auto isSeparator = [](const auto& p) { + return ModInfo::getByIndex(p.second)->isSeparator(); + }; + auto& ibp = m_core.currentProfile()->getAllIndexesByPriority(); - // start right after the current priority and look for the next + // start right after/before the current priority and look for the next // separator - auto it = ibp.find(newPriority + 1); - for (; it != ibp.end(); ++it) { - auto info = ModInfo::getByIndex(it->second); - if (info->isSeparator()) { + if (m_view->sortOrder() == Qt::AscendingOrder) { + auto it = std::find_if(ibp.find(newPriority + 1), ibp.end(), isSeparator); + if (it != ibp.end()) { newPriority = it->first; - break; + } + else { + newPriority = -1; } } - - // no separator found, create at the end - if (it == ibp.end()) { - newPriority = -1; + else { + auto it = std::find_if(std::reverse_iterator{ ibp.find(newPriority - 1) }, ibp.rend(), isSeparator); + if (it != ibp.rend()) { + newPriority = it->first + 1; + } + else { + // create "before" priority 0, i.e. at the end in descending priority. + newPriority = 0; + } } } } -- cgit v1.3.1 From 49c2c8f3330edccf54d1b5cc9958295288358c1c Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 11 Jan 2021 19:44:43 +0100 Subject: Add setting to enable/disable collapsible priority depending on the sort order. --- src/modlistview.cpp | 2 +- src/settings.cpp | 11 +++++--- src/settings.h | 4 +-- src/settingsdialog.ui | 53 ++++++++++++++++++++++++++++++++++++- src/settingsdialoguserinterface.cpp | 20 +++++++++----- src/settingsdialoguserinterface.h | 6 +++++ 6 files changed, 82 insertions(+), 14 deletions(-) (limited to 'src/modlistview.cpp') diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 88c588f6..ae905a6e 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -687,7 +687,7 @@ void ModListView::updateGroupByProxy() else if (groupIndex == GroupBy::NEXUS_ID) { nextProxy = m_byNexusIdProxy; } - else if (m_core->settings().interface().collapsibleSeparators() + else if (m_core->settings().interface().collapsibleSeparators(m_sortProxy->sortOrder()) && m_sortProxy->sortColumn() == ModList::COL_PRIORITY) { m_byPriorityProxy->setSortOrder(m_sortProxy->sortOrder()); nextProxy = m_byPriorityProxy; diff --git a/src/settings.cpp b/src/settings.cpp index 488a9b01..d1f3ef4f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2175,14 +2175,17 @@ void InterfaceSettings::setStyleName(const QString& name) set(m_Settings, "Settings", "style", name); } -bool InterfaceSettings::collapsibleSeparators() const +bool InterfaceSettings::collapsibleSeparators(Qt::SortOrder order) const { - return get(m_Settings, "Settings", "collapsible_separators", true); + return get(m_Settings, "Settings", + order == Qt::AscendingOrder ? "collapsible_separators_asc" : "collapsible_separators_dsc", + order == Qt::AscendingOrder); } -void InterfaceSettings::setCollapsibleSeparators(bool b) +void InterfaceSettings::setCollapsibleSeparators(bool ascending, bool descending) { - set(m_Settings, "Settings", "collapsible_separators", b); + set(m_Settings, "Settings", "collapsible_separators_asc", ascending); + set(m_Settings, "Settings", "collapsible_separators_dsc", descending); } bool InterfaceSettings::collapsibleSeparatorsConflicts() const diff --git a/src/settings.h b/src/settings.h index efcfee57..484ce163 100644 --- a/src/settings.h +++ b/src/settings.h @@ -623,8 +623,8 @@ public: // whether to use collapsible separators when possible // - bool collapsibleSeparators() const; - void setCollapsibleSeparators(bool b); + bool collapsibleSeparators(Qt::SortOrder order) const; + void setCollapsibleSeparators(bool ascending, bool descending); // whether to display mod conflicts on separators when collapsed // diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index d5c93c5c..b23e6d90 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -306,7 +306,10 @@ If you disable this feature, MO will only display official DLCs this way. Please false - true + false + + + false @@ -315,6 +318,54 @@ If you disable this feature, MO will only display official DLCs this way. Please 7 + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + When sorting by + + + + + + + ascending priority + + + true + + + + + + + descending priority + + + + + + diff --git a/src/settingsdialoguserinterface.cpp b/src/settingsdialoguserinterface.cpp index 5d856395..cdd30f2e 100644 --- a/src/settingsdialoguserinterface.cpp +++ b/src/settingsdialoguserinterface.cpp @@ -13,16 +13,15 @@ UserInterfaceSettingsTab::UserInterfaceSettingsTab(Settings& s, SettingsDialog& { // connect before setting to trigger - QObject::connect(ui->collapsibleSeparatorsBox, &QGroupBox::toggled, [=](auto&& on) { - ui->collapsibleSeparatorsConflictsBox->setEnabled(on); - ui->collapsibleSeparatorsPerProfileBox->setEnabled(on); - }); + QObject::connect(ui->collapsibleSeparatorsAscBox, &QCheckBox::toggled, [=] { updateCollapsibleSeparatorsGroup(); }); + QObject::connect(ui->collapsibleSeparatorsDscBox, &QCheckBox::toggled, [=] { updateCollapsibleSeparatorsGroup(); }); // mod list ui->displayForeignBox->setChecked(settings().interface().displayForeign()); ui->colorSeparatorsBox->setChecked(settings().colors().colorSeparatorScrollbar()); ui->collapsibleSeparatorsConflictsBox->setChecked(settings().interface().collapsibleSeparatorsConflicts()); - ui->collapsibleSeparatorsBox->setChecked(settings().interface().collapsibleSeparators()); + ui->collapsibleSeparatorsAscBox->setChecked(settings().interface().collapsibleSeparators(Qt::AscendingOrder)); + ui->collapsibleSeparatorsDscBox->setChecked(settings().interface().collapsibleSeparators(Qt::DescendingOrder)); ui->collapsibleSeparatorsPerProfileBox->setChecked(settings().interface().collapsibleSeparatorsPerProfile()); ui->saveFiltersBox->setChecked(settings().interface().saveFilters()); @@ -42,7 +41,8 @@ void UserInterfaceSettingsTab::update() // mod list settings().colors().setColorSeparatorScrollbar(ui->colorSeparatorsBox->isChecked()); settings().interface().setDisplayForeign(ui->displayForeignBox->isChecked()); - settings().interface().setCollapsibleSeparators(ui->collapsibleSeparatorsBox->isChecked()); + settings().interface().setCollapsibleSeparators( + ui->collapsibleSeparatorsAscBox->isChecked(), ui->collapsibleSeparatorsDscBox->isChecked()); settings().interface().setCollapsibleSeparatorsConflicts(ui->collapsibleSeparatorsConflictsBox->isChecked()); settings().interface().setCollapsibleSeparatorsPerProfile(ui->collapsibleSeparatorsPerProfileBox->isChecked()); settings().interface().setSaveFilters(ui->saveFiltersBox->isChecked()); @@ -54,3 +54,11 @@ void UserInterfaceSettingsTab::update() // colors ui->colorTable->commitColors(); } + +void UserInterfaceSettingsTab::updateCollapsibleSeparatorsGroup() +{ + const auto checked = ui->collapsibleSeparatorsAscBox->isChecked() || + ui->collapsibleSeparatorsDscBox->isChecked(); + ui->collapsibleSeparatorsConflictsBox->setEnabled(checked); + ui->collapsibleSeparatorsPerProfileBox->setEnabled(checked); +} diff --git a/src/settingsdialoguserinterface.h b/src/settingsdialoguserinterface.h index 8b4d48fa..4609ae54 100644 --- a/src/settingsdialoguserinterface.h +++ b/src/settingsdialoguserinterface.h @@ -10,6 +10,12 @@ public: UserInterfaceSettingsTab(Settings& settings, SettingsDialog& dialog); void update() override; + +protected slots: + + // enable/disable the collapsible separators group depending on + // the checkbox states + void updateCollapsibleSeparatorsGroup(); }; #endif // SETTINGSDIALOGGENERAL_H -- cgit v1.3.1