GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
PropertyFolderOrProperty.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2023 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "GDCore/Serialization/SerializerElement.h"
12 #include "GDCore/String.h"
13 #include "GDCore/Project/QuickCustomization.h"
14 
15 namespace gd {
16 class Project;
17 class NamedPropertyDescriptor;
18 class SerializerElement;
19 class PropertiesContainer;
20 } // namespace gd
21 
22 namespace gd {
23 
30 class GD_CORE_API PropertyFolderOrProperty {
31  public:
37 
38  virtual ~PropertyFolderOrProperty();
39 
44  PropertyFolderOrProperty* parent_ = nullptr);
45 
50  PropertyFolderOrProperty* parent_ = nullptr);
51 
55  gd::NamedPropertyDescriptor& GetProperty() const { return *property; }
56 
60  bool IsFolder() const { return !folderName.empty(); }
61 
65  const gd::String& GetFolderName() const { return folderName; }
66 
71  void SetFolderName(const gd::String& name);
72 
77  bool HasPropertyNamed(const gd::String& name);
78 
83  PropertyFolderOrProperty& GetPropertyNamed(const gd::String& name);
84 
89  std::size_t GetChildrenCount() const {
90  if (IsFolder()) return children.size();
91  return 0;
92  }
93 
97  PropertyFolderOrProperty& GetChildAt(std::size_t index);
98 
102  const PropertyFolderOrProperty& GetChildAt(std::size_t index) const;
103 
109  PropertyFolderOrProperty& GetPropertyChild(const gd::String& name);
110 
115  PropertyFolderOrProperty& GetOrCreateChildFolder(const gd::String& name);
116 
122  if (parent == nullptr) {
123  return badPropertyFolderOrProperty;
124  }
125  return *parent;
126  };
127 
132  bool IsRootFolder() { return !property && !parent; }
133 
137  void MoveChild(std::size_t oldIndex, std::size_t newIndex);
138 
143  void RemoveFolderChild(const PropertyFolderOrProperty& childToRemove);
144 
149  void RemoveRecursivelyPropertyNamed(const gd::String& name);
150 
154  void Clear();
155 
160  void InsertProperty(gd::NamedPropertyDescriptor* insertedProperty,
161  std::size_t position = (size_t)-1);
162 
167  PropertyFolderOrProperty& InsertNewFolder(const gd::String& newFolderName,
168  std::size_t position);
169 
174  bool IsADescendantOf(const PropertyFolderOrProperty& otherPropertyFolderOrProperty);
175 
180  std::size_t GetChildPosition(const PropertyFolderOrProperty& child) const;
181 
186  void MovePropertyFolderOrPropertyToAnotherFolder(
187  gd::PropertyFolderOrProperty& propertyFolderOrProperty,
188  gd::PropertyFolderOrProperty& newParentFolder,
189  std::size_t newPosition);
190 
195 
198  void SerializeTo(SerializerElement& element) const;
199 
203  void UnserializeFrom(gd::Project& project,
204  const SerializerElement& element,
205  PropertiesContainer& propertiesContainer);
207 
208  void UpdateGroupNameOfAllProperties();
209 
210  private:
211  void SetGroupNameOfAllProperties(const gd::String& groupName);
212  const gd::String &GetGroupName();
213 
214  static gd::PropertyFolderOrProperty badPropertyFolderOrProperty;
215  static gd::String emptyGroupName;
216 
218  parent = nullptr; // nullptr if root folder, points to the parent folder otherwise.
219 
220  // Representing a property:
221  gd::NamedPropertyDescriptor* property; // nullptr if folderName is set.
222 
223  // or representing a folder:
224  gd::String folderName; // Empty if property is set.
225 
226  std::vector<std::unique_ptr<PropertyFolderOrProperty>>
227  children; // Folder children.
228 };
229 
230 } // namespace gd
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
A container of properties, used for custom behaviors, custom objects, extensions.....
Definition: PropertiesContainer.h:17
Class representing a folder structure in order to organize properties in folders (to be used with a P...
Definition: PropertyFolderOrProperty.h:30
PropertyFolderOrProperty & GetParent()
Returns the parent of the instance. If the instance has no parent (root folder), the null property is...
Definition: PropertyFolderOrProperty.h:121
bool IsRootFolder()
Returns true if the instance is a root folder (that's to say it has no parent).
Definition: PropertyFolderOrProperty.h:132
const gd::String & GetFolderName() const
Returns the name of the folder.
Definition: PropertyFolderOrProperty.h:65
bool IsFolder() const
Returns true if the instance represents a folder.
Definition: PropertyFolderOrProperty.h:60
std::size_t GetChildrenCount() const
Returns the number of children. Returns 0 if the instance represents a property.
Definition: PropertyFolderOrProperty.h:89
gd::NamedPropertyDescriptor & GetProperty() const
Returns the property behind the instance.
Definition: PropertyFolderOrProperty.h:55
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24