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.
|
||||
* 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.
|
||||
* For example: "1.5.1"
|
||||
*/
|
||||
virtual QString name() = 0;
|
||||
virtual QString name() const = 0;
|
||||
|
||||
/*!
|
||||
* This should return a string that describes
|
||||
* the kind of version this is (Stable, Beta, Snapshot, whatever)
|
||||
*/
|
||||
virtual QString typeString() const = 0;
|
||||
virtual bool operator<(BaseVersion& a) { return name() < a.name(); }
|
||||
virtual bool operator>(BaseVersion& a) { return name() > a.name(); }
|
||||
virtual bool operator<(BaseVersion& a) const { return name() < a.name(); }
|
||||
virtual bool operator>(BaseVersion& a) const { return name() > a.name(); }
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(BaseVersion::Ptr)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "BaseVersion.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);
|
||||
if (archCompare != 0)
|
||||
@@ -35,17 +35,17 @@ bool JavaInstall::operator<(const JavaInstall& rhs)
|
||||
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;
|
||||
}
|
||||
|
||||
bool JavaInstall::operator>(const JavaInstall& rhs)
|
||||
bool JavaInstall::operator>(const JavaInstall& rhs) const
|
||||
{
|
||||
return (!operator<(rhs)) && (!operator==(rhs));
|
||||
}
|
||||
|
||||
bool JavaInstall::operator<(BaseVersion& a)
|
||||
bool JavaInstall::operator<(BaseVersion& a) const
|
||||
{
|
||||
try {
|
||||
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 {
|
||||
return operator>(dynamic_cast<JavaInstall&>(a));
|
||||
|
||||
@@ -24,17 +24,17 @@
|
||||
struct JavaInstall : public BaseVersion {
|
||||
JavaInstall() {}
|
||||
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 bool operator<(BaseVersion& a) override;
|
||||
virtual bool operator>(BaseVersion& a) override;
|
||||
bool operator<(const JavaInstall& rhs);
|
||||
bool operator==(const JavaInstall& rhs);
|
||||
bool operator>(const JavaInstall& rhs);
|
||||
virtual bool operator<(BaseVersion& a) const override;
|
||||
virtual bool operator>(BaseVersion& a) const override;
|
||||
bool operator<(const JavaInstall& rhs) const;
|
||||
bool operator==(const JavaInstall& rhs) const;
|
||||
bool operator>(const JavaInstall& rhs) const;
|
||||
|
||||
JavaVersion id;
|
||||
QString arch;
|
||||
|
||||
@@ -78,7 +78,7 @@ MetadataPtr parseJavaMeta(const QJsonObject& in)
|
||||
return meta;
|
||||
}
|
||||
|
||||
bool Metadata::operator<(const Metadata& rhs)
|
||||
bool Metadata::operator<(const Metadata& rhs) const
|
||||
{
|
||||
auto id = 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;
|
||||
}
|
||||
|
||||
bool Metadata::operator==(const Metadata& rhs)
|
||||
bool Metadata::operator==(const Metadata& rhs) const
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
bool Metadata::operator<(BaseVersion& a)
|
||||
bool Metadata::operator<(BaseVersion& a) const
|
||||
{
|
||||
try {
|
||||
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 {
|
||||
return operator>(dynamic_cast<Metadata&>(a));
|
||||
|
||||
@@ -32,17 +32,17 @@ enum class DownloadType { Manifest, Archive, Unknown };
|
||||
|
||||
class Metadata : public BaseVersion {
|
||||
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 bool operator<(BaseVersion& a) override;
|
||||
virtual bool operator>(BaseVersion& a) override;
|
||||
bool operator<(const Metadata& rhs);
|
||||
bool operator==(const Metadata& rhs);
|
||||
bool operator>(const Metadata& rhs);
|
||||
virtual bool operator<(BaseVersion& a) const override;
|
||||
virtual bool operator>(BaseVersion& a) const override;
|
||||
bool operator<(const Metadata& rhs) const;
|
||||
bool operator==(const Metadata& rhs) const;
|
||||
bool operator>(const Metadata& rhs) const;
|
||||
|
||||
QString m_name;
|
||||
QString vendor;
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
|
||||
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;
|
||||
}
|
||||
QString Meta::Version::name()
|
||||
QString Meta::Version::name() const
|
||||
{
|
||||
if (m_data)
|
||||
return m_data->name;
|
||||
@@ -88,7 +88,7 @@ QString Meta::Version::localFilename() const
|
||||
|
||||
::Version Meta::Version::toComparableVersion() const
|
||||
{
|
||||
return { const_cast<Meta::Version*>(this)->descriptor() };
|
||||
return { descriptor() };
|
||||
}
|
||||
|
||||
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);
|
||||
virtual ~Version() = default;
|
||||
|
||||
QString descriptor() override;
|
||||
QString name() override;
|
||||
QString descriptor() const override;
|
||||
QString name() const override;
|
||||
QString typeString() const override;
|
||||
|
||||
QString uid() const { return m_uid; }
|
||||
|
||||
@@ -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
|
||||
{
|
||||
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
|
||||
{
|
||||
if (indexes.size() == 0)
|
||||
return new QMimeData();
|
||||
QList<QUrl> urls;
|
||||
|
||||
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]);
|
||||
|
||||
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();
|
||||
}
|
||||
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"
|
||||
|
||||
@@ -39,7 +39,7 @@ void ProgressWidget::progressFormat(QString format)
|
||||
m_bar->setFormat(format);
|
||||
}
|
||||
|
||||
void ProgressWidget::watch(const Task* task)
|
||||
void ProgressWidget::watch(Task* task)
|
||||
{
|
||||
if (!task)
|
||||
return;
|
||||
@@ -61,11 +61,11 @@ void ProgressWidget::watch(const Task* task)
|
||||
connect(m_task, &Task::started, this, &ProgressWidget::show);
|
||||
}
|
||||
|
||||
void ProgressWidget::start(const Task* task)
|
||||
void ProgressWidget::start(Task* task)
|
||||
{
|
||||
watch(task);
|
||||
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)
|
||||
|
||||
@@ -27,10 +27,10 @@ class ProgressWidget : public QWidget {
|
||||
|
||||
public slots:
|
||||
/** 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 */
|
||||
void start(const Task* task);
|
||||
void start(Task* task);
|
||||
|
||||
/** Blocking way of waiting for a task to finish. */
|
||||
bool exec(std::shared_ptr<Task> task);
|
||||
@@ -50,7 +50,7 @@ class ProgressWidget : public QWidget {
|
||||
private:
|
||||
QLabel* m_label = nullptr;
|
||||
QProgressBar* m_bar = nullptr;
|
||||
const Task* m_task = nullptr;
|
||||
Task* m_task = nullptr;
|
||||
|
||||
bool m_hide_if_inactive = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user