GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
PropertyDescriptor.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-present Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #ifndef GDCORE_PROPERTYDESCRIPTOR
7 #define GDCORE_PROPERTYDESCRIPTOR
8 #include <vector>
9 
10 #include "GDCore/Project/MeasurementUnit.h"
11 #include "GDCore/Project/QuickCustomization.h"
12 #include "GDCore/String.h"
13 
14 namespace gd {
15 class SerializerElement;
16 }
17 
18 namespace gd {
19 
20 class GD_CORE_API PropertyDescriptorChoice {
21  public:
22  PropertyDescriptorChoice(const gd::String& value, const gd::String& label)
23  : value(value), label(label) {}
24 
25  const gd::String& GetValue() const { return value; }
26  const gd::String& GetLabel() const { return label; }
27 
28  private:
29  gd::String value;
30  gd::String label;
31 };
32 
38 class GD_CORE_API PropertyDescriptor {
39  public:
47  : currentValue(propertyValue),
48  type("string"),
49  label(""),
50  hidden(false),
51  deprecated(false),
52  advanced(false),
53  hasImpactOnOtherProperties(false),
54  measurementUnit(gd::MeasurementUnit::GetUndefined()),
55  quickCustomizationVisibility(QuickCustomization::Visibility::Default) {}
56 
61  : hidden(false),
62  deprecated(false),
63  advanced(false),
64  hasImpactOnOtherProperties(false),
65  measurementUnit(gd::MeasurementUnit::GetUndefined()),
66  quickCustomizationVisibility(QuickCustomization::Visibility::Default) {
67  };
68 
72  virtual ~PropertyDescriptor();
73 
78  currentValue = value;
79  return *this;
80  }
81 
90  type = type_;
91  return *this;
92  }
93 
98  label = label_;
99  return *this;
100  }
101 
106  description = description_;
107  return *this;
108  }
109 
115  group = group_;
116  return *this;
117  }
118 
119  PropertyDescriptor& ClearChoices() {
120  choices.clear();
121  return *this;
122  }
123 
124  PropertyDescriptor& AddChoice(const gd::String& value,
125  const gd::String& label) {
126  choices.push_back(PropertyDescriptorChoice(value, label));
127  return *this;
128  }
129 
133  PropertyDescriptor& SetExtraInfo(const std::vector<gd::String>& info) {
134  extraInformation = info;
135  return *this;
136  }
137 
146  extraInformation.push_back(info);
147  return *this;
148  }
149 
154  const gd::MeasurementUnit& measurementUnit_) {
155  measurementUnit = measurementUnit_;
156  return *this;
157  }
158 
159  const gd::String& GetValue() const { return currentValue; }
160  const gd::String& GetType() const { return type; }
161  const gd::String& GetLabel() const { return label; }
162  const gd::String& GetDescription() const { return description; }
163  const gd::String& GetGroup() const { return group; }
164  const gd::MeasurementUnit& GetMeasurementUnit() const {
165  return measurementUnit;
166  }
167 
168  const std::vector<gd::String>& GetExtraInfo() const {
169  return extraInformation;
170  }
171 
172  std::vector<gd::String>& GetExtraInfo() { return extraInformation; }
173 
174  const std::vector<PropertyDescriptorChoice>& GetChoices() const {
175  return choices;
176  }
177 
181  PropertyDescriptor& SetHidden(bool enable = true) {
182  hidden = enable;
183  return *this;
184  }
185 
189  bool IsHidden() const { return hidden; }
190 
194  PropertyDescriptor& SetDeprecated(bool enable = true) {
195  deprecated = enable;
196  return *this;
197  }
198 
202  bool IsDeprecated() const { return deprecated; }
203 
207  PropertyDescriptor& SetAdvanced(bool enable = true) {
208  advanced = enable;
209  return *this;
210  }
211 
215  bool IsAdvanced() const { return advanced; }
216 
221  bool HasImpactOnOtherProperties() const { return hasImpactOnOtherProperties; }
222 
228  hasImpactOnOtherProperties = enable;
229  return *this;
230  }
231 
232  QuickCustomization::Visibility GetQuickCustomizationVisibility() const {
233  return quickCustomizationVisibility;
234  }
235 
236  PropertyDescriptor& SetQuickCustomizationVisibility(
237  QuickCustomization::Visibility visibility) {
238  quickCustomizationVisibility = visibility;
239  return *this;
240  }
241 
245 
248  virtual void SerializeTo(SerializerElement& element) const;
249 
253  virtual void UnserializeFrom(const SerializerElement& element);
254 
258  virtual void SerializeValuesTo(SerializerElement& element) const;
259 
263  virtual void UnserializeValuesFrom(const SerializerElement& element);
265 
266  private:
267  gd::String currentValue;
268  gd::String
269  type;
271  gd::String label; //< The user-friendly property name
272  gd::String description; //< The user-friendly property description
273  gd::String group; //< The user-friendly property group
274  std::vector<PropertyDescriptorChoice>
275  choices; //< The optional choices for the property.
276  std::vector<gd::String>
277  extraInformation;
279  bool hidden;
280  bool deprecated;
281  bool advanced;
282  bool hasImpactOnOtherProperties;
284  measurementUnit; //< The unit of measurement of the property vale.
285  QuickCustomization::Visibility quickCustomizationVisibility;
286 };
287 
288 } // namespace gd
289 
290 #endif
A unit of measurement.
Definition: MeasurementUnit.h:24
Definition: PropertyDescriptor.h:20
Used to describe a property shown in a property grid.
Definition: PropertyDescriptor.h:38
PropertyDescriptor & SetValue(gd::String value)
Change the value displayed in the property grid.
Definition: PropertyDescriptor.h:77
bool IsHidden() const
Check if the property should be shown or hidden in the editor.
Definition: PropertyDescriptor.h:189
PropertyDescriptor & SetHasImpactOnOtherProperties(bool enable)
Set if the property has impact on other properties - which means a change must re-render other proper...
Definition: PropertyDescriptor.h:227
bool IsDeprecated() const
Check if the property is deprecated.
Definition: PropertyDescriptor.h:202
PropertyDescriptor & SetHidden(bool enable=true)
Set if the property should be shown or hidden in the editor.
Definition: PropertyDescriptor.h:181
PropertyDescriptor & SetExtraInfo(const std::vector< gd::String > &info)
Set and replace the additional information for the property.
Definition: PropertyDescriptor.h:133
PropertyDescriptor & SetGroup(gd::String group_)
Change the group where this property is displayed to the user, if any.
Definition: PropertyDescriptor.h:114
PropertyDescriptor & SetDeprecated(bool enable=true)
Set if the property is deprecated.
Definition: PropertyDescriptor.h:194
bool HasImpactOnOtherProperties() const
Check if the property has impact on other properties - which means a change must re-render other prop...
Definition: PropertyDescriptor.h:221
bool IsAdvanced() const
Check if the property is marked as advanced.
Definition: PropertyDescriptor.h:215
PropertyDescriptor()
Empty constructor creating an empty property to be displayed.
Definition: PropertyDescriptor.h:60
PropertyDescriptor & SetMeasurementUnit(const gd::MeasurementUnit &measurementUnit_)
Change the unit of measurement of the property value.
Definition: PropertyDescriptor.h:153
PropertyDescriptor & SetAdvanced(bool enable=true)
Set if the property is marked as advanced.
Definition: PropertyDescriptor.h:207
PropertyDescriptor(gd::String propertyValue)
Create a property being a simple gd::String with the specified value.
Definition: PropertyDescriptor.h:46
PropertyDescriptor & SetType(gd::String type_)
Change the type of the value displayed in the property grid.
Definition: PropertyDescriptor.h:89
PropertyDescriptor & AddExtraInfo(const gd::String &info)
Add an information about the property.
Definition: PropertyDescriptor.h:145
PropertyDescriptor & SetDescription(gd::String description_)
Change the description displayed to the user, if any.
Definition: PropertyDescriptor.h:105
PropertyDescriptor & SetLabel(gd::String label_)
Change the label displayed in the property grid.
Definition: PropertyDescriptor.h:97
Definition: QuickCustomization.h:6
Visibility
Definition: QuickCustomization.h:8
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24