Remove some unnecessary const_casting (#4150)
This commit is contained in:
@@ -30,21 +30,21 @@ class BaseVersion {
|
|||||||
* A string used to identify this version in config files.
|
* A string used to identify this version in config files.
|
||||||
* This should be unique within the version list or shenanigans will occur.
|
* This should be unique within the version list or shenanigans will occur.
|
||||||
*/
|
*/
|
||||||
virtual QString descriptor() = 0;
|
virtual QString descriptor() const = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* The name of this version as it is displayed to the user.
|
* The name of this version as it is displayed to the user.
|
||||||
* For example: "1.5.1"
|
* For example: "1.5.1"
|
||||||
*/
|
*/
|
||||||
virtual QString name() = 0;
|
virtual QString name() const = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This should return a string that describes
|
* This should return a string that describes
|
||||||
* the kind of version this is (Stable, Beta, Snapshot, whatever)
|
* the kind of version this is (Stable, Beta, Snapshot, whatever)
|
||||||
*/
|
*/
|
||||||
virtual QString typeString() const = 0;
|
virtual QString typeString() const = 0;
|
||||||
virtual bool operator<(BaseVersion& a) { return name() < a.name(); }
|
virtual bool operator<(BaseVersion& a) const { return name() < a.name(); }
|
||||||
virtual bool operator>(BaseVersion& a) { return name() > a.name(); }
|
virtual bool operator>(BaseVersion& a) const { return name() > a.name(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BaseVersion::Ptr)
|
Q_DECLARE_METATYPE(BaseVersion::Ptr)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "BaseVersion.h"
|
#include "BaseVersion.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
bool JavaInstall::operator<(const JavaInstall& rhs)
|
bool JavaInstall::operator<(const JavaInstall& rhs) const
|
||||||
{
|
{
|
||||||
auto archCompare = StringUtils::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
|
auto archCompare = StringUtils::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
|
||||||
if (archCompare != 0)
|
if (archCompare != 0)
|
||||||
@@ -35,17 +35,17 @@ bool JavaInstall::operator<(const JavaInstall& rhs)
|
|||||||
return StringUtils::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
return StringUtils::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator==(const JavaInstall& rhs)
|
bool JavaInstall::operator==(const JavaInstall& rhs) const
|
||||||
{
|
{
|
||||||
return arch == rhs.arch && id == rhs.id && path == rhs.path;
|
return arch == rhs.arch && id == rhs.id && path == rhs.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator>(const JavaInstall& rhs)
|
bool JavaInstall::operator>(const JavaInstall& rhs) const
|
||||||
{
|
{
|
||||||
return (!operator<(rhs)) && (!operator==(rhs));
|
return (!operator<(rhs)) && (!operator==(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator<(BaseVersion& a)
|
bool JavaInstall::operator<(BaseVersion& a) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return operator<(dynamic_cast<JavaInstall&>(a));
|
return operator<(dynamic_cast<JavaInstall&>(a));
|
||||||
@@ -54,7 +54,7 @@ bool JavaInstall::operator<(BaseVersion& a)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaInstall::operator>(BaseVersion& a)
|
bool JavaInstall::operator>(BaseVersion& a) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return operator>(dynamic_cast<JavaInstall&>(a));
|
return operator>(dynamic_cast<JavaInstall&>(a));
|
||||||
|
|||||||
@@ -24,17 +24,17 @@
|
|||||||
struct JavaInstall : public BaseVersion {
|
struct JavaInstall : public BaseVersion {
|
||||||
JavaInstall() {}
|
JavaInstall() {}
|
||||||
JavaInstall(QString id, QString arch, QString path) : id(id), arch(arch), path(path) {}
|
JavaInstall(QString id, QString arch, QString path) : id(id), arch(arch), path(path) {}
|
||||||
virtual QString descriptor() override { return id.toString(); }
|
virtual QString descriptor() const override { return id.toString(); }
|
||||||
|
|
||||||
virtual QString name() override { return id.toString(); }
|
virtual QString name() const override { return id.toString(); }
|
||||||
|
|
||||||
virtual QString typeString() const override { return arch; }
|
virtual QString typeString() const override { return arch; }
|
||||||
|
|
||||||
virtual bool operator<(BaseVersion& a) override;
|
virtual bool operator<(BaseVersion& a) const override;
|
||||||
virtual bool operator>(BaseVersion& a) override;
|
virtual bool operator>(BaseVersion& a) const override;
|
||||||
bool operator<(const JavaInstall& rhs);
|
bool operator<(const JavaInstall& rhs) const;
|
||||||
bool operator==(const JavaInstall& rhs);
|
bool operator==(const JavaInstall& rhs) const;
|
||||||
bool operator>(const JavaInstall& rhs);
|
bool operator>(const JavaInstall& rhs) const;
|
||||||
|
|
||||||
JavaVersion id;
|
JavaVersion id;
|
||||||
QString arch;
|
QString arch;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ MetadataPtr parseJavaMeta(const QJsonObject& in)
|
|||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Metadata::operator<(const Metadata& rhs)
|
bool Metadata::operator<(const Metadata& rhs) const
|
||||||
{
|
{
|
||||||
auto id = version;
|
auto id = version;
|
||||||
if (id < rhs.version) {
|
if (id < rhs.version) {
|
||||||
@@ -97,17 +97,17 @@ bool Metadata::operator<(const Metadata& rhs)
|
|||||||
return StringUtils::naturalCompare(m_name, rhs.m_name, Qt::CaseInsensitive) < 0;
|
return StringUtils::naturalCompare(m_name, rhs.m_name, Qt::CaseInsensitive) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Metadata::operator==(const Metadata& rhs)
|
bool Metadata::operator==(const Metadata& rhs) const
|
||||||
{
|
{
|
||||||
return version == rhs.version && m_name == rhs.m_name;
|
return version == rhs.version && m_name == rhs.m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Metadata::operator>(const Metadata& rhs)
|
bool Metadata::operator>(const Metadata& rhs) const
|
||||||
{
|
{
|
||||||
return (!operator<(rhs)) && (!operator==(rhs));
|
return (!operator<(rhs)) && (!operator==(rhs));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Metadata::operator<(BaseVersion& a)
|
bool Metadata::operator<(BaseVersion& a) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return operator<(dynamic_cast<Metadata&>(a));
|
return operator<(dynamic_cast<Metadata&>(a));
|
||||||
@@ -116,7 +116,7 @@ bool Metadata::operator<(BaseVersion& a)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Metadata::operator>(BaseVersion& a)
|
bool Metadata::operator>(BaseVersion& a) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return operator>(dynamic_cast<Metadata&>(a));
|
return operator>(dynamic_cast<Metadata&>(a));
|
||||||
|
|||||||
@@ -32,17 +32,17 @@ enum class DownloadType { Manifest, Archive, Unknown };
|
|||||||
|
|
||||||
class Metadata : public BaseVersion {
|
class Metadata : public BaseVersion {
|
||||||
public:
|
public:
|
||||||
virtual QString descriptor() override { return version.toString(); }
|
virtual QString descriptor() const override { return version.toString(); }
|
||||||
|
|
||||||
virtual QString name() override { return m_name; }
|
virtual QString name() const override { return m_name; }
|
||||||
|
|
||||||
virtual QString typeString() const override { return vendor; }
|
virtual QString typeString() const override { return vendor; }
|
||||||
|
|
||||||
virtual bool operator<(BaseVersion& a) override;
|
virtual bool operator<(BaseVersion& a) const override;
|
||||||
virtual bool operator>(BaseVersion& a) override;
|
virtual bool operator>(BaseVersion& a) const override;
|
||||||
bool operator<(const Metadata& rhs);
|
bool operator<(const Metadata& rhs) const;
|
||||||
bool operator==(const Metadata& rhs);
|
bool operator==(const Metadata& rhs) const;
|
||||||
bool operator>(const Metadata& rhs);
|
bool operator>(const Metadata& rhs) const;
|
||||||
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString vendor;
|
QString vendor;
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
|
|
||||||
Meta::Version::Version(const QString& uid, const QString& version) : BaseVersion(), m_uid(uid), m_version(version) {}
|
Meta::Version::Version(const QString& uid, const QString& version) : BaseVersion(), m_uid(uid), m_version(version) {}
|
||||||
|
|
||||||
QString Meta::Version::descriptor()
|
QString Meta::Version::descriptor() const
|
||||||
{
|
{
|
||||||
return m_version;
|
return m_version;
|
||||||
}
|
}
|
||||||
QString Meta::Version::name()
|
QString Meta::Version::name() const
|
||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data)
|
||||||
return m_data->name;
|
return m_data->name;
|
||||||
@@ -88,7 +88,7 @@ QString Meta::Version::localFilename() const
|
|||||||
|
|
||||||
::Version Meta::Version::toComparableVersion() const
|
::Version Meta::Version::toComparableVersion() const
|
||||||
{
|
{
|
||||||
return { const_cast<Meta::Version*>(this)->descriptor() };
|
return { descriptor() };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Meta::Version::setType(const QString& type)
|
void Meta::Version::setType(const QString& type)
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ class Version : public QObject, public BaseVersion, public BaseEntity {
|
|||||||
explicit Version(const QString& uid, const QString& version);
|
explicit Version(const QString& uid, const QString& version);
|
||||||
virtual ~Version() = default;
|
virtual ~Version() = default;
|
||||||
|
|
||||||
QString descriptor() override;
|
QString descriptor() const override;
|
||||||
QString name() override;
|
QString name() const override;
|
||||||
QString typeString() const override;
|
QString typeString() const override;
|
||||||
|
|
||||||
QString uid() const { return m_uid; }
|
QString uid() const { return m_uid; }
|
||||||
|
|||||||
@@ -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"
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void ProgressWidget::progressFormat(QString format)
|
|||||||
m_bar->setFormat(format);
|
m_bar->setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressWidget::watch(const Task* task)
|
void ProgressWidget::watch(Task* task)
|
||||||
{
|
{
|
||||||
if (!task)
|
if (!task)
|
||||||
return;
|
return;
|
||||||
@@ -61,11 +61,11 @@ void ProgressWidget::watch(const Task* task)
|
|||||||
connect(m_task, &Task::started, this, &ProgressWidget::show);
|
connect(m_task, &Task::started, this, &ProgressWidget::show);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressWidget::start(const Task* task)
|
void ProgressWidget::start(Task* task)
|
||||||
{
|
{
|
||||||
watch(task);
|
watch(task);
|
||||||
if (!m_task->isRunning())
|
if (!m_task->isRunning())
|
||||||
QMetaObject::invokeMethod(const_cast<Task*>(m_task), "start", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(m_task, "start", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProgressWidget::exec(std::shared_ptr<Task> task)
|
bool ProgressWidget::exec(std::shared_ptr<Task> task)
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ class ProgressWidget : public QWidget {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/** Watch the progress of a task. */
|
/** Watch the progress of a task. */
|
||||||
void watch(const Task* task);
|
void watch(Task* task);
|
||||||
|
|
||||||
/** Watch the progress of a task, and start it if needed */
|
/** Watch the progress of a task, and start it if needed */
|
||||||
void start(const Task* task);
|
void start(Task* task);
|
||||||
|
|
||||||
/** Blocking way of waiting for a task to finish. */
|
/** Blocking way of waiting for a task to finish. */
|
||||||
bool exec(std::shared_ptr<Task> task);
|
bool exec(std::shared_ptr<Task> task);
|
||||||
@@ -50,7 +50,7 @@ class ProgressWidget : public QWidget {
|
|||||||
private:
|
private:
|
||||||
QLabel* m_label = nullptr;
|
QLabel* m_label = nullptr;
|
||||||
QProgressBar* m_bar = nullptr;
|
QProgressBar* m_bar = nullptr;
|
||||||
const Task* m_task = nullptr;
|
Task* m_task = nullptr;
|
||||||
|
|
||||||
bool m_hide_if_inactive = false;
|
bool m_hide_if_inactive = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user