BPS C++ API  2.24.4
bpspropertyobject.h
Go to the documentation of this file.
1 
4 #ifndef BPSPROPERTYOBJECT_H
5 #define BPSPROPERTYOBJECT_H
6 
7 #include "bpscore_global.h"
8 #include <QObject>
9 #include <QStringList>
10 #include <QVariant>
11 
21 {
22  Q_OBJECT
24 
25 public:
26 
31  BpsPropertyObject(QObject *aParent = nullptr);
32 
38  BpsPropertyObject(const QString& aName, QObject *aParent = nullptr);
39 
45 
46  virtual ~BpsPropertyObject();
47 
52  void clear();
53 
60 
69  void addProperty(const char* aName, const QVariant& aValue);
70 
77  bool hasProperty(const char* aName) const;
78 
98  void addAttribute(const char* aProperty, const char* aAttribute, const QVariant& aValue = true);
99 
106  QVariant attribute(const char* aProperty, const char* aAttribute) const;
107 
113  QList<QByteArray> attributeNames(const char* aProperty) const;
114 
120 
125 
129  int childCount() const;
130 
136  BpsPropertyObject* childAt(int aIndex) const;
137 
143  int childIndex(BpsPropertyObject* aChild) const;
144 
150  void insertChild(int aIndex, BpsPropertyObject* aChild);
151 
157 
164 
171 
177  void moveChild(int aOldIndex, int aNewIndex);
178 
182  void emitValues();
183 
201  QString propertyAsString(const char* aName) const;
202 
206  bool isModified() const;
207 
212  bool isValid(BpsPropertyObject* aObject) const;
213 
220  QString makeXml(const QString& aDocType, bool aFormat = false) const;
221 
227  void loadXml(const QString& aDocType, const QString& aXml);
228 
229 public slots:
230 
241  virtual bool setProperty(const char* aName, const QVariant& aValue);
242 
255  bool setPropertyAsString(const char* aName, const QString& aValue);
256 
261  void setModified(bool aModified = true);
262 
263 signals:
264 
271 
278  void propertyChanged(const QByteArray& aName, const QVariant& aNewValue, const QVariant& aOldValue);
279 
284  void modifiedChanged(bool aModified);
285 
291  void childInserted(int aIndex, BpsPropertyObject* aChild);
292 
299  void childRemoved(int aIndex, BpsPropertyObject* aChild);
300 
306  void childMoved(int aOldIndex, int aNewIndex);
307 
308 protected:
309 
317  virtual BpsPropertyObject* xmlCreateObject(const QString& aTagName, int aLevel) const;
318 
324  virtual QString xmlTagName(int aLevel) const;
325 
326 };
327 
328 #endif // BPSPROPERTYOBJECT_H
Public include file for BPS CORE library macros.
#define BPSCORE_EXPORT
Declare class to be an import from the shared library.
Definition: bpscore_global.h:22
#define BPS_PRIVATE(Class)
Declare pointer to private object in a public class.
Definition: bpsglobals.h:102
This class is a generic editable object.
Definition: bpspropertyobject.h:21
BpsPropertyObject(QObject *aParent=nullptr)
Constructor for BpsPropertyObject.
BpsPropertyObject(const QString &aName, QObject *aParent=nullptr)
Constructor for BpsPropertyObject.
void clear()
Removes all dynamic properties and deletes all children.
void addAttribute(const char *aProperty, const char *aAttribute, const QVariant &aValue=true)
Adds or remove an attribute to/from an existing property.
void appendChild(BpsPropertyObject *aChild)
Appends a child to the end of the children list.
BpsPropertyObject & operator=(const BpsPropertyObject &aOther)
Assignment operator.
void insertChild(int aIndex, BpsPropertyObject *aChild)
Insert a child at the specified position in the children list.
void childMoved(int aOldIndex, int aNewIndex)
This signal is emitted when a child is moved.
void addProperty(const char *aName, const QVariant &aValue)
Add or remove a property.
BpsPropertyObject * parent() const
Get the parent of this object.
void modifiedChanged(bool aModified)
This signal is emitted when the modification status is changed.
virtual QString xmlTagName(int aLevel) const
Define a XML tag for the element of the level.
void loadXml(const QString &aDocType, const QString &aXml)
Load the object from XML.
int childCount() const
bool isValid(BpsPropertyObject *aObject) const
void propertyChanged(const QByteArray &aName, const QVariant &aNewValue, const QVariant &aOldValue)
This signal is emitted whenever a property changes, or after emitValues().
QVariant attribute(const char *aProperty, const char *aAttribute) const
Get the attributes value.
void setModified(bool aModified=true)
Set or clear the modification status.
bool hasProperty(const char *aName) const
Check if a property with given name has been added by BpsPropertyObject::addProperty().
BpsPropertyObject * removeChild(BpsPropertyObject *aChild)
Remove a child.
QList< QByteArray > attributeNames(const char *aProperty) const
Get a list of all attributes defined for a certain property.
BpsPropertyObject * removeChild(int aIndex)
Remove a child.
int childIndex(BpsPropertyObject *aChild) const
Get index of a child.
bool setPropertyAsString(const char *aName, const QString &aValue)
Set the value of a property by converting from a string.
void emitValues()
Emits valueChanged() for all properties.
QString makeXml(const QString &aDocType, bool aFormat=false) const
Creates XML to save the object and its children.
void childInserted(int aIndex, BpsPropertyObject *aChild)
This signal is emitted when a new child is inserted.
bool isModified() const
BpsPropertyObject * childAt(int aIndex) const
Get pointer to indexed child element.
BpsPropertyObject(const BpsPropertyObject &aOther)
Copy-constructor for BpsPropertyObject.
virtual bool setProperty(const char *aName, const QVariant &aValue)
Set the value of a property.
QList< BpsPropertyObject * > children() const
void moveChild(int aOldIndex, int aNewIndex)
Move a child in the list.
void childRemoved(int aIndex, BpsPropertyObject *aChild)
This signal is emitted when a child is removed.
virtual BpsPropertyObject * xmlCreateObject(const QString &aTagName, int aLevel) const
Create a new object while processing loadXml().
void objectChanged()
This signal is emitted whenever anything in the object or any of its descendants (children,...
QString propertyAsString(const char *aName) const
Gets a string representation of the value.