diff --git a/src/widgets/filterwidget.cpp b/src/widgets/filterwidget.cpp index 609cab90..a97d2cc8 100644 --- a/src/widgets/filterwidget.cpp +++ b/src/widgets/filterwidget.cpp @@ -1,96 +1,96 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filterwidget.h" #include #include #include #include #include #include "presentation/artifactfilterproxymodel.h" #include "ui_filterwidget.h" using namespace Widgets; FilterWidget::FilterWidget(QWidget *parent) : QWidget(parent), ui(new Ui::FilterWidget), m_model(new Presentation::ArtifactFilterProxyModel(this)) { ui->setupUi(this); ui->extension->hide(); ui->sortTypeCombo->addItem(i18n("Sort by title"), Presentation::ArtifactFilterProxyModel::TitleSort); ui->sortTypeCombo->addItem(i18n("Sort by date"), Presentation::ArtifactFilterProxyModel::DateSort); setFocusProxy(ui->filterEdit); connect(ui->filterEdit, &QLineEdit::textChanged, this, &FilterWidget::onTextChanged); connect(ui->sortTypeCombo, static_cast(&QComboBox::currentIndexChanged), this, &FilterWidget::onSortTypeChanged); connect(ui->ascendingButton, &QToolButton::clicked, this, &FilterWidget::onAscendingClicked); connect(ui->descendingButton, &QToolButton::clicked, this, &FilterWidget::onDescendingClicked); } FilterWidget::~FilterWidget() { delete ui; } Presentation::ArtifactFilterProxyModel *FilterWidget::proxyModel() const { return m_model; } void FilterWidget::clear() { ui->filterEdit->clear(); } +void FilterWidget::setShowFutureTasks(bool show) +{ + m_model->setShowFutureTasks(show); +} + void FilterWidget::onTextChanged(const QString &text) { m_model->setFilterFixedString(text); } void FilterWidget::onSortTypeChanged(int index) { const int data = ui->sortTypeCombo->itemData(index).toInt(); m_model->setSortType(Presentation::ArtifactFilterProxyModel::SortType(data)); } void FilterWidget::onAscendingClicked() { m_model->setSortOrder(Qt::AscendingOrder); } void FilterWidget::onDescendingClicked() { m_model->setSortOrder(Qt::DescendingOrder); } - -void FilterWidget::onShowFutureChanged(bool show) -{ - m_model->setShowFutureTasks(show); -} diff --git a/src/widgets/filterwidget.h b/src/widgets/filterwidget.h index dd49f212..d9f28fba 100644 --- a/src/widgets/filterwidget.h +++ b/src/widgets/filterwidget.h @@ -1,70 +1,70 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WIDGETS_FILTERWIDGET_H #define WIDGETS_FILTERWIDGET_H #include class QComboBox; class QLineEdit; namespace Presentation { class ArtifactFilterProxyModel; } namespace Ui { class FilterWidget; } namespace Widgets { class FilterWidget : public QWidget { Q_OBJECT public: explicit FilterWidget(QWidget *parent = Q_NULLPTR); ~FilterWidget(); Presentation::ArtifactFilterProxyModel *proxyModel() const; public slots: void clear(); + void setShowFutureTasks(bool show); private slots: void onTextChanged(const QString &text); void onSortTypeChanged(int index); void onAscendingClicked(); void onDescendingClicked(); - void onShowFutureChanged(bool show); private: Ui::FilterWidget *ui; Presentation::ArtifactFilterProxyModel *m_model; }; } #endif // WIDGETS_FILTERWIDGET_H diff --git a/tests/units/widgets/filterwidgettest.cpp b/tests/units/widgets/filterwidgettest.cpp index 8e9d38bc..71049f02 100644 --- a/tests/units/widgets/filterwidgettest.cpp +++ b/tests/units/widgets/filterwidgettest.cpp @@ -1,201 +1,217 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include "widgets/filterwidget.h" #include "presentation/artifactfilterproxymodel.h" class FilterWidgetTest : public QObject { Q_OBJECT private slots: void shouldHaveDefaultState() { Widgets::FilterWidget filter; QVERIFY(filter.proxyModel()); QVERIFY(!filter.proxyModel()->sourceModel()); QCOMPARE(filter.proxyModel()->filterRegExp(), QRegExp()); QCOMPARE(filter.proxyModel()->sortOrder(), Qt::AscendingOrder); QCOMPARE(filter.proxyModel()->sortType(), Presentation::ArtifactFilterProxyModel::TitleSort); QLineEdit *filterEdit = filter.findChild(QStringLiteral("filterEdit")); QVERIFY(filterEdit); QVERIFY(filterEdit->isVisibleTo(&filter)); QVERIFY(filterEdit->text().isEmpty()); QCOMPARE(filterEdit->placeholderText(), i18n("Filter...")); auto extensionButton = filter.findChild(QStringLiteral("extensionButton")); QVERIFY(extensionButton); QVERIFY(extensionButton->isVisibleTo(&filter)); QVERIFY(!extensionButton->isChecked()); QVERIFY(extensionButton->autoRaise()); QComboBox *sortTypeCombo = filter.findChild(QStringLiteral("sortTypeCombo")); QVERIFY(sortTypeCombo); QVERIFY(!sortTypeCombo->isVisibleTo(&filter)); QCOMPARE(sortTypeCombo->currentIndex(), 0); auto ascendingButton = filter.findChild(QStringLiteral("ascendingButton")); QVERIFY(ascendingButton); QVERIFY(!ascendingButton->isVisibleTo(&filter)); QVERIFY(ascendingButton->isChecked()); QVERIFY(ascendingButton->autoRaise()); auto descendingButton = filter.findChild(QStringLiteral("descendingButton")); QVERIFY(descendingButton); QVERIFY(!descendingButton->isVisibleTo(&filter)); QVERIFY(!descendingButton->isChecked()); QVERIFY(descendingButton->autoRaise()); } void shouldChangeAppliedFilter() { // GIVEN Widgets::FilterWidget filter; QLineEdit *filterEdit = filter.findChild(QStringLiteral("filterEdit")); QVERIFY(filterEdit); // WHEN QTest::keyClicks(filterEdit, QStringLiteral("find me")); // THEN QCOMPARE(filter.proxyModel()->filterRegExp().pattern(), QStringLiteral("find me")); } void shouldClearFilter() { // GIVEN Widgets::FilterWidget filter; QLineEdit *filterEdit = filter.findChild(QStringLiteral("filterEdit")); QVERIFY(filterEdit); filterEdit->setText("Foo"); // WHEN filter.clear(); // THEN QVERIFY(filterEdit->text().isEmpty()); QVERIFY(filter.proxyModel()->filterRegExp().pattern().isEmpty()); } void shouldShowExtension() { // GIVEN Widgets::FilterWidget filter; QAbstractButton *extensionButton = filter.findChild(QStringLiteral("extensionButton")); QVERIFY(extensionButton); QComboBox *sortTypeCombo = filter.findChild(QStringLiteral("sortTypeCombo")); QVERIFY(sortTypeCombo); QAbstractButton *ascendingButton = filter.findChild(QStringLiteral("ascendingButton")); QVERIFY(ascendingButton); QAbstractButton *descendingButton = filter.findChild(QStringLiteral("descendingButton")); QVERIFY(descendingButton); // WHEN extensionButton->click(); // THEN QVERIFY(extensionButton->isChecked()); QVERIFY(sortTypeCombo->isVisibleTo(&filter)); QVERIFY(descendingButton->isVisibleTo(&filter)); QVERIFY(descendingButton->isVisibleTo(&filter)); // WHEN extensionButton->click(); // THEN QVERIFY(!extensionButton->isChecked()); QVERIFY(!sortTypeCombo->isVisibleTo(&filter)); QVERIFY(!descendingButton->isVisibleTo(&filter)); QVERIFY(!descendingButton->isVisibleTo(&filter)); } void shouldChangeSortType() { // GIVEN Widgets::FilterWidget filter; QComboBox *sortTypeCombo = filter.findChild(QStringLiteral("sortTypeCombo")); QVERIFY(sortTypeCombo); // WHEN sortTypeCombo->setCurrentIndex(1); // THEN QCOMPARE(filter.proxyModel()->sortType(), Presentation::ArtifactFilterProxyModel::DateSort); // WHEN sortTypeCombo->setCurrentIndex(0); // THEN QCOMPARE(filter.proxyModel()->sortType(), Presentation::ArtifactFilterProxyModel::TitleSort); } void shouldChangeSortOrder() { // GIVEN Widgets::FilterWidget filter; QAbstractButton *ascendingButton = filter.findChild(QStringLiteral("ascendingButton")); QVERIFY(ascendingButton); QAbstractButton *descendingButton = filter.findChild(QStringLiteral("descendingButton")); QVERIFY(descendingButton); // WHEN descendingButton->click(); // THEN QVERIFY(!ascendingButton->isChecked()); QVERIFY(descendingButton->isChecked()); QCOMPARE(filter.proxyModel()->sortOrder(), Qt::DescendingOrder); // WHEN ascendingButton->click(); // THEN QVERIFY(ascendingButton->isChecked()); QVERIFY(!descendingButton->isChecked()); QCOMPARE(filter.proxyModel()->sortOrder(), Qt::AscendingOrder); } + + void shouldShowFutureTasks() + { + // GIVEN + Widgets::FilterWidget filter; + filter.setShowFutureTasks(false); + + // THEN + QVERIFY(!filter.proxyModel()->showFutureTasks()); + + // WHEN + filter.setShowFutureTasks(true); + + // THEN + QVERIFY(filter.proxyModel()->showFutureTasks()); + } }; ZANSHIN_TEST_MAIN(FilterWidgetTest) #include "filterwidgettest.moc"