Merge pull request #833 from Bubu/clion_suggestions

Go through some CLion (clazy, clang-tidy) suggestions in InputBar{cpp.h}
This commit is contained in:
DeepBlueV7.X 2021-12-03 02:06:49 +01:00 committed by GitHub
commit c7a29d1fb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 41 deletions

3
.gitignore vendored
View file

@ -59,6 +59,9 @@ ui_*.h
*.swo
*.swn
# CLion
/.idea
#####=== CMake ===#####
CMakeCache.txt

View file

@ -21,19 +21,15 @@
#include "Cache.h"
#include "ChatPage.h"
#include "CombinedImagePackModel.h"
#include "CompletionProxyModel.h"
#include "Config.h"
#include "Logging.h"
#include "MainWindow.h"
#include "MatrixClient.h"
#include "RoomsModel.h"
#include "TimelineModel.h"
#include "TimelineViewManager.h"
#include "UserSettingsPage.h"
#include "UsersModel.h"
#include "Utils.h"
#include "dialogs/PreviewUploadOverlay.h"
#include "emoji/EmojiModel.h"
#include "blurhash.hpp"
@ -86,7 +82,7 @@ InputBar::insertMimeData(const QMimeData *md)
}
}
if (!path.isEmpty() && QFileInfo{path}.exists()) {
if (!path.isEmpty() && QFileInfo::exists(path)) {
showPreview(*md, path, formats);
} else {
nhlog::ui()->warn("Clipboard does not contain any valid file paths.");
@ -159,7 +155,7 @@ InputBar::updateAtRoom(const QString &t)
}
void
InputBar::setText(QString newText)
InputBar::setText(const QString &newText)
{
if (history_.empty())
history_.push_front(newText);
@ -174,7 +170,10 @@ InputBar::setText(QString newText)
emit textChanged(newText);
}
void
InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_)
InputBar::updateState(int selectionStart_,
int selectionEnd_,
int cursorPosition_,
const QString &text_)
{
if (text_.isEmpty())
stopTyping();
@ -292,7 +291,7 @@ InputBar::openFileSelection()
}
void
InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify)
InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbowify)
{
mtx::events::msg::Text text = {};
text.body = msg.trimmed().toStdString();
@ -305,7 +304,7 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify)
text.body = msg.trimmed().replace(conf::strings::matrixToMarkdownLink, "\\1").toStdString();
// Don't send formatted_body, when we don't need to
if (text.formatted_body.find("<") == std::string::npos)
if (text.formatted_body.find('<') == std::string::npos)
text.formatted_body = "";
else
text.format = "org.matrix.custom.html";
@ -328,13 +327,13 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify)
for (const auto &line : related.quoted_body.split("\n")) {
if (firstLine) {
firstLine = false;
body = QString("> <%1> %2\n").arg(related.quoted_user).arg(line);
body = QString("> <%1> %2\n").arg(related.quoted_user, line);
} else {
body += QString("> %1\n").arg(line);
}
}
text.body = QString("%1\n%2").arg(body).arg(msg).toStdString();
text.body = QString("%1\n%2").arg(body, msg).toStdString();
// NOTE(Nico): rich replies always need a formatted_body!
text.format = "org.matrix.custom.html";
@ -356,7 +355,7 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify)
}
void
InputBar::emote(QString msg, bool rainbowify)
InputBar::emote(const QString &msg, bool rainbowify)
{
auto html = utils::markdownToHtml(msg, rainbowify);
@ -384,7 +383,7 @@ InputBar::emote(QString msg, bool rainbowify)
}
void
InputBar::notice(QString msg, bool rainbowify)
InputBar::notice(const QString &msg, bool rainbowify)
{
auto html = utils::markdownToHtml(msg, rainbowify);
@ -566,7 +565,7 @@ InputBar::sticker(CombinedImagePackModel *model, int row)
}
void
InputBar::command(QString command, QString args)
InputBar::command(const QString &command, QString args)
{
if (command == "me") {
emote(args, false);
@ -595,15 +594,15 @@ InputBar::command(QString command, QString args)
.toStdString();
member.membership = mtx::events::state::Membership::Join;
http::client()->send_state_event(room->roomId().toStdString(),
http::client()->user_id().to_string(),
member,
[](mtx::responses::EventId, mtx::http::RequestErr err) {
if (err)
nhlog::net()->error(
"Failed to set room displayname: {}",
err->matrix_error.error);
});
http::client()->send_state_event(
room->roomId().toStdString(),
http::client()->user_id().to_string(),
member,
[](const mtx::responses::EventId &, mtx::http::RequestErr err) {
if (err)
nhlog::net()->error("Failed to set room displayname: {}",
err->matrix_error.error);
});
} else if (command == "shrug") {
message("¯\\_(ツ)_/¯" + (args.isEmpty() ? "" : " " + args));
} else if (command == "fliptable") {
@ -654,15 +653,14 @@ InputBar::command(QString command, QString args)
}
void
InputBar::showPreview(const QMimeData &source, QString path, const QStringList &formats)
InputBar::showPreview(const QMimeData &source, const QString &path, const QStringList &formats)
{
dialogs::PreviewUploadOverlay *previewDialog_ =
new dialogs::PreviewUploadOverlay(ChatPage::instance());
auto *previewDialog_ = new dialogs::PreviewUploadOverlay(ChatPage::instance());
previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
// Force SVG to _not_ be handled as an image, but as raw data
if (source.hasImage() && (!formats.size() || formats.front() != "image/svg+xml")) {
if (formats.size() && formats.front().startsWith("image/")) {
if (source.hasImage() && (formats.empty() || formats.front() != "image/svg+xml")) {
if (!formats.empty() && formats.front().startsWith("image/")) {
// known format, keep as-is
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
} else {
@ -672,7 +670,7 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
} else if (!path.isEmpty())
previewDialog_->setPreview(path);
else if (!formats.isEmpty()) {
auto mime = formats.first();
const auto &mime = formats.first();
previewDialog_->setPreview(source.data(mime), mime);
} else {
setUploading(false);
@ -688,7 +686,7 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
previewDialog_,
&dialogs::PreviewUploadOverlay::confirmUpload,
this,
[this](const QByteArray data, const QString &mime, const QString &fn) {
[this](const QByteArray &data, const QString &mime, const QString &fn) {
if (!data.size()) {
nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}",
mime.toStdString(),

View file

@ -32,7 +32,7 @@ class InputBar : public QObject
Q_PROPERTY(QString text READ text NOTIFY textChanged)
public:
InputBar(TimelineModel *parent)
explicit InputBar(TimelineModel *parent)
: QObject()
, room(parent)
{
@ -45,20 +45,20 @@ public:
}
public slots:
QString text() const;
[[nodiscard]] QString text() const;
QString previousText();
QString nextText();
void setText(QString newText);
void setText(const QString &newText);
bool containsAtRoom() const { return containsAtRoom_; }
[[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; }
void send();
void paste(bool fromMouse);
void insertMimeData(const QMimeData *data);
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString &text);
void openFileSelection();
bool uploading() const { return uploading_; }
void message(QString body,
[[nodiscard]] bool uploading() const { return uploading_; }
void message(const QString &body,
MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED,
bool rainbowify = false);
void reaction(const QString &reactedEvent, const QString &reactionKey);
@ -75,9 +75,9 @@ signals:
void containsAtRoomChanged();
private:
void emote(QString body, bool rainbowify);
void notice(QString body, bool rainbowify);
void command(QString name, QString args);
void emote(const QString &body, bool rainbowify);
void notice(const QString &body, bool rainbowify);
void command(const QString &name, QString args);
void image(const QString &filename,
const std::optional<mtx::crypto::EncryptedFile> &file,
const QString &url,
@ -101,7 +101,7 @@ private:
const QString &mime,
uint64_t dsize);
void showPreview(const QMimeData &source, QString path, const QStringList &formats);
void showPreview(const QMimeData &source, const QString &path, const QStringList &formats);
void setUploading(bool value)
{
if (value != uploading_) {