annotate src/filterwidget.cpp @ 24:6b9b5efcd7f4

Add missing copyright header
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 May 2015 17:47:57 +0200
parents e12284a222ba
children 64a51a42c01f
rev   line source
24
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 18
diff changeset
1 /* Copyright (C) 2014 by Intevation GmbH
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 18
diff changeset
2 *
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 18
diff changeset
3 * 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
4 * and comes with ABSOLUTELY NO WARRANTY!
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 18
diff changeset
5 * See LICENSE.txt for details.
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 18
diff changeset
6 */
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 #include "filterwidget.h"
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include <QComboBox>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 #include <QHBoxLayout>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 #include <QGroupBox>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include <QSortFilterProxyModel>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include <QAbstractItemModel>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <QLineEdit>
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <QDebug>
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 FilterWidget::FilterWidget(QSortFilterProxyModel *model, QWidget *parent, Qt::WindowFlags f) :
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 QWidget(parent, f),
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 mModel(model) {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 Q_ASSERT(model);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 setupGUI();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 connect(mModel, &QSortFilterProxyModel::sourceModelChanged,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 this, &FilterWidget::headersChanged);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 connect(mCombo, idxChanged, this,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 &FilterWidget::filterChanged);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 connect(mEditLine, &QLineEdit::textChanged, this,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 &FilterWidget::filterChanged);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 }
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 void FilterWidget::headersChanged() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 QAbstractItemModel *newSource = mModel->sourceModel();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 Q_ASSERT(newSource);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 mCombo->clear();
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
37 mColFilterMap.clear();
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
38 int addedItems = 0;
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 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
40 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
41 if (!entry.startsWith("#")) {
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
42 mCombo->addItem(entry);
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
43 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
44 } else {
17
73efe717b944 Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents: 14
diff changeset
45 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
46 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
47 }
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
48 }
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 }
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 void FilterWidget::filterChanged() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 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
54 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex()));
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 mModel->setFilterWildcard(filterText);
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
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 void FilterWidget::setupGUI() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 QHBoxLayout *root = new QHBoxLayout;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 QGroupBox *baseGroup = new QGroupBox(tr("Filter"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 root->addWidget(baseGroup);
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 QHBoxLayout *baseLayout = new QHBoxLayout;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 baseGroup->setLayout(baseLayout);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 mCombo = new QComboBox;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 baseLayout->addWidget(mCombo);
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 mEditLine = new QLineEdit;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 mEditLine->setPlaceholderText(tr("Filter expression"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 mEditLine->setClearButtonEnabled(true);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 baseLayout->addWidget(mEditLine);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 setLayout(root);
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
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)