OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
PropertyBase.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/Flags.h"
10#include "OTCore/Serializable.h"
13
14// std header
15#include <map>
16#include <list>
17#include <string>
18
19#pragma warning(disable:4251)
20
21namespace ot {
22
26 public:
30 NoFlags = 0x0000,
31 IsReadOnly = 0x0001,
32 IsProtected = 0x0002,
33 IsHidden = 0x0004,
34 HasMultipleValues = 0x0008,
35 HasInputError = 0x0010,
36 IsDeletable = 0x0020,
37 AllowCustomValues = 0x1000,
38 AllowMultiselection = 0x2000
39 };
40
44
46 static std::string toString(PropertyFlag _flag);
47
49 static PropertyFlag stringToFlag(const std::string& _flag);
50
52 static std::list<std::string> toStringList(PropertyFlags _flags);
53
55 static PropertyFlags stringListToFlags(const std::list<std::string>& _flags);
56
59 PropertyBase(PropertyFlags _flags = PropertyFlags(NoFlags));
60
64 PropertyBase(const std::string& _name, PropertyFlags _flags = PropertyFlags(NoFlags));
65
68 PropertyBase(const PropertyBase& _other);
69
71 virtual ~PropertyBase() {};
72
75 PropertyBase& operator = (const PropertyBase& _other);
76
77 // ###########################################################################################################################################################################################################################################################################################################################
78
79 // Base class functions
80
84 virtual void addToJsonObject(ot::JsonValue& _object, ot::JsonAllocator& _allocator) const override;
85
89 virtual void setFromJsonObject(const ot::ConstJsonObject& _object) override;
90
91 // ###########################################################################################################################################################################################################################################################################################################################
92
93 // Setter / Getter
94
95 void setPropertyName(const std::string& _name) { m_name = _name; };
96 const std::string& getPropertyName(void) const { return m_name; };
97
100 void setPropertyTitle(const std::string& _title) { m_title = _title; };
101
104 const std::string& getPropertyTitle(void) const { return (m_title.empty() ? m_name : m_title); };
105
106 void setPropertyTip(const std::string& _tip) { m_tip = _tip; };
107 std::string& getPropertyTip(void) { return m_tip; };
108 const std::string& getPropertyTip(void) const { return m_tip; };
109
110 void setPropertyFlag(PropertyFlag _flag, bool _active = true) { m_flags.setFlag(_flag, _active); };
111 void setPropertyFlags(PropertyFlags _flags) { m_flags = _flags; };
112 PropertyFlags& getPropertyFlags(void) { return m_flags; };
113 const PropertyFlags& getPropertyFlags(void) const { return m_flags; };
114
115 void setSpecialType(const std::string& _type) { m_specialType = _type; };
116 const std::string& getSpecialType(void) const { return m_specialType; };
117
118 void addAdditionalPropertyData(const std::string& _key, const std::string& _data) { m_data.insert_or_assign(_key, _data); };
119 void setAdditionalPropertyData(const std::map<std::string, std::string>& _data) { m_data = _data; };
120 const std::map<std::string, std::string>& getAllAdditionalPropertyData(void) const { return m_data; };
121 std::string getAdditionalPropertyData(const std::string& _key) const;
122
123 private:
124 std::string m_tip;
125 std::string m_name;
126 std::string m_title;
127 std::string m_specialType;
128 std::map<std::string, std::string> m_data;
129 PropertyFlags m_flags;
130 };
131
132}
133
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:129
This file contains defines that may be used simplyfy class creation.
#define OT_GUI_API_EXPORT
Definition OTGuiAPIExport.h:9
The Flags class is a wrapper around a enum that allows bitwise operations (flags)....
Definition Flags.h:214
The PropertyBase class is used to hold general Property information.
Definition PropertyBase.h:25
void addAdditionalPropertyData(const std::string &_key, const std::string &_data)
Definition PropertyBase.h:118
virtual ~PropertyBase()
Destructor.
Definition PropertyBase.h:71
void setPropertyTip(const std::string &_tip)
Definition PropertyBase.h:106
const std::map< std::string, std::string > & getAllAdditionalPropertyData(void) const
Definition PropertyBase.h:120
std::string & getPropertyTip(void)
Definition PropertyBase.h:107
void setPropertyTitle(const std::string &_title)
Set the property title If no title set the name will be used as title.
Definition PropertyBase.h:100
PropertyFlag
The PropertyFlag enum contains different settings for properties.
Definition PropertyBase.h:29
void setPropertyFlags(PropertyFlags _flags)
Definition PropertyBase.h:111
const std::string & getPropertyTip(void) const
Definition PropertyBase.h:108
const std::string & getPropertyTitle(void) const
Property title If no title set the name will be used as title.
Definition PropertyBase.h:104
void setPropertyName(const std::string &_name)
Definition PropertyBase.h:95
const std::string & getSpecialType(void) const
Definition PropertyBase.h:116
void setPropertyFlag(PropertyFlag _flag, bool _active=true)
Definition PropertyBase.h:110
void setSpecialType(const std::string &_type)
Definition PropertyBase.h:115
Flags< PropertyFlag > PropertyFlags
The PropertyFlag enum contains different settings for properties.
Definition PropertyBase.h:43
void setAdditionalPropertyData(const std::map< std::string, std::string > &_data)
Definition PropertyBase.h:119
const std::string & getPropertyName(void) const
Definition PropertyBase.h:96
PropertyFlags & getPropertyFlags(void)
Definition PropertyBase.h:112
const PropertyFlags & getPropertyFlags(void) const
Definition PropertyBase.h:113
The Serializable class is the default interface of serializable objects.
Definition Serializable.h:17
Definition Connector.h:8
OT_GUI_API_EXPORT std::list< std::string > toStringList(const LockTypeFlags &_flags)
Definition GuiTypes.cpp:426
rapidjson::Value JsonValue
Writable JSON value.
Definition JSON.h:27
rapidjson::GenericObject< true, rapidjson::GenericValue< rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > > > ConstJsonObject
Read only JSON Object.
Definition JSON.h:35
OT_GUI_API_EXPORT std::string toString(ColorStyleName _colorStyleName)
Definition ColorStyleTypes.cpp:10
rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > JsonAllocator
Allocator used for writing to JSON values.
Definition JSON.h:30