annotate src/filterwidget.cpp @ 67:10569ebcf496

Added tag 0.9.2 for changeset 098a10fc2e83
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 22 May 2015 12:34:36 +0200
parents 4e16fbd10945
children 3916cb3c9105
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"
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 #include <QComboBox>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 #include <QHBoxLayout>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include <QGroupBox>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include <QSortFilterProxyModel>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <QAbstractItemModel>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <QLineEdit>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include <QDebug>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 FilterWidget::FilterWidget(QSortFilterProxyModel *model, QWidget *parent, Qt::WindowFlags f) :
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 QWidget(parent, f),
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 mModel(model) {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 Q_ASSERT(model);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 setupGUI();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 connect(mModel, &QSortFilterProxyModel::sourceModelChanged,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 this, &FilterWidget::headersChanged);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 connect(mCombo, idxChanged, this,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 &FilterWidget::filterChanged);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 connect(mEditLine, &QLineEdit::textChanged, 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 }
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 void FilterWidget::headersChanged() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 QAbstractItemModel *newSource = mModel->sourceModel();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 Q_ASSERT(newSource);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 mCombo->clear();
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
38 mColFilterMap.clear();
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
39 int addedItems = 0;
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 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
41 QString entry = newSource->headerData(i, Qt::Horizontal).toString();
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
42 if (!entry.startsWith("#")) {
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
43 mCombo->addItem(entry);
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
44 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
45 } else {
17
73efe717b944 Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents: 14
diff changeset
46 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
47 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
48 }
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
49 }
4
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 }
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 void FilterWidget::filterChanged() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 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
55 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex()));
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 mModel->setFilterWildcard(filterText);
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
57 emit filterHasChanged();
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 }
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 void FilterWidget::setupGUI() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 QHBoxLayout *root = new QHBoxLayout;
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 QGroupBox *baseGroup = new QGroupBox(tr("Filter"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 root->addWidget(baseGroup);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 QHBoxLayout *baseLayout = new QHBoxLayout;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 baseGroup->setLayout(baseLayout);
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 mCombo = new QComboBox;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 baseLayout->addWidget(mCombo);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 mEditLine = new QLineEdit;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 mEditLine->setPlaceholderText(tr("Filter expression"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 mEditLine->setClearButtonEnabled(true);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 baseLayout->addWidget(mEditLine);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 setLayout(root);
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
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)