From e9f6129a4ce5db25bcb6de47be94ee89357713d0 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 7 May 2018 11:06:49 +0200 Subject: Allow to hide empty overview bundles in roster This fixes a regression of commit 19eefe668. Test-Information: Ran Swift and verified that the 'Unread' bundle is never shown if empty. Change-Id: If13b84291e08d14bbbed57f53e0999e78e20f21d diff --git a/Swift/QtUI/QtChatOverviewBundle.cpp b/Swift/QtUI/QtChatOverviewBundle.cpp index 8505541..121ae2e 100644 --- a/Swift/QtUI/QtChatOverviewBundle.cpp +++ b/Swift/QtUI/QtChatOverviewBundle.cpp @@ -6,7 +6,6 @@ #include -#include #include #include #include @@ -93,7 +92,7 @@ QtChatOverviewBundle::QtChatOverviewBundle(ChattablesModel* rootModel, QString n nameLabel->setStyleSheet("color: white;"); headerLayout->addWidget(nameLabel); headerLayout->addStretch(); - if (!hideWhenEmpty) { + if (!hideWhenEmpty_) { filterLabel_ = new QtClickableLabel(this); filterLabel_->setText(tr("Online")); filterLabel_->setStyleSheet("color: white;"); @@ -106,6 +105,19 @@ QtChatOverviewBundle::QtChatOverviewBundle(ChattablesModel* rootModel, QString n listView_->setItemDelegate(new QtChatOverviewDelegate(this)); connect(listView_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleItemClicked(const QModelIndex&))); mainLayout->addWidget(listView_); + + if (hideWhenEmpty_) { + connect(proxyModel_, &QAbstractItemModel::modelReset, this, [&](){ + updateVisibility(); + }); + connect(proxyModel_, &QAbstractItemModel::rowsInserted, this, [&](){ + updateVisibility(); + }); + connect(proxyModel_, &QAbstractItemModel::rowsRemoved, this, [&](){ + updateVisibility(); + }); + updateVisibility(); + } } QtChatOverviewBundle::~QtChatOverviewBundle() {} @@ -121,6 +133,12 @@ void QtChatOverviewBundle::handleFilterClicked() { } } +void QtChatOverviewBundle::updateVisibility() { + auto shouldBeVisible = (proxyModel_->rowCount(listView_->rootIndex()) > 0); + setVisible(shouldBeVisible); +} + + void QtChatOverviewBundle::handleItemClicked(const QModelIndex& index) { clicked(JID(Q2PSTRING(index.data(ChattablesModel::JIDRole).toString()))); } diff --git a/Swift/QtUI/QtChatOverviewBundle.h b/Swift/QtUI/QtChatOverviewBundle.h index 6e232ca..95fd5d2 100644 --- a/Swift/QtUI/QtChatOverviewBundle.h +++ b/Swift/QtUI/QtChatOverviewBundle.h @@ -49,6 +49,9 @@ namespace Swift { void handleItemClicked(const QModelIndex&); private: + void updateVisibility(); + + private: ChattablesModel* rootModel_; QtExpandedListView* listView_; BundleFilter* proxyModel_; -- cgit v0.10.2-6-g49f6