mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-09-19 08:59:17 -04:00
Avoid const-cast in WorldList - subclass is unnecessary and result->formats() is correct
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
5ef61aa445
commit
24726ea621
@ -36,6 +36,7 @@
|
|||||||
#include "WorldList.h"
|
#include "WorldList.h"
|
||||||
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
|
#include <qmimedata.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
@ -301,50 +302,31 @@ QStringList WorldList::mimeTypes() const
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorldMimeData : public QMimeData {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
WorldMimeData(QList<World> worlds) { m_worlds = worlds; }
|
|
||||||
QStringList formats() const { return QMimeData::formats() << "text/uri-list"; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QVariant retrieveData(const QString& mimetype, QMetaType type) const
|
|
||||||
{
|
|
||||||
QList<QUrl> urls;
|
|
||||||
for (auto& world : m_worlds) {
|
|
||||||
if (!world.isValid() || !world.isOnFS())
|
|
||||||
continue;
|
|
||||||
QString worldPath = world.container().absoluteFilePath();
|
|
||||||
qDebug() << worldPath;
|
|
||||||
urls.append(QUrl::fromLocalFile(worldPath));
|
|
||||||
}
|
|
||||||
const_cast<WorldMimeData*>(this)->setUrls(urls);
|
|
||||||
return QMimeData::retrieveData(mimetype, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<World> m_worlds;
|
|
||||||
};
|
|
||||||
|
|
||||||
QMimeData* WorldList::mimeData(const QModelIndexList& indexes) const
|
QMimeData* WorldList::mimeData(const QModelIndexList& indexes) const
|
||||||
{
|
{
|
||||||
if (indexes.size() == 0)
|
QList<QUrl> urls;
|
||||||
return new QMimeData();
|
|
||||||
|
|
||||||
QList<World> worlds_;
|
|
||||||
for (auto idx : indexes) {
|
for (auto idx : indexes) {
|
||||||
if (idx.column() != 0)
|
if (idx.column() != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int row = idx.row();
|
int row = idx.row();
|
||||||
if (row < 0 || row >= this->m_worlds.size())
|
if (row < 0 || row >= this->m_worlds.size())
|
||||||
continue;
|
continue;
|
||||||
worlds_.append(this->m_worlds[row]);
|
|
||||||
|
const World& world = m_worlds[row];
|
||||||
|
|
||||||
|
if (!world.isValid() || !world.isOnFS())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QString worldPath = world.container().absoluteFilePath();
|
||||||
|
qDebug() << worldPath;
|
||||||
|
urls.append(QUrl::fromLocalFile(worldPath));
|
||||||
}
|
}
|
||||||
if (!worlds_.size()) {
|
|
||||||
return new QMimeData();
|
auto result = new QMimeData();
|
||||||
}
|
result->setUrls(urls);
|
||||||
return new WorldMimeData(worlds_);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags WorldList::flags(const QModelIndex& index) const
|
Qt::ItemFlags WorldList::flags(const QModelIndex& index) const
|
||||||
@ -453,5 +435,3 @@ void WorldList::loadWorldsAsync()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "WorldList.moc"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user