Mercurial > retraceit
annotate src/filterwidget.cpp @ 96:a9e72af2e6fa 1.2
(Auto) Update translations
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 29 Jun 2015 15:40:19 +0200 |
parents | 07e1e47954f6 |
children |
rev | line source |
---|---|
25
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
24
diff
changeset
|
1 /* Copyright (C) 2015 by ETH Zürich |
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
24
diff
changeset
|
2 * Software engineering by Intevation GmbH |
24
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
18
diff
changeset
|
3 * |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
18
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
18
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
18
diff
changeset
|
6 * See LICENSE.txt for details. |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
18
diff
changeset
|
7 */ |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "filterwidget.h" |
89
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
9 #include "constants.h" |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 |
89
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
11 #include <QSettings> |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QComboBox> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #include <QHBoxLayout> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 #include <QGroupBox> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #include <QSortFilterProxyModel> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include <QAbstractItemModel> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #include <QLineEdit> |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #include <QDebug> |
89
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
19 #include <QCheckBox> |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
21 FilterWidget::FilterWidget(QSortFilterProxyModel *model, bool addWithEmptyChk, |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
22 QWidget *parent, Qt::WindowFlags f) : |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 QWidget(parent, f), |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
24 mModel(model), |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
25 mWithEmptyChk(addWithEmptyChk) { |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 Q_ASSERT(model); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 setupGUI(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 connect(mCombo, idxChanged, this, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 &FilterWidget::filterChanged); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged())); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 connect(mEditLine, &QLineEdit::textChanged, this, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 &FilterWidget::filterChanged); |
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 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 void FilterWidget::headersChanged() { |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
38 mCombo->blockSignals(true); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 QAbstractItemModel *newSource = mModel->sourceModel(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 Q_ASSERT(newSource); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 mCombo->clear(); |
14
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
42 mColFilterMap.clear(); |
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
43 int addedItems = 0; |
89
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
44 QSettings settings; |
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
45 settings.beginGroup(HIDE_CONFIG_GROUP); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 for (int i=0; i < newSource->columnCount(); i++) { |
14
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
47 QString entry = newSource->headerData(i, Qt::Horizontal).toString(); |
89
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
48 if (settings.value(entry, false).toBool()) { |
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
49 continue; |
b8c7644a9d49
Add config settings to hide specific columns
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
50 } |
14
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
51 if (!entry.startsWith("#")) { |
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
52 mCombo->addItem(entry); |
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
53 mColFilterMap.insert(addedItems++, i); |
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
54 } else { |
17
73efe717b944
Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents:
14
diff
changeset
|
55 if (!newSource->setHeaderData(i, Qt::Horizontal, entry.remove(0,1), Qt::DisplayRole)) { |
73efe717b944
Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents:
14
diff
changeset
|
56 qDebug() << "Setting header data failed."; |
73efe717b944
Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents:
14
diff
changeset
|
57 } |
14
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
58 } |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 } |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
60 mCombo->blockSignals(false); |
4
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 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 void FilterWidget::filterChanged() { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 QString filterText = mEditLine->text(); |
14
315e6988952a
Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents:
4
diff
changeset
|
65 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex())); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 mModel->setFilterWildcard(filterText); |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
67 emit filterHasChanged(); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 void FilterWidget::setupGUI() { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 QHBoxLayout *root = new QHBoxLayout; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 QGroupBox *baseGroup = new QGroupBox(tr("Filter")); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 root->addWidget(baseGroup); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 QHBoxLayout *baseLayout = new QHBoxLayout; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 baseGroup->setLayout(baseLayout); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 mCombo = new QComboBox; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 baseLayout->addWidget(mCombo); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 mEditLine = new QLineEdit; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 mEditLine->setPlaceholderText(tr("Filter expression")); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 mEditLine->setClearButtonEnabled(true); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 baseLayout->addWidget(mEditLine); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
87 if (mWithEmptyChk) { |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
88 mEmptyChk = new QCheckBox(tr("Include empty fields")); |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
89 baseLayout->addWidget(mEmptyChk); |
94
07e1e47954f6
Default to include empty fields
Andre Heinecke <andre.heinecke@intevation.de>
parents:
89
diff
changeset
|
90 mEmptyChk->setCheckState(Qt::Checked); |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
91 connect(mEmptyChk, &QCheckBox::stateChanged, this, &FilterWidget::includeEmptyChanged); |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
92 } |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
93 |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 setLayout(root); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 |