Merge pull request #853 from MTRNord/MTRNord/clang-tidy

Apply selective clang-tidy suggestions
This commit is contained in:
DeepBlueV7.X 2021-12-28 17:36:20 +00:00 committed by GitHub
commit 5a21029423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 83 deletions

View file

@ -15,9 +15,9 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSettings>
#include <QStandardPaths> #include <QStandardPaths>
#include <QVariant> #include <QVariant>
#include <utility>
#include "Cache_p.h" #include "Cache_p.h"
#include "ChatPage.h" #include "ChatPage.h"
@ -330,7 +330,7 @@ qml_mtx_events::fromRoomEventType(qml_mtx_events::EventType t)
}; };
} }
TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent) TimelineModel::TimelineModel(TimelineViewManager *manager, const QString &room_id, QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, events(room_id.toStdString(), this) , events(room_id.toStdString(), this)
, room_id_(room_id) , room_id_(room_id)
@ -355,7 +355,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
[](const QString &msg) { emit ChatPage::instance()->showNotification(msg); }, [](const QString &msg) { emit ChatPage::instance()->showNotification(msg); },
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, &TimelineModel::dataAtIdChanged, this, [this](QString id) { connect(this, &TimelineModel::dataAtIdChanged, this, [this](const QString &id) {
relatedEventCacheBuster++; relatedEventCacheBuster++;
auto idx = idToIndex(id); auto idx = idToIndex(id);
@ -404,26 +404,28 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
connect(&events, connect(&events,
&EventStore::startDMVerification, &EventStore::startDMVerification,
this, this,
[this](mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> msg) { [this](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg) {
ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this); ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this);
}); });
connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
this->updateFlowEventId(event_id); this->updateFlowEventId(std::move(event_id));
}); });
// When a message is sent, check if the current edit/reply relates to that message, // When a message is sent, check if the current edit/reply relates to that message,
// and update the event_id so that it points to the sent message and not the pending one. // and update the event_id so that it points to the sent message and not the pending one.
connect( connect(&events,
&events, &EventStore::messageSent, this, [this](std::string txn_id, std::string event_id) { &EventStore::messageSent,
if (edit_.toStdString() == txn_id) { this,
edit_ = QString::fromStdString(event_id); [this](const std::string &txn_id, const std::string &event_id) {
emit editChanged(edit_); if (edit_.toStdString() == txn_id) {
} edit_ = QString::fromStdString(event_id);
if (reply_.toStdString() == txn_id) { emit editChanged(edit_);
reply_ = QString::fromStdString(event_id); }
emit replyChanged(reply_); if (reply_.toStdString() == txn_id) {
} reply_ = QString::fromStdString(event_id);
}); emit replyChanged(reply_);
}
});
connect( connect(
manager_, &TimelineViewManager::initialSyncChanged, &events, &EventStore::enableKeyRequests); manager_, &TimelineViewManager::initialSyncChanged, &events, &EventStore::enableKeyRequests);
@ -486,7 +488,7 @@ TimelineModel::rowCount(const QModelIndex &parent) const
} }
QVariantMap QVariantMap
TimelineModel::getDump(QString eventId, QString relatedTo) const TimelineModel::getDump(const QString &eventId, const QString &relatedTo) const
{ {
if (auto event = events.get(eventId.toStdString(), relatedTo.toStdString())) if (auto event = events.get(eventId.toStdString(), relatedTo.toStdString()))
return data(*event, Dump).toMap(); return data(*event, Dump).toMap();
@ -772,7 +774,7 @@ TimelineModel::data(const QModelIndex &index, int role) const
} }
QVariant QVariant
TimelineModel::dataById(QString id, int role, QString relatedTo) TimelineModel::dataById(const QString &id, int role, const QString &relatedTo)
{ {
if (auto event = events.get(id.toStdString(), relatedTo.toStdString())) if (auto event = events.get(id.toStdString(), relatedTo.toStdString()))
return data(*event, role); return data(*event, role);
@ -1052,13 +1054,13 @@ TimelineModel::readEvent(const std::string &id)
} }
QString QString
TimelineModel::displayName(QString id) const TimelineModel::displayName(const QString &id) const
{ {
return cache::displayName(room_id_, id).toHtmlEscaped(); return cache::displayName(room_id_, id).toHtmlEscaped();
} }
QString QString
TimelineModel::avatarUrl(QString id) const TimelineModel::avatarUrl(const QString &id) const
{ {
return cache::avatarUrl(room_id_, id); return cache::avatarUrl(room_id_, id);
} }
@ -1079,7 +1081,7 @@ TimelineModel::formatDateSeparator(QDate date) const
} }
void void
TimelineModel::viewRawMessage(QString id) TimelineModel::viewRawMessage(const QString &id)
{ {
auto e = events.get(id.toStdString(), "", false); auto e = events.get(id.toStdString(), "", false);
if (!e) if (!e)
@ -1089,17 +1091,17 @@ TimelineModel::viewRawMessage(QString id)
} }
void void
TimelineModel::forwardMessage(QString eventId, QString roomId) TimelineModel::forwardMessage(const QString &eventId, QString roomId)
{ {
auto e = events.get(eventId.toStdString(), ""); auto e = events.get(eventId.toStdString(), "");
if (!e) if (!e)
return; return;
emit forwardToRoom(e, roomId); emit forwardToRoom(e, std::move(roomId));
} }
void void
TimelineModel::viewDecryptedRawMessage(QString id) TimelineModel::viewDecryptedRawMessage(const QString &id)
{ {
auto e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1112,19 +1114,19 @@ TimelineModel::viewDecryptedRawMessage(QString id)
void void
TimelineModel::openUserProfile(QString userid) TimelineModel::openUserProfile(QString userid)
{ {
UserProfile *userProfile = new UserProfile(room_id_, userid, manager_, this); UserProfile *userProfile = new UserProfile(room_id_, std::move(userid), manager_, this);
connect(this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl); connect(this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl);
emit manager_->openProfile(userProfile); emit manager_->openProfile(userProfile);
} }
void void
TimelineModel::replyAction(QString id) TimelineModel::replyAction(const QString &id)
{ {
setReply(id); setReply(id);
} }
void void
TimelineModel::unpin(QString id) TimelineModel::unpin(const QString &id)
{ {
auto pinned = auto pinned =
cache::client()->getStateEvent<mtx::events::state::PinnedEvents>(room_id_.toStdString()); cache::client()->getStateEvent<mtx::events::state::PinnedEvents>(room_id_.toStdString());
@ -1154,7 +1156,7 @@ TimelineModel::unpin(QString id)
} }
void void
TimelineModel::pin(QString id) TimelineModel::pin(const QString &id)
{ {
auto pinned = auto pinned =
cache::client()->getStateEvent<mtx::events::state::PinnedEvents>(room_id_.toStdString()); cache::client()->getStateEvent<mtx::events::state::PinnedEvents>(room_id_.toStdString());
@ -1184,7 +1186,7 @@ TimelineModel::editAction(QString id)
} }
RelatedInfo RelatedInfo
TimelineModel::relatedInfo(QString id) TimelineModel::relatedInfo(const QString &id)
{ {
auto event = events.get(id.toStdString(), ""); auto event = events.get(id.toStdString(), "");
if (!event) if (!event)
@ -1200,7 +1202,7 @@ TimelineModel::showReadReceipts(QString id)
} }
void void
TimelineModel::redactEvent(QString id) TimelineModel::redactEvent(const QString &id)
{ {
if (!id.isEmpty()) { if (!id.isEmpty()) {
auto edits = events.edits(id.toStdString()); auto edits = events.edits(id.toStdString());
@ -1237,7 +1239,7 @@ TimelineModel::redactEvent(QString id)
} }
int int
TimelineModel::idToIndex(QString id) const TimelineModel::idToIndex(const QString &id) const
{ {
if (id.isEmpty()) if (id.isEmpty())
return -1; return -1;
@ -1449,14 +1451,15 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event)
} }
void void
TimelineModel::openMedia(QString eventId) TimelineModel::openMedia(const QString &eventId)
{ {
cacheMedia(eventId, cacheMedia(eventId, [](const QString &filename) {
[](QString filename) { QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); }); QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
});
} }
bool bool
TimelineModel::saveMedia(QString eventId) const TimelineModel::saveMedia(const QString &eventId) const
{ {
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), "");
if (!event) if (!event)
@ -1530,7 +1533,8 @@ TimelineModel::saveMedia(QString eventId) const
} }
void void
TimelineModel::cacheMedia(QString eventId, std::function<void(const QString)> callback) TimelineModel::cacheMedia(const QString &eventId,
const std::function<void(const QString)> &callback)
{ {
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), "");
if (!event) if (!event)
@ -1619,7 +1623,7 @@ TimelineModel::cacheMedia(QString eventId, std::function<void(const QString)> ca
} }
void void
TimelineModel::cacheMedia(QString eventId) TimelineModel::cacheMedia(const QString &eventId)
{ {
cacheMedia(eventId, NULL); cacheMedia(eventId, NULL);
} }
@ -1675,7 +1679,7 @@ TimelineModel::scrollTimerEvent()
} }
void void
TimelineModel::requestKeyForEvent(QString id) TimelineModel::requestKeyForEvent(const QString &id)
{ {
auto encrypted_event = events.get(id.toStdString(), "", false); auto encrypted_event = events.get(id.toStdString(), "", false);
if (encrypted_event) { if (encrypted_event) {
@ -1686,7 +1690,7 @@ TimelineModel::requestKeyForEvent(QString id)
} }
void void
TimelineModel::copyLinkToEvent(QString eventId) const TimelineModel::copyLinkToEvent(const QString &eventId) const
{ {
QStringList vias; QStringList vias;
@ -1726,7 +1730,7 @@ TimelineModel::copyLinkToEvent(QString eventId) const
} }
QString QString
TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg) TimelineModel::formatTypingUsers(const std::vector<QString> &users, const QColor &bg)
{ {
QString temp = QString temp =
tr("%1 and %2 are typing.", tr("%1 and %2 are typing.",
@ -1780,7 +1784,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
} }
QString QString
TimelineModel::formatJoinRuleEvent(QString id) TimelineModel::formatJoinRuleEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1818,7 +1822,7 @@ TimelineModel::formatJoinRuleEvent(QString id)
} }
QString QString
TimelineModel::formatGuestAccessEvent(QString id) TimelineModel::formatGuestAccessEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1842,7 +1846,7 @@ TimelineModel::formatGuestAccessEvent(QString id)
} }
QString QString
TimelineModel::formatHistoryVisibilityEvent(QString id) TimelineModel::formatHistoryVisibilityEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1874,7 +1878,7 @@ TimelineModel::formatHistoryVisibilityEvent(QString id)
} }
QString QString
TimelineModel::formatPowerLevelEvent(QString id) TimelineModel::formatPowerLevelEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1892,7 +1896,7 @@ TimelineModel::formatPowerLevelEvent(QString id)
} }
QVariantMap QVariantMap
TimelineModel::formatRedactedEvent(QString id) TimelineModel::formatRedactedEvent(const QString &id)
{ {
QVariantMap pair{{"first", ""}, {"second", ""}}; QVariantMap pair{{"first", ""}, {"second", ""}};
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
@ -1930,7 +1934,7 @@ TimelineModel::formatRedactedEvent(QString id)
} }
void void
TimelineModel::acceptKnock(QString id) TimelineModel::acceptKnock(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1954,7 +1958,7 @@ TimelineModel::acceptKnock(QString id)
} }
bool bool
TimelineModel::showAcceptKnockButton(QString id) TimelineModel::showAcceptKnockButton(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -1975,7 +1979,7 @@ TimelineModel::showAcceptKnockButton(QString id)
} }
QString QString
TimelineModel::formatMemberEvent(QString id) TimelineModel::formatMemberEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e) if (!e)
@ -2079,7 +2083,7 @@ TimelineModel::formatMemberEvent(QString id)
} }
void void
TimelineModel::setEdit(QString newEdit) TimelineModel::setEdit(const QString &newEdit)
{ {
if (newEdit.isEmpty()) { if (newEdit.isEmpty()) {
resetEdit(); resetEdit();
@ -2238,7 +2242,7 @@ TimelineModel::directChatOtherUserId() const
{ {
if (roomMemberCount() < 3) { if (roomMemberCount() < 3) {
QString id; QString id;
for (auto member : cache::getMembers(room_id_.toStdString())) for (const auto &member : cache::getMembers(room_id_.toStdString()))
if (member.user_id != UserSettings::instance()->userId()) if (member.user_id != UserSettings::instance()->userId())
id = member.user_id; id = member.user_id;
return id; return id;

View file

@ -189,7 +189,7 @@ class TimelineModel : public QAbstractListModel
public: public:
explicit TimelineModel(TimelineViewManager *manager, explicit TimelineModel(TimelineViewManager *manager,
QString room_id, const QString &room_id,
QObject *parent = nullptr); QObject *parent = nullptr);
enum Roles enum Roles
@ -237,49 +237,50 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const; QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const;
Q_INVOKABLE QVariant dataById(QString id, int role, QString relatedTo); Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo);
bool canFetchMore(const QModelIndex &) const override; bool canFetchMore(const QModelIndex &) const override;
void fetchMore(const QModelIndex &) override; void fetchMore(const QModelIndex &) override;
Q_INVOKABLE QString displayName(QString id) const; Q_INVOKABLE QString displayName(const QString &id) const;
Q_INVOKABLE QString avatarUrl(QString id) const; Q_INVOKABLE QString avatarUrl(const QString &id) const;
Q_INVOKABLE QString formatDateSeparator(QDate date) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const;
Q_INVOKABLE QString formatTypingUsers(const std::vector<QString> &users, QColor bg); Q_INVOKABLE QString formatTypingUsers(const std::vector<QString> &users, const QColor &bg);
Q_INVOKABLE bool showAcceptKnockButton(QString id); Q_INVOKABLE bool showAcceptKnockButton(const QString &id);
Q_INVOKABLE void acceptKnock(QString id); Q_INVOKABLE void acceptKnock(const QString &id);
Q_INVOKABLE QString formatMemberEvent(QString id); Q_INVOKABLE QString formatMemberEvent(const QString &id);
Q_INVOKABLE QString formatJoinRuleEvent(QString id); Q_INVOKABLE QString formatJoinRuleEvent(const QString &id);
Q_INVOKABLE QString formatHistoryVisibilityEvent(QString id); Q_INVOKABLE QString formatHistoryVisibilityEvent(const QString &id);
Q_INVOKABLE QString formatGuestAccessEvent(QString id); Q_INVOKABLE QString formatGuestAccessEvent(const QString &id);
Q_INVOKABLE QString formatPowerLevelEvent(QString id); Q_INVOKABLE QString formatPowerLevelEvent(const QString &id);
Q_INVOKABLE QVariantMap formatRedactedEvent(QString id); Q_INVOKABLE QVariantMap formatRedactedEvent(const QString &id);
Q_INVOKABLE void viewRawMessage(QString id); Q_INVOKABLE void viewRawMessage(const QString &id);
Q_INVOKABLE void forwardMessage(QString eventId, QString roomId); Q_INVOKABLE void forwardMessage(const QString &eventId, QString roomId);
Q_INVOKABLE void viewDecryptedRawMessage(QString id); Q_INVOKABLE void viewDecryptedRawMessage(const QString &id);
Q_INVOKABLE void openUserProfile(QString userid); Q_INVOKABLE void openUserProfile(QString userid);
Q_INVOKABLE void editAction(QString id); Q_INVOKABLE void editAction(QString id);
Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void replyAction(const QString &id);
Q_INVOKABLE void unpin(QString id); Q_INVOKABLE void unpin(const QString &id);
Q_INVOKABLE void pin(QString id); Q_INVOKABLE void pin(const QString &id);
Q_INVOKABLE void showReadReceipts(QString id); Q_INVOKABLE void showReadReceipts(QString id);
Q_INVOKABLE void redactEvent(QString id); Q_INVOKABLE void redactEvent(const QString &id);
Q_INVOKABLE int idToIndex(QString id) const; Q_INVOKABLE int idToIndex(const QString &id) const;
Q_INVOKABLE QString indexToId(int index) const; Q_INVOKABLE QString indexToId(int index) const;
Q_INVOKABLE void openMedia(QString eventId); Q_INVOKABLE void openMedia(const QString &eventId);
Q_INVOKABLE void cacheMedia(QString eventId); Q_INVOKABLE void cacheMedia(const QString &eventId);
Q_INVOKABLE bool saveMedia(QString eventId) const; Q_INVOKABLE bool saveMedia(const QString &eventId) const;
Q_INVOKABLE void showEvent(QString eventId); Q_INVOKABLE void showEvent(QString eventId);
Q_INVOKABLE void copyLinkToEvent(QString eventId) const; Q_INVOKABLE void copyLinkToEvent(const QString &eventId) const;
void cacheMedia(QString eventId, std::function<void(const QString filename)> callback); void
cacheMedia(const QString &eventId, const std::function<void(const QString filename)> &callback);
Q_INVOKABLE void sendReset() Q_INVOKABLE void sendReset()
{ {
beginResetModel(); beginResetModel();
endResetModel(); endResetModel();
} }
Q_INVOKABLE void requestKeyForEvent(QString id); Q_INVOKABLE void requestKeyForEvent(const QString &id);
std::vector<::Reaction> reactions(const std::string &event_id) std::vector<::Reaction> reactions(const std::string &event_id)
{ {
@ -296,7 +297,7 @@ public:
void syncState(const mtx::responses::State &state); void syncState(const mtx::responses::State &state);
template<class T> template<class T>
void sendMessageEvent(const T &content, mtx::events::EventType eventType); void sendMessageEvent(const T &content, mtx::events::EventType eventType);
RelatedInfo relatedInfo(QString id); RelatedInfo relatedInfo(const QString &id);
DescInfo lastMessage() const { return lastMessage_; } DescInfo lastMessage() const { return lastMessage_; }
bool isSpace() const { return isSpace_; } bool isSpace() const { return isSpace_; }
@ -320,7 +321,7 @@ public slots:
int currentIndex() const { return idToIndex(currentId); } int currentIndex() const { return idToIndex(currentId); }
void eventShown(); void eventShown();
void markEventsAsRead(const std::vector<QString> &event_ids); void markEventsAsRead(const std::vector<QString> &event_ids);
QVariantMap getDump(QString eventId, QString relatedTo) const; QVariantMap getDump(const QString &eventId, const QString &relatedTo) const;
void updateTypingUsers(const std::vector<QString> &users) void updateTypingUsers(const std::vector<QString> &users)
{ {
if (this->typingUsers_ != users) { if (this->typingUsers_ != users) {
@ -331,7 +332,7 @@ public slots:
std::vector<QString> typingUsers() const { return typingUsers_; } std::vector<QString> typingUsers() const { return typingUsers_; }
bool paginationInProgress() const { return m_paginationInProgress; } bool paginationInProgress() const { return m_paginationInProgress; }
QString reply() const { return reply_; } QString reply() const { return reply_; }
void setReply(QString newReply) void setReply(const QString &newReply)
{ {
if (edit_.startsWith('m')) if (edit_.startsWith('m'))
return; return;
@ -349,7 +350,7 @@ public slots:
} }
} }
QString edit() const { return edit_; } QString edit() const { return edit_; }
void setEdit(QString newEdit); void setEdit(const QString &newEdit);
void resetEdit(); void resetEdit();
void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; } void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; }
void clearTimeline() { events.clearTimeline(); } void clearTimeline() { events.clearTimeline(); }
@ -367,8 +368,8 @@ public slots:
QString roomAvatarUrl() const; QString roomAvatarUrl() const;
QString roomId() const { return room_id_; } QString roomId() const { return room_id_; }
bool hasMentions() { return highlight_count > 0; } bool hasMentions() const { return highlight_count > 0; }
int notificationCount() { return notification_count; } int notificationCount() const { return notification_count; }
QString scrollTarget() const; QString scrollTarget() const;