Commit 798177ee authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Tomaz Canabrava
Browse files

Add filtermodel class for the QuickCommands plugin

parent bc4a631b
......@@ -6,6 +6,7 @@ SOURCES
quickcommandsplugin.cpp
quickcommandswidget.cpp
quickcommandsmodel.cpp
filtermodel.cpp
${EXTRA_QUICKCOMMANDSPLUGIN_SRCS}
INSTALL_NAMESPACE
"konsoleplugins"
......
/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "filtermodel.h"
FilterModel::FilterModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
FilterModel::~FilterModel() = default;
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
auto text = filterRegularExpression().pattern();
if (text.isEmpty()) {
return true;
}
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
if (sourceModel()->rowCount(idx) != 0) {
return true;
}
bool result = idx.data(Qt::DisplayRole).toString().toLower().contains(text.toLower());
return m_invertFilter == false ? result : !result;
}
void FilterModel::setInvertFilter(bool invert)
{
m_invertFilter = invert;
invalidateFilter();
}
/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QSortFilterProxyModel>
class FilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit FilterModel(QObject *parent);
~FilterModel() override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
void setInvertFilter(bool invert);
private:
bool m_invertFilter = false;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment