summaryrefslogtreecommitdiff
path: root/src/modlistbypriorityproxy.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-27 18:22:36 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:15 +0100
commit6444dd7f5c3596181a50fb408c012e3ed71fc283 (patch)
tree55eb0700f176f22f68028f1dbb1c5e5673930ee7 /src/modlistbypriorityproxy.cpp
parent6e3476586681e9897570cf2ea1ef5ed7b701bc19 (diff)
Fix drag-and-drop of separators.
Diffstat (limited to 'src/modlistbypriorityproxy.cpp')
-rw-r--r--src/modlistbypriorityproxy.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp
index 465c6342..1bbf9459 100644
--- a/src/modlistbypriorityproxy.cpp
+++ b/src/modlistbypriorityproxy.cpp
@@ -160,6 +160,37 @@ bool ModListByPriorityProxy::setData(const QModelIndex& index, const QVariant& v
bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const
{
+ bool firstRowSeparator = false;
+ try {
+ QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
+ QDataStream stream(&encoded, QIODevice::ReadOnly);
+
+ int firstRowPriority = INT_MAX;
+ unsigned int firstRowIndex = -1;
+
+ while (!stream.atEnd()) {
+ int sourceRow, col;
+ QMap<int, QVariant> roleDataMap;
+ stream >> sourceRow >> col >> roleDataMap;
+ if (col == 0) {
+ if (m_Profile->getModPriority(sourceRow) < firstRowPriority) {
+ firstRowIndex = sourceRow;
+ firstRowPriority = m_Profile->getModPriority(sourceRow);
+ }
+ }
+ }
+
+ firstRowSeparator = firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator();
+ }
+ catch (std::exception const&) {
+
+ }
+
+ // first row is a separator, we can drop it anywhere
+ if (firstRowSeparator) {
+ return QAbstractProxyModel::canDropMimeData(data, action, row, column, parent);
+ }
+
if (!parent.isValid() && row >= 0) {
// the row may be outside of the children list if we insert at the end