Skip to content
Snippets Groups Projects
Commit 097e45d4 authored by kh1's avatar kh1
Browse files

Implement filter functionality for topic chooser.

Task-number: QTCREATORBUG-1685
parent 14fb0d01
No related branches found
No related tags found
No related merge requests found
VPATH += $$PWD
INCLUDEPATH *= $$PWD $$PWD/..
DEPENDPATH *= $$PWD $$PWD/..
INCLUDEPATH *= $$PWD $$PWD/.. \
$$PWD/../.. $$PWD/../../utils
DEPENDPATH *= $$PWD $$PWD/.. \
$$PWD/../.. $$PWD/../../utils
# Input
HEADERS += \
......
......@@ -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();
}
......@@ -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
<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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment