31 #include <QDataStream> 32 #include <QTextStream> 36 #include <QStringList> 71 virtual QString objectKind()
const = 0;
97 virtual bool setProperty(
const QString& pname,
const QVariant& value) = 0;
155 virtual bool setSpecification(
const QByteArray& data) = 0;
183 if (val < 0 || val >= enumVals.
size()) {
184 klfWarning(
"Invalid value: "<<val<<
" for enum values "<<enumVals) ;
187 return enumVals[val];
323 virtual bool hasPropertyValue(
const QString& propName)
const;
331 virtual bool hasPropertyValue(
int propId)
const;
424 void setAllPropertiesFromByteArray(
const QByteArray& data);
458 ToStringUseHtml = 0x0001,
459 ToStringUseHtmlDiv = 0x0002,
460 ToStringQuoteValues = 0x0004,
461 ToStringAllProperties = 0x0008
467 virtual QString toString(uint toStringFlags = 0)
const;
472 int propertyMaxId()
const;
477 bool propertyIdRegistered(
int propId)
const;
482 bool propertyNameRegistered(
const QString& propertyName)
const;
487 int propertyIdForName(
const QString& propertyName)
const;
492 QString propertyNameForId(
int propId)
const;
522 virtual void propertyValueChanged(
int propId,
const QVariant& oldValue,
530 virtual bool doSetProperty(
const QString& propname,
const QVariant& value);
536 virtual bool doSetProperty(
int propId,
const QVariant& value);
543 virtual int doLoadProperty(
const QString& propname,
const QVariant& value);
548 void registerBuiltInProperty(
int propId,
const QString& propName)
const;
554 int registerProperty(
const QString& propertyName)
const;
605 static void registerBuiltInProperty(
const QString& propNameSpace,
int propId,
621 static int registerProperty(
const QString& propNameSpace,
const QString& propertyName);
630 static int propertyMaxId(
const QString& propNameSpace);
639 static bool propertyIdRegistered(
const QString& propNameSpace,
int propId);
648 static bool propertyNameRegistered(
const QString& propNameSpace,
const QString& propertyName);
662 static int propertyIdForName(
const QString& propNameSpace,
const QString& propertyName);
671 static QString propertyNameForId(
const QString& propNameSpace,
int propId);
715 static int internalRegisterProperty(
const QString& propNameSpace,
const QString& name,
765 : pPObj(pobj), pPropId(propId)
769 : pPObj(other.pPObj), pPropId(other.pPropId)
779 : pPObj(pobj), pPropId(builtInPropId)
790 : pPObj(pobj), pPropId(builtInPropId)
798 return variantValue();
804 const T operator ()()
const 810 pPObj->setProperty(pPropId, v);
815 pPObj->setProperty(pPropId, QVariant::fromValue<T>(value));
821 return this->operator=(value.
value());
826 return pPObj->property(pPropId);
834 template<
class VariantType>
837 QVariant v = pPObj->property(pPropId);
838 return T(v.
value<VariantType>());
841 template<
class VariantType>
842 void set(
const T& value)
844 pPObj->setProperty(pPropId, QVariant::fromValue<VariantType>(value));
846 void set(
const T& value)
851 template<
class VariantType>
854 return (value<VariantType>() == other.
value<VariantType>());
858 return equals<T>(other);
863 return (value() == val);
867 return (value() == other.
value());
871 void init(
const QString& pname)
873 if (!pPObj->propertyIdRegistered(pPropId)) {
875 registerbuiltinprop(pPObj, pPropId, pname);
879 qPrintable(propertyNameSpace(pPObj))<<
": Built-In property ID "<<pPropId
880 <<
" does not have name "<<pname<<
" !",
888 inline QDebug & operator<<(QDebug & str, const KLFPObjPropRef<T> & p)
902 doregister(Register, name);
907 return doregister(Query, name);
911 enum Action { Query, Register };
912 static int doregister(Action action,
const char * name)
924 fprintf(stderr,
"ERRORORROOERROR: %s: what is your action?? `%d' for name `%s'\n",
936 #define KLF_DECLARE_POBJ_TYPE(TYPE) \ 937 static KLFPObjRegisteredType __klf_pobj_regtype_##TYPE = KLFPObjRegisteredType(#TYPE) ; 944 doregister(Register, name);
949 return doregister(Query, name);
953 enum Action { Query, Register };
954 static int doregister(Action action,
const char * name)
966 fprintf(stderr,
"ERRORORROORORR: %s: what is your action?? `%d' for name `%s'\n",
974 #define KLF_DECLARE_SPECIFYABLE_TYPE(TYPE) \ 975 static KLFSpecifyableRegisteredType __klf_specifyable_regtype_##TYPE = KLFSpecifyableRegisteredType(#TYPE) ; const KLFPObjPropRef & operator=(const KLFPObjPropRef &value)
QString propertyNameSpace() const
bool operator==(const T &val) const
static bool isRegistered(const char *name)
KLF_EXPORT QDataStream & operator<<(QDataStream &stream, const KLFEnumType &e)
static bool isRegistered(const char *name)
KLFPObjPropRef(KLFPropertizedObject *pobj, int builtInPropId, const QString &pname, const T &value)
Base declarations for klatexformula and some utilities.
const KLFPObjPropRef & operator=(const T &value)
void setEnumValues(const QStringList &list)
const KLFPObjPropRef & operator=(const QVariant &v)
QString join(const QString &separator) const
virtual bool setProperty(const QString &pname, const QVariant &value)=0
Assign a value to a property.
void registerBuiltInProperty(int propId, const QString &propName) const
QString enumValue() const
A class that holds properties.
virtual QMap< QString, QVariant > allProperties() const
Convenience function to retrieve all properties.
KLF_EXPORT QDataStream & operator>>(QDataStream &stream, KLFEnumType &e)
KLFPObjPropRef(KLFPropertizedObject *pobj, int builtInPropId, const QString &pname)
An abstract object characterized by properties.
virtual QByteArray typeNameFor(const QString &property) const
Corresonding type for the given property.
void append(const T &value)
QString fromUtf8(const char *str, int size)
virtual QStringList propertyNameList() const =0
Queries what property are (or can be) set.
virtual QVariant property(const QString &propName) const =0
get a property's value
QStringList enumValues() const
#define klfWarning(streamableItems)
bool equals(const KLFPObjPropRef &other) const
QVariant variantValue() const
void registerbuiltinprop(KLFPropertizedObject *obj, int propid, const QString &pname)
bool operator==(const KLFEnumType &a, const KLFEnumType &b)
Q_DECLARE_METATYPE(KLFEnumType)
bool equals(const KLFPObjPropRef &other) const
ToStringFlag
Flags for tuning the toString() method.
bool contains(const T &value) const
QString propertyNameSpace(KLFPropertizedObject *obj) const
KLFEnumType(const KLFEnumType ©)
KLFPObjPropRef(const KLFPObjPropRef &other)
KLFPObjRegisteredType(const char *name)
virtual QString objectKind() const
QVector< QVariant > propertyVector() const
bool setSpecification(const QByteArray &data)
virtual bool setAllProperties(const QMap< QString, QVariant > &data)
Convenience function to load a set of property values.
virtual bool hasFixedTypes() const
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
Asserting Conditions (NON-FATAL)
bool operator==(const KLFPObjPropRef &other) const
KLFSpecifyableRegisteredType(const char *name)
KLFPObjPropRef(KLFPropertizedObject *pobj, int propId)
virtual QByteArray typeSpecificationFor(const QString &property) const
A type specification for the given property.
QByteArray specification() const
KLFEnumType(int initvalue=0)
QByteArray toUtf8() const