mirror of
https://github.com/ModOrganizer2/modorganizer.git
synced 2026-07-27 13:58:24 -07:00
Small refactoring to avoid duplicated code.
This commit is contained in:
+4
-4
@@ -1108,7 +1108,7 @@ int ModList::dropPriority(int row, const QModelIndex& parent) const
|
||||
return newPriority;
|
||||
}
|
||||
|
||||
std::vector<int> ModList::sourceRows(const QMimeData* mimeData) const
|
||||
std::vector<int> ModList::sourceRows(const QMimeData* mimeData)
|
||||
{
|
||||
QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
|
||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||
@@ -1125,7 +1125,7 @@ std::vector<int> ModList::sourceRows(const QMimeData* mimeData) const
|
||||
return sourceRows;
|
||||
}
|
||||
|
||||
std::optional<std::pair<QString, QString>> ModList::relativeUrl(const QUrl& url) const
|
||||
std::optional<std::pair<QString, QString>> ModList::relativeUrl(const QUrl& url)
|
||||
{
|
||||
if (!url.isLocalFile()) {
|
||||
return {};
|
||||
@@ -1211,7 +1211,7 @@ bool ModList::dropMod(const QMimeData *mimeData, int row, const QModelIndex &par
|
||||
}
|
||||
|
||||
try {
|
||||
std::vector<int> sourceRows = this->sourceRows(mimeData);
|
||||
std::vector<int> sourceRows = ModList::sourceRows(mimeData);
|
||||
changeModPriority(sourceRows, newPriority);
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
@@ -1229,7 +1229,7 @@ bool ModList::dropArchive(const QMimeData* mimeData, int row, const QModelIndex&
|
||||
}
|
||||
|
||||
try {
|
||||
std::vector<int> sourceRows = this->sourceRows(mimeData);
|
||||
std::vector<int> sourceRows = ModList::sourceRows(mimeData);
|
||||
if (sourceRows.size() == 1) {
|
||||
emit downloadArchiveDropped(sourceRows[0], priority);
|
||||
}
|
||||
|
||||
+2
-2
@@ -372,12 +372,12 @@ private:
|
||||
// retrieve the relative path of file and its origin given a URL from Mime data
|
||||
// returns an empty optional if the URL is not a valid file for dropping
|
||||
//
|
||||
std::optional<std::pair<QString, QString>> relativeUrl(const QUrl&) const;
|
||||
static std::optional<std::pair<QString, QString>> relativeUrl(const QUrl&);
|
||||
|
||||
// return the source rows from the given mime data for drag&drop of mods or
|
||||
// installation archives
|
||||
//
|
||||
std::vector<int> sourceRows(const QMimeData* mimeData) const;
|
||||
static std::vector<int> sourceRows(const QMimeData* mimeData);
|
||||
|
||||
bool dropURLs(const QMimeData* mimeData, int row, const QModelIndex& parent);
|
||||
bool dropMod(const QMimeData* mimeData, int row, const QModelIndex& parent);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user