summaryrefslogtreecommitdiff
path: root/src/modlistbypriorityproxy.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-28 13:50:43 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:15 +0100
commit4636d7bd5d092ff47146248232cd73c8d0254d7a (patch)
tree2b24e8f0847a0fd18c98646ea1aea4e9e994bb91 /src/modlistbypriorityproxy.cpp
parentaddb38645b41507ae8e0536bb83d3b99d365f664 (diff)
Small refactoring to avoid duplicated code.
Diffstat (limited to 'src/modlistbypriorityproxy.cpp')
-rw-r--r--src/modlistbypriorityproxy.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp
index dc51617e..eb931aa9 100644
--- a/src/modlistbypriorityproxy.cpp
+++ b/src/modlistbypriorityproxy.cpp
@@ -160,35 +160,30 @@ 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);
+ if (data->hasText()) {
+ bool firstRowSeparator = false;
- int firstRowPriority = INT_MAX;
- unsigned int firstRowIndex = -1;
+ try {
+ 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) {
+ for (auto sourceRow : ModList::sourceRows(data)) {
if (m_Profile->getModPriority(sourceRow) < firstRowPriority) {
firstRowIndex = sourceRow;
firstRowPriority = m_Profile->getModPriority(sourceRow);
}
}
- }
- firstRowSeparator = firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator();
- }
- catch (std::exception const&) {
+ 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);
+ // 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) {