Debian Codegraph @

avogadro/rendering/groupnode.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_RENDERING_GROUPNODE_H
7 #define AVOGADRO_RENDERING_GROUPNODE_H
8
9 #include "node.h"
10
11 #include <list>
12
13 namespace Avogadro {
14 namespace Rendering {
15
16 /**
17 * @class GroupNode groupnode.h <avogadro/rendering/groupnode.h>
18 * @brief The GroupNode class provides common API for grouping child nodes.
19 * @author Marcus D. Hanwell
20 *
21 * The GroupNode may be used to group items together, but for most other
22 * purposes a more derived Node type would be the correct choice.
23 */
24
25 class AVOGADRORENDERING_EXPORT GroupNode : public Node
26 {
27 public:
28 enum NodeType
29 {
30 ALL = 0,
31 NONE = -1,
32 UI = 1,
33 GEOMETRY = 2,
34 };
35 struct NodeInfo
36 {
37 NodeInfo() : ui(NONE), node(nullptr) {}
38 NodeInfo(Node* n, NodeType u) : ui(u), node(n) {}
39 NodeType ui;
40 Node* node;
41 };
42
43 explicit GroupNode(GroupNode* parent = nullptr);
44 ~GroupNode() override;
45
46 /**
47 * Accept a visit from our friendly visitor.
48 */
49 void accept(Visitor&) override;
50
51 /**
52 * @brief Add a child node, this node will have its parent set and will be
53 * deleted by this node upon destruction.
54 * @param node Node to be added.
55 */
56 void addChild(Node* node, NodeType ui = NodeType::GEOMETRY);
57 /**
58 * @brief Add a child node, this node will have its parent set and will be
59 * deleted by this node upon destruction.
60 * @param node Node to be added.
61 */
62 void addUIChild(Node* node);
63
64 /**
65 * @brief Remove child node, this node will no longer be deleted.
66 * @param node Node to be removed.
67 * @return True if the node was removed, false if it was not found.
68 */
69 bool removeChild(Node* node);
70
71 /**
72 * @brief Get the child Node at the specified index.
73 * @param index The index of the child.
74 * @return A pointer to the child node, or nullptr if the index is out of
75 * range.
76 * time complexity: O(n)
77 */
78 Node* child(size_t index);
79
80 /**
81 * @brief check if the Node exists in this GroupNode.
82 * @param node Node to search.
83 * @return True if the node was found, false otherwise.
84 */
85 bool hasChild(Node* node) const;
86
87 /**
88 * @return The number of child nodes contained by the GroupNode.
89 */
90 size_t childCount() const { return m_children.size(); }
91
92 /**
93 * @brief Get a reference to the child nodes list.
94 */
95 std::list<NodeInfo>& children() { return m_children; }
96 const std::list<NodeInfo>& children() const { return m_children; }
97
98 /**
99 * @brief Remove all non UI-children.
100 */
101 void clear();
102
103 /**
104 * @brief Remove all UI-children.
105 */
106 void clearUI();
107
108 protected:
109 void clear(NodeType type);
110 std::list<NodeInfo> m_children;
111 };
112
113 } // End namespace Rendering
114 } // End namespace Avogadro
115
116 #endif // AVOGADRO_RENDERING_GROUPNODE_H