-
Notifications
You must be signed in to change notification settings - Fork 155
How to create new types of properties
You can look at any particular property implementation to learn how to create new properties. For example see PropertyBool.h and PropertyBool.cpp.
Here I will briefly describe minimal requirements and helpful classes for new property classes.
Any property class must be derived from QtnProperty class. Usually I make three classes for one type (bool in case of boolean properties), see PropertyBool.h file mentioned above.
The first class QtnPropertyBool stores bool value by itself, the second one QtnPropertyBoolCallback uses callbacks to retrieve and store bool value. And finally QtnPropertyBoolBase as base class for two previous classes. You are free to develop only one class QtnPropertyFoo that stores value of Foo type if you are not going to use callback properties.
If you are developing property that holds single value, you can use QtnSinglePropertyBase helper class as a base class. QtnSinglePropertyBase implements value/setValue functions and some other useful stuff. You only have to override it's valueImpl and setValueImpl abstract functions to decide where and how retrieve or store property value. For example see implementation of the QtnPropertyBoolBase class:
class QTN_PE_CORE_EXPORT QtnPropertyBoolBase: public QtnSinglePropertyBase<bool>
{
Q_OBJECT
QtnPropertyBoolBase(const QtnPropertyBoolBase& other) Q_DECL_EQ_DELETE;
public:
explicit QtnPropertyBoolBase(QObject *parent)
: QtnSinglePropertyBase<bool>(parent)
{
}
protected:
// string conversion implementation
bool fromStrImpl(const QString& str) override;
bool toStrImpl(QString& str) const override;
P_PROPERTY_DECL_MEMBER_OPERATORS(QtnPropertyBoolBase)
};
P_PROPERTY_DECL_ALL_OPERATORS(QtnPropertyBoolBase, bool)
Another useful class is QtnSinglePropertyValue. It used to