diff --git a/plugins/problemreporter/problemsview.h b/plugins/problemreporter/problemsview.h --- a/plugins/problemreporter/problemsview.h +++ b/plugins/problemreporter/problemsview.h @@ -104,6 +104,8 @@ QAction* m_errorSeverityAction = nullptr; QAction* m_warningSeverityAction = nullptr; QAction* m_hintSeverityAction = nullptr; + + QString m_filterText; }; } diff --git a/plugins/problemreporter/problemsview.cpp b/plugins/problemreporter/problemsview.cpp --- a/plugins/problemreporter/problemsview.cpp +++ b/plugins/problemreporter/problemsview.cpp @@ -23,9 +23,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -201,6 +203,37 @@ currentView()->model()->setGrouping(index); }); } + + { + QTimer* filterTimer = new QTimer(this); + filterTimer->setSingleShot(true); + + connect(filterTimer, &QTimer::timeout, [this]() { + int idx = m_tabWidget->indexOf(currentView()); + int rows = currentView()->setFilter(m_filterText); + + updateTab(idx, rows); + }); + + QLineEdit* filterEdit = new QLineEdit(this); + filterEdit->setClearButtonEnabled(true); + filterEdit->setPlaceholderText(i18n("Search...")); + + QSizePolicy p(filterEdit->sizePolicy()); + p.setHorizontalPolicy(QSizePolicy::Fixed); + filterEdit->setSizePolicy(p); + + connect(filterEdit, &QLineEdit::textChanged, [this, filterTimer](const QString& filterText) { + m_filterText = filterText; + filterTimer->start(500); + }); + + QWidgetAction* filterAction = new QWidgetAction(this); + filterAction->setDefaultWidget(filterEdit); + addAction(filterAction); + + setFocusProxy(filterEdit); + } } void ProblemsView::updateActions() @@ -229,6 +262,8 @@ } problemModel->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + + setFocus(); // set focus to default widget (filterEdit) } /// TODO: Move to util? diff --git a/plugins/problemreporter/problemtreeview.h b/plugins/problemreporter/problemtreeview.h --- a/plugins/problemreporter/problemtreeview.h +++ b/plugins/problemreporter/problemtreeview.h @@ -50,6 +50,8 @@ const QVector& roles = QVector()) override; void reset() override; + int setFilter(const QString& filterText); + public slots: void openDocumentForCurrentProblem(); diff --git a/plugins/problemreporter/problemtreeview.cpp b/plugins/problemreporter/problemtreeview.cpp --- a/plugins/problemreporter/problemtreeview.cpp +++ b/plugins/problemreporter/problemtreeview.cpp @@ -100,6 +100,8 @@ connect(model(), &QAbstractItemModel::rowsInserted, this, &ProblemTreeView::changed); connect(model(), &QAbstractItemModel::rowsRemoved, this, &ProblemTreeView::changed); connect(model(), &QAbstractItemModel::modelReset, this, &ProblemTreeView::changed); + + m_proxy->setFilterKeyColumn(-1); } ProblemTreeView::~ProblemTreeView() @@ -151,6 +153,13 @@ resizeColumns(); } +int ProblemTreeView::setFilter(const QString& filterText) +{ + m_proxy->setFilterRegExp(QRegExp(filterText, Qt::CaseInsensitive, QRegExp::FixedString)); + + return m_proxy->rowCount(); +} + ProblemModel* ProblemTreeView::model() const { return static_cast(m_proxy->sourceModel());