Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSortedCategorizedListModel< TModel > Class Template Reference

#include <kis_categorized_list_model.h>

+ Inheritance diagram for KisSortedCategorizedListModel< TModel >:

Public Member Functions

bool entryAt (Entry_Type &entry, QModelIndex index) const
 
QModelIndex indexOf (const Entry_Type &entry) const
 
 KisSortedCategorizedListModel (QObject *parent)
 

Protected Member Functions

void initializeModel (TModel *model)
 
bool lessThanPriority (const QModelIndex &left, const QModelIndex &right, const QString &priorityCategory) const
 

Private Types

typedef TModel::Entry_Type Entry_Type
 

Private Attributes

TModel * m_model {nullptr}
 

Detailed Description

template<class TModel>
class KisSortedCategorizedListModel< TModel >

Definition at line 199 of file kis_categorized_list_model.h.

Member Typedef Documentation

◆ Entry_Type

template<class TModel >
typedef TModel::Entry_Type KisSortedCategorizedListModel< TModel >::Entry_Type
private

Definition at line 201 of file kis_categorized_list_model.h.

Constructor & Destructor Documentation

◆ KisSortedCategorizedListModel()

template<class TModel >
KisSortedCategorizedListModel< TModel >::KisSortedCategorizedListModel ( QObject * parent)
inline

Definition at line 205 of file kis_categorized_list_model.h.

206 : QSortFilterProxyModel(parent)
207 {
208 }

Member Function Documentation

◆ entryAt()

template<class TModel >
bool KisSortedCategorizedListModel< TModel >::entryAt ( Entry_Type & entry,
QModelIndex index ) const
inline

Definition at line 230 of file kis_categorized_list_model.h.

230 {
231 QModelIndex srcIndex = mapToSource(index);
232 return m_model->entryAt(entry, srcIndex);
233 }

◆ indexOf()

template<class TModel >
QModelIndex KisSortedCategorizedListModel< TModel >::indexOf ( const Entry_Type & entry) const
inline

We don't use the source model's indexOf(), because the items might be duplicated and we need to return the topmost one in the sorted order.

Definition at line 210 of file kis_categorized_list_model.h.

210 {
217 Entry_Type e;
218
219 for (int i = 0; i < rowCount(); i++) {
220 QModelIndex index = this->index(i, 0);
221
222 if (entryAt(e, index) && e == entry) {
223 return index;
224 }
225 }
226
227 return QModelIndex();
228 }
bool entryAt(Entry_Type &entry, QModelIndex index) const

◆ initializeModel()

template<class TModel >
void KisSortedCategorizedListModel< TModel >::initializeModel ( TModel * model)
inlineprotected

Definition at line 236 of file kis_categorized_list_model.h.

236 {
237 m_model = model;
238 setSourceModel(model);
239 setSortRole(TModel::SortRole);
240 }

◆ lessThanPriority()

template<class TModel >
bool KisSortedCategorizedListModel< TModel >::lessThanPriority ( const QModelIndex & left,
const QModelIndex & right,
const QString & priorityCategory ) const
inlineprotected

Definition at line 242 of file kis_categorized_list_model.h.

244 {
245
246 QString leftKey = sourceModel()->data(left, sortRole()).toString();
247 QString rightKey = sourceModel()->data(right, sortRole()).toString();
248
249 bool leftIsSpecial = leftKey.startsWith(priorityCategory);
250 bool rightIsSpecial = rightKey.startsWith(priorityCategory);
251
252 return leftIsSpecial != rightIsSpecial ?
253 leftIsSpecial : leftKey < rightKey;
254 }

Member Data Documentation

◆ m_model

template<class TModel >
TModel* KisSortedCategorizedListModel< TModel >::m_model {nullptr}
private

Definition at line 257 of file kis_categorized_list_model.h.

257{nullptr};

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