Warning, file /office/calligra/libs/widgetutils/KoProperties.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002    Copyright (c) 2006-2007 Boudewijn Rempt <boud@valdyas.org>
0003    Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019  */
0020 #ifndef _KO_PROPERTIES_H
0021 #define _KO_PROPERTIES_H
0022 
0023 #include <QString>
0024 #include <QMap>
0025 #include <QVariant>
0026 #include "kowidgetutils_export.h"
0027 
0028 class QDomElement;
0029 
0030 /**
0031  * A KoProperties is the (de-)serializable representation of
0032  * a key-value map. The serialisation format is XML.
0033  */
0034 class KOWIDGETUTILS_EXPORT KoProperties
0035 {
0036 public:
0037 
0038     /**
0039      * Create a new properties object
0040      */
0041     KoProperties();
0042 
0043     /**
0044      * Copy constructor
0045      */
0046     KoProperties(const KoProperties &other);
0047 
0048     ~KoProperties();
0049 
0050 public:
0051 
0052     /**
0053      * Fill the properties object from the XML dom node.
0054      *
0055      * load() does not touch existing properties if loading fails.
0056      *
0057      * @param root the root node of the properties subtree.
0058      */
0059     void load(const QDomElement &root);
0060 
0061     /**
0062      * Fill the properties object from the XML encoded
0063      * representation in string.
0064      *
0065      * load() does not touch existing properties if loading fails.
0066      *
0067      * @param string the stored properties.
0068      * @return false if loading failing, true if it succeeded
0069      */
0070     bool load(const QString &string);
0071 
0072     /**
0073      * Returns an iterator over the properties. The iterator is not
0074      * suitable for adding or removing properties.
0075      */
0076     QMapIterator<QString, QVariant> propertyIterator() const;
0077 
0078     /**
0079      * @return true if this KoProperties object does not contain any
0080      * properties.
0081      */
0082     bool isEmpty() const;
0083 
0084     /**
0085      * @brief Create a serialized version of these properties (as XML) with root as the root element.
0086      * @param root as the root element in the generated XML.
0087      */
0088     QString store(const QString &root) const;
0089 
0090     void save(QDomElement &root) const;
0091 
0092     /**
0093      * Set the property with name to value.
0094      */
0095     void setProperty(const QString &name, const QVariant &value);
0096 
0097     /**
0098      * Set value to the value associated with property name
0099      * @return false if the specified property did not exist.
0100      */
0101     bool property(const QString &name, QVariant &value) const;
0102 
0103     /**
0104      * Return a property by name, wrapped in a QVariant.
0105      * A typical usage:
0106      *  @code
0107      *      KoProperties *props = new KoProperties();
0108      *      props->setProperty("name", "Marcy");
0109      *      props->setProperty("age", 25);
0110      *      QString name = props->property("name").toString();
0111      *      int age = props->property("age").toInt();
0112      *  @endcode
0113      * @return a property by name, wrapped in a QVariant.
0114      * @param name the name (or key) with which the variant was registered.
0115      * @see intProperty() stringProperty()
0116      */
0117     QVariant property(const QString &name) const;
0118 
0119     /**
0120      * Return an integer property by name.
0121      * A typical usage:
0122      *  @code
0123      *      KoProperties *props = new KoProperties();
0124      *      props->setProperty("age", 25);
0125      *      int age = props->intProperty("age");
0126      *  @endcode
0127      * @return an integer property by name
0128      * @param name the name (or key) with which the variant was registered.
0129      * @param defaultValue the default value, should there not be any property by the name this will be returned.
0130      * @see property() stringProperty()
0131      */
0132     int intProperty(const QString &name, int defaultValue = 0) const;
0133 
0134     /**
0135      * Return a qreal property by name.
0136      * @param name the name (or key) with which the variant was registered.
0137      * @param defaultValue the default value, should there not be any property by the name this will be returned.
0138      */
0139     qreal doubleProperty(const QString &name, qreal defaultValue = 0.0) const;
0140 
0141     /**
0142      * Return a boolean property by name.
0143      * @param name the name (or key) with which the variant was registered.
0144      * @param defaultValue the default value, should there not be any property by the name this will be returned.
0145      */
0146     bool boolProperty(const QString &name, bool defaultValue = false) const;
0147 
0148     /**
0149      * Return an QString property by name.
0150      * A typical usage:
0151      *  @code
0152      *      KoProperties *props = new KoProperties();
0153      *      props->setProperty("name", "Marcy");
0154      *      QString name = props->stringProperty("name");
0155      *  @endcode
0156      * @return an QString property by name
0157      * @param name the name (or key) with which the variant was registered.
0158      * @see property() intProperty()
0159      * @param defaultValue the default value, should there not be any property by the name this will be returned.
0160      */
0161     QString stringProperty(const QString &name, const QString &defaultValue = QString()) const;
0162 
0163     /**
0164      * Returns true if the specified key is present in this properties
0165      * object.
0166      */
0167     bool contains(const QString &key) const;
0168 
0169     /**
0170      * Returns the value associated with the specified key if this
0171      * properties object contains the specified key; otherwise return
0172      * an empty QVariant.
0173      */
0174     QVariant value(const QString &key) const;
0175 
0176     bool operator==(const KoProperties &other) const;
0177     KoProperties operator=(const KoProperties &other) const;
0178     
0179 private:
0180 
0181     class Private;
0182     Private * const d;
0183 };
0184 
0185 #endif // _KO_PROPERTIES_H