File indexing completed on 2025-01-19 04:56:41
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include "filterwidget.h" 0008 0009 #include <QBoxLayout> 0010 #include <QComboBox> 0011 #include <QLineEdit> 0012 #include <QToolButton> 0013 0014 #include <KLocalizedString> 0015 0016 #include "presentation/taskfilterproxymodel.h" 0017 0018 #include "ui_filterwidget.h" 0019 0020 using namespace Widgets; 0021 0022 FilterWidget::FilterWidget(QWidget *parent) 0023 : QWidget(parent), 0024 ui(new Ui::FilterWidget), 0025 m_model(new Presentation::TaskFilterProxyModel(this)) 0026 { 0027 ui->setupUi(this); 0028 ui->extension->hide(); 0029 ui->sortTypeCombo->addItem(i18n("Sort by title"), Presentation::TaskFilterProxyModel::TitleSort); 0030 ui->sortTypeCombo->addItem(i18n("Sort by date"), Presentation::TaskFilterProxyModel::DateSort); 0031 setFocusProxy(ui->filterEdit); 0032 0033 connect(ui->filterEdit, &QLineEdit::textChanged, this, &FilterWidget::onTextChanged); 0034 connect(ui->sortTypeCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &FilterWidget::onSortTypeChanged); 0035 connect(ui->ascendingButton, &QToolButton::clicked, this, &FilterWidget::onAscendingClicked); 0036 connect(ui->descendingButton, &QToolButton::clicked, this, &FilterWidget::onDescendingClicked); 0037 } 0038 0039 FilterWidget::~FilterWidget() 0040 { 0041 delete ui; 0042 } 0043 0044 Presentation::TaskFilterProxyModel *FilterWidget::proxyModel() const 0045 { 0046 return m_model; 0047 } 0048 0049 void FilterWidget::clear() 0050 { 0051 ui->filterEdit->clear(); 0052 } 0053 0054 void FilterWidget::setShowDoneTasks(bool show) 0055 { 0056 m_model->setShowDoneTasks(show); 0057 } 0058 0059 void FilterWidget::setShowFutureTasks(bool show) 0060 { 0061 m_model->setShowFutureTasks(show); 0062 } 0063 0064 void FilterWidget::onTextChanged(const QString &text) 0065 { 0066 m_model->setFilterRegularExpression(QRegularExpression::escape(text)); 0067 } 0068 0069 void FilterWidget::onSortTypeChanged(int index) 0070 { 0071 const int data = ui->sortTypeCombo->itemData(index).toInt(); 0072 m_model->setSortType(Presentation::TaskFilterProxyModel::SortType(data)); 0073 } 0074 0075 void FilterWidget::onAscendingClicked() 0076 { 0077 m_model->setSortOrder(Qt::AscendingOrder); 0078 } 0079 0080 void FilterWidget::onDescendingClicked() 0081 { 0082 m_model->setSortOrder(Qt::DescendingOrder); 0083 } 0084 0085 #include "moc_filterwidget.cpp"