1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 17:15:34 +00:00

components/contentselector cleanup; case-insensative functions marked as [[maybe_unused]] as they are only used on windows and it is better to be explicit than implicit

This commit is contained in:
Bret Curtis 2020-10-24 21:23:55 +02:00
parent ba3aad31c1
commit f062dcdc70
11 changed files with 26 additions and 49 deletions

View file

@ -84,7 +84,7 @@ namespace Bsa
Files::IStreamPtr getFile(const FileRecord& fileRecord); Files::IStreamPtr getFile(const FileRecord& fileRecord);
public: public:
CompressedBSAFile(); CompressedBSAFile();
virtual ~CompressedBSAFile(); ~CompressedBSAFile() override;
//checks version of BSA from file header //checks version of BSA from file header
static BsaVersion detectVersion(std::string filePath); static BsaVersion detectVersion(std::string filePath);

View file

@ -20,7 +20,7 @@ namespace Config
class GameSettings class GameSettings
{ {
public: public:
GameSettings(Files::ConfigurationManager &cfg); explicit GameSettings(Files::ConfigurationManager &cfg);
~GameSettings(); ~GameSettings();
inline QString value(const QString &key, const QString &defaultValue = QString()) inline QString value(const QString &key, const QString &defaultValue = QString())

View file

@ -8,10 +8,11 @@
#include <QDebug> #include <QDebug>
#include <components/esm/esmreader.hpp> #include <components/esm/esmreader.hpp>
#include <utility>
ContentSelectorModel::ContentModel::ContentModel(QObject *parent, QIcon warningIcon) : ContentSelectorModel::ContentModel::ContentModel(QObject *parent, QIcon warningIcon) :
QAbstractTableModel(parent), QAbstractTableModel(parent),
mWarningIcon(warningIcon), mWarningIcon(std::move(warningIcon)),
mMimeType ("application/omwcontent"), mMimeType ("application/omwcontent"),
mMimeTypes (QStringList() << mMimeType), mMimeTypes (QStringList() << mMimeType),
mColumnCount (1), mColumnCount (1),
@ -81,7 +82,7 @@ const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(co
QModelIndex ContentSelectorModel::ContentModel::indexFromItem(const EsmFile *item) const QModelIndex ContentSelectorModel::ContentModel::indexFromItem(const EsmFile *item) const
{ {
//workaround: non-const pointer cast for calls from outside contentmodel/contentselector //workaround: non-const pointer cast for calls from outside contentmodel/contentselector
EsmFile *non_const_file_ptr = const_cast<EsmFile *>(item); auto *non_const_file_ptr = const_cast<EsmFile *>(item);
if (item) if (item)
return index(mFiles.indexOf(non_const_file_ptr),0); return index(mFiles.indexOf(non_const_file_ptr),0);
@ -354,7 +355,7 @@ QMimeData *ContentSelectorModel::ContentModel::mimeData(const QModelIndexList &i
encodedData.append(item(index.row())->encodedData()); encodedData.append(item(index.row())->encodedData());
} }
QMimeData *mimeData = new QMimeData(); auto *mimeData = new QMimeData();
mimeData->setData(mMimeType, encodedData); mimeData->setData(mMimeType, encodedData);
return mimeData; return mimeData;
@ -438,11 +439,10 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path)
fileReader.setEncoder(&encoder); fileReader.setEncoder(&encoder);
fileReader.open(std::string(dir.absoluteFilePath(path2).toUtf8().constData())); fileReader.open(std::string(dir.absoluteFilePath(path2).toUtf8().constData()));
EsmFile *file = new EsmFile(path2); auto *file = new EsmFile(path2);
for (std::vector<ESM::Header::MasterData>::const_iterator itemIter = fileReader.getGameFiles().begin(); for (const auto & itemIter : fileReader.getGameFiles())
itemIter != fileReader.getGameFiles().end(); ++itemIter) file->addGameFile(QString::fromUtf8(itemIter.name.c_str()));
file->addGameFile(QString::fromUtf8(itemIter->name.c_str()));
file->setAuthor (QString::fromUtf8(fileReader.getAuthor().c_str())); file->setAuthor (QString::fromUtf8(fileReader.getAuthor().c_str()));
file->setDate (info.lastModified()); file->setDate (info.lastModified());

View file

@ -24,7 +24,7 @@ namespace ContentSelectorModel
Q_OBJECT Q_OBJECT
public: public:
explicit ContentModel(QObject *parent, QIcon warningIcon); explicit ContentModel(QObject *parent, QIcon warningIcon);
~ContentModel(); ~ContentModel() override;
void setEncoding(const QString &encoding); void setEncoding(const QString &encoding);

View file

@ -2,6 +2,7 @@
#include <QMimeData> #include <QMimeData>
#include <QDataStream> #include <QDataStream>
#include <utility>
int ContentSelectorModel::EsmFile::sPropertyCount = 7; int ContentSelectorModel::EsmFile::sPropertyCount = 7;
QString ContentSelectorModel::EsmFile::sToolTip = QString("<b>Author:</b> %1<br/> \ QString ContentSelectorModel::EsmFile::sToolTip = QString("<b>Author:</b> %1<br/> \
@ -13,7 +14,7 @@ QString ContentSelectorModel::EsmFile::sToolTip = QString("<b>Author:</b> %1<br/
ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent) ContentSelectorModel::EsmFile::EsmFile(QString fileName, ModelItem *parent)
: ModelItem(parent), mFileName(fileName), mFormat(0) : ModelItem(parent), mFileName(std::move(fileName)), mFormat(0)
{} {}
void ContentSelectorModel::EsmFile::setFileName(const QString &fileName) void ContentSelectorModel::EsmFile::setFileName(const QString &fileName)
@ -65,7 +66,7 @@ QByteArray ContentSelectorModel::EsmFile::encodedData() const
bool ContentSelectorModel::EsmFile::isGameFile() const bool ContentSelectorModel::EsmFile::isGameFile() const
{ {
return (mGameFiles.size() == 0) && return (mGameFiles.empty()) &&
(mFileName.endsWith(QLatin1String(".esm"), Qt::CaseInsensitive) || (mFileName.endsWith(QLatin1String(".esm"), Qt::CaseInsensitive) ||
mFileName.endsWith(QLatin1String(".omwgame"), Qt::CaseInsensitive)); mFileName.endsWith(QLatin1String(".omwgame"), Qt::CaseInsensitive));
} }
@ -76,31 +77,24 @@ QVariant ContentSelectorModel::EsmFile::fileProperty(const FileProperty prop) co
{ {
case FileProperty_FileName: case FileProperty_FileName:
return mFileName; return mFileName;
break;
case FileProperty_Author: case FileProperty_Author:
return mAuthor; return mAuthor;
break;
case FileProperty_Format: case FileProperty_Format:
return mFormat; return mFormat;
break;
case FileProperty_DateModified: case FileProperty_DateModified:
return mModified.toString(Qt::ISODate); return mModified.toString(Qt::ISODate);
break;
case FileProperty_FilePath: case FileProperty_FilePath:
return mPath; return mPath;
break;
case FileProperty_Description: case FileProperty_Description:
return mDescription; return mDescription;
break;
case FileProperty_GameFile: case FileProperty_GameFile:
return mGameFiles; return mGameFiles;
break;
default: default:
break; break;

View file

@ -28,17 +28,14 @@ namespace ContentSelectorModel
FileProperty_GameFile = 6 FileProperty_GameFile = 6
}; };
EsmFile(QString fileName = QString(), ModelItem *parent = 0); explicit EsmFile(QString fileName = QString(), ModelItem *parent = nullptr);
// EsmFile(const EsmFile &);
~EsmFile() ~EsmFile() override = default;
{}
void setFileProperty (const FileProperty prop, const QString &value); void setFileProperty (FileProperty prop, const QString &value);
void setFileName(const QString &fileName); void setFileName(const QString &fileName);
void setAuthor(const QString &author); void setAuthor(const QString &author);
void setSize(const int size);
void setDate(const QDateTime &modified); void setDate(const QDateTime &modified);
void setFormat(const int format); void setFormat(const int format);
void setFilePath(const QString &path); void setFilePath(const QString &path);
@ -46,7 +43,7 @@ namespace ContentSelectorModel
void setDescription(const QString &description); void setDescription(const QString &description);
inline void addGameFile (const QString &name) {mGameFiles.append(name); } inline void addGameFile (const QString &name) {mGameFiles.append(name); }
QVariant fileProperty (const FileProperty prop) const; QVariant fileProperty (FileProperty prop) const;
inline QString fileName() const { return mFileName; } inline QString fileName() const { return mFileName; }
inline QString author() const { return mAuthor; } inline QString author() const { return mAuthor; }

View file

@ -2,6 +2,7 @@
#define LOADORDERERROR_HPP #define LOADORDERERROR_HPP
#include <QString> #include <QString>
#include <utility>
namespace ContentSelectorModel namespace ContentSelectorModel
{ {
@ -19,7 +20,7 @@ namespace ContentSelectorModel
inline LoadOrderError() : mErrorCode(ErrorCode_None) {} inline LoadOrderError() : mErrorCode(ErrorCode_None) {}
inline LoadOrderError(ErrorCode errorCode, QString fileName) inline LoadOrderError(ErrorCode errorCode, QString fileName)
: mErrorCode(errorCode), mFileName(fileName) {} : mErrorCode(errorCode), mFileName(std::move(fileName)) {}
inline ErrorCode errorCode() const { return mErrorCode; } inline ErrorCode errorCode() const { return mErrorCode; }
inline QString fileName() const { return mFileName; } inline QString fileName() const { return mFileName; }
QString toolTip() const; QString toolTip() const;

View file

@ -2,21 +2,13 @@
ContentSelectorModel::ModelItem::ModelItem(ModelItem *parent) ContentSelectorModel::ModelItem::ModelItem(ModelItem *parent)
: mParentItem(parent) : mParentItem(parent)
{ { }
}
/*
ContentSelectorModel::ModelItem::ModelItem(const ModelItem *parent)
// : mParentItem(parent)
{
}
*/
ContentSelectorModel::ModelItem::~ModelItem() ContentSelectorModel::ModelItem::~ModelItem()
{ {
qDeleteAll(mChildItems); qDeleteAll(mChildItems);
} }
ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::parent() const ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::parent() const
{ {
return mParentItem; return mParentItem;
@ -33,9 +25,6 @@ int ContentSelectorModel::ModelItem::row() const
{ {
if (mParentItem) if (mParentItem)
return 1; return 1;
//return mParentItem->childRow(const_cast<ModelItem*>(this));
//return mParentItem->mChildItems.indexOf(const_cast<ModelItem*>(this));
return -1; return -1;
} }
@ -48,7 +37,6 @@ int ContentSelectorModel::ModelItem::childCount() const
int ContentSelectorModel::ModelItem::childRow(ModelItem *child) const int ContentSelectorModel::ModelItem::childRow(ModelItem *child) const
{ {
Q_ASSERT(child); Q_ASSERT(child);
return mChildItems.indexOf(child); return mChildItems.indexOf(child);
} }
@ -57,7 +45,6 @@ ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::child(int row)
return mChildItems.value(row); return mChildItems.value(row);
} }
void ContentSelectorModel::ModelItem::appendChild(ModelItem *item) void ContentSelectorModel::ModelItem::appendChild(ModelItem *item)
{ {
mChildItems.append(item); mChildItems.append(item);

View file

@ -11,10 +11,8 @@ namespace ContentSelectorModel
Q_OBJECT Q_OBJECT
public: public:
ModelItem(ModelItem *parent = 0); explicit ModelItem(ModelItem *parent = nullptr);
//ModelItem(const ModelItem *parent = 0); ~ModelItem() override;
~ModelItem();
ModelItem *parent() const; ModelItem *parent() const;
int row() const; int row() const;

View file

@ -89,7 +89,7 @@ bool naturalSortLessThanCS( const QString &left, const QString &right )
return (naturalCompare( left, right, Qt::CaseSensitive ) < 0); return (naturalCompare( left, right, Qt::CaseSensitive ) < 0);
} }
bool naturalSortLessThanCI( const QString &left, const QString &right ) [[maybe_unused]] bool naturalSortLessThanCI( const QString &left, const QString &right )
{ {
return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0); return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0);
} }
@ -99,7 +99,7 @@ bool naturalSortGreaterThanCS( const QString &left, const QString &right )
return (naturalCompare( left, right, Qt::CaseSensitive ) > 0); return (naturalCompare( left, right, Qt::CaseSensitive ) > 0);
} }
bool naturalSortGreaterThanCI( const QString &left, const QString &right ) [[maybe_unused]] bool naturalSortGreaterThanCI( const QString &left, const QString &right )
{ {
return (naturalCompare( left, right, Qt::CaseInsensitive ) > 0); return (naturalCompare( left, right, Qt::CaseInsensitive ) > 0);
} }

View file

@ -4,8 +4,8 @@
#include <QString> #include <QString>
bool naturalSortLessThanCS( const QString &left, const QString &right ); bool naturalSortLessThanCS( const QString &left, const QString &right );
bool naturalSortLessThanCI( const QString &left, const QString &right ); [[maybe_unused]] bool naturalSortLessThanCI( const QString &left, const QString &right );
bool naturalSortGreaterThanCS( const QString &left, const QString &right ); bool naturalSortGreaterThanCS( const QString &left, const QString &right );
bool naturalSortGreaterThanCI( const QString &left, const QString &right ); [[maybe_unused]] bool naturalSortGreaterThanCI( const QString &left, const QString &right );
#endif #endif