diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-11 20:57:32 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-11 20:57:32 +0100 |
| commit | 16b825bc5d9a03a3d0ef6453e07cf298e23965a2 (patch) | |
| tree | aab9ad1deea19fb0e7a204ef4da64180c0398c07 | |
| parent | 49c2c8f3330edccf54d1b5cc9958295288358c1c (diff) | |
Fix drop in first item of separators.
| -rw-r--r-- | src/modlistbypriorityproxy.cpp | 55 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 11 | ||||
| -rw-r--r-- | src/modlistsortproxy.h | 4 |
3 files changed, 48 insertions, 22 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index eca7108c..4fd589a4 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -257,25 +257,29 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction else { if (row >= 0) { - MOBase::log::debug("row={}, name={}, expand={}, drop={}", row, m_Root.children[row]->mod->name(), m_dropExpanded, m_dropPosition); if (!parent.isValid()) { if (row < m_Root.children.size()) { - sourceRow = m_Root.children[row]->index; - if (row > 0 - && m_sortOrder == Qt::AscendingOrder - && m_Root.children[row - 1]->mod->isSeparator() - && !m_Root.children[row - 1]->children.empty() - && m_dropExpanded - && m_dropPosition == ModListView::DropPosition::BelowItem) { + if (m_sortOrder == Qt::AscendingOrder) { + sourceRow = m_Root.children[row]->index; + if (row > 0 + && m_sortOrder == Qt::AscendingOrder + && m_Root.children[row - 1]->mod->isSeparator() + && !m_Root.children[row - 1]->children.empty() + && m_dropExpanded + && m_dropPosition == ModListView::DropPosition::BelowItem) { sourceRow = m_Root.children[row - 1]->children[0]->index; + } } - else if (row > 0 - && m_sortOrder == Qt::DescendingOrder - && m_Root.children[row]->mod->isSeparator() - && !m_Root.children[row]->children.empty() - && (!m_dropExpanded - || m_dropPosition == ModListView::DropPosition::AboveItem)) { - sourceRow = m_Root.children[row]->children.back()->index; + else { + sourceRow = m_Root.children[row - 1]->index; + if (row > 0 + && m_sortOrder == Qt::DescendingOrder + && m_Root.children[row - 1]->mod->isSeparator() + && !m_Root.children[row - 1]->children.empty() + && (!m_dropExpanded + || m_dropPosition == ModListView::DropPosition::AboveItem)) { + sourceRow = m_Root.children[row - 1]->children.back()->index; + } } } else { @@ -285,12 +289,25 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction else { auto* item = static_cast<TreeItem*>(parent.internalPointer()); - if (row < item->children.size()) { - sourceRow = item->children[row]->index; + if (m_sortOrder == Qt::DescendingOrder + && row == 0 && m_dropPosition == ModListView::DropPosition::AboveItem) { + sourceRow = item->index; } - else if (parent.row() + 1 < m_Root.children.size()) { - sourceRow = m_Root.children[parent.row() + 1]->index; + else { + + if (m_sortOrder == Qt::DescendingOrder) { + row--; + } + + if (row < item->children.size()) { + sourceRow = item->children[row]->index; + } + else if (parent.row() + 1 < m_Root.children.size()) { + sourceRow = m_Root.children[parent.row() + 1]->index; + } } + + } } else if (parent.isValid()) { diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index bc28490f..1077a833 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -18,6 +18,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. */
#include "modlistsortproxy.h"
+#include "modlistbypriorityproxy.h"
#include "modlistdropinfo.h"
#include "modinfo.h"
#include "profile.h"
@@ -279,7 +280,6 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const bool ModListSortProxy::optionsMatchMod(ModInfo::Ptr info, bool) const
{
-
return true;
}
@@ -598,6 +598,11 @@ bool ModListSortProxy::filterAcceptsRow(int source_row, const QModelIndex &paren }
}
+bool ModListSortProxy::sourceIsByPriorityProxy() const
+{
+ return dynamic_cast<ModListByPriorityProxy*>(sourceModel()) != nullptr;
+}
+
bool ModListSortProxy::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const
{
ModListDropInfo dropInfo(data, *m_Organizer);
@@ -620,7 +625,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 && row != -1) {
+ if (sortOrder() == Qt::DescendingOrder && row != -1 && !sourceIsByPriorityProxy()) {
--row;
}
@@ -645,7 +650,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 && row != -1) {
+ if (sortOrder() == Qt::DescendingOrder && row != -1 && !sourceIsByPriorityProxy()) {
--row;
}
diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h index 421c82cc..23be77ed 100644 --- a/src/modlistsortproxy.h +++ b/src/modlistsortproxy.h @@ -140,6 +140,10 @@ private: bool filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const;
bool filterMatchesModOr(ModInfo::Ptr info, bool enabled) const;
+ // check if the source model is the by-priority proxy
+ //
+ bool sourceIsByPriorityProxy() const;
+
private slots:
void aboutToChangeData();
|
