From f062dcdc7009cba89e55d8f24547c26a866f7ed9 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Sat, 24 Oct 2020 21:23:55 +0200 Subject: [PATCH] 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 --- components/bsa/compressedbsafile.hpp | 2 +- components/config/gamesettings.hpp | 2 +- components/contentselector/model/contentmodel.cpp | 14 +++++++------- components/contentselector/model/contentmodel.hpp | 2 +- components/contentselector/model/esmfile.cpp | 12 +++--------- components/contentselector/model/esmfile.hpp | 11 ++++------- .../contentselector/model/loadordererror.hpp | 3 ++- components/contentselector/model/modelitem.cpp | 15 +-------------- components/contentselector/model/modelitem.hpp | 6 ++---- components/contentselector/model/naturalsort.cpp | 4 ++-- components/contentselector/model/naturalsort.hpp | 4 ++-- 11 files changed, 26 insertions(+), 49 deletions(-) diff --git a/components/bsa/compressedbsafile.hpp b/components/bsa/compressedbsafile.hpp index deddfae38b..38c2cf347f 100644 --- a/components/bsa/compressedbsafile.hpp +++ b/components/bsa/compressedbsafile.hpp @@ -84,7 +84,7 @@ namespace Bsa Files::IStreamPtr getFile(const FileRecord& fileRecord); public: CompressedBSAFile(); - virtual ~CompressedBSAFile(); + ~CompressedBSAFile() override; //checks version of BSA from file header static BsaVersion detectVersion(std::string filePath); diff --git a/components/config/gamesettings.hpp b/components/config/gamesettings.hpp index ccb1d5fd25..8e5052d207 100644 --- a/components/config/gamesettings.hpp +++ b/components/config/gamesettings.hpp @@ -20,7 +20,7 @@ namespace Config class GameSettings { public: - GameSettings(Files::ConfigurationManager &cfg); + explicit GameSettings(Files::ConfigurationManager &cfg); ~GameSettings(); inline QString value(const QString &key, const QString &defaultValue = QString()) diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 86208d7af6..d669ebbd03 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -8,10 +8,11 @@ #include #include +#include ContentSelectorModel::ContentModel::ContentModel(QObject *parent, QIcon warningIcon) : QAbstractTableModel(parent), - mWarningIcon(warningIcon), + mWarningIcon(std::move(warningIcon)), mMimeType ("application/omwcontent"), mMimeTypes (QStringList() << mMimeType), mColumnCount (1), @@ -81,7 +82,7 @@ const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(co QModelIndex ContentSelectorModel::ContentModel::indexFromItem(const EsmFile *item) const { //workaround: non-const pointer cast for calls from outside contentmodel/contentselector - EsmFile *non_const_file_ptr = const_cast(item); + auto *non_const_file_ptr = const_cast(item); if (item) 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()); } - QMimeData *mimeData = new QMimeData(); + auto *mimeData = new QMimeData(); mimeData->setData(mMimeType, encodedData); return mimeData; @@ -438,11 +439,10 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) fileReader.setEncoder(&encoder); fileReader.open(std::string(dir.absoluteFilePath(path2).toUtf8().constData())); - EsmFile *file = new EsmFile(path2); + auto *file = new EsmFile(path2); - for (std::vector::const_iterator itemIter = fileReader.getGameFiles().begin(); - itemIter != fileReader.getGameFiles().end(); ++itemIter) - file->addGameFile(QString::fromUtf8(itemIter->name.c_str())); + for (const auto & itemIter : fileReader.getGameFiles()) + file->addGameFile(QString::fromUtf8(itemIter.name.c_str())); file->setAuthor (QString::fromUtf8(fileReader.getAuthor().c_str())); file->setDate (info.lastModified()); diff --git a/components/contentselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp index 030865b35a..86104cdc12 100644 --- a/components/contentselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -24,7 +24,7 @@ namespace ContentSelectorModel Q_OBJECT public: explicit ContentModel(QObject *parent, QIcon warningIcon); - ~ContentModel(); + ~ContentModel() override; void setEncoding(const QString &encoding); diff --git a/components/contentselector/model/esmfile.cpp b/components/contentselector/model/esmfile.cpp index 46a7c96008..0bd973dff2 100644 --- a/components/contentselector/model/esmfile.cpp +++ b/components/contentselector/model/esmfile.cpp @@ -2,6 +2,7 @@ #include #include +#include int ContentSelectorModel::EsmFile::sPropertyCount = 7; QString ContentSelectorModel::EsmFile::sToolTip = QString("Author: %1
\ @@ -13,7 +14,7 @@ QString ContentSelectorModel::EsmFile::sToolTip = QString("Author: %1
+#include namespace ContentSelectorModel { @@ -19,7 +20,7 @@ namespace ContentSelectorModel inline LoadOrderError() : mErrorCode(ErrorCode_None) {} inline LoadOrderError(ErrorCode errorCode, QString fileName) - : mErrorCode(errorCode), mFileName(fileName) {} + : mErrorCode(errorCode), mFileName(std::move(fileName)) {} inline ErrorCode errorCode() const { return mErrorCode; } inline QString fileName() const { return mFileName; } QString toolTip() const; diff --git a/components/contentselector/model/modelitem.cpp b/components/contentselector/model/modelitem.cpp index e1d737c2d4..0a2b6c93d2 100644 --- a/components/contentselector/model/modelitem.cpp +++ b/components/contentselector/model/modelitem.cpp @@ -2,21 +2,13 @@ ContentSelectorModel::ModelItem::ModelItem(ModelItem *parent) : mParentItem(parent) -{ -} -/* -ContentSelectorModel::ModelItem::ModelItem(const ModelItem *parent) - // : mParentItem(parent) -{ -} -*/ +{ } ContentSelectorModel::ModelItem::~ModelItem() { qDeleteAll(mChildItems); } - ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::parent() const { return mParentItem; @@ -33,9 +25,6 @@ int ContentSelectorModel::ModelItem::row() const { if (mParentItem) return 1; - //return mParentItem->childRow(const_cast(this)); - //return mParentItem->mChildItems.indexOf(const_cast(this)); - return -1; } @@ -48,7 +37,6 @@ int ContentSelectorModel::ModelItem::childCount() const int ContentSelectorModel::ModelItem::childRow(ModelItem *child) const { Q_ASSERT(child); - return mChildItems.indexOf(child); } @@ -57,7 +45,6 @@ ContentSelectorModel::ModelItem *ContentSelectorModel::ModelItem::child(int row) return mChildItems.value(row); } - void ContentSelectorModel::ModelItem::appendChild(ModelItem *item) { mChildItems.append(item); diff --git a/components/contentselector/model/modelitem.hpp b/components/contentselector/model/modelitem.hpp index e4ea7acc6a..94a18201a5 100644 --- a/components/contentselector/model/modelitem.hpp +++ b/components/contentselector/model/modelitem.hpp @@ -11,10 +11,8 @@ namespace ContentSelectorModel Q_OBJECT public: - ModelItem(ModelItem *parent = 0); - //ModelItem(const ModelItem *parent = 0); - - ~ModelItem(); + explicit ModelItem(ModelItem *parent = nullptr); + ~ModelItem() override; ModelItem *parent() const; int row() const; diff --git a/components/contentselector/model/naturalsort.cpp b/components/contentselector/model/naturalsort.cpp index 50d1e77de0..36c01216be 100644 --- a/components/contentselector/model/naturalsort.cpp +++ b/components/contentselector/model/naturalsort.cpp @@ -89,7 +89,7 @@ bool naturalSortLessThanCS( const QString &left, const QString &right ) 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); } @@ -99,7 +99,7 @@ bool naturalSortGreaterThanCS( const QString &left, const QString &right ) 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); } diff --git a/components/contentselector/model/naturalsort.hpp b/components/contentselector/model/naturalsort.hpp index 8386e4e9f0..73e058f978 100644 --- a/components/contentselector/model/naturalsort.hpp +++ b/components/contentselector/model/naturalsort.hpp @@ -4,8 +4,8 @@ #include 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 naturalSortGreaterThanCI( const QString &left, const QString &right ); + [[maybe_unused]] bool naturalSortGreaterThanCI( const QString &left, const QString &right ); #endif