summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2010-06-21 15:35:08 +0200
committerkh1 <qt-info@nokia.com>2010-06-21 15:36:43 +0200
commit097e45d47c436fe0e3f9c69134695f8eb3a22fa2 (patch)
treee23fe88b126e02e5c3d27c3f0789dc06b604400b
parent14fb0d01294bb83ef8bb897344f76e0ceda3f6d6 (diff)
downloadqt-creator-097e45d47c436fe0e3f9c69134695f8eb3a22fa2.tar.gz
Implement filter functionality for topic chooser.
Task-number: QTCREATORBUG-1685
-rw-r--r--src/shared/help/help.pri7
-rw-r--r--src/shared/help/topicchooser.cpp45
-rw-r--r--src/shared/help/topicchooser.h9
-rw-r--r--src/shared/help/topicchooser.ui168
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 <QtCore/QMap>
#include <QtCore/QUrl>
-#include "topicchooser.h"
+#include <QtGui/QStandardItemModel>
+#include <QtGui/QSortFilterProxyModel>
TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
const QMap<QString, QUrl> &links)
: QDialog(parent)
+ , m_filterModel(new QSortFilterProxyModel(this))
{
ui.setupUi(this);
ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword));
+ QStandardItemModel *model = new QStandardItemModel(this);
+ m_filterModel->setSourceModel(model);
+ m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+
QMap<QString, QUrl>::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 <QtCore/QUrl>
#include <QtCore/QMap>
+#include <QtCore/QModelIndex>
#include <QtCore/QString>
#include <QtGui/QDialog>
+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<QUrl> 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 @@
-<UI version="4.0" stdsetdef="1" >
- <class>TopicChooser</class>
- <widget class="QDialog" name="TopicChooser" >
- <property name="objectName" >
- <string notr="true">TopicChooser</string>
- </property>
- <property name="geometry" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TopicChooser</class>
+ <widget class="QDialog" name="TopicChooser">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>391</width>
- <height>223</height>
+ <width>393</width>
+ <height>218</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>Choose Topic</string>
</property>
- <property name="sizeGripEnabled" >
+ <property name="sizeGripEnabled">
<bool>true</bool>
- </property>
- <layout class="QVBoxLayout" >
- <property name="objectName" >
- <string notr="true">unnamed</string>
- </property>
- <property name="margin" >
- <number>11</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QLabel" name="label" >
- <property name="objectName" >
- <string notr="true">label</string>
- </property>
- <property name="text" >
+ <widget class="QLabel" name="label">
+ <property name="text">
<string>&amp;Topics</string>
</property>
- <property name="buddy" stdset="0" >
+ <property name="buddy">
<cstring>listWidget</cstring>
</property>
</widget>
</item>
<item>
- <widget class="QListWidget" name="listWidget" >
- <property name="objectName" >
- <string notr="true">listWidget</string>
- </property>
- </widget>
+ <widget class="Utils::FilterLineEdit" name="lineEdit"/>
</item>
<item>
- <widget class="QWidget" name="Layout16" >
- <property name="objectName" >
- <string notr="true">Layout16</string>
+ <widget class="QListView" name="listWidget"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="unnamed">
+ <property name="spacing">
+ <number>6</number>
</property>
- <layout class="QHBoxLayout" >
- <property name="objectName" >
- <string notr="true">unnamed</string>
- </property>
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <spacer name="Horizontal Spacing2" >
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- <property name="sizeType" >
- <enum>Expanding</enum>
- </property>
- <property name="orientation" >
- <enum>Horizontal</enum>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="buttonDisplay" >
- <property name="objectName" >
- <string notr="true">buttonDisplay</string>
- </property>
- <property name="text" >
- <string>&amp;Display</string>
- </property>
- <property name="autoDefault" >
- <bool>true</bool>
- </property>
- <property name="default" >
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="buttonCancel" >
- <property name="objectName" >
- <string notr="true">buttonCancel</string>
- </property>
- <property name="text" >
- <string>&amp;Close</string>
- </property>
- <property name="autoDefault" >
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <spacer name="Horizontal Spacing2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonDisplay">
+ <property name="text">
+ <string>&amp;Display</string>
+ </property>
+ <property name="autoDefault">
+ <bool>true</bool>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonCancel">
+ <property name="text">
+ <string>&amp;Close</string>
+ </property>
+ <property name="autoDefault">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</widget>
-</UI>
+ <customwidgets>
+ <customwidget>
+ <class>Utils::FilterLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header location="global">utils/filterlineedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>