comparison src/filterwidget.cpp @ 88:3916cb3c9105

Add new FilterSort model that allows to include empty values
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 19 Jun 2015 14:26:16 +0200
parents 4e16fbd10945
children b8c7644a9d49
comparison
equal deleted inserted replaced
87:3b3a1384eb5f 88:3916cb3c9105
13 #include <QSortFilterProxyModel> 13 #include <QSortFilterProxyModel>
14 #include <QAbstractItemModel> 14 #include <QAbstractItemModel>
15 #include <QLineEdit> 15 #include <QLineEdit>
16 #include <QDebug> 16 #include <QDebug>
17 17
18 FilterWidget::FilterWidget(QSortFilterProxyModel *model, QWidget *parent, Qt::WindowFlags f) : 18 FilterWidget::FilterWidget(QSortFilterProxyModel *model, bool addWithEmptyChk,
19 QWidget *parent, Qt::WindowFlags f) :
19 QWidget(parent, f), 20 QWidget(parent, f),
20 mModel(model) { 21 mModel(model),
22 mWithEmptyChk(addWithEmptyChk) {
21 Q_ASSERT(model); 23 Q_ASSERT(model);
22 setupGUI(); 24 setupGUI();
23 25
24 connect(mModel, &QSortFilterProxyModel::sourceModelChanged,
25 this, &FilterWidget::headersChanged);
26 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged; 26 void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged;
27 connect(mCombo, idxChanged, this, 27 connect(mCombo, idxChanged, this,
28 &FilterWidget::filterChanged); 28 &FilterWidget::filterChanged);
29 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged())); 29 //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
30 connect(mEditLine, &QLineEdit::textChanged, this, 30 connect(mEditLine, &QLineEdit::textChanged, this,
31 &FilterWidget::filterChanged); 31 &FilterWidget::filterChanged);
32 } 32 }
33 33
34 void FilterWidget::headersChanged() { 34 void FilterWidget::headersChanged() {
35 mCombo->blockSignals(true);
35 QAbstractItemModel *newSource = mModel->sourceModel(); 36 QAbstractItemModel *newSource = mModel->sourceModel();
36 Q_ASSERT(newSource); 37 Q_ASSERT(newSource);
37 mCombo->clear(); 38 mCombo->clear();
38 mColFilterMap.clear(); 39 mColFilterMap.clear();
39 int addedItems = 0; 40 int addedItems = 0;
46 if (!newSource->setHeaderData(i, Qt::Horizontal, entry.remove(0,1), Qt::DisplayRole)) { 47 if (!newSource->setHeaderData(i, Qt::Horizontal, entry.remove(0,1), Qt::DisplayRole)) {
47 qDebug() << "Setting header data failed."; 48 qDebug() << "Setting header data failed.";
48 } 49 }
49 } 50 }
50 } 51 }
52 mCombo->blockSignals(false);
51 } 53 }
52 54
53 void FilterWidget::filterChanged() { 55 void FilterWidget::filterChanged() {
54 QString filterText = mEditLine->text(); 56 QString filterText = mEditLine->text();
55 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex())); 57 mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex()));
72 mEditLine = new QLineEdit; 74 mEditLine = new QLineEdit;
73 mEditLine->setPlaceholderText(tr("Filter expression")); 75 mEditLine->setPlaceholderText(tr("Filter expression"));
74 mEditLine->setClearButtonEnabled(true); 76 mEditLine->setClearButtonEnabled(true);
75 baseLayout->addWidget(mEditLine); 77 baseLayout->addWidget(mEditLine);
76 78
79 if (mWithEmptyChk) {
80 mEmptyChk = new QCheckBox(tr("Include empty fields"));
81 baseLayout->addWidget(mEmptyChk);
82 connect(mEmptyChk, &QCheckBox::stateChanged, this, &FilterWidget::includeEmptyChanged);
83 }
84
77 setLayout(root); 85 setLayout(root);
78 } 86 }
79 87
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)