annotate src/filterwidget.cpp @ 23:d9626e84b93d

Added tag 0.0.2 for changeset 0a08c1c2531a
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 14 Apr 2015 18:58:49 +0200
parents e12284a222ba
children 6b9b5efcd7f4
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();
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
31 mColFilterMap.clear();
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
32 int addedItems = 0;
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 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
34 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
35 if (!entry.startsWith("#")) {
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
36 mCombo->addItem(entry);
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
37 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
38 } else {
17
73efe717b944 Fix bug in csv model to allow changing headerdata
Andre Heinecke <andre.heinecke@intevation.de>
parents: 14
diff changeset
39 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
40 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
41 }
14
315e6988952a Only add entries that do not start with # to filter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 4
diff changeset
42 }
4
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
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 void FilterWidget::filterChanged() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 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
48 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex()));
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 mModel->setFilterWildcard(filterText);
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::setupGUI() {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 QHBoxLayout *root = new QHBoxLayout;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 QGroupBox *baseGroup = new QGroupBox(tr("Filter"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 root->addWidget(baseGroup);
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 QHBoxLayout *baseLayout = new QHBoxLayout;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 baseGroup->setLayout(baseLayout);
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 mCombo = new QComboBox;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 baseLayout->addWidget(mCombo);
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 mEditLine = new QLineEdit;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 mEditLine->setPlaceholderText(tr("Filter expression"));
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 mEditLine->setClearButtonEnabled(true);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 baseLayout->addWidget(mEditLine);
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 setLayout(root);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 }
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)