summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-09-05 15:44:24 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-09-07 10:47:40 (GMT)
commit615b87497cd8d4eedc386f002931d6d353f53ccd (patch)
tree2e3b0946e74415149b33973668ba9216d6f61d13 /Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
parentb54df5d2a50d4dda0e63ac06050d4ed306952dbb (diff)
downloadswift-615b87497cd8d4eedc386f002931d6d353f53ccd.zip
swift-615b87497cd8d4eedc386f002931d6d353f53ccd.tar.bz2
Add ability to filter results in "Search Room" dialog
This is implemented with the help of an implementation of QSortFilterProxyModel which filters room names based on a user search string. Test-Information: Tested on OS X 10.11.6 with Qt 5.5.1. Tested UX with different MUC services and search strings. Change-Id: I88085d089493008b2197a4aeb45d8c4d75724b9c
Diffstat (limited to 'Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp')
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
index 114ec1d..f69da41 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
@@ -12,6 +12,7 @@
#include <QMovie>
#include <QPushButton>
#include <QScrollBar>
+#include <QSortFilterProxyModel>
#include <QTimer>
#include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h>
@@ -20,6 +21,7 @@
#include <Swift/QtUI/MUCSearch/MUCSearchDelegate.h>
#include <Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h>
#include <Swift/QtUI/MUCSearch/MUCSearchModel.h>
+#include <Swift/QtUI/MUCSearch/QtLeafSortFilterProxyModel.h>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -30,10 +32,12 @@ QtMUCSearchWindow::QtMUCSearchWindow() {
setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
setModal(true);
- ui_.filter_->hide();
model_ = new MUCSearchModel();
+ sortFilterProxyModel_ = new QtLeafSortFilterProxyModel(this);
+ sortFilterProxyModel_->setSourceModel(model_);
+ sortFilterProxyModel_->setDynamicSortFilter(true);
delegate_ = new MUCSearchDelegate();
- ui_.results_->setModel(model_);
+ ui_.results_->setModel(sortFilterProxyModel_);
ui_.results_->setItemDelegate(delegate_);
ui_.results_->setHeaderHidden(true);
ui_.results_->setRootIsDecorated(true);
@@ -41,7 +45,7 @@ QtMUCSearchWindow::QtMUCSearchWindow() {
ui_.results_->setAlternatingRowColors(true);
ui_.results_->setSortingEnabled(true);
ui_.results_->sortByColumn(0, Qt::AscendingOrder);
- connect(ui_.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch()));
+ connect(ui_.searchButton_, SIGNAL(clicked()), this, SLOT(handleSearch()));
connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&)));
connect(ui_.results_->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(handleSelectionChanged (const QItemSelection&, const QItemSelection&)));
connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
@@ -50,6 +54,7 @@ QtMUCSearchWindow::QtMUCSearchWindow() {
connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept()));
ui_.okButton->setEnabled(false);
connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(ui_.filter_, SIGNAL(textChanged(const QString&)), this, SLOT(handleFilterStringChanged(const QString&)));
throbber_ = new QLabel(tr("Searching"), ui_.results_);
throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_));
@@ -104,7 +109,7 @@ void QtMUCSearchWindow::handleActivated(const QModelIndex& index) {
if (!index.isValid()) {
return;
}
- if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) {
+ if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(sortFilterProxyModel_->mapToSource(index).internalPointer()))) {
accept();
}
}
@@ -119,7 +124,12 @@ void QtMUCSearchWindow::handleSearch(const QString& service) {
}
}
+void QtMUCSearchWindow::handleFilterStringChanged(const QString& filterString) {
+ sortFilterProxyModel_->setFilterRegExp(filterString);
+}
+
void QtMUCSearchWindow::show() {
+ ui_.filter_->clear();
QWidget::show();
QWidget::activateWindow();
}
@@ -197,7 +207,7 @@ MUCSearchRoomItem* QtMUCSearchWindow::getSelectedRoom() const {
return nullptr;
}
else {
- return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer()));
+ return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(sortFilterProxyModel_->mapToSource(lstIndex.first()).internalPointer()));
}
}