File indexing completed on 2024-04-28 16:30:31

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGNODEOBJECT_H
0007 #define SKGNODEOBJECT_H
0008 /** @file
0009  * This file defines classes SKGNodeObject.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 
0014 #include "skgdefine.h"
0015 #include "skgnamedobject.h"
0016 
0017 class SKGDocument;
0018 /**
0019  * This class manages node object
0020  */
0021 class SKGBASEMODELER_EXPORT SKGNodeObject final : public SKGNamedObject
0022 {
0023     /**
0024      * Order of the node
0025      */
0026     Q_PROPERTY(double order READ getOrder WRITE setOrder)  // clazy:exclude=qproperty-without-notify
0027     /**
0028      * Full name of the node
0029      */
0030     Q_PROPERTY(QString fullName READ getFullName)  // clazy:exclude=qproperty-without-notify
0031     /**
0032      * Data of the node
0033      */
0034     Q_PROPERTY(QString data READ getData WRITE setData)  // clazy:exclude=qproperty-without-notify
0035 
0036 public:
0037     /**
0038      * Indicates if a node is opened
0039      */
0040     bool opened;
0041 
0042     /**
0043      * default constructor
0044      */
0045     explicit SKGNodeObject();
0046 
0047     /**
0048      * Constructor
0049      * @param iDocument the document containing the object
0050      * @param iID the identifier in @p iTable of the object
0051      */
0052     explicit SKGNodeObject(SKGDocument* iDocument, int iID = 0);
0053 
0054     /**
0055      * Copy constructor
0056      * @param iObject the object to copy
0057      */
0058     SKGNodeObject(const SKGNodeObject& iObject);
0059 
0060     /**
0061      * Copy constructor
0062      * @param iObject the object to copy
0063      */
0064     explicit SKGNodeObject(const SKGObjectBase& iObject);
0065 
0066     /**
0067      * Operator affectation
0068      * @param iObject the object to copy
0069      */
0070     SKGNodeObject& operator= (const SKGObjectBase& iObject);
0071 
0072     /**
0073      * Operator affectation
0074      * @param iObject the object to copy
0075      */
0076     SKGNodeObject& operator= (const SKGNodeObject& iObject);
0077 
0078     /**
0079      * Destructor
0080      */
0081     virtual ~SKGNodeObject();
0082 
0083     /**
0084      * Create a node branch if needed and return the leaf of the branch
0085      * @param iDocument the document where to create
0086      * @param iFullPath the full path. Example: cat1|cat2|cat3
0087      * @param oNode the leaf of the branch
0088      * @param iRenameIfAlreadyExist if a leaf with the expected name already exist than the leaf will be renamed and created
0089      * @return an object managing the error.
0090      *   @see SKGError
0091      */
0092     static SKGError createPathNode(SKGDocument* iDocument,
0093                                    const QString& iFullPath,
0094                                    SKGNodeObject& oNode,
0095                                    bool iRenameIfAlreadyExist = false);
0096 
0097     /**
0098      * Set the name of this object
0099      * @param iName the name
0100      * @return an object managing the error
0101      *   @see SKGError
0102      */
0103     SKGError setName(const QString& iName) override;
0104 
0105     /**
0106      * Get the full name of this node.
0107      * The full name is the unique name of the node.
0108      * It is computed by the concatenation of names for all
0109      * the fathers of this node.
0110      * @return the full name
0111      */
0112     QString getFullName() const;
0113 
0114     /**
0115      * Add a node
0116      * @param oNode the created node
0117      * @return an object managing the error.
0118      *   @see SKGError
0119      */
0120     SKGError addNode(SKGNodeObject& oNode);
0121 
0122     /**
0123      * Move the node by changing the parent
0124      * @param iNode the parent node
0125      * @return an object managing the error.
0126      *   @see SKGError
0127      */
0128     SKGError setParentNode(const SKGNodeObject& iNode);
0129 
0130     /**
0131      * Get the parent node
0132      * @param oNode the parent node
0133      * @return an object managing the error.
0134      *   @see SKGError
0135      */
0136     SKGError getParentNode(SKGNodeObject& oNode) const;
0137 
0138     /**
0139      * Remove the parent node. The node will be a root.
0140      * @return an object managing the error.
0141      *   @see SKGError
0142      */
0143     SKGError removeParentNode();
0144 
0145     /**
0146      * Get nodes
0147      * @param oNodeList the list of nodes under the current one
0148      * @return an object managing the error
0149      *   @see SKGError
0150      */
0151     SKGError getNodes(SKGListSKGObjectBase& oNodeList) const;
0152 
0153     /**
0154      * Set the order for the node in its parent
0155      * @param iOrder the order. (-1 means "at the end")
0156      * @return an object managing the error
0157      *   @see SKGError
0158      */
0159     SKGError setOrder(double iOrder);
0160 
0161     /**
0162      * Get the order for the node in its parent
0163      * @return the order
0164      */
0165     double getOrder() const;
0166 
0167     /**
0168      * Set data of this node
0169      * @param iData the data
0170      * @return an object managing the error
0171      *   @see SKGError
0172      */
0173     SKGError setData(const QString& iData);
0174 
0175     /**
0176      * Get data of this node
0177      * @return the data
0178      */
0179     QString getData() const;
0180 
0181     /**
0182      * To know if the node is a folder or not
0183      * @return true of false
0184      */
0185     bool isFolder() const;
0186 
0187     /**
0188      * Set icon of this node
0189      * @param iIcon the icon name
0190      * @return an object managing the error
0191      *   @see SKGError
0192      */
0193     SKGError setIcon(const QString& iIcon);
0194 
0195     /**
0196      * Get icon of this node
0197      * @return the icon
0198      */
0199     QIcon getIcon() const;
0200 
0201     /**
0202      * Set autostart mode of this node
0203      * @param iAutoStart the autostart mode
0204      * @return an object managing the error
0205      *   @see SKGError
0206      */
0207     SKGError setAutoStart(bool iAutoStart);
0208 
0209     /**
0210      * Get autostart mode of this node
0211      * @return the autostart mode
0212      */
0213     bool isAutoStart() const;
0214 
0215 protected:
0216     /**
0217      * Get where clause needed to identify objects.
0218      * For this class, the whereclause is based on name + rd_node_id
0219      * @return the where clause
0220      */
0221     QString getWhereclauseId() const override;
0222 };
0223 /**
0224  * Declare the class
0225  */
0226 Q_DECLARE_TYPEINFO(SKGNodeObject, Q_MOVABLE_TYPE);
0227 #endif