From 424b7fba3798efa4e85294403c182bfa5a203619 Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Wed, 16 Feb 2022 21:15:25 -0600 Subject: [PATCH] applied some clang modernize (#2435) --- src/cli/commandargument.cpp | 11 ++++---- src/cli/commandargument.h | 2 +- src/cli/commandlineparser.cpp | 15 +++++------ src/cli/commandoption.cpp | 30 +++++++++++---------- src/cli/commandoption.h | 14 +++++----- src/core/capturerequest.cpp | 5 ++-- src/core/capturerequest.h | 2 +- src/core/flameshotdbusadapter.cpp | 2 +- src/tools/abstractpathtool.cpp | 4 +-- src/tools/arrow/arrowtool.cpp | 3 ++- src/tools/circlecount/circlecounttool.cpp | 8 +++--- src/tools/launcher/launcheritemdelegate.cpp | 2 +- src/utils/abstractlogger.cpp | 6 ++--- src/utils/colorutils.cpp | 6 ++--- src/utils/globalvalues.cpp | 4 +-- src/utils/request.cpp | 3 ++- src/utils/valuehandler.cpp | 11 ++++---- src/utils/valuehandler.h | 4 +-- src/widgets/capture/capturewidget.cpp | 10 +++---- src/widgets/capture/selectionwidget.cpp | 5 ++-- src/widgets/capture/selectionwidget.h | 2 +- src/widgets/loadspinner.cpp | 1 - src/widgets/updatenotificationwidget.cpp | 5 ++-- src/widgets/updatenotificationwidget.h | 2 +- 24 files changed, 82 insertions(+), 75 deletions(-) diff --git a/src/cli/commandargument.cpp b/src/cli/commandargument.cpp index f11b68be..dd791986 100644 --- a/src/cli/commandargument.cpp +++ b/src/cli/commandargument.cpp @@ -3,12 +3,13 @@ #include "commandargument.h" -CommandArgument::CommandArgument() {} +#include -CommandArgument::CommandArgument(const QString& name, - const QString& description) - : m_name(name) - , m_description(description) +CommandArgument::CommandArgument() = default; + +CommandArgument::CommandArgument(QString name, QString description) + : m_name(std::move(name)) + , m_description(std::move(description)) {} void CommandArgument::setName(const QString& name) diff --git a/src/cli/commandargument.h b/src/cli/commandargument.h index 07d23b71..14f1f903 100644 --- a/src/cli/commandargument.h +++ b/src/cli/commandargument.h @@ -9,7 +9,7 @@ class CommandArgument { public: CommandArgument(); - explicit CommandArgument(const QString& name, const QString& description); + explicit CommandArgument(QString name, QString description); void setName(const QString& name); QString name() const; diff --git a/src/cli/commandlineparser.cpp b/src/cli/commandlineparser.cpp index 000cd74b..298c239b 100644 --- a/src/cli/commandlineparser.cpp +++ b/src/cli/commandlineparser.cpp @@ -67,10 +67,10 @@ QString optionsToString(const QList& options, if (!arguments.isEmpty()) { result += QObject::tr("Arguments") + ":\n"; } - for (int i = 0; i < arguments.length(); ++i) { + for (const auto& argument : arguments) { result += QStringLiteral(" %1 %2\n") - .arg(arguments.at(i).name().leftJustified(size, ' ')) - .arg(arguments.at(i).description()); + .arg(argument.name().leftJustified(size, ' ')) + .arg(argument.description()); } return result; } @@ -363,9 +363,8 @@ CommandLineParser::Node* CommandLineParser::findParent( } // find the parent in the subNodes recursively Node* res = nullptr; - for (auto i = m_parseTree.subNodes.begin(); i != m_parseTree.subNodes.end(); - ++i) { - res = recursiveParentSearch(parent, *i); + for (auto& subNode : m_parseTree.subNodes) { + res = recursiveParentSearch(parent, subNode); if (res != nullptr) { break; } @@ -381,8 +380,8 @@ CommandLineParser::Node* CommandLineParser::recursiveParentSearch( if (node.argument == parent) { res = &node; } else { - for (auto i = node.subNodes.begin(); i != node.subNodes.end(); ++i) { - res = recursiveParentSearch(parent, *i); + for (auto& subNode : node.subNodes) { + res = recursiveParentSearch(parent, subNode); if (res != nullptr) { break; } diff --git a/src/cli/commandoption.cpp b/src/cli/commandoption.cpp index 850a1e63..d990ef11 100644 --- a/src/cli/commandoption.cpp +++ b/src/cli/commandoption.cpp @@ -3,26 +3,28 @@ #include "commandoption.h" +#include + CommandOption::CommandOption(const QString& name, - const QString& description, - const QString& valueName, - const QString& defaultValue) + QString description, + QString valueName, + QString defaultValue) : m_names(name) - , m_description(description) - , m_valueName(valueName) - , m_value(defaultValue) + , m_description(std::move(description)) + , m_valueName(std::move(valueName)) + , m_value(std::move(defaultValue)) { m_checker = [](QString const&) { return true; }; } -CommandOption::CommandOption(const QStringList& names, - const QString& description, - const QString& valueName, - const QString& defaultValue) - : m_names(names) - , m_description(description) - , m_valueName(valueName) - , m_value(defaultValue) +CommandOption::CommandOption(QStringList names, + QString description, + QString valueName, + QString defaultValue) + : m_names(std::move(names)) + , m_description(std::move(description)) + , m_valueName(std::move(valueName)) + , m_value(std::move(defaultValue)) { m_checker = [](QString const&) -> bool { return true; }; } diff --git a/src/cli/commandoption.h b/src/cli/commandoption.h index c7787a4b..990ddde6 100644 --- a/src/cli/commandoption.h +++ b/src/cli/commandoption.h @@ -12,14 +12,14 @@ class CommandOption { public: CommandOption(const QString& name, - const QString& description, - const QString& valueName = QString(), - const QString& defaultValue = QString()); + QString description, + QString valueName = QString(), + QString defaultValue = QString()); - CommandOption(const QStringList& names, - const QString& description, - const QString& valueName = QString(), - const QString& defaultValue = QString()); + CommandOption(QStringList names, + QString description, + QString valueName = QString(), + QString defaultValue = QString()); void setName(const QString& name); void setNames(const QStringList& names); diff --git a/src/core/capturerequest.cpp b/src/core/capturerequest.cpp index 07ba5308..0d3aa315 100644 --- a/src/core/capturerequest.cpp +++ b/src/core/capturerequest.cpp @@ -14,15 +14,16 @@ #include #include #include +#include CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode, const uint delay, - const QVariant& data, + QVariant data, CaptureRequest::ExportTask tasks) : m_mode(mode) , m_delay(delay) , m_tasks(tasks) - , m_data(data) + , m_data(std::move(data)) {} CaptureRequest::CaptureMode CaptureRequest::captureMode() const diff --git a/src/core/capturerequest.h b/src/core/capturerequest.h index 0cb79716..ac8f885c 100644 --- a/src/core/capturerequest.h +++ b/src/core/capturerequest.h @@ -31,7 +31,7 @@ public: CaptureRequest(CaptureMode mode, const uint delay = 0, - const QVariant& data = QVariant(), + QVariant data = QVariant(), ExportTask tasks = NO_TASK); void setStaticID(uint id); diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp index e6e5ee20..11632e9f 100644 --- a/src/core/flameshotdbusadapter.cpp +++ b/src/core/flameshotdbusadapter.cpp @@ -8,7 +8,7 @@ FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent) : QDBusAbstractAdaptor(parent) {} -FlameshotDBusAdapter::~FlameshotDBusAdapter() {} +FlameshotDBusAdapter::~FlameshotDBusAdapter() = default; void FlameshotDBusAdapter::attachScreenshotToClipboard(const QByteArray& data) { diff --git a/src/tools/abstractpathtool.cpp b/src/tools/abstractpathtool.cpp index 761ce968..14aee433 100644 --- a/src/tools/abstractpathtool.cpp +++ b/src/tools/abstractpathtool.cpp @@ -126,8 +126,8 @@ void AbstractPathTool::move(const QPoint& mousePos) } QPoint basePos = *pos(); QPoint offset = mousePos - basePos; - for (int index = 0; index < m_points.size(); ++index) { - m_points[index] += offset; + for (auto& m_point : m_points) { + m_point += offset; } } diff --git a/src/tools/arrow/arrowtool.cpp b/src/tools/arrow/arrowtool.cpp index 0890098c..f17fd33b 100644 --- a/src/tools/arrow/arrowtool.cpp +++ b/src/tools/arrow/arrowtool.cpp @@ -50,8 +50,9 @@ QLine getShorterLine(QPoint p1, QPoint p2, const int thickness) // looks not very bad val = thickness / 4; l.setLength(val); - } else + } else { l.setLength(l.length() + thickness * 2 - val); + } return l.toLine(); } diff --git a/src/tools/circlecount/circlecounttool.cpp b/src/tools/circlecount/circlecounttool.cpp index 4570901e..7d0458e7 100644 --- a/src/tools/circlecount/circlecounttool.cpp +++ b/src/tools/circlecount/circlecounttool.cpp @@ -46,10 +46,10 @@ QRect CircleCountTool::boundingRect() const return {}; } int bubble_size = size() + THICKNESS_OFFSET + PADDING_VALUE; - return QRect(points().first.x() - bubble_size, - points().first.y() - bubble_size, - bubble_size * 2, - bubble_size * 2); + return { points().first.x() - bubble_size, + points().first.y() - bubble_size, + bubble_size * 2, + bubble_size * 2 }; } QString CircleCountTool::name() const diff --git a/src/tools/launcher/launcheritemdelegate.cpp b/src/tools/launcher/launcheritemdelegate.cpp index 2a0a6f24..12554018 100644 --- a/src/tools/launcher/launcheritemdelegate.cpp +++ b/src/tools/launcher/launcheritemdelegate.cpp @@ -49,5 +49,5 @@ QSize LauncherItemDelegate::sizeHint(const QStyleOptionViewItem& option, Q_UNUSED(option) Q_UNUSED(index) const int size = GlobalValues::buttonBaseSize(); - return QSize(static_cast(size * 3.2), static_cast(size * 3.7)); + return { static_cast(size * 3.2), static_cast(size * 3.7) }; } diff --git a/src/utils/abstractlogger.cpp b/src/utils/abstractlogger.cpp index 57382ec3..083d0fcd 100644 --- a/src/utils/abstractlogger.cpp +++ b/src/utils/abstractlogger.cpp @@ -32,17 +32,17 @@ AbstractLogger::~AbstractLogger() AbstractLogger AbstractLogger::info(int targets) { - return AbstractLogger(Info, targets); + return { Info, targets }; } AbstractLogger AbstractLogger::warning(int targets) { - return AbstractLogger(Warning, targets); + return { Warning, targets }; } AbstractLogger AbstractLogger::error(int targets) { - return AbstractLogger(Error, targets); + return { Error, targets }; } AbstractLogger& AbstractLogger::sendMessage(QString msg, Channel channel) diff --git a/src/utils/colorutils.cpp b/src/utils/colorutils.cpp index e484fb57..0526efc7 100644 --- a/src/utils/colorutils.cpp +++ b/src/utils/colorutils.cpp @@ -18,7 +18,7 @@ QColor ColorUtils::contrastColor(const QColor& c) { int change = colorIsDark(c) ? 30 : -45; - return QColor(qBound(0, c.red() + change, 255), - qBound(0, c.green() + change, 255), - qBound(0, c.blue() + change, 255)); + return { qBound(0, c.red() + change, 255), + qBound(0, c.green() + change, 255), + qBound(0, c.blue() + change, 255) }; } diff --git a/src/utils/globalvalues.cpp b/src/utils/globalvalues.cpp index 0556ae48..fe94354f 100644 --- a/src/utils/globalvalues.cpp +++ b/src/utils/globalvalues.cpp @@ -21,7 +21,7 @@ QString GlobalValues::iconPath() #if USE_MONOCHROME_ICON return QString(":img/app/flameshot.monochrome.svg"); #else - return QString(":img/app/flameshot.svg"); + return { ":img/app/flameshot.svg" }; #endif } @@ -30,6 +30,6 @@ QString GlobalValues::iconPathPNG() #if USE_MONOCHROME_ICON return QString(":img/app/flameshot.monochrome.png"); #else - return QString(":img/app/flameshot.png"); + return { ":img/app/flameshot.png" }; #endif } \ No newline at end of file diff --git a/src/utils/request.cpp b/src/utils/request.cpp index e743bc13..81ecbd47 100644 --- a/src/utils/request.cpp +++ b/src/utils/request.cpp @@ -18,4 +18,5 @@ OrgFreedesktopPortalRequestInterface::OrgFreedesktopPortalRequestInterface( parent) {} -OrgFreedesktopPortalRequestInterface::~OrgFreedesktopPortalRequestInterface() {} +OrgFreedesktopPortalRequestInterface::~OrgFreedesktopPortalRequestInterface() = + default; diff --git a/src/utils/valuehandler.cpp b/src/utils/valuehandler.cpp index 2502c6a6..3f1f9bc0 100644 --- a/src/utils/valuehandler.cpp +++ b/src/utils/valuehandler.cpp @@ -23,7 +23,7 @@ QVariant ValueHandler::value(const QVariant& val) QVariant ValueHandler::fallback() { - return QVariant(); + return {}; } QVariant ValueHandler::representation(const QVariant& val) @@ -68,8 +68,8 @@ QString Bool::expected() // STRING -String::String(const QString& def) - : m_def(def) +String::String(QString def) + : m_def(std::move(def)) {} bool String::check(const QVariant&) @@ -89,8 +89,8 @@ QString String::expected() // COLOR -Color::Color(const QColor& def) - : m_def(def) +Color::Color(QColor def) + : m_def(std::move(def)) {} bool Color::check(const QVariant& val) @@ -512,6 +512,7 @@ bool Region::check(const QVariant& val) } #include // TODO remove after FIXME (see below) +#include QVariant Region::process(const QVariant& val) { diff --git a/src/utils/valuehandler.h b/src/utils/valuehandler.h index 2a240f64..f17af6a5 100644 --- a/src/utils/valuehandler.h +++ b/src/utils/valuehandler.h @@ -99,7 +99,7 @@ private: class String : public ValueHandler { public: - String(const QString& def); + String(QString def); bool check(const QVariant&) override; QVariant fallback() override; QString expected() override; @@ -111,7 +111,7 @@ private: class Color : public ValueHandler { public: - Color(const QColor& def); + Color(QColor def); bool check(const QVariant& val) override; QVariant process(const QVariant& val) override; QVariant fallback() override; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 1e86fbf3..af27b150 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -1696,7 +1696,7 @@ void CaptureWidget::redo() QRect CaptureWidget::extendedSelection() const { if (!m_selection->isVisible()) { - return QRect(); + return {}; } QRect r = m_selection->geometry(); return extendedRect(r); @@ -1705,10 +1705,10 @@ QRect CaptureWidget::extendedSelection() const QRect CaptureWidget::extendedRect(const QRect& r) const { auto devicePixelRatio = m_context.screenshot.devicePixelRatio(); - return QRect(r.left() * devicePixelRatio, - r.top() * devicePixelRatio, - r.width() * devicePixelRatio, - r.height() * devicePixelRatio); + return { static_cast(r.left() * devicePixelRatio), + static_cast(r.top() * devicePixelRatio), + static_cast(r.width() * devicePixelRatio), + static_cast(r.height() * devicePixelRatio) }; } QRect CaptureWidget::paddedUpdateRect(const QRect& r) const diff --git a/src/widgets/capture/selectionwidget.cpp b/src/widgets/capture/selectionwidget.cpp index dba822ab..1b6fb710 100644 --- a/src/widgets/capture/selectionwidget.cpp +++ b/src/widgets/capture/selectionwidget.cpp @@ -11,12 +11,13 @@ #include #include #include +#include #define MARGIN (m_THandle.width()) -SelectionWidget::SelectionWidget(const QColor& c, QWidget* parent) +SelectionWidget::SelectionWidget(QColor c, QWidget* parent) : QWidget(parent) - , m_color(c) + , m_color(std::move(c)) , m_activeSide(NO_SIDE) , m_ignoreMouse(false) { diff --git a/src/widgets/capture/selectionwidget.h b/src/widgets/capture/selectionwidget.h index edb87b68..fcc8dae4 100644 --- a/src/widgets/capture/selectionwidget.h +++ b/src/widgets/capture/selectionwidget.h @@ -25,7 +25,7 @@ public: CENTER = 0b10000, }; - explicit SelectionWidget(const QColor& c, QWidget* parent = nullptr); + explicit SelectionWidget(QColor c, QWidget* parent = nullptr); SideType getMouseSide(const QPoint& mousePos) const; QVector handlerAreas(); diff --git a/src/widgets/loadspinner.cpp b/src/widgets/loadspinner.cpp index ab708857..59f82acb 100644 --- a/src/widgets/loadspinner.cpp +++ b/src/widgets/loadspinner.cpp @@ -11,7 +11,6 @@ LoadSpinner::LoadSpinner(QWidget* parent) : QWidget(parent) - , m_startAngle(0) , m_span(0) , m_growing(true) { diff --git a/src/widgets/updatenotificationwidget.cpp b/src/widgets/updatenotificationwidget.cpp index f19481ce..e24e0e91 100644 --- a/src/widgets/updatenotificationwidget.cpp +++ b/src/widgets/updatenotificationwidget.cpp @@ -12,14 +12,15 @@ #include #include #include +#include UpdateNotificationWidget::UpdateNotificationWidget( QWidget* parent, const QString& appLatestVersion, - const QString& appLatestUrl) + QString appLatestUrl) : QWidget(parent) , m_appLatestVersion(appLatestVersion) - , m_appLatestUrl(appLatestUrl) + , m_appLatestUrl(std::move(appLatestUrl)) , m_layout(nullptr) { setMinimumSize(400, 100); diff --git a/src/widgets/updatenotificationwidget.h b/src/widgets/updatenotificationwidget.h index b214842c..b19ae267 100644 --- a/src/widgets/updatenotificationwidget.h +++ b/src/widgets/updatenotificationwidget.h @@ -20,7 +20,7 @@ class UpdateNotificationWidget : public QWidget public: explicit UpdateNotificationWidget(QWidget* parent, const QString& appLatestVersion, - const QString& appLatestUrl); + QString appLatestUrl); void setAppLatestVersion(const QString& latestVersion); void hide();