Krita Source Code Documentation
Loading...
Searching...
No Matches
KisModelIndexConverter Class Reference

#include <kis_model_index_converter.h>

+ Inheritance diagram for KisModelIndexConverter:

Public Member Functions

KisNodeDummydummyFromIndex (QModelIndex index) override
 
KisNodeDummydummyFromRow (int row, QModelIndex parent) override
 
bool indexFromAddedDummy (KisNodeDummy *parentDummy, int index, const QString &newNodeMetaObjectType, QModelIndex &parentIndex, int &row) override
 
QModelIndex indexFromDummy (KisNodeDummy *dummy) override
 
 KisModelIndexConverter (KisDummiesFacadeBase *dummiesFacade, KisNodeModel *model, bool showGlobalSelection)
 
int rowCount (QModelIndex parent) override
 
- Public Member Functions inherited from KisModelIndexConverterBase
virtual ~KisModelIndexConverterBase ()
 

Private Member Functions

bool checkDummyMetaObjectType (const QString &type)
 
bool checkDummyType (KisNodeDummy *dummy)
 

Private Attributes

KisDummiesFacadeBasem_dummiesFacade
 
KisNodeModelm_model
 
bool m_showGlobalSelection
 

Detailed Description

The class for converting to/from QModelIndex and KisNodeDummy when the root node is hidden (ShowRootLayer == false). All the selection masks owned by the root layer are hidden as well.

Definition at line 22 of file kis_model_index_converter.h.

Constructor & Destructor Documentation

◆ KisModelIndexConverter()

KisModelIndexConverter::KisModelIndexConverter ( KisDummiesFacadeBase * dummiesFacade,
KisNodeModel * model,
bool showGlobalSelection )

Definition at line 18 of file kis_model_index_converter.cpp.

21 : m_dummiesFacade(dummiesFacade),
22 m_model(model),
23 m_showGlobalSelection(showGlobalSelection)
24{
25}
KisDummiesFacadeBase * m_dummiesFacade

Member Function Documentation

◆ checkDummyMetaObjectType()

bool KisModelIndexConverter::checkDummyMetaObjectType ( const QString & type)
inlineprivate

Definition at line 32 of file kis_model_index_converter.cpp.

33{
34 const QString selectionMaskType = KisSelectionMask::staticMetaObject.className();
35 const QString referencesLayerType = KisReferenceImagesLayer::staticMetaObject.className();
36 const QString decorationsLayerType = KisDecorationsWrapperLayer::staticMetaObject.className();
37
38 return (type != selectionMaskType || m_showGlobalSelection) &&
39 type != referencesLayerType &&
40 type != decorationsLayerType;
41}

References m_showGlobalSelection.

◆ checkDummyType()

bool KisModelIndexConverter::checkDummyType ( KisNodeDummy * dummy)
inlineprivate

Definition at line 27 of file kis_model_index_converter.cpp.

28{
30}
bool isGUIVisible(bool showGlobalSelection) const

References KisNodeDummy::isGUIVisible(), and m_showGlobalSelection.

◆ dummyFromIndex()

KisNodeDummy * KisModelIndexConverter::dummyFromIndex ( QModelIndex index)
overridevirtual

Returns the dummy associated with the index WARNING: index must be valid

Note
cannot return null

Implements KisModelIndexConverterBase.

Definition at line 78 of file kis_model_index_converter.cpp.

79{
80 Q_ASSERT(index.isValid());
81 Q_ASSERT(index.internalPointer());
82 return static_cast<KisNodeDummy*>(index.internalPointer());
83}

◆ dummyFromRow()

KisNodeDummy * KisModelIndexConverter::dummyFromRow ( int row,
QModelIndex parent )
overridevirtual

Returns the dummy staying in the specified row of a parent May return null in case of inconsistency

Implements KisModelIndexConverterBase.

Definition at line 43 of file kis_model_index_converter.cpp.

44{
45
46 KisNodeDummy *parentDummy = parent.isValid() ?
47 dummyFromIndex(parent) : m_dummiesFacade->rootDummy();
48
49 if(!parentDummy) return 0;
50
51 KisNodeDummy *resultDummy = 0;
52
53 // a child of the root node
54 if(!parentDummy->parent()) {
55 KisNodeDummy *currentDummy = parentDummy->lastChild();
56 while(currentDummy) {
57 if(checkDummyType(currentDummy)) {
58 if(!row) {
59 resultDummy = currentDummy;
60 break;
61 }
62 row--;
63 }
64 currentDummy = currentDummy->prevSibling();
65 }
66 }
67 // a child of other layer
68 else {
69 int rowCount = parentDummy->childCount();
70 int index = rowCount - row - 1;
71 resultDummy = parentDummy->at(index);
72 }
73
74
75 return resultDummy;
76}
KisNodeDummy * dummyFromIndex(QModelIndex index) override
bool checkDummyType(KisNodeDummy *dummy)
int rowCount(QModelIndex parent) override
KisNodeDummy * at(int index) const
KisNodeDummy * lastChild() const
KisNodeDummy * parent() const
KisNodeDummy * prevSibling() const
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KisNodeDummy::at(), checkDummyType(), KisNodeDummy::childCount(), dummyFromIndex(), KisNodeDummy::lastChild(), m_dummiesFacade, KisNodeDummy::parent(), KisNodeDummy::prevSibling(), KisDummiesFacadeBase::rootDummy(), and rowCount().

