Mercurial > retraceit
annotate src/filterwidget.cpp @ 10:f290e8c4e097
Add media icons to player widget
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 26 Mar 2015 16:41:08 +0100 |
parents | e4748da7140b |
children | 315e6988952a |
rev | line source |
---|---|
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 #include "filterwidget.h" |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 #include <QComboBox> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 #include <QHBoxLayout> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 #include <QGroupBox> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 #include <QSortFilterProxyModel> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 #include <QAbstractItemModel> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include <QLineEdit> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include <QDebug> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 FilterWidget::FilterWidget(QSortFilterProxyModel *model, QWidget *parent, Qt::WindowFlags f) : |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 QWidget(parent, f), |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 mModel(model) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 Q_ASSERT(model); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 setupGUI(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 connect(mModel, &QSortFilterProxyModel::sourceModelChanged, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 this, &FilterWidget::headersChanged); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 connect(mCombo, idxChanged, this, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 &FilterWidget::filterChanged); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged())); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 connect(mEditLine, &QLineEdit::textChanged, this, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 &FilterWidget::filterChanged); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 void FilterWidget::headersChanged() { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 QAbstractItemModel *newSource = mModel->sourceModel(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 Q_ASSERT(newSource); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 mCombo->clear(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 for (int i=0; i < newSource->columnCount(); i++) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 mCombo->addItem(newSource->headerData(i, Qt::Horizontal).toString()); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 void FilterWidget::filterChanged() { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 QString filterText = mEditLine->text(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 if (filterText.size() < 1) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 return; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 mModel->setFilterKeyColumn(mCombo->currentIndex()); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 mModel->setFilterWildcard(filterText); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 void FilterWidget::setupGUI() { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 QHBoxLayout *root = new QHBoxLayout; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 QGroupBox *baseGroup = new QGroupBox(tr("Filter")); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 root->addWidget(baseGroup); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 QHBoxLayout *baseLayout = new QHBoxLayout; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 baseGroup->setLayout(baseLayout); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 mCombo = new QComboBox; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 baseLayout->addWidget(mCombo); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 mEditLine = new QLineEdit; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 mEditLine->setPlaceholderText(tr("Filter expression")); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 mEditLine->setClearButtonEnabled(true); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 baseLayout->addWidget(mEditLine); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 setLayout(root); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 |