diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-07 21:46:58 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-10 10:27:30 +0100 |
| commit | 7d9fa5e4f96840321ff996b4c637b7cd686c3570 (patch) | |
| tree | d078e7264f80edafe0e05360edaa3fb6d79a990f | |
| parent | fc60ea5b7a023493375a6fced6572156f48e36c3 (diff) | |
Fix drop below collapsed separator.
| -rw-r--r-- | src/modlistbypriorityproxy.cpp | 38 | ||||
| -rw-r--r-- | src/modlistbypriorityproxy.h | 10 | ||||
| -rw-r--r-- | src/modlistview.cpp | 10 | ||||
| -rw-r--r-- | src/modlistview.h | 8 |
4 files changed, 49 insertions, 17 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index 6f549d91..c0d70571 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -183,6 +183,25 @@ bool ModListByPriorityProxy::setData(const QModelIndex& index, const QVariant& v return QAbstractProxyModel::setData(index, value, role); } +std::pair<bool, bool> ModListByPriorityProxy::dropSeparators(const ModListDropInfo& dropInfo) const +{ + bool hasSeparator = false; + unsigned int firstRowIndex = -1; + + int firstRowPriority = INT_MAX; + for (auto sourceRow : dropInfo.rows()) { + hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); + if (m_profile->getModPriority(sourceRow) < firstRowPriority) { + firstRowIndex = sourceRow; + firstRowPriority = m_profile->getModPriority(sourceRow); + } + } + + bool firstRowSeparator = firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator(); + + return { hasSeparator, firstRowSeparator }; +} + bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const { ModListDropInfo dropInfo(data, m_core); @@ -193,19 +212,7 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi if (dropInfo.isModDrop()) { - bool hasSeparator = false; - unsigned int firstRowIndex = -1; - - int firstRowPriority = INT_MAX; - for (auto sourceRow : dropInfo.rows()) { - hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); - if (m_profile->getModPriority(sourceRow) < firstRowPriority) { - firstRowIndex = sourceRow; - firstRowPriority = m_profile->getModPriority(sourceRow); - } - } - - bool firstRowSeparator = firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator(); + auto [hasSeparator, firstRowSeparator] = dropSeparators(dropInfo); // row = -1 and invalid parent means we're dropping onto an item, we don't want to drop // separators onto items or items into their own separator @@ -264,6 +271,7 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction } } else { + if (row >= 0) { if (!parent.isValid()) { if (row < m_Root.children.size()) { @@ -271,6 +279,7 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction if (row > 0 && 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; } @@ -316,7 +325,8 @@ QModelIndex ModListByPriorityProxy::index(int row, int column, const QModelIndex return createIndex(row, column, parentItem->children[row].get()); } -void ModListByPriorityProxy::onDropEnter(const QMimeData*, ModListView::DropPosition dropPosition) +void ModListByPriorityProxy::onDropEnter(const QMimeData*, bool dropExpanded, ModListView::DropPosition dropPosition) { + m_dropExpanded = dropExpanded; m_dropPosition = dropPosition; } diff --git a/src/modlistbypriorityproxy.h b/src/modlistbypriorityproxy.h index 6b48678a..c64a7973 100644 --- a/src/modlistbypriorityproxy.h +++ b/src/modlistbypriorityproxy.h @@ -16,6 +16,7 @@ #include "modlistview.h" class ModList; +class ModListDropInfo; class Profile; class ModListByPriorityProxy : public QAbstractProxyModel @@ -46,7 +47,7 @@ public: public slots: - void onDropEnter(const QMimeData* data, ModListView::DropPosition dropPosition); + void onDropEnter(const QMimeData* data, bool dropExpanded, ModListView::DropPosition dropPosition); protected slots: @@ -54,6 +55,11 @@ protected slots: private: + // returns a pair of boolean, the first one indicates if the drop info + // contains separators, the first one if the first row is a separator + // + std::pair<bool, bool> dropSeparators(const ModListDropInfo& dropInfo) const; + void buildTree(); struct TreeItem { @@ -83,6 +89,8 @@ private: private: OrganizerCore& m_core; Profile* m_profile; + + bool m_dropExpanded = false; ModListView::DropPosition m_dropPosition = ModListView::DropPosition::OnItem; }; diff --git a/src/modlistview.cpp b/src/modlistview.cpp index ec31d4dc..91d522a6 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -1295,10 +1295,18 @@ void ModListView::dragMoveEvent(QDragMoveEvent* event) void ModListView::dropEvent(QDropEvent* event)
{
+ // from Qt source
+ QModelIndex index;
+ if (viewport()->rect().contains(event->pos())) {
+ index = indexAt(event->pos());
+ if (!index.isValid() || !visualRect(index).contains(event->pos()))
+ index = QModelIndex();
+ }
+
// this event is used by the byPriorityProxy to know if allow
// dropping mod between a separator and its first mod (there
// is no way to deduce this except using dropIndicatorPosition())
- emit dropEntered(event->mimeData(), static_cast<DropPosition>(dropIndicatorPosition()));
+ emit dropEntered(event->mimeData(), isExpanded(index), static_cast<DropPosition>(dropIndicatorPosition()));
// see selectedIndexes()
m_inDragMoveEvent = true;
diff --git a/src/modlistview.h b/src/modlistview.h index d8e08a99..6301a5da 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -90,8 +90,14 @@ public: signals:
+ // emitted for dragEnter events
+ //
void dragEntered(const QMimeData* mimeData);
- void dropEntered(const QMimeData* mimeData, DropPosition position);
+
+ // emitted for dropEnter events, the boolean indicates if the drop target
+ // is expanded and the position of the indicator
+ //
+ void dropEntered(const QMimeData* mimeData, bool dropExpanded, DropPosition position);
public slots:
|
