summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews/customsortfiltermodel/window.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2013-04-08 10:12:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-12 10:36:23 +0200
commit23964bc338b9b00e204d45a917a0bb330cb795c4 (patch)
treed57b9b48b801a909e48d2d9edf5389b0d9352b3e /examples/widgets/itemviews/customsortfiltermodel/window.cpp
parent9ee4a121938ec74bca61040e481657c25939f425 (diff)
Add clear button and side action to customsortfiltermodel example.
Demonstrate the new side widgets feature of QLineEdit. Change-Id: I1c4289c652abf2209e50601871249008fdec4f6b Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'examples/widgets/itemviews/customsortfiltermodel/window.cpp')
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/window.cpp37
1 files changed, 10 insertions, 27 deletions
diff --git a/examples/widgets/itemviews/customsortfiltermodel/window.cpp b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
index a1456bbcac..0dbc902fb8 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/window.cpp
+++ b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
@@ -42,6 +42,7 @@
#include "mysortfilterproxymodel.h"
#include "window.h"
+#include "filterwidget.h"
//! [0]
Window::Window()
@@ -63,19 +64,12 @@ Window::Window()
//! [2]
//! [3]
- filterCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive filter"));
- filterCaseSensitivityCheckBox->setChecked(true);
-
- filterPatternLineEdit = new QLineEdit;
- filterPatternLineEdit->setText("Grace|Sports");
+ filterWidget = new FilterWidget;
+ filterWidget->setText("Grace|Sports");
+ connect(filterWidget, SIGNAL(filterChanged()), this, SLOT(textFilterChanged()));
filterPatternLabel = new QLabel(tr("&Filter pattern:"));
- filterPatternLabel->setBuddy(filterPatternLineEdit);
-
- filterSyntaxComboBox = new QComboBox;
- filterSyntaxComboBox->addItem(tr("Regular expression"), QRegExp::RegExp);
- filterSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
- filterSyntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
+ filterPatternLabel->setBuddy(filterWidget);
fromDateEdit = new QDateEdit;
fromDateEdit->setDate(QDate(1970, 01, 01));
@@ -87,11 +81,7 @@ Window::Window()
toLabel = new QLabel(tr("&To:"));
toLabel->setBuddy(toDateEdit);
- connect(filterPatternLineEdit, SIGNAL(textChanged(QString)),
- this, SLOT(textFilterChanged()));
- connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
- this, SLOT(textFilterChanged()));
- connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
+ connect(filterWidget, SIGNAL(textChanged(QString)),
this, SLOT(textFilterChanged()));
connect(fromDateEdit, SIGNAL(dateChanged(QDate)),
this, SLOT(dateFilterChanged()));
@@ -111,9 +101,7 @@ Window::Window()
QGridLayout *proxyLayout = new QGridLayout;
proxyLayout->addWidget(proxyView, 0, 0, 1, 3);
proxyLayout->addWidget(filterPatternLabel, 1, 0);
- proxyLayout->addWidget(filterPatternLineEdit, 1, 1);
- proxyLayout->addWidget(filterSyntaxComboBox, 1, 2);
- proxyLayout->addWidget(filterCaseSensitivityCheckBox, 2, 0, 1, 3);
+ proxyLayout->addWidget(filterWidget, 1, 1);
proxyLayout->addWidget(fromLabel, 3, 0);
proxyLayout->addWidget(fromDateEdit, 3, 1, 1, 2);
proxyLayout->addWidget(toLabel, 4, 0);
@@ -145,14 +133,9 @@ void Window::setSourceModel(QAbstractItemModel *model)
//! [8]
void Window::textFilterChanged()
{
- QRegExp::PatternSyntax syntax =
- QRegExp::PatternSyntax(filterSyntaxComboBox->itemData(
- filterSyntaxComboBox->currentIndex()).toInt());
- Qt::CaseSensitivity caseSensitivity =
- filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
- : Qt::CaseInsensitive;
-
- QRegExp regExp(filterPatternLineEdit->text(), caseSensitivity, syntax);
+ QRegExp regExp(filterWidget->text(),
+ filterWidget->caseSensitivity(),
+ filterWidget->patternSyntax());
proxyModel->setFilterRegExp(regExp);
}
//! [8]