From 64b765529ef562bbad3d55c09f407ef547c4a5b3 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Fri, 15 Nov 2024 20:50:49 +0100 Subject: [PATCH] refactor: Fix some clang-tidy warnings --- src/core/application.cpp | 6 +++--- src/gui/guiapplication.cpp | 2 +- src/misc/applicationinfo.cpp | 8 +++----- src/misc/applicationinfo.h | 8 ++++---- src/misc/audio/audiodeviceinfo.cpp | 14 +++++--------- src/misc/audio/audiodeviceinfo.h | 2 +- src/misc/audio/audiodeviceinfolist.cpp | 2 -- src/misc/audio/audiodeviceinfolist.h | 4 ++-- src/misc/audio/audiosettings.cpp | 5 +---- src/misc/audio/audiosettings.h | 5 +---- src/misc/audio/audioutils.h | 2 +- src/misc/audio/notificationsounds.h | 2 +- src/misc/audio/registermetadataaudio.cpp | 24 +++++++++++------------- src/misc/audio/registermetadataaudio.h | 2 +- src/misc/collection.h | 24 ++++++++++++------------ src/misc/comparefunctions.h | 2 +- src/misc/compressutils.h | 2 +- src/misc/crashinfo.cpp | 13 +++---------- src/misc/crashinfo.h | 4 ++-- src/misc/datacache.cpp | 1 - src/misc/datacache.h | 1 - src/swiftlauncher/main.cpp | 2 +- src/swiftlauncher/swiftlauncher.cpp | 2 +- 23 files changed, 56 insertions(+), 81 deletions(-) diff --git a/src/core/application.cpp b/src/core/application.cpp index 911e9aaea..79b15ca1a 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -261,7 +261,7 @@ namespace swift::core switch (application) { case CApplicationInfo::PilotClientCore: searchFor = "core"; break; - case CApplicationInfo::Laucher: searchFor = "launcher"; break; + case CApplicationInfo::Launcher: searchFor = "launcher"; break; case CApplicationInfo::MappingTool: searchFor = "data"; break; case CApplicationInfo::PilotClientGui: searchFor = "gui"; break; default: break; @@ -278,8 +278,8 @@ namespace swift::core bool CApplication::startLauncher() { - static const QString launcher = CApplication::getExecutableForApplication(CApplicationInfo::Application::Laucher); - if (launcher.isEmpty() || CApplication::isApplicationRunning(CApplicationInfo::Laucher)) { return false; } + static const QString launcher = CApplication::getExecutableForApplication(CApplicationInfo::Application::Launcher); + if (launcher.isEmpty() || CApplication::isApplicationRunning(CApplicationInfo::Launcher)) { return false; } // const QStringList args = this->argumentsJoined({}, { "--dbus", "--core", "--coreaudio" }); const QStringList args = this->argumentsJoined({}, { "--dbus", "--core" }); diff --git a/src/gui/guiapplication.cpp b/src/gui/guiapplication.cpp index c6865b633..1d63e2d66 100644 --- a/src/gui/guiapplication.cpp +++ b/src/gui/guiapplication.cpp @@ -676,7 +676,7 @@ namespace swift::gui addMenuForStyleSheets(menu); QAction *a = nullptr; bool c = false; - if (this->getApplicationInfo().getApplication() != CApplicationInfo::Laucher) + if (this->getApplicationInfo().getApplication() != CApplicationInfo::Launcher) { menu.addSeparator(); a = menu.addAction(CIcons::swiftLauncher24(), "Start swift launcher"); diff --git a/src/misc/applicationinfo.cpp b/src/misc/applicationinfo.cpp index 86543e47a..94b866503 100644 --- a/src/misc/applicationinfo.cpp +++ b/src/misc/applicationinfo.cpp @@ -15,8 +15,6 @@ SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc, CApplicationInfo) namespace swift::misc { - CApplicationInfo::CApplicationInfo() {} - CApplicationInfo::CApplicationInfo(Application app) : m_app(app), m_wordSize(CBuildConfig::buildWordSize()), m_exePath(QCoreApplication::applicationDirPath()), @@ -43,7 +41,7 @@ namespace swift::misc switch (getApplication()) { - case Laucher: return launcher; + case Launcher: return launcher; case PilotClientCore: return core; case PilotClientGui: return gui; case MappingTool: return mapping; @@ -94,7 +92,7 @@ namespace swift::misc { switch (getApplication()) { - case Laucher: return CIcons::SwiftLauncher16; + case Launcher: return CIcons::SwiftLauncher16; case PilotClientCore: return CIcons::SwiftCore16; case PilotClientGui: return CIcons::Swift16; case MappingTool: return CIcons::SwiftDatabase16; @@ -218,7 +216,7 @@ namespace swift::misc if (a.contains("test")) { return CApplicationInfo::UnitTest; } // names like testcore if (a.contains("sample")) { return CApplicationInfo::Sample; } if (a.contains("core")) { return CApplicationInfo::PilotClientCore; } - if (a.contains("launcher")) { return CApplicationInfo::Laucher; } + if (a.contains("launcher")) { return CApplicationInfo::Launcher; } if (a.contains("gui")) { return CApplicationInfo::PilotClientGui; } if (a.contains("data") || a.contains("mapping")) { return CApplicationInfo::MappingTool; } return CApplicationInfo::Unknown; diff --git a/src/misc/applicationinfo.h b/src/misc/applicationinfo.h index 589f45883..082a95a7e 100644 --- a/src/misc/applicationinfo.h +++ b/src/misc/applicationinfo.h @@ -28,7 +28,7 @@ namespace swift::misc enum Application { Unknown, - Laucher, + Launcher, PilotClientCore, PilotClientGui, MappingTool, @@ -52,7 +52,7 @@ namespace swift::misc }; //! Default constructor. - CApplicationInfo(); + CApplicationInfo() = default; //! Constructor. CApplicationInfo(Application app); @@ -154,7 +154,7 @@ namespace swift::misc //! Name of swift core static const QString &swiftCore(); - //! Info automatically initalized + //! Info automatically initialized static const CApplicationInfo &autoInfo(); //! File name of the application info file @@ -165,7 +165,7 @@ namespace swift::misc private: int m_app = static_cast(Unknown); - int m_wordSize; + int m_wordSize {}; QString m_exePath; QString m_applicationDataDir; QString m_version; diff --git a/src/misc/audio/audiodeviceinfo.cpp b/src/misc/audio/audiodeviceinfo.cpp index 5d8786d00..b7afba66d 100644 --- a/src/misc/audio/audiodeviceinfo.cpp +++ b/src/misc/audio/audiodeviceinfo.cpp @@ -6,7 +6,6 @@ #include "misc/comparefunctions.h" #include "misc/verify.h" -#include #include #include #include @@ -49,19 +48,18 @@ namespace swift::misc::audio CAudioDeviceInfo CAudioDeviceInfo::getDefaultOutputDevice() { - return CAudioDeviceInfo(OutputDevice, QMediaDevices::defaultAudioOutput().description()); + return { OutputDevice, QMediaDevices::defaultAudioOutput().description() }; } CAudioDeviceInfo CAudioDeviceInfo::getDefaultInputDevice() { - return CAudioDeviceInfo(InputDevice, QMediaDevices::defaultAudioInput().description()); + return { InputDevice, QMediaDevices::defaultAudioInput().description() }; } QVariant CAudioDeviceInfo::propertyByIndex(CPropertyIndexRef index) const { if (index.isMyself()) { return QVariant::fromValue(*this); } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexDeviceType: return QVariant::fromValue(this->getType()); case IndexDeviceTypeAsString: return QVariant::fromValue(this->getTypeAsString()); @@ -79,8 +77,7 @@ namespace swift::misc::audio (*this) = variant.value(); return; } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexDeviceType: m_type = static_cast(variant.toInt()); return; case IndexName: m_deviceName = variant.toString(); return; @@ -93,8 +90,7 @@ namespace swift::misc::audio int CAudioDeviceInfo::comparePropertyByIndex(CPropertyIndexRef index, const CAudioDeviceInfo &compareValue) const { if (index.isMyself()) { return m_deviceName.compare(compareValue.m_deviceName, Qt::CaseInsensitive); } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexDeviceTypeAsString: case IndexDeviceType: return Compare::compare(m_type, compareValue.m_type); diff --git a/src/misc/audio/audiodeviceinfo.h b/src/misc/audio/audiodeviceinfo.h index 7005b7293..7400ed904 100644 --- a/src/misc/audio/audiodeviceinfo.h +++ b/src/misc/audio/audiodeviceinfo.h @@ -119,4 +119,4 @@ namespace swift::misc::audio Q_DECLARE_METATYPE(swift::misc::audio::CAudioDeviceInfo) Q_DECLARE_METATYPE(swift::misc::audio::CAudioDeviceInfo::DeviceType) -#endif // guard +#endif // SWIFT_MISC_AUDIO_AUDIODEVICE_H diff --git a/src/misc/audio/audiodeviceinfolist.cpp b/src/misc/audio/audiodeviceinfolist.cpp index 54f7412c4..16f0b01d3 100644 --- a/src/misc/audio/audiodeviceinfolist.cpp +++ b/src/misc/audio/audiodeviceinfolist.cpp @@ -12,8 +12,6 @@ SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::audio, CAudioDeviceInfo, CAudioDeviceI namespace swift::misc::audio { - CAudioDeviceInfoList::CAudioDeviceInfoList() {} - CAudioDeviceInfoList::CAudioDeviceInfoList(const CSequence &other) : CSequence(other) {} diff --git a/src/misc/audio/audiodeviceinfolist.h b/src/misc/audio/audiodeviceinfolist.h index 1420716ce..75b9f8544 100644 --- a/src/misc/audio/audiodeviceinfolist.h +++ b/src/misc/audio/audiodeviceinfolist.h @@ -30,7 +30,7 @@ namespace swift::misc::audio using CSequence::CSequence; //! Default constructor. - CAudioDeviceInfoList(); + CAudioDeviceInfoList() = default; //! Construct from a base class object. CAudioDeviceInfoList(const CSequence &other); @@ -101,4 +101,4 @@ namespace swift::misc::audio Q_DECLARE_METATYPE(swift::misc::audio::CAudioDeviceInfoList) Q_DECLARE_METATYPE(swift::misc::CCollection) -#endif // guard +#endif // SWIFT_MISC_AUDIO_AUDIODEVICELIST_H diff --git a/src/misc/audio/audiosettings.cpp b/src/misc/audio/audiosettings.cpp index 70ea5dfde..8599b6dcb 100644 --- a/src/misc/audio/audiosettings.cpp +++ b/src/misc/audio/audiosettings.cpp @@ -5,7 +5,6 @@ #include "misc/swiftdirectories.h" #include "misc/fileutils.h" #include -#include #include using namespace swift::misc::audio; @@ -76,9 +75,7 @@ namespace swift::misc::audio void CSettings::setNotificationVolume(int volume) { - m_notificationVolume = volume; - if (m_notificationVolume < 0) { m_notificationVolume = 0; } - else if (m_notificationVolume > 100) { m_notificationVolume = 100; } + m_notificationVolume = std::clamp(volume, 0, 100); } void CSettings::setOutVolume(int volume) diff --git a/src/misc/audio/audiosettings.h b/src/misc/audio/audiosettings.h index 71a53c342..82a470553 100644 --- a/src/misc/audio/audiosettings.h +++ b/src/misc/audio/audiosettings.h @@ -65,9 +65,6 @@ namespace swift::misc::audio bool afvBlocked() const { return this->isNotificationFlagSet(CNotificationSounds::AFVBlocked); } //! @} - //! Settings value - CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag); - //! Directory void setNotificationSoundDirectory(const QString &dir); @@ -167,4 +164,4 @@ namespace swift::misc::audio Q_DECLARE_METATYPE(swift::misc::audio::CSettings) -#endif // guard +#endif // SWIFT_MISC_AUDIO_SETTINGS_H diff --git a/src/misc/audio/audioutils.h b/src/misc/audio/audioutils.h index 175ca45af..eede30d70 100644 --- a/src/misc/audio/audioutils.h +++ b/src/misc/audio/audioutils.h @@ -14,7 +14,7 @@ namespace swift::misc::audio SWIFT_MISC_EXPORT bool startWindowsMixer(); //! On windows init the audio devices - //! \remarks workaround for WSAPI driver crashes, hoping that upfront init already sets global vars. etc. + //! \remarks workaround for WASAPI driver crashes, hoping that upfront init already sets global vars. etc. SWIFT_MISC_EXPORT void initWindowsAudioDevices(); } diff --git a/src/misc/audio/notificationsounds.h b/src/misc/audio/notificationsounds.h index b27c568d4..affa30606 100644 --- a/src/misc/audio/notificationsounds.h +++ b/src/misc/audio/notificationsounds.h @@ -75,4 +75,4 @@ namespace swift::misc::audio Q_DECLARE_METATYPE(swift::misc::audio::CNotificationSounds::Notification) Q_DECLARE_METATYPE(swift::misc::audio::CNotificationSounds::NotificationFlag) -#endif // guard +#endif // SWIFT_MISC_NOTIFICATIONSOUNDS_H diff --git a/src/misc/audio/registermetadataaudio.cpp b/src/misc/audio/registermetadataaudio.cpp index f4c6bb0df..35ee1d168 100644 --- a/src/misc/audio/registermetadataaudio.cpp +++ b/src/misc/audio/registermetadataaudio.cpp @@ -10,21 +10,19 @@ #include -namespace swift::misc +namespace swift::misc::audio { - namespace audio + //! Register metadata for audio / voice + void registerMetadata() { - //! Register metadata for audio / voice - void registerMetadata() - { - CAudioDeviceInfo::registerMetadata(); - CAudioDeviceInfoList::registerMetadata(); - CSettings::registerMetadata(); + CAudioDeviceInfo::registerMetadata(); + CAudioDeviceInfoList::registerMetadata(); + CSettings::registerMetadata(); - // ENUMs - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - } + // ENUMs + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); } +} -} // ns +// ns diff --git a/src/misc/audio/registermetadataaudio.h b/src/misc/audio/registermetadataaudio.h index 6fdef94dd..562afd358 100644 --- a/src/misc/audio/registermetadataaudio.h +++ b/src/misc/audio/registermetadataaudio.h @@ -14,4 +14,4 @@ namespace swift::misc::audio SWIFT_MISC_EXPORT void registerMetadata(); } // ns -#endif // guard +#endif // SWIFT_MISC_AUDIO_REGISTERMETADATAAUDIO_H diff --git a/src/misc/collection.h b/src/misc/collection.h index 8d9d26cfe..03a7aa69c 100644 --- a/src/misc/collection.h +++ b/src/misc/collection.h @@ -77,7 +77,7 @@ namespace swift::misc typename QMap::iterator insert(const T &value) { return QMap::insert(value, value); } //! Default constructor. - QOrderedSet() {} + QOrderedSet() = default; //! Initializer list constructor. QOrderedSet(std::initializer_list il) @@ -104,37 +104,37 @@ namespace swift::misc { public: //! STL compatibility - typedef T key_type; + using key_type = T; //! STL compatibility - typedef T value_type; + using value_type = T; //! STL compatibility - typedef T &reference; + using reference = T &; //! STL compatibility - typedef const T &const_reference; + using const_reference = const T &; //! STL compatibility - typedef T *pointer; + using pointer = T *; //! STL compatibility - typedef const T *const_pointer; + using const_pointer = const T *; //! STL compatibility - typedef typename QOrderedSet::const_iterator const_iterator; + using const_iterator = typename QOrderedSet::const_iterator; //! STL compatibility - typedef const_iterator iterator; // can't modify elements in-place + using iterator = const_iterator; // can't modify elements in-place //! STL compatibility - typedef ptrdiff_t difference_type; + using difference_type = ptrdiff_t; //! STL compatibility - typedef int size_type; + using size_type = int; //! Default constructor. - CCollection() {} + CCollection() = default; //! Initializer list constructor. CCollection(std::initializer_list il) : m_impl(il) {} diff --git a/src/misc/comparefunctions.h b/src/misc/comparefunctions.h index c4ebc99de..35bb6fb25 100644 --- a/src/misc/comparefunctions.h +++ b/src/misc/comparefunctions.h @@ -44,4 +44,4 @@ namespace swift::misc::Compare } } // ns -#endif +#endif // SWIFT_MISC_COMPAREFUNCTIONS_H diff --git a/src/misc/compressutils.h b/src/misc/compressutils.h index 59f6b7d86..ec43703bb 100644 --- a/src/misc/compressutils.h +++ b/src/misc/compressutils.h @@ -41,4 +41,4 @@ namespace swift::misc }; } // ns -#endif // guard +#endif // SWIFT_MISC_COMPRESSUTILS_H diff --git a/src/misc/crashinfo.cpp b/src/misc/crashinfo.cpp index 0893ea464..eae1ea8f7 100644 --- a/src/misc/crashinfo.cpp +++ b/src/misc/crashinfo.cpp @@ -5,14 +5,10 @@ #include "misc/fileutils.h" #include "misc/worker.h" -#include - SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc, CCrashInfo) namespace swift::misc { - CCrashInfo::CCrashInfo() {} - QString CCrashInfo::convertToQString(bool i18n) const { Q_UNUSED(i18n); @@ -38,8 +34,7 @@ namespace swift::misc QVariant CCrashInfo::propertyByIndex(CPropertyIndexRef index) const { if (index.isMyself()) { return QVariant::fromValue(*this); } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexUserName: return QVariant::fromValue(m_userName); case IndexInfo: return QVariant::fromValue(m_info); @@ -57,8 +52,7 @@ namespace swift::misc (*this) = variant.value(); return; } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexUserName: this->setUserName(variant.toString()); break; case IndexInfo: this->setUserName(variant.toString()); break; @@ -71,8 +65,7 @@ namespace swift::misc int CCrashInfo::comparePropertyByIndex(CPropertyIndexRef index, const CCrashInfo &compareValue) const { if (index.isMyself()) { return this->getInfo().compare(compareValue.getInfo()); } - const ColumnIndex i = index.frontCasted(); - switch (i) + switch (index.frontCasted()) { case IndexUserName: return this->getUserName().compare(compareValue.getUserName()); case IndexInfo: return this->getInfo().compare(compareValue.getInfo()); diff --git a/src/misc/crashinfo.h b/src/misc/crashinfo.h index 4709d64fe..8f09fef46 100644 --- a/src/misc/crashinfo.h +++ b/src/misc/crashinfo.h @@ -29,7 +29,7 @@ namespace swift::misc }; //! Default constructor. - CCrashInfo(); + CCrashInfo() = default; //! Get user name const QString &getUserName() const { return m_userName; } @@ -104,4 +104,4 @@ namespace swift::misc Q_DECLARE_METATYPE(swift::misc::CCrashInfo) -#endif // guard +#endif // SWIFT_MISC_CRASHINFO_H diff --git a/src/misc/datacache.cpp b/src/misc/datacache.cpp index 008752dab..42604f4bf 100644 --- a/src/misc/datacache.cpp +++ b/src/misc/datacache.cpp @@ -5,7 +5,6 @@ #include "misc/datacache.h" #include "misc/atomicfile.h" -#include "misc/directoryutils.h" #include "misc/identifier.h" #include "misc/logmessage.h" #include "misc/processinfo.h" diff --git a/src/misc/datacache.h b/src/misc/datacache.h index 7d2347d62..a7771a503 100644 --- a/src/misc/datacache.h +++ b/src/misc/datacache.h @@ -11,7 +11,6 @@ #include "misc/identifier.h" #include "misc/propertyindexref.h" #include "misc/statusmessage.h" -#include "misc/logcategories.h" #include "misc/valuecache.h" #include "misc/valuecacheprivate.h" #include "misc/variantmap.h" diff --git a/src/swiftlauncher/main.cpp b/src/swiftlauncher/main.cpp index d9217dedb..9eedf09fa 100644 --- a/src/swiftlauncher/main.cpp +++ b/src/swiftlauncher/main.cpp @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv)); QApplication qa(argc, argv); // needed Q_UNUSED(qa) - CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Laucher, CIcons::swiftLauncher1024()); + CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Launcher, CIcons::swiftLauncher1024()); a.addNetworkOptions(); // so it can be passed (hand over) to started applications a.addDBusAddressOption(); // required by the dbus server address selector const QCommandLineOption installerOption { { "i", "installer" }, QCoreApplication::translate("main", "Installer setup.") }; diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index 40e737001..4b1ba04e0 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -408,7 +408,7 @@ void CSwiftLauncher::saveSetup() bool CSwiftLauncher::warnAboutOtherSwiftApplications() { CApplicationInfoList running = CGuiApplication::getRunningApplications(); - running.removeApplication(CApplicationInfo::Laucher); + running.removeApplication(CApplicationInfo::Launcher); if (running.isEmpty()) { return true; } // getting here means another application is running