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

#include <kis_model_index_converter_show_all.h>

+ Inheritance diagram for KisModelIndexConverterShowAll:

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
 
 KisModelIndexConverterShowAll (KisDummiesFacadeBase *dummiesFacade, KisNodeModel *model)
 
int rowCount (QModelIndex parent) override
 
- Public Member Functions inherited from KisModelIndexConverterBase
virtual ~KisModelIndexConverterBase ()
 

Private Attributes

KisDummiesFacadeBasem_dummiesFacade
 
KisNodeModelm_model
 

Detailed Description

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

Definition at line 22 of file kis_model_index_converter_show_all.h.

Constructor & Destructor Documentation

◆ KisModelIndexConverterShowAll()

KisModelIndexConverterShowAll::KisModelIndexConverterShowAll ( KisDummiesFacadeBase * dummiesFacade,
KisNodeModel * model )

Definition at line 14 of file kis_model_index_converter_show_all.cpp.

16 : m_dummiesFacade(dummiesFacade),
17 m_model(model)
18{
19}

Member Function Documentation

◆ dummyFromIndex()

KisNodeDummy * KisModelIndexConverterShowAll::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 34 of file kis_model_index_converter_show_all.cpp.

35{
36 Q_ASSERT(index.isValid());
37 Q_ASSERT(index.internalPointer());
38 return static_cast<KisNodeDummy*>(index.internalPointer());
39}

◆ dummyFromRow()

KisNodeDummy * KisModelIndexConverterShowAll::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 21 of file kis_model_index_converter_show_all.cpp.

22{
23 Q_ASSERT(parent.isValid() || !row);
24
25 if(!parent.isValid()) return m_dummiesFacade->rootDummy();
26
27 KisNodeDummy *parentDummy = dummyFromIndex(parent);
28
29 int rowCount = parentDummy->childCount();
30 int index = rowCount - row - 1;
31 return parentDummy->at(index);
32}
virtual KisNodeDummy * rootDummy() const =0
KisNodeDummy * dummyFromIndex(QModelIndex index) override
KisNodeDummy * at(int index) const
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KisNodeDummy::at(), KisNodeDummy::childCount(), dummyFromIndex(), m_dummiesFacade, KisDummiesFacadeBase::rootDummy(), and rowCount().

◆ indexFromAddedDummy()

bool KisModelIndexConverterShowAll::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 56 of file kis_model_index_converter_show_all.cpp.

61{
62 Q_UNUSED(newNodeMetaObjectType);
63
64 Q_ASSERT(parentDummy || !index);
65
66 if(!parentDummy) {
67 row = 0;
68 parentIndex = QModelIndex();
69 }
70 else {
71 int rowCount = parentDummy->childCount();
72 row = rowCount - index;
73 parentIndex = indexFromDummy(parentDummy);
74 }
75 return true;
76}
QModelIndex indexFromDummy(KisNodeDummy *dummy) override

References KisNodeDummy::childCount(), indexFromDummy(), and rowCount().

◆ indexFromDummy()

QModelIndex KisModelIndexConverterShowAll::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 41 of file kis_model_index_converter_show_all.cpp.

42{
43 int row = 0;
44
45 KisNodeDummy *parentDummy = dummy->parent();
46
47 if(parentDummy) {
48 int rowCount = parentDummy->childCount();
49 int index = parentDummy->indexOf(dummy);
50 row = rowCount - index - 1;
51 }
52
53 return m_model->createIndex(row, 0, (void*)dummy);
54}
KisNodeDummy * parent() const
int indexOf(KisNodeDummy *child) const

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

◆ rowCount()

int KisModelIndexConverterShowAll::rowCount ( QModelIndex parent)
overridevirtual

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

Implements KisModelIndexConverterBase.

Definition at line 78 of file kis_model_index_converter_show_all.cpp.

79{
80 if(!parent.isValid()) return 1;
81
82 KisNodeDummy *parentDummy = dummyFromIndex(parent);
83
84 return parentDummy->childCount();
85}

References KisNodeDummy::childCount(), and dummyFromIndex().

Member Data Documentation

◆ m_dummiesFacade

KisDummiesFacadeBase* KisModelIndexConverterShowAll::m_dummiesFacade
private

Definition at line 39 of file kis_model_index_converter_show_all.h.

◆ m_model

KisNodeModel* KisModelIndexConverterShowAll::m_model
private

Definition at line 40 of file kis_model_index_converter_show_all.h.


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