From 0f76f0115ef2820dbad754138fb55c237db0619b Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 31 Oct 2017 07:26:41 +0200 Subject: [PATCH] lint --- include/CommunitiesList.h | 38 ++++---- include/CommunitiesListItem.h | 76 ++++++++------- include/Community.h | 7 +- include/RoomList.h | 4 +- include/ui/Theme.h | 4 +- src/ChatPage.cc | 63 +++++++------ src/CommunitiesList.cc | 173 ++++++++++++++++++---------------- src/CommunitiesListItem.cc | 43 ++++----- src/Community.cc | 53 +++++------ src/MatrixClient.cc | 22 +++-- src/RoomList.cc | 26 ++--- 11 files changed, 261 insertions(+), 248 deletions(-) diff --git a/include/CommunitiesList.h b/include/CommunitiesList.h index ffa3cfcf..53715363 100644 --- a/include/CommunitiesList.h +++ b/include/CommunitiesList.h @@ -1,44 +1,42 @@ #pragma once -#include #include #include #include +#include -#include "MatrixClient.h" #include "CommunitiesListItem.h" #include "Community.h" +#include "MatrixClient.h" #include "ui/Theme.h" class CommunitiesList : public QWidget { - Q_OBJECT + Q_OBJECT public: - CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); - ~CommunitiesList(); + CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); + ~CommunitiesList(); - void setCommunities(const QMap> &communities); - void clear(); + void setCommunities(const QMap> &communities); + void clear(); - void addCommunity(QSharedPointer community, - const QString &community_id); - void removeCommunity(const QString &community_id); + void addCommunity(QSharedPointer community, const QString &community_id); + void removeCommunity(const QString &community_id); signals: - void communityChanged(const QString &community_id); + void communityChanged(const QString &community_id); public slots: - void updateCommunityAvatar(const QString &community_id, - const QPixmap &img); - void highlightSelectedCommunity(const QString &community_id); + void updateCommunityAvatar(const QString &community_id, const QPixmap &img); + void highlightSelectedCommunity(const QString &community_id); private: - QVBoxLayout *topLayout_; - QVBoxLayout *contentsLayout_; - QWidget *scrollAreaContents_; - QScrollArea *scrollArea_; + QVBoxLayout *topLayout_; + QVBoxLayout *contentsLayout_; + QWidget *scrollAreaContents_; + QScrollArea *scrollArea_; - QMap> communities_; + QMap> communities_; - QSharedPointer client_; + QSharedPointer client_; }; diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h index 52b3e849..5df67268 100644 --- a/include/CommunitiesListItem.h +++ b/include/CommunitiesListItem.h @@ -1,83 +1,81 @@ #pragma once -#include -#include +#include #include #include -#include +#include +#include -#include "ui/Theme.h" -#include "Menu.h" #include "Community.h" +#include "Menu.h" +#include "ui/Theme.h" class CommunitiesListItem : public QWidget { - Q_OBJECT + Q_OBJECT public: - CommunitiesListItem(QSharedPointer community, - QString community_id, - QWidget *parent = nullptr); + CommunitiesListItem(QSharedPointer community, + QString community_id, + QWidget *parent = nullptr); - ~CommunitiesListItem(); + ~CommunitiesListItem(); - void setCommunity(QSharedPointer community); + void setCommunity(QSharedPointer community); - inline bool isPressed() const; - inline void setAvatar(const QImage &avatar_image); + inline bool isPressed() const; + inline void setAvatar(const QImage &avatar_image); signals: - void clicked(const QString &community_id); + void clicked(const QString &community_id); public slots: - void setPressedState(bool state); + void setPressedState(bool state); protected: - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; - void contextMenuEvent(QContextMenuEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; private: - const int IconSize = 55; + const int IconSize = 55; - QSharedPointer community_; - QString communityId_; - QString communityName_; - QString communityShortDescription; + QSharedPointer community_; + QString communityId_; + QString communityName_; + QString communityShortDescription; - QPixmap communityAvatar_; + QPixmap communityAvatar_; - Menu *menu_; - bool isPressed_ = false; + Menu *menu_; + bool isPressed_ = false; }; inline bool CommunitiesListItem::isPressed() const { - return isPressed_; + return isPressed_; } inline void CommunitiesListItem::setAvatar(const QImage &avatar_image) { - communityAvatar_ = QPixmap::fromImage( - avatar_image.scaled(IconSize, - IconSize, - Qt::IgnoreAspectRatio, - Qt::SmoothTransformation)); - update(); + communityAvatar_ = QPixmap::fromImage( + avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + update(); } class WorldCommunityListItem : public CommunitiesListItem { - Q_OBJECT + Q_OBJECT public: - WorldCommunityListItem(QWidget *parent = nullptr); - ~WorldCommunityListItem(); + WorldCommunityListItem(QWidget *parent = nullptr); + ~WorldCommunityListItem(); protected: - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + private: - const int IconSize = 55; + const int IconSize = 55; }; diff --git a/include/Community.h b/include/Community.h index 2dccbbc8..0d70dee1 100644 --- a/include/Community.h +++ b/include/Community.h @@ -1,13 +1,13 @@ #pragma once -#include #include -#include +#include #include +#include class Community : public QObject { - Q_OBJECT + Q_OBJECT public: void parseProfile(const QJsonObject &profile); @@ -55,7 +55,6 @@ Community::getLongDescription() const return long_description_; } - inline const QList Community::getRoomList() const { diff --git a/include/RoomList.h b/include/RoomList.h index 9e58b64b..b44e99d6 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -87,8 +87,8 @@ private: QMap> rooms_; QString selectedRoom_; - bool filterRooms_ = false; - QList roomFilter_ = QList(); //which rooms to include in the room list + bool filterRooms_ = false; + QList roomFilter_ = QList(); // which rooms to include in the room list QSharedPointer client_; }; diff --git a/include/ui/Theme.h b/include/ui/Theme.h index 4d482fe3..c2e4ab59 100644 --- a/include/ui/Theme.h +++ b/include/ui/Theme.h @@ -13,8 +13,8 @@ enum class AvatarType }; namespace sidebar { -static const int SmallSize = 60; -static const int NormalSize = 300; +static const int SmallSize = 60; +static const int NormalSize = 300; static const int CommunitiesSidebarSize = 64; } // Default font size. diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 12e9b82a..8cd7007d 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -63,7 +63,7 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) communitiesList_ = new CommunitiesList(client, this); communitiesSideBarLayout_->addWidget(communitiesList_); - //communitiesSideBarLayout_->addStretch(1); + // communitiesSideBarLayout_->addStretch(1); topLayout_->addWidget(communitiesSideBar_); auto splitter = new Splitter(this); @@ -256,22 +256,27 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) SIGNAL(getOwnCommunitiesResponse(QList)), this, SLOT(updateOwnCommunitiesInfo(QList))); - connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, + connect(client_.data(), + &MatrixClient::communityProfileRetrieved, + this, [=](QString communityId, QJsonObject profile) { - communityManager_[communityId]->parseProfile(profile); - }); - connect(client_.data(), &MatrixClient::communityRoomsRetrieved, this, + communityManager_[communityId]->parseProfile(profile); + }); + connect(client_.data(), + &MatrixClient::communityRoomsRetrieved, + this, [=](QString communityId, QJsonObject rooms) { - communityManager_[communityId]->parseRooms(rooms); + communityManager_[communityId]->parseRooms(rooms); - if (communityId == current_community_) { - if (communityId == "world") { - room_list_->setFilterRooms(false); - } else { - room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); - } - } - }); + if (communityId == current_community_) { + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter( + communityManager_[communityId]->getRoomList()); + } + } + }); connect(client_.data(), SIGNAL(ownAvatarRetrieved(const QPixmap &)), this, @@ -301,14 +306,18 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) } }); - connect(communitiesList_, &CommunitiesList::communityChanged, this, [=](const QString &communityId) { - current_community_ = communityId; - if (communityId == "world") { - room_list_->setFilterRooms(false); - } else { - room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); - } - }); + connect(communitiesList_, + &CommunitiesList::communityChanged, + this, + [=](const QString &communityId) { + current_community_ = communityId; + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter( + communityManager_[communityId]->getRoomList()); + } + }); AvatarProvider::init(client); } @@ -489,13 +498,13 @@ ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_na void ChatPage::updateOwnCommunitiesInfo(const QList &own_communities) { - for (int i = 0; i < own_communities.size(); i++) { - QSharedPointer community = QSharedPointer(new Community()); + for (int i = 0; i < own_communities.size(); i++) { + QSharedPointer community = QSharedPointer(new Community()); - communityManager_[own_communities[i]] = community; - } + communityManager_[own_communities[i]] = community; + } - communitiesList_->setCommunities(communityManager_); + communitiesList_->setCommunities(communityManager_); } void diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc index 739ad4d6..c40155e5 100644 --- a/src/CommunitiesList.cc +++ b/src/CommunitiesList.cc @@ -3,53 +3,58 @@ #include CommunitiesList::CommunitiesList(QSharedPointer client, QWidget *parent) - : QWidget(parent) - , client_(client) + : QWidget(parent) + , client_(client) { - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(1); - setSizePolicy(sizePolicy); + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(1); + setSizePolicy(sizePolicy); - setStyleSheet("border-style: none;"); + setStyleSheet("border-style: none;"); - topLayout_ = new QVBoxLayout(this); - topLayout_->setSpacing(0); - topLayout_->setMargin(0); + topLayout_ = new QVBoxLayout(this); + topLayout_->setSpacing(0); + topLayout_->setMargin(0); - setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); - scrollArea_ = new QScrollArea(this); - scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - scrollArea_->setWidgetResizable(true); - scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); + scrollArea_ = new QScrollArea(this); + scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + scrollArea_->setWidgetResizable(true); + scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); - scrollAreaContents_ = new QWidget(); + scrollAreaContents_ = new QWidget(); - contentsLayout_ = new QVBoxLayout(scrollAreaContents_); - contentsLayout_->setSpacing(0); - contentsLayout_->setMargin(0); + contentsLayout_ = new QVBoxLayout(scrollAreaContents_); + contentsLayout_->setSpacing(0); + contentsLayout_->setMargin(0); - WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); - contentsLayout_->addWidget(world_list_item); - communities_.insert("world", QSharedPointer(world_list_item)); - connect(world_list_item, &WorldCommunityListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); - contentsLayout_->addStretch(1); + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + contentsLayout_->addWidget(world_list_item); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, + &WorldCommunityListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->addStretch(1); - scrollArea_->setWidget(scrollAreaContents_); - topLayout_->addWidget(scrollArea_); + scrollArea_->setWidget(scrollAreaContents_); + topLayout_->addWidget(scrollArea_); - connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, - [=](QString communityId, QJsonObject profile) { - client_->fetchCommunityAvatar(communityId, QUrl(profile["avatar_url"].toString())); - }); - connect(client_.data(), - SIGNAL(communityAvatarRetrieved(const QString &, const QPixmap &)), - this, - SLOT(updateCommunityAvatar(const QString &,const QPixmap &))); + connect(client_.data(), + &MatrixClient::communityProfileRetrieved, + this, + [=](QString communityId, QJsonObject profile) { + client_->fetchCommunityAvatar(communityId, + QUrl(profile["avatar_url"].toString())); + }); + connect(client_.data(), + SIGNAL(communityAvatarRetrieved(const QString &, const QPixmap &)), + this, + SLOT(updateCommunityAvatar(const QString &, const QPixmap &))); } CommunitiesList::~CommunitiesList() {} @@ -57,87 +62,89 @@ CommunitiesList::~CommunitiesList() {} void CommunitiesList::setCommunities(const QMap> &communities) { - communities_.clear(); + communities_.clear(); - //TODO: still not sure how to handle the "world" special-case - WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); - communities_.insert("world", QSharedPointer(world_list_item)); - connect(world_list_item, &WorldCommunityListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); - contentsLayout_->insertWidget(0, world_list_item); + // TODO: still not sure how to handle the "world" special-case + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, + &WorldCommunityListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->insertWidget(0, world_list_item); - for (auto it = communities.constBegin(); it != communities.constEnd(); it++) { - const auto community_id = it.key(); - const auto community = it.value(); + for (auto it = communities.constBegin(); it != communities.constEnd(); it++) { + const auto community_id = it.key(); + const auto community = it.value(); - addCommunity(community, community_id); + addCommunity(community, community_id); - client_->fetchCommunityProfile(community_id); - client_->fetchCommunityRooms(community_id); - } + client_->fetchCommunityProfile(community_id); + client_->fetchCommunityRooms(community_id); + } - world_list_item->setPressedState(true); - emit communityChanged("world"); + world_list_item->setPressedState(true); + emit communityChanged("world"); } void CommunitiesList::clear() { - communities_.clear(); + communities_.clear(); } void CommunitiesList::addCommunity(QSharedPointer community, const QString &community_id) { - CommunitiesListItem *list_item = new CommunitiesListItem(community, - community_id, - scrollArea_); + CommunitiesListItem *list_item = + new CommunitiesListItem(community, community_id, scrollArea_); - communities_.insert(community_id, QSharedPointer(list_item)); + communities_.insert(community_id, QSharedPointer(list_item)); - client_->fetchCommunityAvatar(community_id, community->getAvatar()); + client_->fetchCommunityAvatar(community_id, community->getAvatar()); - contentsLayout_->insertWidget(contentsLayout_->count()-1, list_item); + contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item); - connect(list_item, &CommunitiesListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); + connect(list_item, + &CommunitiesListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); } void CommunitiesList::removeCommunity(const QString &community_id) { - communities_.remove(community_id); + communities_.remove(community_id); } void CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img) { - if (!communities_.contains(community_id)) { - qWarning() << "Avatar update on nonexistent community" << community_id; - return; - } - - communities_.value(community_id)->setAvatar(img.toImage()); + if (!communities_.contains(community_id)) { + qWarning() << "Avatar update on nonexistent community" << community_id; + return; + } + communities_.value(community_id)->setAvatar(img.toImage()); } void CommunitiesList::highlightSelectedCommunity(const QString &community_id) { - emit communityChanged(community_id); + emit communityChanged(community_id); - if (!communities_.contains(community_id)) { - qDebug() << "CommunitiesList: clicked unknown community"; - return; - } - - for (auto it = communities_.constBegin(); it != communities_.constEnd(); it++) { - if (it.key() != community_id) { - it.value()->setPressedState(false); - } else { - it.value()->setPressedState(true); - scrollArea_->ensureWidgetVisible( - qobject_cast(it.value().data())); + if (!communities_.contains(community_id)) { + qDebug() << "CommunitiesList: clicked unknown community"; + return; + } + + for (auto it = communities_.constBegin(); it != communities_.constEnd(); it++) { + if (it.key() != community_id) { + it.value()->setPressedState(false); + } else { + it.value()->setPressedState(true); + scrollArea_->ensureWidgetVisible( + qobject_cast(it.value().data())); + } } - } } diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc index 1a2c1d7c..5f4253f6 100644 --- a/src/CommunitiesListItem.cc +++ b/src/CommunitiesListItem.cc @@ -3,14 +3,14 @@ CommunitiesListItem::CommunitiesListItem(QSharedPointer community, QString community_id, QWidget *parent) - : QWidget(parent) - , community_(community) - , communityId_(community_id) + : QWidget(parent) + , community_(community) + , communityId_(community_id) { - //menu_ = new Menu(this); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFixedHeight(ui::sidebar::CommunitiesSidebarSize); - setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + // menu_ = new Menu(this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFixedHeight(ui::sidebar::CommunitiesSidebarSize); + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); } CommunitiesListItem::~CommunitiesListItem() {} @@ -18,20 +18,21 @@ CommunitiesListItem::~CommunitiesListItem() {} void CommunitiesListItem::setCommunity(QSharedPointer community) { - community_ = community; + community_ = community; } void CommunitiesListItem::setPressedState(bool state) { - if (isPressed_ != state) { - isPressed_ = state; - update(); - } + if (isPressed_ != state) { + isPressed_ = state; + update(); + } } void -CommunitiesListItem::mousePressEvent(QMouseEvent *event) { +CommunitiesListItem::mousePressEvent(QMouseEvent *event) +{ if (event->buttons() == Qt::RightButton) { QWidget::mousePressEvent(event); return; @@ -47,7 +48,6 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) { Q_UNUSED(event); - QPainter p(this); p.setRenderHint(QPainter::TextAntialiasing); p.setRenderHint(QPainter::SmoothPixmapTransform); @@ -65,7 +65,7 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) p.setPen(QColor("#333")); - QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); font.setBold(false); p.setPen(Qt::NoPen); @@ -91,14 +91,15 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) p.save(); QPainterPath path; - path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + path.addEllipse( + (width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.setClipPath(path); p.drawPixmap(avatarRegion, communityAvatar_); p.restore(); } - //TODO: Discord-style community ping counts? + // TODO: Discord-style community ping counts? /*if (unreadMsgCount_ > 0) { QColor textColor("white"); QColor backgroundColor("#38A3D8"); @@ -142,11 +143,11 @@ CommunitiesListItem::contextMenuEvent(QContextMenuEvent *event) { Q_UNUSED(event); - //menu_->popup(event->globalPos()); + // menu_->popup(event->globalPos()); } WorldCommunityListItem::WorldCommunityListItem(QWidget *parent) - : CommunitiesListItem(QSharedPointer(), "", parent) + : CommunitiesListItem(QSharedPointer(), "", parent) { } @@ -190,10 +191,10 @@ WorldCommunityListItem::paintEvent(QPaintEvent *event) p.setPen(Qt::NoPen); p.setBrush(brush); - QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2); QPainterPath path; - path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + path.addEllipse((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.setClipPath(path); p.drawPixmap(avatarRegion, worldIcon); diff --git a/src/Community.cc b/src/Community.cc index 79b4b45b..df425e88 100644 --- a/src/Community.cc +++ b/src/Community.cc @@ -1,45 +1,44 @@ #include "include/Community.h" -#include #include +#include void Community::parseProfile(const QJsonObject &profile) { - if (profile["name"].type() == QJsonValue::Type::String) { - name_ = profile["name"].toString(); - } else { - name_ = "Unnamed Community"; //TODO: what is correct here? - } + if (profile["name"].type() == QJsonValue::Type::String) { + name_ = profile["name"].toString(); + } else { + name_ = "Unnamed Community"; // TODO: what is correct here? + } - if (profile["avatar_url"].type() == QJsonValue::Type::String) { - avatar_ = QUrl(profile["avatar_url"].toString()); - } else { - avatar_ = QUrl(); - } + if (profile["avatar_url"].type() == QJsonValue::Type::String) { + avatar_ = QUrl(profile["avatar_url"].toString()); + } else { + avatar_ = QUrl(); + } - if (profile["short_description"].type() == QJsonValue::Type::String) { - short_description_ = profile["short_description"].toString(); - } else { - short_description_ = ""; - } - - if (profile["long_description"].type() == QJsonValue::Type::String) { - long_description_ = profile["long_description"].toString(); - } else { - long_description_ = ""; - } + if (profile["short_description"].type() == QJsonValue::Type::String) { + short_description_ = profile["short_description"].toString(); + } else { + short_description_ = ""; + } + if (profile["long_description"].type() == QJsonValue::Type::String) { + long_description_ = profile["long_description"].toString(); + } else { + long_description_ = ""; + } } void Community::parseRooms(const QJsonObject &rooms) { - rooms_.clear(); + rooms_.clear(); - for (auto i = 0; ireadAll(); auto json = QJsonDocument::fromJson(data); try { - QList response; - for (auto it = json["groups"].toArray().constBegin(); it != json["groups"].toArray().constEnd(); it++) { - response.append(it->toString()); - } - emit getOwnCommunitiesResponse(response); + QList response; + for (auto it = json["groups"].toArray().constBegin(); + it != json["groups"].toArray().constEnd(); + it++) { + response.append(it->toString()); + } + emit getOwnCommunitiesResponse(response); } catch (DeserializationException &e) { - qWarning() << "Own communities:" << e.what(); + qWarning() << "Own communities:" << e.what(); } }); } @@ -606,7 +608,7 @@ MatrixClient::fetchCommunityProfile(const QString &communityId) QNetworkReply *reply = get(request); connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { - reply->deleteLater(); + reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -615,7 +617,7 @@ MatrixClient::fetchCommunityProfile(const QString &communityId) return; } - auto data = reply->readAll(); + auto data = reply->readAll(); const auto json = QJsonDocument::fromJson(data).object(); emit communityProfileRetrieved(communityId, json); @@ -636,7 +638,7 @@ MatrixClient::fetchCommunityRooms(const QString &communityId) QNetworkReply *reply = get(request); connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { - reply->deleteLater(); + reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -645,7 +647,7 @@ MatrixClient::fetchCommunityRooms(const QString &communityId) return; } - auto data = reply->readAll(); + auto data = reply->readAll(); const auto json = QJsonDocument::fromJson(data).object(); emit communityRoomsRetrieved(communityId, json); diff --git a/src/RoomList.cc b/src/RoomList.cc index 0aafd331..de853377 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -296,21 +296,21 @@ RoomList::setFilterRooms(bool filterRooms) { filterRooms_ = filterRooms; - for (int i=0; icount(); i++) { + for (int i = 0; i < contentsLayout_->count(); i++) { + // If roomFilter_ contains the room for the current RoomInfoListItem, + // show the list item, otherwise hide it + RoomInfoListItem *listitem = + (RoomInfoListItem *)contentsLayout_->itemAt(i)->widget(); - //If roomFilter_ contains the room for the current RoomInfoListItem, - //show the list item, otherwise hide it - RoomInfoListItem *listitem = (RoomInfoListItem *) contentsLayout_->itemAt(i)->widget(); - - if (listitem != nullptr) { - if (!filterRooms) { - contentsLayout_->itemAt(i)->widget()->show(); - } else if (roomFilter_.contains(listitem->roomId())) { - contentsLayout_->itemAt(i)->widget()->show(); - } else { - contentsLayout_->itemAt(i)->widget()->hide(); + if (listitem != nullptr) { + if (!filterRooms) { + contentsLayout_->itemAt(i)->widget()->show(); + } else if (roomFilter_.contains(listitem->roomId())) { + contentsLayout_->itemAt(i)->widget()->show(); + } else { + contentsLayout_->itemAt(i)->widget()->hide(); + } } - } } if (filterRooms_ && !roomFilter_.contains(selectedRoom_)) {