Krita Source Code Documentation
Loading...
Searching...
No Matches
CommandBarFilterModel Class Reference
+ Inheritance diagram for CommandBarFilterModel:

Public Member Functions

 CommandBarFilterModel (QObject *parent=nullptr)
 
Q_SLOT void setFilterString (const QString &string)
 

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 
bool lessThan (const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
 

Private Attributes

QString m_pattern
 

Detailed Description

Definition at line 26 of file katecommandbar.cpp.

Constructor & Destructor Documentation

◆ CommandBarFilterModel()

CommandBarFilterModel::CommandBarFilterModel ( QObject * parent = nullptr)
inline

Definition at line 29 of file katecommandbar.cpp.

30 : QSortFilterProxyModel(parent)
31 {
32 }

Member Function Documentation

◆ filterAcceptsRow()

bool CommandBarFilterModel::filterAcceptsRow ( int sourceRow,
const QModelIndex & sourceParent ) const
inlineoverrideprotected

Definition at line 49 of file katecommandbar.cpp.

50 {
51 if (m_pattern.isEmpty()) {
52 return true;
53 }
54
55 int score = 0;
56 const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
57 if (idx.isValid()){
58 const QString row = idx.data(Qt::DisplayRole).toString();
59 int pos = row.indexOf(QLatin1Char(':'));
60 if (pos < 0) {
61 return false;
62 }
63 const QString actionName = row.mid(pos + 2);
64 const bool res = kfts::fuzzy_match_sequential(m_pattern, actionName, score);
65 sourceModel()->setData(idx, score, CommandModel::Score);
66 return res;
67 }
68 return false;
69 }
static Q_DECL_UNUSED bool fuzzy_match_sequential(const QString pattern, const QString str, int &outScore)
This is a special case function which doesn't score separator matches higher than sequential matches....

References kfts::fuzzy_match_sequential(), m_pattern, and CommandModel::Score.

◆ lessThan()

bool CommandBarFilterModel::lessThan ( const QModelIndex & sourceLeft,
const QModelIndex & sourceRight ) const
inlineoverrideprotected

Definition at line 42 of file katecommandbar.cpp.

43 {
44 const int l = sourceLeft.data(CommandModel::Score).toInt();
45 const int r = sourceRight.data(CommandModel::Score).toInt();
46 return l < r;
47 }

References CommandModel::Score.

◆ setFilterString()

Q_SLOT void CommandBarFilterModel::setFilterString ( const QString & string)
inline

Definition at line 34 of file katecommandbar.cpp.

35 {
36 beginResetModel();
37 m_pattern = string;
38 endResetModel();
39 }

References m_pattern.

Member Data Documentation

◆ m_pattern

QString CommandBarFilterModel::m_pattern
private

Definition at line 72 of file katecommandbar.cpp.


The documentation for this class was generated from the following file: