Seamly2D
Code documentation
vpropertyset.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vpropertyset.h
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #ifndef VPROPERTYSET_H
22 #define VPROPERTYSET_H
23 
24 #include <qcompilerdetection.h>
25 #include <QMap>
26 #include <QString>
27 #include <QtGlobal>
28 
29 #include "vproperty.h"
30 
31 template <class Key, class T> class QMap;
32 template <typename T> class QList;
33 
34 namespace VPE
35 {
36 
37 // Forward declaration
38 class VPropertySetPrivate;
39 
40 // todo: better description
41 //! \brief VPropertySet is a simple class for managing a set of properties.
42 //! If you don't need all the Model-functionality, chose this class
43 //! over VPropertyModel.
44 //!
45 
46 //!
48 {
49 public:
50  //! Default constructor, creating an empty property set
51  VPropertySet();
52 
53  //! Destructor
54  virtual ~VPropertySet();
55 
56  //! Adds the property to the model and attaches it to the parentid. Note that if the property has a parent which is
57  //! not part of this set, it will be removed from that parent.
58  //! \param property The property to add
59  //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added.
60  //! If the property was filed under another ID before, that will no longer be valid.
61  //! \param parentid The property's ID to which to add the property as child. Pass empty string to add it to the
62  //! root properties.
63  virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid);
64 
65  //! Adds the property to the model and attaches it to the parent property.
66  //! \param property The property to add
67  //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added.
68  //! If the property was filed under another ID before, that will no longer be valid.
69  //! \param parent_property The property to which to add the property as child. Pass NULL to add it to the root
70  //! properties.
71  virtual bool addProperty(VProperty* property, const QString& id, VProperty* parent_property = nullptr);
72 
73  //! Checks whether a property belongs to this set and returns the result
74  //! \param property The property to check for
75  //! \return True, if the property is part of this set, false otherwise
76  virtual bool hasProperty(VProperty* property) const;
77 
78  //! Gets a property by it's ID
79  virtual VProperty* getProperty(const QString& id) const;
80 
81  //! Removes a property from the set and returns it
82  virtual VProperty* takeProperty(const QString& id);
83 
84  //! Removes a property from the set and deletes it
85  virtual void removeProperty(const QString& id);
86 
87  //! Removes a property from the set and deletes it optionally
88  virtual void removeProperty(VProperty* prop, bool delete_property = true);
89 
90  //! Returns the number of properties with in ID that are directly accessable by getProperty()
91  virtual int count() const;
92 
93  //! Clears the set and (optionally) deletes all properties
94  //! \param delete_properties Set this to false, if you don't want the properties to get deleted.
95  virtual void clear(bool delete_properties = true);
96 
97  //! Returns the ID of the property within the set
98  //! The concept of property IDs is, that the object that manages the properties
99  //! and not the properties themselves handle the IDs.
100  //! \param prop The property of which to get the ID.
101  //! \param look_for_parent_id If this is TRUE and the property has no ID, all the parent properties are checked.
102  //! \return Returns the ID under which the property is stored within the set
103  virtual QString getPropertyID(const VProperty* prop, bool look_for_parent_id = true) const;
104 
105  //! Returns a const reference to the map of properties
107 
108  //! Returns a const reference to the list of root properties
109  const QList<VProperty*>& getRootProperties() const;
110 
111  //! Returns the root property in a certain row
112  //! \param row The root row in which to look for the root property
113  VProperty* getRootProperty(int row) const;
114 
115  //! Returns the number of independent properties
116  int getRootPropertyCount() const;
117 
118  //! Clones the property set
119  Q_REQUIRED_RESULT VPropertySet* clone() const;
120 
121 protected:
122  //! Checks whether a property belongs to this set and returns the result
123  //! \param property The property to check for
124  //! \param parent The parent property from which to start checking all the children
125  //! \return True, if the property is part of this set, false otherwise
126  virtual bool hasProperty(VProperty* property, VProperty* parent) const;
127 
128  //! Clones a property into another property set
129  void cloneProperty(VProperty* property_to_clone, VProperty* parent_property, VPropertySet* output_set) const;
130 
131  //! Recursivly removes a property's child properties from the set, but not from the parent
132  virtual void removePropertyFromSet(VProperty* prop);
133 
134  //! The data
136 private:
137  Q_DISABLE_COPY(VPropertySet)
138 };
139 
140 }
141 
142 #endif // VPROPERTYMODEL_H
VPropertySet is a simple class for managing a set of properties. If you don't need all the Model-func...
Definition: vpropertyset.h:48
VPropertySetPrivate * d_ptr
The data.
Definition: vpropertyset.h:135
virtual void removeProperty(const QString &id)
Removes a property from the set and deletes it.
Q_REQUIRED_RESULT VPropertySet * clone() const
Clones the property set.
virtual void clear(bool delete_properties=true)
Clears the set and (optionally) deletes all properties.
virtual ~VPropertySet()
Destructor.
VProperty * getRootProperty(int row) const
Returns the root property in a certain row.
virtual bool addProperty(VProperty *property, const QString &id, const QString &parentid)
Adds the property to the model and attaches it to the parentid. Note that if the property has a paren...
virtual int count() const
Returns the number of properties with in ID that are directly accessable by getProperty()
VPropertySet()
Default constructor, creating an empty property set.
virtual QString getPropertyID(const VProperty *prop, bool look_for_parent_id=true) const
Returns the ID of the property within the set The concept of property IDs is, that the object that ma...
virtual void removePropertyFromSet(VProperty *prop)
Recursivly removes a property's child properties from the set, but not from the parent.
virtual bool hasProperty(VProperty *property) const
Checks whether a property belongs to this set and returns the result.
virtual VProperty * getProperty(const QString &id) const
Gets a property by it's ID.
void cloneProperty(VProperty *property_to_clone, VProperty *parent_property, VPropertySet *output_set) const
Clones a property into another property set.
int getRootPropertyCount() const
Returns the number of independent properties.
const QMap< QString, VProperty * > & getPropertiesMap() const
Returns a const reference to the map of properties.
const QList< VProperty * > & getRootProperties() const
Returns a const reference to the list of root properties.
virtual VProperty * takeProperty(const QString &id)
Removes a property from the set and returns it.