◆ indexFromAddedDummy()

bool KisModelIndexConverter::indexFromAddedDummy ( KisNodeDummy * parentDummy,
int index,
const QString & newNodeMetaObjectType,
QModelIndex & parentIndex,
int & row )
overridevirtual

Calculates the parent and the position in the model for newly created dummy

Parameters
parentDummythe dummy parent
indexthe dummy index
newNodeMetaObjectTypeis a class name of a newly added node This name is got from Qt's meta object system so you must compare this value against a corresponding staticMetaObject object only. We do not pass a pointer to a real node to limit the access to real nodes.
parentIndexthe parent index
rowthe dummy row
Returns
whether the new dummy will be shown in the model

Implements KisModelIndexConverterBase.

Definition at line 117 of file kis_model_index_converter.cpp.

122{
123 // adding a root node
124 if(!parentDummy) {
125 Q_ASSERT(!index);
126 return false;
127 }
128
129 // adding a child of the root node
130 if(!parentDummy->parent()) {
131 if(!checkDummyMetaObjectType(newNodeMetaObjectType)) {
132 return false;
133 }
134
135 row = 0;
136
137 parentIndex = QModelIndex();
138 KisNodeDummy *dummy = parentDummy->lastChild();
139 int toScan = parentDummy->childCount() - index;
140 while(dummy && toScan > 0) {
141 if(checkDummyType(dummy)) {
142 row++;
143 }
144 dummy = dummy->prevSibling();
145 toScan--;
146 }
147 }
148 // everything else
149 else {
150 parentIndex = indexFromDummy(parentDummy);
151 int rowCount = parentDummy->childCount();
152 row = rowCount - index;
153 }
154
155 return true;
156}
bool checkDummyMetaObjectType(const QString &type)
QModelIndex indexFromDummy(KisNodeDummy *dummy) override

References checkDummyMetaObjectType(), checkDummyType(), KisNodeDummy::childCount(), indexFromDummy(), KisNodeDummy::lastChild(), KisNodeDummy::parent(), KisNodeDummy::prevSibling(), and rowCount().

◆ indexFromDummy()

QModelIndex KisModelIndexConverter::indexFromDummy ( KisNodeDummy * dummy)
overridevirtual

Returns the index corresponding to the position of the dummy in the model. Will return invalid index if the dummy should be hidden

Implements KisModelIndexConverterBase.

Definition at line 85 of file kis_model_index_converter.cpp.

86{
87 Q_ASSERT(dummy);
88 KisNodeDummy *parentDummy = dummy->parent();
89
90 // a root node
91 if(!parentDummy) return QModelIndex();
92
93 int row = 0;
94
95 // a child of the root node
96 if(!parentDummy->parent()) {
97 if(!checkDummyType(dummy)) return QModelIndex();
98
99 KisNodeDummy *currentDummy = parentDummy->lastChild();
100 while(currentDummy && currentDummy != dummy) {
101 if(checkDummyType(currentDummy)) {
102 row++;
103 }
104 currentDummy = currentDummy->prevSibling();
105 }
106 }
107 // a child of other layer
108 else {
109 int rowCount = parentDummy->childCount();
110 int index = parentDummy->indexOf(dummy);
111 row = rowCount - index - 1;
112 }
113
114 return m_model->createIndex(row, 0, (void*)dummy);
115}
int indexOf(KisNodeDummy *child) const

References checkDummyType(), KisNodeDummy::childCount(), KisNodeDummy::indexOf(), KisNodeDummy::lastChild(), m_model, KisNodeDummy::parent(), KisNodeDummy::prevSibling(), and rowCount().

◆ rowCount()

int KisModelIndexConverter::rowCount ( QModelIndex parent)
overridevirtual

Returns the number of children of the given index of the model

Implements KisModelIndexConverterBase.

Definition at line 158 of file kis_model_index_converter.cpp.

159{
160 KisNodeDummy *dummy = parent.isValid() ?
161 dummyFromIndex(parent) : m_dummiesFacade->rootDummy();
162
163 // a root node (hidden)
164 if(!dummy) return 0;
165
166 int numChildren = 0;
167
168 // children of the root node
169 if(!dummy->parent()) {
170 KisNodeDummy *currentDummy = dummy->lastChild();
171 while(currentDummy) {
172 if(checkDummyType(currentDummy)) {
173 numChildren++;
174 }
175
176 currentDummy = currentDummy->prevSibling();
177 }
178 }
179 // children of other nodes
180 else {
181 numChildren = dummy->childCount();
182 }
183
184 return numChildren;
185}

References checkDummyType(), KisNodeDummy::childCount(), dummyFromIndex(), KisNodeDummy::lastChild(), m_dummiesFacade, KisNodeDummy::parent(), KisNodeDummy::prevSibling(), and KisDummiesFacadeBase::rootDummy().

Member Data Documentation

◆ m_dummiesFacade

KisDummiesFacadeBase* KisModelIndexConverter::m_dummiesFacade
private

Definition at line 44 of file kis_model_index_converter.h.

◆ m_model

KisNodeModel* KisModelIndexConverter::m_model
private

Definition at line 45 of file kis_model_index_converter.h.

◆ m_showGlobalSelection

bool KisModelIndexConverter::m_showGlobalSelection
private

Definition at line 46 of file kis_model_index_converter.h.


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