summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-11 19:15:39 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-11 19:15:39 +0100
commit08520822eb91c065a0893da0e2e9d11574450208 (patch)
treed137ce8d040e8b149876b4e986dd817e3d25e56a
parente53905329a7a204ad0ad41600a9fb3040b942991 (diff)
Fix drop in separator and create mod in separator in descending priority.
-rw-r--r--src/modlistbypriorityproxy.cpp3
-rw-r--r--src/modlistsortproxy.cpp4
-rw-r--r--src/modlistview.cpp5
-rw-r--r--src/modlistview.h3
-rw-r--r--src/modlistviewactions.cpp31
5 files changed, 30 insertions, 16 deletions
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;
+ }
}
}
}