From 097e45d47c436fe0e3f9c69134695f8eb3a22fa2 Mon Sep 17 00:00:00 2001 From: kh1 Date: Mon, 21 Jun 2010 15:35:08 +0200 Subject: Implement filter functionality for topic chooser. Task-number: QTCREATORBUG-1685 --- src/shared/help/help.pri | 7 +- src/shared/help/topicchooser.cpp | 45 +++++++---- src/shared/help/topicchooser.h | 9 +++ src/shared/help/topicchooser.ui | 168 +++++++++++++++++---------------------- 4 files changed, 117 insertions(+), 112 deletions(-) diff --git a/src/shared/help/help.pri b/src/shared/help/help.pri index 27ce8b4267..f1371152a9 100644 --- a/src/shared/help/help.pri +++ b/src/shared/help/help.pri @@ -1,7 +1,10 @@ VPATH += $$PWD -INCLUDEPATH *= $$PWD $$PWD/.. -DEPENDPATH *= $$PWD $$PWD/.. +INCLUDEPATH *= $$PWD $$PWD/.. \ + $$PWD/../.. $$PWD/../../utils + +DEPENDPATH *= $$PWD $$PWD/.. \ + $$PWD/../.. $$PWD/../../utils # Input HEADERS += \ diff --git a/src/shared/help/topicchooser.cpp b/src/shared/help/topicchooser.cpp index 1b036df1f3..d311264cdf 100644 --- a/src/shared/help/topicchooser.cpp +++ b/src/shared/help/topicchooser.cpp @@ -27,44 +27,57 @@ ** **************************************************************************/ +#include "topicchooser.h" + #include #include -#include "topicchooser.h" +#include +#include TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, const QMap &links) : QDialog(parent) + , m_filterModel(new QSortFilterProxyModel(this)) { ui.setupUi(this); ui.label->setText(tr("Choose a topic for %1:").arg(keyword)); + QStandardItemModel *model = new QStandardItemModel(this); + m_filterModel->setSourceModel(model); + m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + QMap::const_iterator it = links.constBegin(); for (; it != links.constEnd(); ++it) { m_links.append(it.value()); - ui.listWidget->addItem(it.key()); + model->appendRow(new QStandardItem(it.key())); } - - if (ui.listWidget->count() != 0) - ui.listWidget->setCurrentRow(0); + + ui.listWidget->setModel(m_filterModel); + ui.listWidget->setUniformItemSizes(true); + ui.listWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + + if (m_filterModel->rowCount() != 0) + ui.listWidget->setCurrentIndex(m_filterModel->index(0, 0)); ui.listWidget->setFocus(); connect(ui.buttonDisplay, SIGNAL(clicked()), this, SLOT(accept())); connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); - connect(ui.listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, - SLOT(accept())); + connect(ui.listWidget, SIGNAL(activated(QModelIndex)), this, + SLOT(activated(QModelIndex))); + connect(ui.lineEdit, SIGNAL(filterChanged(QString)), m_filterModel, + SLOT(setFilterFixedString(QString))); } QUrl TopicChooser::link() const { - QListWidgetItem *item = ui.listWidget->currentItem(); - if (!item) - return QUrl(); - - if (item->text().isEmpty()) - return QUrl(); + if (m_activedIndex.isValid()) + return m_links.at(m_filterModel->mapToSource(m_activedIndex).row()); + return QUrl(); +} - const int row = ui.listWidget->row(item); - Q_ASSERT(row < m_links.count()); - return m_links.at(row); +void TopicChooser::activated(const QModelIndex &index) +{ + m_activedIndex = index; + accept(); } diff --git a/src/shared/help/topicchooser.h b/src/shared/help/topicchooser.h index 82bb8523c0..a387c4d820 100644 --- a/src/shared/help/topicchooser.h +++ b/src/shared/help/topicchooser.h @@ -34,10 +34,13 @@ #include #include +#include #include #include +class QSortFilterProxyModel; + class TopicChooser : public QDialog { Q_OBJECT @@ -48,9 +51,15 @@ public: QUrl link() const; +private slots: + void activated(const QModelIndex &index); + private: Ui::TopicChooser ui; QList m_links; + + QModelIndex m_activedIndex; + QSortFilterProxyModel *m_filterModel; }; #endif // TOPICCHOOSER_H diff --git a/src/shared/help/topicchooser.ui b/src/shared/help/topicchooser.ui index d4c90bb4b3..120cb2ee34 100644 --- a/src/shared/help/topicchooser.ui +++ b/src/shared/help/topicchooser.ui @@ -1,116 +1,96 @@ - - TopicChooser - - - TopicChooser - - + + + TopicChooser + + 0 0 - 391 - 223 + 393 + 218 - + Choose Topic - + true - - - - unnamed - - - 11 - - - 6 - + + - - - label - - + + &Topics - + listWidget - - - listWidget - - + - - - Layout16 + + + + + + 6 - - - unnamed - - - 0 - - - 6 - - - - - - 20 - 20 - - - - Expanding - - - Horizontal - - - - - - - buttonDisplay - - - &Display - - - true - - - true - - - - - - - buttonCancel - - - &Close - - - true - - - - - + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + &Display + + + true + + + true + + + + + + + &Close + + + true + + + + - + + + Utils::FilterLineEdit + QLineEdit +
utils/filterlineedit.h
+
+
+ + + -- cgit v1.2.1