diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index aa114cef0..788f5d32e 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -348,7 +348,7 @@ void BrowserService::addEntry(const QString& id, const QString& realm, const QString& group, const QString& groupUuid, - QSharedPointer selectedDb) + const QSharedPointer& selectedDb) { if (thread() != QThread::currentThread()) { QMetaObject::invokeMethod(this, @@ -482,7 +482,8 @@ void BrowserService::updateEntry(const QString& id, } } -QList BrowserService::searchEntries(QSharedPointer db, const QString& hostname, const QString& url) +QList +BrowserService::searchEntries(const QSharedPointer& db, const QString& hostname, const QString& url) { QList entries; auto* rootGroup = db->rootGroup(); @@ -549,7 +550,7 @@ QList BrowserService::searchEntries(const QString& url, const StringPair return entries; } -void BrowserService::convertAttributesToCustomData(QSharedPointer currentDb) +void BrowserService::convertAttributesToCustomData(const QSharedPointer& currentDb) { auto db = currentDb ? currentDb : getDatabase(); if (!db) { @@ -770,7 +771,7 @@ BrowserService::checkAccess(const Entry* entry, const QString& host, const QStri return Unknown; } -Group* BrowserService::findCreateAddEntryGroup(QSharedPointer selectedDb) +Group* BrowserService::findCreateAddEntryGroup(const QSharedPointer& selectedDb) { auto db = selectedDb ? selectedDb : getDatabase(); if (!db) { @@ -955,7 +956,7 @@ bool BrowserService::moveSettingsToCustomData(Entry* entry, const QString& name) return false; } -int BrowserService::moveKeysToCustomData(Entry* entry, QSharedPointer db) const +int BrowserService::moveKeysToCustomData(Entry* entry, const QSharedPointer& db) const { int keyCounter = 0; for (const auto& key : entry->attributes()->keys()) { diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index 8db7be5d8..240fe232c 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -54,10 +54,10 @@ public: const QString& realm, const QString& group, const QString& groupUuid, - QSharedPointer selectedDb = {}); - QList searchEntries(QSharedPointer db, const QString& hostname, const QString& url); + const QSharedPointer& selectedDb = {}); + QList searchEntries(const QSharedPointer& db, const QString& hostname, const QString& url); QList searchEntries(const QString& url, const StringPairList& keyList); - void convertAttributesToCustomData(QSharedPointer currentDb = {}); + void convertAttributesToCustomData(const QSharedPointer& currentDb = {}); public: static const char KEEPASSXCBROWSER_NAME[]; @@ -106,7 +106,7 @@ private: const QString& realm); QJsonObject prepareEntry(const Entry* entry); Access checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm); - Group* findCreateAddEntryGroup(QSharedPointer selectedDb = {}); + Group* findCreateAddEntryGroup(const QSharedPointer& selectedDb = {}); int sortPriority(const Entry* entry, const QString& host, const QString& submitUrl, const QString& baseSubmitUrl) const; bool matchUrlScheme(const QString& url); @@ -116,7 +116,7 @@ private: QSharedPointer selectedDatabase(); QJsonArray addChildrenToGroup(Group* group); bool moveSettingsToCustomData(Entry* entry, const QString& name) const; - int moveKeysToCustomData(Entry* entry, QSharedPointer db) const; + int moveKeysToCustomData(Entry* entry, const QSharedPointer& db) const; bool checkLegacySettings(); void hideWindow() const; void raiseWindow(const bool force = false); diff --git a/src/cli/Clip.cpp b/src/cli/Clip.cpp index 25aea06e1..6e346f25c 100644 --- a/src/cli/Clip.cpp +++ b/src/cli/Clip.cpp @@ -77,7 +77,7 @@ int Clip::execute(const QStringList& arguments) return clipEntry(db, args.at(1), args.value(2), parser.isSet(totp), parser.isSet(Command::QuietOption)); } -int Clip::clipEntry(QSharedPointer database, +int Clip::clipEntry(const QSharedPointer& database, const QString& entryPath, const QString& timeout, bool clipTotp, diff --git a/src/cli/Clip.h b/src/cli/Clip.h index bdc1de03d..65a616955 100644 --- a/src/cli/Clip.h +++ b/src/cli/Clip.h @@ -26,7 +26,7 @@ public: Clip(); ~Clip(); int execute(const QStringList& arguments) override; - int clipEntry(QSharedPointer database, + int clipEntry(const QSharedPointer& database, const QString& entryPath, const QString& timeout, bool clipTotp, diff --git a/src/cli/Create.cpp b/src/cli/Create.cpp index 39aca63b6..b8c094f90 100644 --- a/src/cli/Create.cpp +++ b/src/cli/Create.cpp @@ -74,7 +74,7 @@ int Create::execute(const QStringList& arguments) return EXIT_FAILURE; } - QString databaseFilename = args.at(0); + const QString& databaseFilename = args.at(0); if (QFileInfo::exists(databaseFilename)) { err << QObject::tr("File %1 already exists.").arg(databaseFilename) << endl; return EXIT_FAILURE; @@ -150,7 +150,7 @@ QSharedPointer Create::getPasswordFromStdin() * @param fileKey Resulting fileKey * @return true if the key file was loaded succesfully */ -bool Create::loadFileKey(QString path, QSharedPointer& fileKey) +bool Create::loadFileKey(const QString& path, QSharedPointer& fileKey) { QTextStream err(Utils::STDERR, QIODevice::WriteOnly); diff --git a/src/cli/Create.h b/src/cli/Create.h index 9c14d37b2..85993eaeb 100644 --- a/src/cli/Create.h +++ b/src/cli/Create.h @@ -33,7 +33,7 @@ public: private: QSharedPointer getPasswordFromStdin(); QSharedPointer getFileKeyFromStdin(); - bool loadFileKey(QString path, QSharedPointer& fileKey); + bool loadFileKey(const QString& path, QSharedPointer& fileKey); }; #endif // KEEPASSXC_CREATE_H diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp index aac4e38c2..344e2b7f7 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -135,13 +135,13 @@ namespace Utils auto db = QSharedPointer::create(); QString error; - if (db->open(databaseFilename, compositeKey, &error, false)) { - return db; - }else { - err << error << endl; - return {}; + if (db->open(databaseFilename, compositeKey, &error, false)) { + return db; + } else { + err << error << endl; + return {}; + } } -} /** * Read a user password from STDIN or return a password previously diff --git a/src/core/Config.cpp b/src/core/Config.cpp index edf2ece8e..86ed04e38 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -32,13 +32,13 @@ */ static const QMap deprecationMap = { // >2.3.4 - {"security/hidepassworddetails", "security/HidePasswordPreviewPanel"}, + {QStringLiteral("security/hidepassworddetails"), QStringLiteral("security/HidePasswordPreviewPanel")}, // >2.3.4 - {"GUI/HideDetailsView", "GUI/HidePreviewPanel"}, + {QStringLiteral("GUI/HideDetailsView"), QStringLiteral("GUI/HidePreviewPanel")}, // >2.3.4 - {"GUI/DetailSplitterState", "GUI/PreviewSplitterState"}, + {QStringLiteral("GUI/DetailSplitterState"), QStringLiteral("GUI/PreviewSplitterState")}, // >2.3.4 - {"security/IconDownloadFallbackToGoogle", "security/IconDownloadFallback"}, + {QStringLiteral("security/IconDownloadFallbackToGoogle"), QStringLiteral("security/IconDownloadFallback")}, }; Config* Config::m_instance(nullptr); @@ -91,7 +91,8 @@ void Config::sync() void Config::upgrade() { - for (const auto& setting : deprecationMap.keys()) { + const auto keys = deprecationMap.keys(); + for (const auto& setting : keys) { if (m_settings->contains(setting)) { if (!deprecationMap.value(setting).isEmpty()) { // Add entry with new name and old entry's value diff --git a/src/core/CustomData.cpp b/src/core/CustomData.cpp index 835497215..86adae158 100644 --- a/src/core/CustomData.cpp +++ b/src/core/CustomData.cpp @@ -17,6 +17,8 @@ #include "CustomData.h" +#include "core/Global.h" + CustomData::CustomData(QObject* parent) : QObject(parent) { @@ -44,7 +46,7 @@ bool CustomData::contains(const QString& key) const bool CustomData::containsValue(const QString& value) const { - return m_data.values().contains(value); + return asConst(m_data).values().contains(value); } void CustomData::set(const QString& key, const QString& value) diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index dfa59ec8c..49f5198d2 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -17,6 +17,8 @@ #include "EntryAttachments.h" +#include "core/Global.h" + #include #include @@ -37,7 +39,7 @@ bool EntryAttachments::hasKey(const QString& key) const QSet EntryAttachments::values() const { - return m_attachments.values().toSet(); + return asConst(m_attachments).values().toSet(); } QByteArray EntryAttachments::value(const QString& key) const diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 5c836e1e8..3a696ae66 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -18,6 +18,8 @@ #include "EntryAttributes.h" +#include "core/Global.h" + const QString EntryAttributes::TitleKey = "Title"; const QString EntryAttributes::UserNameKey = "UserName"; const QString EntryAttributes::PasswordKey = "Password"; @@ -72,7 +74,7 @@ bool EntryAttributes::contains(const QString& key) const bool EntryAttributes::containsValue(const QString& value) const { - return m_attributes.values().contains(value); + return asConst(m_attributes).values().contains(value); } bool EntryAttributes::isProtected(const QString& key) const diff --git a/src/core/Merger.cpp b/src/core/Merger.cpp index cc57ae3b2..e4cf0f994 100644 --- a/src/core/Merger.cpp +++ b/src/core/Merger.cpp @@ -616,7 +616,8 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context) auto* sourceMetadata = context.m_sourceDb->metadata(); auto* targetMetadata = context.m_targetDb->metadata(); - for (QUuid customIconId : sourceMetadata->customIcons().keys()) { + const auto keys = sourceMetadata->customIcons().keys(); + for (QUuid customIconId : keys) { QImage customIcon = sourceMetadata->customIcon(customIconId); if (!targetMetadata->containsCustomIcon(customIconId)) { targetMetadata->addCustomIcon(customIconId, customIcon); diff --git a/src/format/CsvExporter.cpp b/src/format/CsvExporter.cpp index 0d9a4e0a7..03d5a576f 100644 --- a/src/format/CsvExporter.cpp +++ b/src/format/CsvExporter.cpp @@ -23,7 +23,7 @@ #include "core/Database.h" #include "core/Group.h" -bool CsvExporter::exportDatabase(const QString& filename, QSharedPointer db) +bool CsvExporter::exportDatabase(const QString& filename, const QSharedPointer& db) { QFile file(filename); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { @@ -33,7 +33,7 @@ bool CsvExporter::exportDatabase(const QString& filename, QSharedPointer db) +bool CsvExporter::exportDatabase(QIODevice* device, const QSharedPointer& db) { QString header; addColumn(header, "Group"); diff --git a/src/format/CsvExporter.h b/src/format/CsvExporter.h index 3cb41c0af..e71cf7fa9 100644 --- a/src/format/CsvExporter.h +++ b/src/format/CsvExporter.h @@ -29,8 +29,8 @@ class QIODevice; class CsvExporter { public: - bool exportDatabase(const QString& filename, QSharedPointer db); - bool exportDatabase(QIODevice* device, QSharedPointer db); + bool exportDatabase(const QString& filename, const QSharedPointer& db); + bool exportDatabase(QIODevice* device, const QSharedPointer& db); QString errorString() const; private: diff --git a/src/format/KdbxXmlReader.cpp b/src/format/KdbxXmlReader.cpp index efef724d9..50c320118 100644 --- a/src/format/KdbxXmlReader.cpp +++ b/src/format/KdbxXmlReader.cpp @@ -124,8 +124,8 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random qWarning("KdbxXmlReader::readDatabase: found %d invalid entry reference(s)", m_tmpParent->children().size()); } - const QSet poolKeys = m_binaryPool.keys().toSet(); - const QSet entryKeys = m_binaryMap.keys().toSet(); + const QSet poolKeys = asConst(m_binaryPool).keys().toSet(); + const QSet entryKeys = asConst(m_binaryMap).keys().toSet(); const QSet unmappedKeys = entryKeys - poolKeys; const QSet unusedKeys = poolKeys - entryKeys; diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 134cbb126..9d52af784 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1532,7 +1532,7 @@ bool DatabaseWidget::saveAs() { while (true) { QString oldFilePath = m_db->filePath(); - if (!QFileInfo(oldFilePath).exists()) { + if (!QFileInfo::exists(oldFilePath)) { oldFilePath = QDir::toNativeSeparators(config()->get("LastDir", QDir::homePath()).toString() + "/" + tr("Passwords").append(".kdbx")); } diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index ecf6d445f..990e480ee 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -113,7 +113,7 @@ void EditWidgetIcons::reset() } void EditWidgetIcons::load(const QUuid& currentUuid, - QSharedPointer database, + const QSharedPointer& database, const IconStruct& iconStruct, const QString& url) { @@ -229,7 +229,6 @@ void EditWidgetIcons::fetchFinished() QImage image; bool fallbackEnabled = config()->get("security/IconDownloadFallback", false).toBool(); bool error = (m_reply->error() != QNetworkReply::NoError); - QUrl url = m_reply->url(); QUrl redirectTarget = getRedirectTarget(m_reply); m_reply->deleteLater(); diff --git a/src/gui/EditWidgetIcons.h b/src/gui/EditWidgetIcons.h index 5c02f31a1..a01b920f0 100644 --- a/src/gui/EditWidgetIcons.h +++ b/src/gui/EditWidgetIcons.h @@ -60,7 +60,7 @@ public: IconStruct state(); void reset(); void load(const QUuid& currentUuid, - QSharedPointer database, + const QSharedPointer& database, const IconStruct& iconStruct, const QString& url = ""); diff --git a/src/gui/MessageBox.cpp b/src/gui/MessageBox.cpp index 5878aff69..582baa5cc 100644 --- a/src/gui/MessageBox.cpp +++ b/src/gui/MessageBox.cpp @@ -20,8 +20,8 @@ MessageBox::Button MessageBox::m_nextAnswer(MessageBox::NoButton); -QMap MessageBox::m_addedButtonLookup = - QMap(); +QHash MessageBox::m_addedButtonLookup = + QHash(); QMap> MessageBox::m_buttonDefs = QMap>(); diff --git a/src/gui/MessageBox.h b/src/gui/MessageBox.h index ded415f6a..b8bd10ad8 100644 --- a/src/gui/MessageBox.h +++ b/src/gui/MessageBox.h @@ -19,6 +19,7 @@ #ifndef KEEPASSX_MESSAGEBOX_H #define KEEPASSX_MESSAGEBOX_H +#include #include #include #include @@ -102,7 +103,7 @@ public: private: static Button m_nextAnswer; - static QMap m_addedButtonLookup; + static QHash m_addedButtonLookup; static QMap> m_buttonDefs; static Button messageBox(QWidget* parent, diff --git a/src/gui/dbsettings/DatabaseSettingsDialog.cpp b/src/gui/dbsettings/DatabaseSettingsDialog.cpp index 550319777..6475793f9 100644 --- a/src/gui/dbsettings/DatabaseSettingsDialog.cpp +++ b/src/gui/dbsettings/DatabaseSettingsDialog.cpp @@ -105,7 +105,7 @@ DatabaseSettingsDialog::~DatabaseSettingsDialog() { } -void DatabaseSettingsDialog::load(QSharedPointer db) +void DatabaseSettingsDialog::load(const QSharedPointer& db) { m_ui->categoryList->setCurrentCategory(0); m_generalWidget->load(db); diff --git a/src/gui/dbsettings/DatabaseSettingsDialog.h b/src/gui/dbsettings/DatabaseSettingsDialog.h index 2a1a89fab..855978f29 100644 --- a/src/gui/dbsettings/DatabaseSettingsDialog.h +++ b/src/gui/dbsettings/DatabaseSettingsDialog.h @@ -61,7 +61,7 @@ public: ~DatabaseSettingsDialog() override; Q_DISABLE_COPY(DatabaseSettingsDialog); - void load(QSharedPointer db); + void load(const QSharedPointer& db); void addSettingsPage(IDatabaseSettingsPage* page); void showMasterKeySettings(); diff --git a/src/gui/dbsettings/DatabaseSettingsWidget.cpp b/src/gui/dbsettings/DatabaseSettingsWidget.cpp index 7b438cc33..4699344a7 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidget.cpp +++ b/src/gui/dbsettings/DatabaseSettingsWidget.cpp @@ -18,6 +18,8 @@ #include "DatabaseSettingsWidget.h" #include "core/Database.h" +#include + #include #include @@ -38,6 +40,6 @@ DatabaseSettingsWidget::~DatabaseSettingsWidget() */ void DatabaseSettingsWidget::load(QSharedPointer db) { - m_db = db; + m_db = std::move(db); initialize(); } diff --git a/src/gui/group/EditGroupWidget.cpp b/src/gui/group/EditGroupWidget.cpp index 4acad5339..41351d3d9 100644 --- a/src/gui/group/EditGroupWidget.cpp +++ b/src/gui/group/EditGroupWidget.cpp @@ -91,7 +91,7 @@ EditGroupWidget::~EditGroupWidget() { } -void EditGroupWidget::loadGroup(Group* group, bool create, QSharedPointer database) +void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer& database) { m_group = group; m_db = database; diff --git a/src/gui/group/EditGroupWidget.h b/src/gui/group/EditGroupWidget.h index f013be796..4de117724 100644 --- a/src/gui/group/EditGroupWidget.h +++ b/src/gui/group/EditGroupWidget.h @@ -55,7 +55,7 @@ public: explicit EditGroupWidget(QWidget* parent = nullptr); ~EditGroupWidget(); - void loadGroup(Group* group, bool create, QSharedPointer database); + void loadGroup(Group* group, bool create, const QSharedPointer& database); void clear(); void addEditPage(IEditGroupPage* page); diff --git a/src/gui/group/GroupView.cpp b/src/gui/group/GroupView.cpp index 567048631..7c3c91355 100644 --- a/src/gui/group/GroupView.cpp +++ b/src/gui/group/GroupView.cpp @@ -50,7 +50,7 @@ GroupView::GroupView(Database* db, QWidget* parent) setDefaultDropAction(Qt::MoveAction); } -void GroupView::changeDatabase(QSharedPointer newDb) +void GroupView::changeDatabase(const QSharedPointer& newDb) { m_model->changeDatabase(newDb.data()); } diff --git a/src/gui/group/GroupView.h b/src/gui/group/GroupView.h index 141706b07..61f7b3bac 100644 --- a/src/gui/group/GroupView.h +++ b/src/gui/group/GroupView.h @@ -30,7 +30,7 @@ class GroupView : public QTreeView public: explicit GroupView(Database* db, QWidget* parent = nullptr); - void changeDatabase(QSharedPointer newDb); + void changeDatabase(const QSharedPointer& newDb); void setModel(QAbstractItemModel* model) override; Group* currentGroup(); void setCurrentGroup(Group* group); diff --git a/src/gui/wizard/NewDatabaseWizardPage.h b/src/gui/wizard/NewDatabaseWizardPage.h index ea5158a00..02df31027 100644 --- a/src/gui/wizard/NewDatabaseWizardPage.h +++ b/src/gui/wizard/NewDatabaseWizardPage.h @@ -38,7 +38,7 @@ class NewDatabaseWizardPage : public QWizardPage public: explicit NewDatabaseWizardPage(QWidget* parent = nullptr); - Q_DISABLE_COPY(NewDatabaseWizardPage); + Q_DISABLE_COPY(NewDatabaseWizardPage) ~NewDatabaseWizardPage() override; void setPageWidget(DatabaseSettingsWidget* page);