File indexing completed on 2024-05-12 16:01:33

0001 /*
0002  *  SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_MODEL_INDEX_CONVERTER_BASE_H
0008 #define __KIS_MODEL_INDEX_CONVERTER_BASE_H
0009 
0010 
0011 #include <QModelIndex>
0012 #include "kritaui_export.h"
0013 class KisNodeDummy;
0014 
0015 /**
0016  * The base class for converting objects to/from QModelIndex used
0017  * in KisNodeModel and  KisNodeDummy used in KisDummiesFacadeBase
0018  * (KisShapeController).
0019  *
0020  * This is not a trivial task, because the indexing of nodes is
0021  * reversed in KisNodeModel.
0022  */
0023 
0024 class KRITAUI_EXPORT KisModelIndexConverterBase
0025 {
0026 public:
0027     virtual ~KisModelIndexConverterBase();
0028 
0029     /**
0030      * Returns the dummy staying in the specified \p row of a \p parent
0031      * May return null in case of inconsistency
0032      */
0033     virtual KisNodeDummy* dummyFromRow(int row, QModelIndex parent) = 0;
0034 
0035     /**
0036      * Returns the dummy associated with the \p index
0037      * WARNING: \p index must be valid
0038      * \note cannot return null
0039      */
0040     virtual KisNodeDummy* dummyFromIndex(QModelIndex index) = 0;
0041 
0042     /**
0043      * Returns the index corresponding to the position of the \p dummy
0044      * in the model. Will return invalid index if the dummy should be hidden
0045      */
0046     virtual QModelIndex indexFromDummy(KisNodeDummy *dummy) = 0;
0047 
0048     /**
0049      * Calculates the parent and the position in the model for newly created dummy
0050      * \param parentDummy the dummy parent
0051      * \param index the dummy index
0052      * \param newNodeMetaObjectType is a class name of a newly added node
0053      *        This name is got from Qt's meta object system so you must
0054      *        compare this value against a corresponding staticMetaObject
0055      *        object only.
0056      *        We do not pass a pointer to a real node to limit the access to
0057      *        real nodes.
0058      * \param parentIndex the parent index
0059      * \param row the dummy row
0060      * \return whether the new dummy will be shown in the model
0061      */
0062     virtual bool indexFromAddedDummy(KisNodeDummy *parentDummy, int index, const QString &newNodeMetaObjectType, QModelIndex &parentIndex, int &row) = 0;
0063 
0064     /**
0065      * Returns the number of children of the given index of the model
0066      */
0067     virtual int rowCount(QModelIndex parent) = 0;
0068 };
0069 
0070 #endif /* __KIS_MODEL_INDEX_CONVERTER_BASE_H */