Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCategorizedListModel< TEntry, TEntryToQStringConverter > Class Template Reference

#include <kis_categorized_list_model.h>

+ Inheritance diagram for KisCategorizedListModel< TEntry, TEntryToQStringConverter >:

Public Types

typedef SpecificCategoriesMapper::DataItem DataItem
 
typedef TEntry Entry_Type
 
typedef KisCategoriesMapper< TEntry, TEntryToQStringConverter > SpecificCategoriesMapper
 
- Public Types inherited from __CategorizedListModelBase
enum  AdditionalRoles {
  IsHeaderRole = Qt::UserRole + 1 , ExpandCategoryRole = Qt::UserRole + 2 , SortRole = Qt::UserRole + 3 , isLockedRole = Qt::UserRole + 4 ,
  isLockableRole = Qt::UserRole + 5 , isToggledRole = Qt::UserRole + 6
}
 

Public Member Functions

SpecificCategoriesMappercategoriesMapper ()
 
const SpecificCategoriesMappercategoriesMapper () const
 
QVariant data (const QModelIndex &idx, int role=Qt::DisplayRole) const override
 
bool entryAt (TEntry &entry, QModelIndex index) const
 
Qt::ItemFlags flags (const QModelIndex &idx) const override
 
QModelIndex indexOf (const TEntry &entry) const
 
 KisCategorizedListModel (QObject *parent=0)
 
int rowCount (const QModelIndex &parent) const override
 
bool setData (const QModelIndex &idx, const QVariant &value, int role=Qt::EditRole) override
 
- Public Member Functions inherited from __CategorizedListModelBase
 __CategorizedListModelBase (QObject *parent)
 
 ~__CategorizedListModelBase () override
 

Private Attributes

SpecificCategoriesMapper m_mapper
 

Detailed Description

template<class TEntry, class TEntryToQStringConverter>
class KisCategorizedListModel< TEntry, TEntryToQStringConverter >

Definition at line 57 of file kis_categorized_list_model.h.

Member Typedef Documentation

◆ DataItem

template<class TEntry , class TEntryToQStringConverter >
typedef SpecificCategoriesMapper::DataItem KisCategorizedListModel< TEntry, TEntryToQStringConverter >::DataItem

Definition at line 62 of file kis_categorized_list_model.h.

◆ Entry_Type

template<class TEntry , class TEntryToQStringConverter >
typedef TEntry KisCategorizedListModel< TEntry, TEntryToQStringConverter >::Entry_Type

Definition at line 60 of file kis_categorized_list_model.h.

◆ SpecificCategoriesMapper

template<class TEntry , class TEntryToQStringConverter >
typedef KisCategoriesMapper<TEntry, TEntryToQStringConverter> KisCategorizedListModel< TEntry, TEntryToQStringConverter >::SpecificCategoriesMapper

Definition at line 61 of file kis_categorized_list_model.h.

Constructor & Destructor Documentation

◆ KisCategorizedListModel()

template<class TEntry , class TEntryToQStringConverter >
KisCategorizedListModel< TEntry, TEntryToQStringConverter >::KisCategorizedListModel ( QObject * parent = 0)
inline

Definition at line 65 of file kis_categorized_list_model.h.

