183 if (val < 0 || val >= enumVals.size()) {
184 klfWarning(
"Invalid value: "<<val<<
" for enum values "<<enumVals) ;
187 return enumVals[val];
202 return enumVals.join(
":").toUtf8();
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;
522 virtual void propertyValueChanged(
int propId,
const QVariant& oldValue,
530 virtual bool doSetProperty(
const QString& propname,
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);
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)
804 const T operator ()()
const
810 pPObj->setProperty(pPropId, v);
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>
851 template<
class VariantType>
863 return (
value() == val);
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<<
" !",
902 doregister(Register, name);
907 return doregister(Query, name);
911 enum Action { Query, Register };
912 static int doregister(Action action,
const char * name)
914 static QList<QByteArray> registered_types;
918 x = registered_types.
contains(QByteArray(name));
921 registered_types.
append(QByteArray(name));
924 fprintf(stderr,
"ERRORORROOERROR: %s: what is your action?? `%d' for name `%s'\n",
925 KLF_FUNC_NAME, (
int)action, name);
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)
956 static QList<QByteArray> registered_types;
960 x = registered_types.
contains(QByteArray(name));
963 registered_types.
append(QByteArray(name));
966 fprintf(stderr,
"ERRORORROORORR: %s: what is your action?? `%d' for name `%s'\n",
967 KLF_FUNC_NAME, (
int)action, name);
974#define KLF_DECLARE_SPECIFYABLE_TYPE(TYPE) \
975 static KLFSpecifyableRegisteredType __klf_specifyable_regtype_##TYPE = KLFSpecifyableRegisteredType(#TYPE) ;
virtual bool hasFixedTypes() const
virtual QVariant property(const QString &propName) const =0
get a property's value
virtual QByteArray typeNameFor(const QString &property) const
Corresonding type for the given property.
KLFAbstractPropertizedObject()
virtual QString objectKind() const =0
A string representing this object type.
virtual bool setAllProperties(const QMap< QString, QVariant > &data)
Convenience function to load a set of property values.
virtual bool setProperty(const QString &pname, const QVariant &value)=0
Assign a value to a property.
virtual QStringList propertyNameList() const =0
Queries what property are (or can be) set.
virtual QByteArray typeSpecificationFor(const QString &property) const
A type specification for the given property.
virtual QMap< QString, QVariant > allProperties() const
Convenience function to retrieve all properties.
QString enumValue() const
void setEnumValues(const QStringList &list)
QByteArray specification() const
bool setSpecification(const QByteArray &data)
KLFEnumType(int initvalue=0)
KLFEnumType(const KLFEnumType ©)
QStringList enumValues() const
QString propertyNameSpace(KLFPropertizedObject *obj) const
void registerbuiltinprop(KLFPropertizedObject *obj, int propid, const QString &pname)
bool operator==(const KLFPObjPropRef &other) const
KLFPObjPropRef(KLFPropertizedObject *pobj, int propId)
const KLFPObjPropRef & operator=(const T &value)
bool equals(const KLFPObjPropRef &other) const
bool equals(const KLFPObjPropRef &other) const
KLFPObjPropRef(KLFPropertizedObject *pobj, int builtInPropId, const QString &pname, const T &value)
KLFPObjPropRef(KLFPropertizedObject *pobj, int builtInPropId, const QString &pname)
const KLFPObjPropRef & operator=(const KLFPObjPropRef &value)
KLFPObjPropRef(const KLFPObjPropRef &other)
bool operator==(const T &val) const
const KLFPObjPropRef & operator=(const QVariant &v)
QVariant variantValue() const
KLFPObjRegisteredType(const char *name)
static bool isRegistered(const char *name)
A class that holds properties.
ToStringFlag
Flags for tuning the toString() method.
@ ToStringQuoteValues
Ensures that non-html output is machine parsable.
@ ToStringUseHtmlDiv
Uses <div> with CSS classes instead of a table (HTML only)
@ ToStringAllProperties
Include also all non-explicitely-set properties.
@ ToStringUseHtml
Encapsulates output in an HTML <table> and escapes strings.
void setAllPropertiesFromByteArray(const QByteArray &data)
Loads all properties saved by allPropertiesToByteArray()
virtual QString objectKind() const
QString propertyNameSpace() const
virtual QVariant property(const QString &propName) const
QStringList propertyNameList() const
A list of properties that have been set.
friend class KLFPObjPropRefHelper
virtual bool setAllProperties(const QMap< QString, QVariant > &propValues)
Initializes properties to given values.
QByteArray allPropertiesToByteArray() const
Saves all the properties in binary form.
KLFPropertizedObject(const QString &propertyNameSpace)
QList< int > propertyIdList() const
A list of properties that have been set.
virtual bool setProperty(const QString &propname, const QVariant &value)
Sets the given property to the given value.
void registerBuiltInProperty(int propId, const QString &propName) const
QMap< QString, QVariant > allProperties() const
Returns all properties that have been set.
QVector< QVariant > propertyVector() const
virtual bool hasPropertyValue(const QString &propName) const
Tests if a property was set.
QDataStream & streamFrom(QDataStream &stream)
Explicit function name for the simple "operator>>".
QDataStream & streamInto(QDataStream &stream) const
Explicit function name for the simple "operator<<".
KLFSpecifyableRegisteredType(const char *name)
static bool isRegistered(const char *name)
virtual bool setSpecification(const QByteArray &data)=0
virtual QByteArray specification() const =0
#define klfWarning(streamableItems)
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
Asserting Conditions (NON-FATAL)
Base declarations for klatexformula and some utilities.
bool operator==(const KLFPropertizedObject &a, const KLFPropertizedObject &b)
KLF_EXPORT QDataStream & operator<<(QDataStream &stream, const KLFEnumType &e)
Q_DECLARE_METATYPE(KLFEnumType)
bool operator==(const KLFEnumType &a, const KLFEnumType &b)
KLF_EXPORT QDataStream & operator>>(QDataStream &stream, KLFEnumType &e)
void append(const T &value)
bool contains(const T &value) const
QString fromUtf8(const char *str, int size)
QVariant fromValue(const T &value)