qtmobility/src/versit/qversitproperty.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 8 71781823f776
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    44 #include "qmobilityglobal.h"
    44 #include "qmobilityglobal.h"
    45 
    45 
    46 #include <QStringList>
    46 #include <QStringList>
    47 #include <QTextCodec>
    47 #include <QTextCodec>
    48 
    48 
    49 QTM_USE_NAMESPACE
    49 QTM_BEGIN_NAMESPACE
    50 
    50 
    51 /*!
    51 /*!
    52   \class QVersitProperty
    52   \class QVersitProperty
    53   \preliminary
    53   \preliminary
    54   \brief The QVersitProperty class stores the name, value, groups and parameters of a Versit property.
    54   \brief The QVersitProperty class stores the name, value, groups and parameters of a Versit property.
    69   correctly into the (text-based) Versit format.
    69   correctly into the (text-based) Versit format.
    70 
    70 
    71   \sa QVersitDocument
    71   \sa QVersitDocument
    72  */
    72  */
    73 
    73 
       
    74 /*!
       
    75   \enum QVersitProperty::ValueType
       
    76   Describes the type of data held in the property's value.
       
    77 
       
    78   The vCard and iCalendar specifications allows a property value to hold a string, binary data, or a
       
    79   nested document.  String values can either be unstructured or structured.  Structured strings can
       
    80   be either of compound type or list type.  A compound value is one that is delimited by semicolons,
       
    81   allows empty components, and has a property-specific cardinality and ordering.  A list value is
       
    82   one that is delimited by commas, does not have empty components, and has no restrictions on
       
    83   cardinality or ordering.
       
    84 
       
    85   \value PlainType The property value holds an unstructured string and can be retrieved with
       
    86   QVersitProperty::value()
       
    87   \value CompoundType The property value holds a compound string and can be retrieved with
       
    88   QVersitProperty::value<QStringList>()
       
    89   \value ListType The property value holds a list of strings and can be retrieved with
       
    90   QVersitProperty::value<QStringList>()
       
    91   \value BinaryType The property value holds a binary value and can be retrieved with
       
    92   QVersitProperty::value<QByteArray>()
       
    93   \value VersitDocumentType The property value holds a nested Versit document and can be retrieved
       
    94   with QVersitProperty::value<QVersitDocument>()
       
    95  */
    74 
    96 
    75 /*! Constructs a new empty property */
    97 /*! Constructs a new empty property */
    76 QVersitProperty::QVersitProperty() : d(new QVersitPropertyPrivate())
    98 QVersitProperty::QVersitProperty() : d(new QVersitPropertyPrivate())
    77 {
    99 {
    78 }
   100 }
   108 bool QVersitProperty::operator!=(const QVersitProperty& other) const
   130 bool QVersitProperty::operator!=(const QVersitProperty& other) const
   109 {
   131 {
   110     return !(*this == other);
   132     return !(*this == other);
   111 }
   133 }
   112 
   134 
       
   135 /*! Returns the hash value for \a key. */
       
   136 uint qHash(const QVersitProperty &key)
       
   137 {
       
   138     uint hash = QT_PREPEND_NAMESPACE(qHash)(key.name()) + QT_PREPEND_NAMESPACE(qHash)(key.value());
       
   139     foreach (const QString& group, key.groups()) {
       
   140         hash += QT_PREPEND_NAMESPACE(qHash)(group);
       
   141     }
       
   142     QHash<QString,QString>::const_iterator it = key.parameters().constBegin();
       
   143     QHash<QString,QString>::const_iterator end = key.parameters().constEnd();
       
   144     while (it != end) {
       
   145         hash += QT_PREPEND_NAMESPACE(qHash)(it.key()) + QT_PREPEND_NAMESPACE(qHash)(it.value());
       
   146         ++it;
       
   147     }
       
   148     return hash;
       
   149 }
       
   150 
       
   151 #ifndef QT_NO_DEBUG_STREAM
       
   152 QDebug operator<<(QDebug dbg, const QVersitProperty& property)
       
   153 {
       
   154     QStringList groups = property.groups();
       
   155     QString name = property.name();
       
   156     QMultiHash<QString,QString> parameters = property.parameters();
       
   157     QString value = property.value();
       
   158     dbg.nospace() << "QVersitProperty(";
       
   159     foreach (const QString& group, groups) {
       
   160         dbg.nospace() << group << '.';
       
   161     }
       
   162     dbg.nospace() << name;
       
   163     QHash<QString,QString>::const_iterator it;
       
   164     for (it = parameters.constBegin(); it != parameters.constEnd(); ++it) {
       
   165         dbg.nospace() << ';' << it.key() << '=' << it.value();
       
   166     }
       
   167     dbg.nospace() << ':' << value;
       
   168     dbg.nospace() << ')';
       
   169     return dbg.maybeSpace();
       
   170 }
       
   171 #endif
       
   172 
   113 /*!
   173 /*!
   114  * Sets the groups in the property to the given list of \a groups.
   174  * Sets the groups in the property to the given list of \a groups.
   115  */
   175  */
   116 void QVersitProperty::setGroups(const QStringList& groups)
   176 void QVersitProperty::setGroups(const QStringList& groups)
   117 {
   177 {
   118     d->mGroups.clear();
   178     d->mGroups.clear();
   119     foreach (QString group, groups) {
   179     foreach (const QString& group, groups) {
   120         d->mGroups.append(group);
   180         d->mGroups.append(group);
   121     }
   181     }
   122 }
   182 }
   123 
   183 
   124 /*!
   184 /*!
   247         return d->mValue.toString();
   307         return d->mValue.toString();
   248     }
   308     }
   249 }
   309 }
   250 
   310 
   251 /*!
   311 /*!
       
   312  * Sets the type of value held in the property to \a type.
       
   313  */
       
   314 void QVersitProperty::setValueType(QVersitProperty::ValueType type)
       
   315 {
       
   316     d->mValueType = type;
       
   317 }
       
   318 
       
   319 /*!
       
   320  * Returns the type of value held in the property.
       
   321  */
       
   322 QVersitProperty::ValueType QVersitProperty::valueType() const
       
   323 {
       
   324     return d->mValueType;
       
   325 }
       
   326 
       
   327 /*!
   252  * Returns true if the property is empty.
   328  * Returns true if the property is empty.
   253  */
   329  */
   254 bool QVersitProperty::isEmpty() const
   330 bool QVersitProperty::isEmpty() const
   255 {
   331 {
   256     return d->mGroups.isEmpty()
   332     return d->mGroups.isEmpty()
   267     d->mGroups.clear();
   343     d->mGroups.clear();
   268     d->mName.clear();
   344     d->mName.clear();
   269     d->mValue.clear();
   345     d->mValue.clear();
   270     d->mParameters.clear();
   346     d->mParameters.clear();
   271 }
   347 }
       
   348 
       
   349 QTM_END_NAMESPACE