Mercurial > retraceit
view src/filterwidget.cpp @ 97:4c97abde1c3e
Added tag 1.2 for changeset a9e72af2e6fa
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 29 Jun 2015 15:41:00 +0200 |
parents | 07e1e47954f6 |
children |
line wrap: on
line source
/* Copyright (C) 2015 by ETH Zürich * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ #include "filterwidget.h" #include "constants.h" #include <QSettings> #include <QComboBox> #include <QHBoxLayout> #include <QGroupBox> #include <QSortFilterProxyModel> #include <QAbstractItemModel> #include <QLineEdit> #include <QDebug> #include <QCheckBox> FilterWidget::FilterWidget(QSortFilterProxyModel *model, bool addWithEmptyChk, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mModel(model), mWithEmptyChk(addWithEmptyChk) { Q_ASSERT(model); setupGUI(); void (QComboBox:: *idxChanged)(int) = &QComboBox::currentIndexChanged; connect(mCombo, idxChanged, this, &FilterWidget::filterChanged); //connect(mCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged())); connect(mEditLine, &QLineEdit::textChanged, this, &FilterWidget::filterChanged); } void FilterWidget::headersChanged() { mCombo->blockSignals(true); QAbstractItemModel *newSource = mModel->sourceModel(); Q_ASSERT(newSource); mCombo->clear(); mColFilterMap.clear(); int addedItems = 0; QSettings settings; settings.beginGroup(HIDE_CONFIG_GROUP); for (int i=0; i < newSource->columnCount(); i++) { QString entry = newSource->headerData(i, Qt::Horizontal).toString(); if (settings.value(entry, false).toBool()) { continue; } if (!entry.startsWith("#")) { mCombo->addItem(entry); mColFilterMap.insert(addedItems++, i); } else { if (!newSource->setHeaderData(i, Qt::Horizontal, entry.remove(0,1), Qt::DisplayRole)) { qDebug() << "Setting header data failed."; } } } mCombo->blockSignals(false); } void FilterWidget::filterChanged() { QString filterText = mEditLine->text(); mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex())); mModel->setFilterWildcard(filterText); emit filterHasChanged(); } void FilterWidget::setupGUI() { QHBoxLayout *root = new QHBoxLayout; QGroupBox *baseGroup = new QGroupBox(tr("Filter")); root->addWidget(baseGroup); QHBoxLayout *baseLayout = new QHBoxLayout; baseGroup->setLayout(baseLayout); mCombo = new QComboBox; baseLayout->addWidget(mCombo); mEditLine = new QLineEdit; mEditLine->setPlaceholderText(tr("Filter expression")); mEditLine->setClearButtonEnabled(true); baseLayout->addWidget(mEditLine); if (mWithEmptyChk) { mEmptyChk = new QCheckBox(tr("Include empty fields")); baseLayout->addWidget(mEmptyChk); mEmptyChk->setCheckState(Qt::Checked); connect(mEmptyChk, &QCheckBox::stateChanged, this, &FilterWidget::includeEmptyChanged); } setLayout(root); }