From 4636d7bd5d092ff47146248232cd73c8d0254d7a Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Mon, 28 Dec 2020 13:50:43 +0100 Subject: Small refactoring to avoid duplicated code. --- src/modlistbypriorityproxy.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/modlistbypriorityproxy.cpp') 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); - - int firstRowPriority = INT_MAX; - unsigned int firstRowIndex = -1; - - while (!stream.atEnd()) { - int sourceRow, col; - QMap roleDataMap; - stream >> sourceRow >> col >> roleDataMap; - if (col == 0) { + if (data->hasText()) { + bool firstRowSeparator = false; + + try { + int firstRowPriority = INT_MAX; + unsigned int firstRowIndex = -1; + + 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) { -- cgit v1.3.1