File indexing completed on 2024-05-12 15:58:28

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef _KIS_NODE_FACADE_H
0007 #define _KIS_NODE_FACADE_H
0008 
0009 #include <QScopedPointer>
0010 
0011 #include "kis_types.h"
0012 #include "kis_node.h"
0013 #include "kritaimage_export.h"
0014 /**
0015  * KisNodeFacade is the public interface to adding and removing nodes.
0016  */
0017 class KRITAIMAGE_EXPORT KisNodeFacade
0018 {
0019 
0020 public:
0021 
0022     /**
0023      * Create a new, empty KisNodeFacade
0024      */
0025     KisNodeFacade();
0026 
0027     /**
0028      * Create a new kisnodefacade for the given root.
0029      */
0030     KisNodeFacade(KisNodeSP root);
0031 
0032     virtual ~KisNodeFacade();
0033 
0034     /**
0035      * Set the rootnode for this facade
0036      */
0037     void setRoot(KisNodeSP root);
0038 
0039     /**
0040      * Return the root node for the graph this facade managed
0041      */
0042     const KisNodeSP root() const;
0043 
0044     /**
0045      * Move the given node to specified position. If the node already
0046      * has a parent, it is removed from the parent's node list.
0047      */
0048     bool moveNode(KisNodeSP node, KisNodeSP parent, KisNodeSP aboveThis);
0049 
0050     /**
0051      * Move the givent node at the specified index. If the node already
0052      * has a parent, it is removed from the parent's node list.
0053      *
0054      * childCount() is a valid index and appends to the end.
0055      */
0056     bool moveNode(KisNodeSP node, KisNodeSP parent, quint32 index);
0057     /**
0058      * Add an already existing node to the image. The node is put on top
0059      * of the nodes in the specified nodegroup. If parent is 0, then
0060      * the root is used as parent.
0061      *
0062      * @param node the node to be added
0063      * @param parent the parent node
0064      */
0065     bool addNode(KisNodeSP node, KisNodeSP parent = KisNodeSP());
0066 
0067     /**
0068      * Add already existing node to the graph.
0069      *
0070      * @param node the node to be added
0071      * @param parent the parent node
0072      * @param aboveThis in the list with child nodes of the specified
0073      *                  parent, add this node above the specified sibling.
0074      *                  if 0, the node is put in the lowermost position in
0075      *                  its group.
0076      * returns false if adding the node didn't work, true if the node got added
0077      */
0078     bool addNode(KisNodeSP node, KisNodeSP parent, KisNodeSP aboveThis);
0079 
0080     /**
0081      * Adds the node as a child of the given parent at the specified
0082      * index.
0083      *
0084      * childCount() is a valid index and appends to the end. Fails and
0085      * returns false if the node is already in this group or any
0086      * other (remove it first.)
0087      */
0088     bool addNode(KisNodeSP node,  KisNodeSP parent, quint32 index);
0089 
0090     /**
0091      * Remove the specified node.
0092      *
0093      * @return false if removing the node failed
0094      */
0095     bool removeNode(KisNodeSP node);
0096 
0097     /**
0098      * Move node up one slot, i.e., nextSibling becomes prevSibling
0099      */
0100     bool raiseNode(KisNodeSP node);
0101 
0102     /**
0103      * Move node down one slot -- i.e, prevSibling becomes
0104      * nextSibling.
0105      *
0106      * @return false if moving the node failed
0107      */
0108     bool lowerNode(KisNodeSP node);
0109 
0110     /**
0111      * Move the given node to the top-most position among its
0112      * siblings.
0113      *
0114      * @return false if moving the node failed.
0115      */
0116     bool toTop(KisNodeSP node);
0117 
0118     /**
0119      * Move the given node to bottom-most position among its siblings.
0120      *
0121      * @return false if moving the node failed.
0122      */
0123     bool toBottom(KisNodeSP node);
0124 
0125 private:
0126 
0127     struct Private;
0128     QScopedPointer<Private> m_d;
0129 };
0130 #endif