1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3  * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4  * SPDX-License-Identifier: GPL-3.0-or-later
5  ***************************************************************************/
6 #ifndef SKGNODEOBJECT_H
7 #define SKGNODEOBJECT_H
8 /** @file
9  * This file defines classes SKGNodeObject.
10  *
11  * @author Stephane MANKOWSKI / Guillaume DE BURE
12  */
13 
14 #include "skgdefine.h"
15 #include "skgnamedobject.h"
16 
17 class SKGDocument;
18 /**
19  * This class manages node object
20  */
21 class SKGBASEMODELER_EXPORT SKGNodeObject final : public SKGNamedObject
22 {
23     /**
24      * Order of the node
25      */
26     Q_PROPERTY(double order READ getOrder WRITE setOrder)  // clazy:exclude=qproperty-without-notify
27     /**
28      * Full name of the node
29      */
30     Q_PROPERTY(QString fullName READ getFullName)  // clazy:exclude=qproperty-without-notify
31     /**
32      * Data of the node
33      */
34     Q_PROPERTY(QString data READ getData WRITE setData)  // clazy:exclude=qproperty-without-notify
35 
36 public:
37     /**
38      * Indicates if a node is opened
39      */
40     bool opened;
41 
42     /**
43      * default constructor
44      */
45     explicit SKGNodeObject();
46 
47     /**
48      * Constructor
49      * @param iDocument the document containing the object
50      * @param iID the identifier in @p iTable of the object
51      */
52     explicit SKGNodeObject(SKGDocument* iDocument, int iID = 0);
53 
54     /**
55      * Copy constructor
56      * @param iObject the object to copy
57      */
58     SKGNodeObject(const SKGNodeObject& iObject);
59 
60     /**
61      * Copy constructor
62      * @param iObject the object to copy
63      */
64     explicit SKGNodeObject(const SKGObjectBase& iObject);
65 
66     /**
67      * Operator affectation
68      * @param iObject the object to copy
69      */
70     SKGNodeObject& operator= (const SKGObjectBase& iObject);
71 
72     /**
73      * Operator affectation
74      * @param iObject the object to copy
75      */
76     SKGNodeObject& operator= (const SKGNodeObject& iObject);
77 
78     /**
79      * Destructor
80      */
81     virtual ~SKGNodeObject();
82 
83     /**
84      * Create a node branch if needed and return the leaf of the branch
85      * @param iDocument the document where to create
86      * @param iFullPath the full path. Example: cat1|cat2|cat3
87      * @param oNode the leaf of the branch
88      * @param iRenameIfAlreadyExist if a leaf with the expected name already exist than the leaf will be renamed and created
89      * @return an object managing the error.
90      *   @see SKGError
91      */
92     static SKGError createPathNode(SKGDocument* iDocument,
93                                    const QString& iFullPath,
94                                    SKGNodeObject& oNode,
95                                    bool iRenameIfAlreadyExist = false);
96 
97     /**
98      * Set the name of this object
99      * @param iName the name
100      * @return an object managing the error
101      *   @see SKGError
102      */
103     SKGError setName(const QString& iName) override;
104 
105     /**
106      * Get the full name of this node.
107      * The full name is the unique name of the node.
108      * It is computed by the concatenation of names for all
109      * the fathers of this node.
110      * @return the full name
111      */
112     QString getFullName() const;
113 
114     /**
115      * Add a node
116      * @param oNode the created node
117      * @return an object managing the error.
118      *   @see SKGError
119      */
120     SKGError addNode(SKGNodeObject& oNode);
121 
122     /**
123      * Move the node by changing the parent
124      * @param iNode the parent node
125      * @return an object managing the error.
126      *   @see SKGError
127      */
128     SKGError setParentNode(const SKGNodeObject& iNode);
129 
130     /**
131      * Get the parent node
132      * @param oNode the parent node
133      * @return an object managing the error.
134      *   @see SKGError
135      */
136     SKGError getParentNode(SKGNodeObject& oNode) const;
137 
138     /**
139      * Remove the parent node. The node will be a root.
140      * @return an object managing the error.
141      *   @see SKGError
142      */
143     SKGError removeParentNode();
144 
145     /**
146      * Get nodes
147      * @param oNodeList the list of nodes under the current one
148      * @return an object managing the error
149      *   @see SKGError
150      */
151     SKGError getNodes(SKGListSKGObjectBase& oNodeList) const;
152 
153     /**
154      * Set the order for the node in its parent
155      * @param iOrder the order. (-1 means "at the end")
156      * @return an object managing the error
157      *   @see SKGError
158      */
159     SKGError setOrder(double iOrder);
160 
161     /**
162      * Get the order for the node in its parent
163      * @return the order
164      */
165     double getOrder() const;
166 
167     /**
168      * Set data of this node
169      * @param iData the data
170      * @return an object managing the error
171      *   @see SKGError
172      */
173     SKGError setData(const QString& iData);
174 
175     /**
176      * Get data of this node
177      * @return the data
178      */
179     QString getData() const;
180 
181     /**
182      * To know if the node is a folder or not
183      * @return true of false
184      */
185     bool isFolder() const;
186 
187     /**
188      * Set icon of this node
189      * @param iIcon the icon name
190      * @return an object managing the error
191      *   @see SKGError
192      */
193     SKGError setIcon(const QString& iIcon);
194 
195     /**
196      * Get icon of this node
197      * @return the icon
198      */
199     QIcon getIcon() const;
200 
201     /**
202      * Set autostart mode of this node
203      * @param iAutoStart the autostart mode
204      * @return an object managing the error
205      *   @see SKGError
206      */
207     SKGError setAutoStart(bool iAutoStart);
208 
209     /**
210      * Get autostart mode of this node
211      * @return the autostart mode
212      */
213     bool isAutoStart() const;
214 
215 protected:
216     /**
217      * Get where clause needed to identify objects.
218      * For this class, the whereclause is based on name + rd_node_id
219      * @return the where clause
220      */
221     QString getWhereclauseId() const override;
222 };
223 /**
224  * Declare the class
225  */
226 Q_DECLARE_TYPEINFO(SKGNodeObject, Q_MOVABLE_TYPE);
227 #endif
228