summary refs log tree commit diff
path: root/src/CommunitiesList.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-24 20:46:37 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-24 20:46:37 +0200
commit1fad9398fce58a8d7bf96bdaa2629a80b336b14c (patch)
tree28483acf18d91d6ccfa40eaa0564e50dd9291c51 /src/CommunitiesList.cc
parentRemove trailing whitespace from text messages (diff)
downloadnheko-1fad9398fce58a8d7bf96bdaa2629a80b336b14c.tar.xz
Use more stl containers & minor refactorings
Diffstat (limited to 'src/CommunitiesList.cc')
-rw-r--r--src/CommunitiesList.cc50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc

index c40155e5..1469dd87 100644 --- a/src/CommunitiesList.cc +++ b/src/CommunitiesList.cc
@@ -34,7 +34,7 @@ CommunitiesList::CommunitiesList(QSharedPointer<MatrixClient> client, QWidget *p WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); contentsLayout_->addWidget(world_list_item); - communities_.insert("world", QSharedPointer<CommunitiesListItem>(world_list_item)); + communities_.emplace("world", QSharedPointer<CommunitiesListItem>(world_list_item)); connect(world_list_item, &WorldCommunityListItem::clicked, this, @@ -57,30 +57,25 @@ CommunitiesList::CommunitiesList(QSharedPointer<MatrixClient> client, QWidget *p SLOT(updateCommunityAvatar(const QString &, const QPixmap &))); } -CommunitiesList::~CommunitiesList() {} - void -CommunitiesList::setCommunities(const QMap<QString, QSharedPointer<Community>> &communities) +CommunitiesList::setCommunities(const std::map<QString, QSharedPointer<Community>> &communities) { communities_.clear(); // TODO: still not sure how to handle the "world" special-case WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); - communities_.insert("world", QSharedPointer<CommunitiesListItem>(world_list_item)); + communities_.emplace("world", QSharedPointer<CommunitiesListItem>(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(); - - addCommunity(community, community_id); + for (const auto &community : communities) { + addCommunity(community.second, community.first); - client_->fetchCommunityProfile(community_id); - client_->fetchCommunityRooms(community_id); + client_->fetchCommunityProfile(community.first); + client_->fetchCommunityRooms(community.first); } world_list_item->setPressedState(true); @@ -88,18 +83,12 @@ CommunitiesList::setCommunities(const QMap<QString, QSharedPointer<Community>> & } void -CommunitiesList::clear() -{ - communities_.clear(); -} - -void CommunitiesList::addCommunity(QSharedPointer<Community> community, const QString &community_id) { CommunitiesListItem *list_item = new CommunitiesListItem(community, community_id, scrollArea_); - communities_.insert(community_id, QSharedPointer<CommunitiesListItem>(list_item)); + communities_.emplace(community_id, QSharedPointer<CommunitiesListItem>(list_item)); client_->fetchCommunityAvatar(community_id, community->getAvatar()); @@ -114,37 +103,36 @@ CommunitiesList::addCommunity(QSharedPointer<Community> community, const QString void CommunitiesList::removeCommunity(const QString &community_id) { - communities_.remove(community_id); + communities_.erase(communities_.find(community_id)); } void CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img) { - if (!communities_.contains(community_id)) { + if (!communityExists(community_id)) { qWarning() << "Avatar update on nonexistent community" << community_id; return; } - communities_.value(community_id)->setAvatar(img.toImage()); + communities_.find(community_id)->second->setAvatar(img.toImage()); } void CommunitiesList::highlightSelectedCommunity(const QString &community_id) { - emit communityChanged(community_id); - - if (!communities_.contains(community_id)) { + if (!communityExists(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); + emit communityChanged(community_id); + + for (const auto &community : communities_) { + if (community.first != community_id) { + community.second->setPressedState(false); } else { - it.value()->setPressedState(true); - scrollArea_->ensureWidgetVisible( - qobject_cast<QWidget *>(it.value().data())); + community.second->setPressedState(true); + scrollArea_->ensureWidgetVisible(community.second.data()); } } }