26 #include <QDataStream>
27 #include <QTextStream>
28 #include <QTextDocument>
33 : pPropNameSpace(propNameSpace)
46 qWarning(
"%s[%s](): Property `%s' not registered.",
KLF_FUNC_NAME, qPrintable(pPropNameSpace),
47 qPrintable(propname));
54 if (propId >= 0 && propId < pProperties.
size()) {
56 return pProperties[
propId];
59 qWarning(
"%s[%s](%d): invalid property ID.",
KLF_FUNC_NAME, qPrintable(pPropNameSpace),
77 qWarning(
"%s[%s](): Property `%s' not registered.",
KLF_FUNC_NAME, qPrintable(pPropNameSpace),
78 qPrintable(propname));
85 if (propId >= 0 && propId < pProperties.
size()) {
88 pProperties[
propId] = value;
93 qWarning(
"%s[%s](id=%d): invalid property ID.",
KLF_FUNC_NAME, qPrintable(pPropNameSpace),
100 if (propId <= maxId) {
101 pProperties.
resize(maxId + 1);
103 if (propId < 0 || propId >= pProperties.
size() ||
105 qWarning(
"%s[%s](id=%d): invalid property id.",
KLF_FUNC_NAME, qPrintable(pPropNameSpace),
110 pProperties[
propId] = value;
131 for (k = 0; k < pProperties.
size(); ++k) {
132 if (pProperties[k].isValid())
143 for (k = 0; k < pProperties.
size(); ++k) {
144 if (pProperties[k].isValid())
159 for (k = 0; k < propertyList.
size(); ++k) {
169 for (k = 0; k < propKeys.size(); ++k) {
212 s =
QString(
"<div class=\"klfpobj_entry\">\n<div class=\"klfpobj_name\">%2</div>\n")
213 .arg(Qt::escape(pPropNameSpace));
215 s =
QString(
"<table class=\"klfpobj_tentry\">\n"
216 "<tr colspan=\"2\" class=\"klfpobj_tname\"><th>%1</th></tr>\n")
217 .arg(Qt::escape(pPropNameSpace));
220 s =
QString(
"%1\n").arg(pPropNameSpace);
223 for (k = 0; k < props.
size(); ++k) {
227 bool canstring = vval.
canConvert(QVariant::String);
231 s +=
QString(
"<div class=\"klfpobj_prop_%1\"><div class=\"klfpobj_propname\">%2</div>: "
232 "<div class=\"klfpobj_propvalue\">%3</div></div>\n")
233 .arg(pname, pname, Qt::escape(value));
235 s +=
QString(
" <tr class=\"klfpobj_tprop_%1\"><td class=\"klfpobj_tpropname\">%2</td>"
236 "<td class=\"klfpobj_tpropvalue\">%3</td></tr>\n")
237 .arg(pname, pname, Qt::escape(value));
240 if (!isnull && canstring) {
243 value =
'"' + value +
'"';
244 }
else if (!isnull) {
317 internalRegisterProperty(pnamespace, name, propId);
321 return internalRegisterProperty(propNameSpace, propName, -1);
325 if ( ! pRegisteredPropertiesMaxId.
contains(propNameSpace) ) {
326 qWarning(
"%s(): property name space `%s' does not exist!",
KLF_FUNC_NAME,
327 qPrintable(propNameSpace));
330 return pRegisteredPropertiesMaxId[propNameSpace];
343 if ( ! pRegisteredProperties.
contains(propNameSpace) ) {
344 qWarning(
"%s: property name space `%s' does not exist!",
KLF_FUNC_NAME,
345 qPrintable(propNameSpace));
351 return propList.
value(name);
355 if ( ! pRegisteredProperties.
contains(propNameSpace) ) {
356 qWarning(
"%s: property name space `%s' does not exist!",
KLF_FUNC_NAME,
357 qPrintable(propNameSpace));
364 if (keyList.
size() > 1) {
365 qWarning(
"%s: What's going on?? property Id=%d not unique in prop name space `%s'.",
372 if ( ! pRegisteredProperties.
contains(propNameSpace) ) {
373 qWarning(
"%s: property name space `%s' does not exist!",
KLF_FUNC_NAME,
374 qPrintable(propNameSpace));
378 return pRegisteredProperties[propNameSpace].
keys();
382 if ( ! pRegisteredProperties.
contains(propNameSpace) ) {
383 qWarning(
"%s: property name space `%s' does not exist!",
KLF_FUNC_NAME,
384 qPrintable(propNameSpace));
388 return pRegisteredProperties[propNameSpace].
values();
393 if ( ! pRegisteredProperties.
contains(propNameSpace) ) {
394 qWarning(
"%s: property name space `%s' does not exist!",
KLF_FUNC_NAME,
395 qPrintable(propNameSpace));
398 return pRegisteredProperties[propNameSpace];
410 int KLFPropertizedObject::internalRegisterProperty(
const QString& propNameSpace,
416 if (pRegisteredPropertiesMaxId.
contains(propNameSpace)) {
417 propMaxId = pRegisteredPropertiesMaxId[propNameSpace];
421 propId = propMaxId + 1;
426 if (propId > propMaxId)
429 if ( propList.
keys(propId).size() > 0 ) {
431 if (propName == oldPropName)
433 qWarning(
"%s[%s]: Property ID `%d' is already registered with conflicting names!\n"
434 "\told name is `%s', new is `%s'",
435 KLF_FUNC_NAME, qPrintable(propNameSpace), propId, qPrintable(oldPropName),
436 qPrintable(propName));
441 qWarning(
"%s[%s]: Cannot Register a property with empty name!", KLF_FUNC_NAME,
442 qPrintable(propNameSpace));
446 qWarning(
"%s[%s]: Property `%s' already registered.", KLF_FUNC_NAME, qPrintable(propNameSpace),
447 qPrintable(propName));
452 pRegisteredProperties[propNameSpace][propName] =
propId;
454 pRegisteredPropertiesMaxId[propNameSpace] = propMaxId;
461 if (a.pPropNameSpace != b.pPropNameSpace)
465 for (k = 0; k < propIds.
size(); ++k)
A class that holds properties.
QStringList propertyNameList() const
A list of properties that have been set.
QDataStream & operator<<(QDataStream &stream, const KLFPropertizedObject &obj)
QList< int > propertyIdList() const
A list of properties that have been set.
virtual ~KLFPropertizedObject()
int propertyMaxId() const
See the corresponding protected static method.
virtual void setProperty(const QString &propname, const QVariant &value)
void registerBuiltInProperty(int propId, const QString &propName) const
QList< int > registeredPropertyIdList() const
See the corresponding protected static method.
Include also all non-explicitely-set properties.
replace(int position, int n, const QString &after)
virtual QString toString(uint toStringFlags=0) const
Formats the property contents in a (human and/or parsable) string.
int registerProperty(const QString &propertyName) const
bool propertyIdRegistered(int propId) const
See the corresponding protected static method.
void setAllPropertiesFromByteArray(const QByteArray &data)
Loads all properties saved by allPropertiesToByteArray()
bool operator==(const KLFPropertizedObject &a, const KLFPropertizedObject &b)
virtual int loadProperty(const QString &propname, const QVariant &value)
int propertyIdForName(const QString &propertyName) const
See the corresponding protected static method.
QMap< QString, QVariant > allProperties() const
Returns all properties that have been set.
Uses
with CSS classes instead of a table (HTML only)
QStringList registeredPropertyNameList() const
See the corresponding protected static method.
QDataStream & operator>>(QDataStream &stream, KLFPropertizedObject &obj)
QMap< QString, int > registeredProperties() const
See the corresponding protected static method.
bool propertyNameRegistered(const QString &propertyName) const
See the corresponding protected static method.
QByteArray allPropertiesToByteArray() const
Saves all the properties in binary form.
Encapsulates output in an HTML
and escapes strings.
virtual void propertyValueChanged(int propId, const QVariant &oldValue, const QVariant &newValue)
void setAllProperties(const QMap< QString, QVariant > &propValues)
Initializes properties to given values.
virtual QVariant property(const QString &propName) const
QString propertyNameForId(int propId) const
See the corresponding protected static method.
KLFPropertizedObject(const QString &propertyNameSpace)
Ensures that non-html output is machine parsable.
Generated by doxygen 1.8.8