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 <FileSystem.h>
|
||||
#include <qmimedata.h>
|
||||
#include <QDebug>
|
||||
#include <QDirIterator>
|
||||
#include <QFileSystemWatcher>
|
||||
@ -301,50 +302,31 @@ QStringList WorldList::mimeTypes() const
|
||||
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
|
||||
{
|
||||
QMimeData* WorldList::mimeData(const QModelIndexList& indexes) const
|
||||
{
|
||||
QList<QUrl> urls;
|
||||
for (auto& world : m_worlds) {
|
||||
|
||||
for (auto idx : indexes) {
|
||||
if (idx.column() != 0)
|
||||
continue;
|
||||
|
||||
int row = idx.row();
|
||||
if (row < 0 || row >= this->m_worlds.size())
|
||||
continue;
|
||||
|
||||
const World& world = m_worlds[row];
|
||||
|
||||
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
|
||||
{
|
||||
if (indexes.size() == 0)
|
||||
return new QMimeData();
|
||||
|
||||
QList<World> worlds_;
|
||||
for (auto idx : indexes) {
|
||||
if (idx.column() != 0)
|
||||
continue;
|
||||
int row = idx.row();
|
||||
if (row < 0 || row >= this->m_worlds.size())
|
||||
continue;
|
||||
worlds_.append(this->m_worlds[row]);
|
||||
}
|
||||
if (!worlds_.size()) {
|
||||
return new QMimeData();
|
||||
}
|
||||
return new WorldMimeData(worlds_);
|
||||
auto result = new QMimeData();
|
||||
result->setUrls(urls);
|
||||
return result;
|
||||
}
|
||||
|
||||
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