From a3c4ebc4605cb753bc9795d044e9a9c84a56da1e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 29 Dec 2021 00:36:43 +0100 Subject: [PATCH] use more literals --- src/Config.h | 8 ++++---- src/Utils.h | 6 +++--- src/dialogs/CreateRoom.cpp | 24 ++++++++++++------------ src/dialogs/ImageOverlay.cpp | 4 ++-- src/dialogs/ImageOverlay.h | 2 +- src/dialogs/ReCaptcha.cpp | 2 +- src/ui/TextField.h | 4 ++-- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Config.h b/src/Config.h index fcf37112..20205ecd 100644 --- a/src/Config.h +++ b/src/Config.h @@ -63,10 +63,10 @@ const QRegularExpression url_regex( QStringLiteral( R"((?((www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'"]+[^!,\.\s<>'"\]\)\:]))(?!["']))")); // match any markdown matrix.to link. Capture group 1 is the link name, group 2 is the target. -static const QRegularExpression matrixToMarkdownLink( - R"(\[(.*?)(?(.*?))"); // clazy:exclude=non-pod-global-static +static const QRegularExpression + matrixToMarkdownLink(QStringLiteral(R"(\[(.*?)(?(.*?))")); } // Window geometry. diff --git a/src/Utils.h b/src/Utils.h index 1d1cb10c..8d085cc1 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -94,8 +94,8 @@ event_body(const mtx::events::collections::TimelineEvents &event); //! Match widgets/events with a description message. template QString -messageDescription(const QString &username = "", - const QString &body = "", +messageDescription(const QString &username = QString(), + const QString &body = QString(), const bool isLocal = false) { using Audio = mtx::events::RoomEvent; @@ -157,7 +157,7 @@ messageDescription(const QString &username = "", return QCoreApplication::translate("message-description sent:", "%1: %2") .arg(username, body); } else if (std::is_same::value) { - return QString("* %1 %2").arg(username, body); + return QStringLiteral("* %1 %2").arg(username, body); } else if (std::is_same::value) { if (isLocal) return QCoreApplication::translate("message-description sent:", diff --git a/src/dialogs/CreateRoom.cpp b/src/dialogs/CreateRoom.cpp index 0600bd13..7a0e5bcd 100644 --- a/src/dialogs/CreateRoom.cpp +++ b/src/dialogs/CreateRoom.cpp @@ -68,17 +68,17 @@ CreateRoom::CreateRoom(QWidget *parent) auto visibilityLabel = new QLabel(tr("Room Visibility"), this); visibilityCombo_ = new QComboBox(this); - visibilityCombo_->addItem("Private"); - visibilityCombo_->addItem("Public"); + visibilityCombo_->addItem(tr("Private")); + visibilityCombo_->addItem(tr("Public")); visibilityLayout->addWidget(visibilityLabel); visibilityLayout->addWidget(visibilityCombo_, 0, Qt::AlignBottom | Qt::AlignRight); auto presetLabel = new QLabel(tr("Room Preset"), this); presetCombo_ = new QComboBox(this); - presetCombo_->addItem("Private Chat"); - presetCombo_->addItem("Public Chat"); - presetCombo_->addItem("Trusted Private Chat"); + presetCombo_->addItem(tr("Private Chat")); + presetCombo_->addItem(tr("Public Chat")); + presetCombo_->addItem(tr("Trusted Private Chat")); presetLayout->addWidget(presetLabel); presetLayout->addWidget(presetCombo_, 0, Qt::AlignBottom | Qt::AlignRight); @@ -119,10 +119,10 @@ CreateRoom::CreateRoom(QWidget *parent) }); connect(visibilityCombo_, - static_cast(&QComboBox::currentTextChanged), + static_cast(&QComboBox::currentIndexChanged), this, - [this](const QString &text) { - if (text == "Private") { + [this](int idx) { + if (idx == 0) { request_.visibility = mtx::common::RoomVisibility::Private; } else { request_.visibility = mtx::common::RoomVisibility::Public; @@ -130,12 +130,12 @@ CreateRoom::CreateRoom(QWidget *parent) }); connect(presetCombo_, - static_cast(&QComboBox::currentTextChanged), + static_cast(&QComboBox::currentIndexChanged), this, - [this](const QString &text) { - if (text == "Private Chat") { + [this](int idx) { + if (idx == 0) { request_.preset = mtx::requests::Preset::PrivateChat; - } else if (text == "Public Chat") { + } else if (idx == 1) { request_.preset = mtx::requests::Preset::PublicChat; } else { request_.preset = mtx::requests::Preset::TrustedPrivateChat; diff --git a/src/dialogs/ImageOverlay.cpp b/src/dialogs/ImageOverlay.cpp index 8890814d..8f38f31b 100644 --- a/src/dialogs/ImageOverlay.cpp +++ b/src/dialogs/ImageOverlay.cpp @@ -14,7 +14,7 @@ using namespace dialogs; -ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) +ImageOverlay::ImageOverlay(const QPixmap &image, QWidget *parent) : QWidget{parent} , originalImage_{image} { @@ -22,7 +22,7 @@ ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) setParent(nullptr); setWindowFlags(windowFlags() | Qt::FramelessWindowHint); - setWindowRole("imageoverlay"); + setWindowRole(QStringLiteral("imageoverlay")); setAttribute(Qt::WA_NoSystemBackground, true); setAttribute(Qt::WA_TranslucentBackground, true); diff --git a/src/dialogs/ImageOverlay.h b/src/dialogs/ImageOverlay.h index 2174279f..ba70fc13 100644 --- a/src/dialogs/ImageOverlay.h +++ b/src/dialogs/ImageOverlay.h @@ -16,7 +16,7 @@ class ImageOverlay : public QWidget { Q_OBJECT public: - ImageOverlay(QPixmap image, QWidget *parent = nullptr); + ImageOverlay(const QPixmap &image, QWidget *parent = nullptr); protected: void mousePressEvent(QMouseEvent *event) override; diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp index a4ada889..6b1d3ab1 100644 --- a/src/dialogs/ReCaptcha.cpp +++ b/src/dialogs/ReCaptcha.cpp @@ -34,7 +34,7 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent) buttonLayout->setContentsMargins(0, 0, 0, 0); buttonLayout->setSpacing(8); - openCaptchaBtn_ = new QPushButton("Open reCAPTCHA", this); + openCaptchaBtn_ = new QPushButton(tr("Open reCAPTCHA"), this); cancelBtn_ = new QPushButton(tr("Cancel"), this); confirmBtn_ = new QPushButton(tr("Confirm"), this); confirmBtn_->setDefault(true); diff --git a/src/ui/TextField.h b/src/ui/TextField.h index e226c84b..a56e3273 100644 --- a/src/ui/TextField.h +++ b/src/ui/TextField.h @@ -87,7 +87,7 @@ public: TextFieldLabel(TextField *parent); inline void setColor(const QColor &color); - inline void setOffset(const QPointF &pos); + inline void setOffset(QPointF pos); inline void setScale(qreal scale); inline QColor color() const; @@ -120,7 +120,7 @@ TextFieldLabel::setColor(const QColor &color) } inline void -TextFieldLabel::setOffset(const QPointF &pos) +TextFieldLabel::setOffset(QPointF pos) { x_ = pos.x(); y_ = pos.y();