67 {
68 connect(&m_mapper, SIGNAL(rowChanged(int)), SLOT(slotRowChanged(int))); // helps with category expand menu
69 connect(&m_mapper, SIGNAL(beginInsertRow(int)), SLOT(slotBeginInsertRow(int)));
70 connect(&m_mapper, SIGNAL(endInsertRow()), SLOT(slotEndInsertRow()));
71 connect(&m_mapper, SIGNAL(beginRemoveRow(int)), SLOT(slotBeginRemoveRow(int)));
72 connect(&m_mapper, SIGNAL(endRemoveRow()), SLOT(slotEndRemoveRow()));
73
74
75
76 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
SpecificCategoriesMapper m_mapper

References connect(), KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper, __CategorizedListModelBase::slotBeginInsertRow(), __CategorizedListModelBase::slotBeginRemoveRow(), __CategorizedListModelBase::slotEndInsertRow(), __CategorizedListModelBase::slotEndRemoveRow(), and __CategorizedListModelBase::slotRowChanged().

Member Function Documentation

◆ categoriesMapper() [1/2]

template<class TEntry , class TEntryToQStringConverter >
SpecificCategoriesMapper * KisCategorizedListModel< TEntry, TEntryToQStringConverter >::categoriesMapper ( )
inline

◆ categoriesMapper() [2/2]

template<class TEntry , class TEntryToQStringConverter >
const SpecificCategoriesMapper * KisCategorizedListModel< TEntry, TEntryToQStringConverter >::categoriesMapper ( ) const
inline

◆ data()

template<class TEntry , class TEntryToQStringConverter >
QVariant KisCategorizedListModel< TEntry, TEntryToQStringConverter >::data ( const QModelIndex & idx,
int role = Qt::DisplayRole ) const
inlineoverride

Definition at line 83 of file kis_categorized_list_model.h.

83 {
84 if (!idx.isValid()) return QVariant();
85
86 typename SpecificCategoriesMapper::DataItem *item =
87 m_mapper.itemFromRow(idx.row());
88 Q_ASSERT(item);
89
90 switch (role) {
91 case IsHeaderRole:
92 return item->isCategory();
94 return item->isCategory() ? item->isExpanded() : item->parentCategory()->isExpanded();
95 case Qt::ToolTipRole:
96 case Qt::DisplayRole:
97 return item->name();
98 case Qt::CheckStateRole:
99 return item->isCheckable() ? item->isChecked() ? Qt::Checked : Qt::Unchecked : QVariant();
100 case SortRole:
101 return item->isCategory() ? item->name() : item->parentCategory()->name() + item->name();
102 case isLockedRole:
103 return item->isLocked();
104 case isLockableRole:
105 return item->isLockable();
106 case isToggledRole:
107 return item->isToggled();
108
109 }
110
111 return QVariant();
112 }
DataItem * itemFromRow(int row) const

References __CategorizedListModelBase::ExpandCategoryRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCategory(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCheckable(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isChecked(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isExpanded(), __CategorizedListModelBase::IsHeaderRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isLockable(), __CategorizedListModelBase::isLockableRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isLocked(), __CategorizedListModelBase::isLockedRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isToggled(), __CategorizedListModelBase::isToggledRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::itemFromRow(), KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::name(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::parentCategory(), and __CategorizedListModelBase::SortRole.

◆ entryAt()

template<class TEntry , class TEntryToQStringConverter >
bool KisCategorizedListModel< TEntry, TEntryToQStringConverter >::entryAt ( TEntry & entry,
QModelIndex index ) const
inline

Definition at line 171 of file kis_categorized_list_model.h.

171 {
172 int row = index.row();
173 if (row < 0 || row >= m_mapper.rowCount()) return false;
174
175 typename SpecificCategoriesMapper::DataItem *item =
177
178 if (!item->isCategory()) {
179 entry = *item->data();
180 return true;
181 }
182
183 return false;
184 }

References KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::data(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCategory(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::itemFromRow(), KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper, and KisCategoriesMapper< TEntry, TEntryToQStringConverter >::rowCount().

◆ flags()

template<class TEntry , class TEntryToQStringConverter >
Qt::ItemFlags KisCategorizedListModel< TEntry, TEntryToQStringConverter >::flags ( const QModelIndex & idx) const
inlineoverride

Definition at line 140 of file kis_categorized_list_model.h.

140 {
141 if (!idx.isValid()) return Qt::NoItemFlags;
142
143 typename SpecificCategoriesMapper::DataItem *item =
144 m_mapper.itemFromRow(idx.row());
145 Q_ASSERT(item);
146
147 Qt::ItemFlags flags = Qt::NoItemFlags;
148
149 if (item->isEnabled()) {
150 flags |= Qt::ItemIsEnabled;
151 }
152
153 if (!item->isCategory()) {
154 flags |= Qt::ItemIsSelectable;
155
156 if (item->isCheckable()) {
157 flags |= Qt::ItemIsUserCheckable;
158 }
159 }
160
161 return flags;
162 }
Qt::ItemFlags flags(const QModelIndex &idx) const override

References KisCategorizedListModel< TEntry, TEntryToQStringConverter >::flags(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCategory(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCheckable(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isEnabled(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::itemFromRow(), and KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper.

◆ indexOf()

template<class TEntry , class TEntryToQStringConverter >
QModelIndex KisCategorizedListModel< TEntry, TEntryToQStringConverter >::indexOf ( const TEntry & entry) const
inline

Definition at line 164 of file kis_categorized_list_model.h.

164 {
165 typename SpecificCategoriesMapper::DataItem *item =
166 m_mapper.fetchOneEntry(entry);
167
168 return index(m_mapper.rowFromItem(item));
169 }
int rowFromItem(DataItem *item) const
DataItem * fetchOneEntry(const TEntry &entry) const

References KisCategoriesMapper< TEntry, TEntryToQStringConverter >::fetchOneEntry(), KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper, and KisCategoriesMapper< TEntry, TEntryToQStringConverter >::rowFromItem().

◆ rowCount()

template<class TEntry , class TEntryToQStringConverter >
int KisCategorizedListModel< TEntry, TEntryToQStringConverter >::rowCount ( const QModelIndex & parent) const
inlineoverride

◆ setData()

template<class TEntry , class TEntryToQStringConverter >
bool KisCategorizedListModel< TEntry, TEntryToQStringConverter >::setData ( const QModelIndex & idx,
const QVariant & value,
int role = Qt::EditRole )
inlineoverride

Definition at line 114 of file kis_categorized_list_model.h.

114 {
115 if (!idx.isValid()) return false;
116
117 typename SpecificCategoriesMapper::DataItem *item =
118 m_mapper.itemFromRow(idx.row());
119 Q_ASSERT(item);
120
121 switch (role) {
123 Q_ASSERT(item->isCategory());
124 item->setExpanded(value.toBool());
125 break;
126 case Qt::CheckStateRole:
127 Q_ASSERT(item->isCheckable());
128 item->setChecked(value.toInt() == Qt::Checked);
129 break;
130 }
131
132 // dataChanged() needs a QVector even though we are just passing one
133 QVector<int> roles;
134 roles.append(role);
135
136 Q_EMIT dataChanged(idx, idx, roles);
137 return true;
138 }
float value(const T *src, size_t ch)

References __CategorizedListModelBase::ExpandCategoryRole, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCategory(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::isCheckable(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::itemFromRow(), KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper, KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::setChecked(), KisCategoriesMapper< TEntry, TEntryToQStringConverter >::DataItem::setExpanded(), and value().

Member Data Documentation

◆ m_mapper

template<class TEntry , class TEntryToQStringConverter >
SpecificCategoriesMapper KisCategorizedListModel< TEntry, TEntryToQStringConverter >::m_mapper
private

Definition at line 195 of file kis_categorized_list_model.h.


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