99 \ingroup contacts-main |
82 \ingroup contacts-main |
100 |
83 |
101 All of the information for a contact is stored in one or more QContactDetail objects. |
84 All of the information for a contact is stored in one or more QContactDetail objects. |
102 |
85 |
103 A detail is a group of logically related bits of data - for example, a street address is a single |
86 A detail is a group of logically related bits of data - for example, a street address is a single |
104 detail that has multiple fields (number, region, country etc). Every QContactDetail has an |
87 detail that has multiple fields (number, region, country etc). Every QContactDetail has the name of an |
105 associated QContactDetailDefinition id that describes the fields, their data type, any |
88 associated QContactDetailDefinition that describes the fields, their data type, and any |
106 restrictions on their values, and any restrictions on creating or updating details of that |
89 restrictions on their values. Different contact managers might have different detail definitions |
107 definition. |
90 for the same name, depending on their capabilities. For example, for the QContactName definition name, |
108 |
91 one manager might not support the middle name field, while a different manager may add an extra field for |
109 One field which is common to all details is the context field. This field is intended to store the |
92 specific extra information not present in the default schema. |
110 context or contexts that this detail is associated with. Commonly this will be something like |
93 |
|
94 Both the names of all the fields, and the name of the associated QContactDetailDefinition are stored |
|
95 as 8-bit strings encoded in Latin 1 for memory conservation. Note, however, that the values stored |
|
96 in each field are not constrained in this way, and full unicode QStrings or QVariant data can be stored. |
|
97 |
|
98 One field which is common to all details is the context field. This field is intended to store one or |
|
99 more contexts that this detail is associated with. Commonly this will be something like |
111 "Home" and/or "Work", although no limitations are placed on which values may be stored in this field |
100 "Home" and/or "Work", although no limitations are placed on which values may be stored in this field |
112 in the default schema. |
101 in the default schema. |
113 |
102 |
114 There are two other, related fields which are common to all details. The first is |
103 There are two other, related fields which are common to all details. The first is |
115 \a QContactDetail::FieldDetailUri, which stores the unique URI of the detail if one exists. |
104 \a QContactDetail::FieldDetailUri, which stores the unique URI of the detail if one exists. |
116 The field is not mandatory, and backends are not required to verify that the given URI is indeed |
105 The field is not mandatory, and backends are not required to verify that the given URI is indeed |
117 unique within the contact. The second field is \a QContactDetail::LinkedDetailUris, which stores |
106 unique within the contact. The second field is \a QContactDetail::LinkedDetailUris, which stores |
118 a list of detail URIs to which this detail is linked. The link is one-way, and intended mainly |
107 a list of detail URIs to which this detail is linked. The link is one-way, and can be used to show |
119 for use by read-only details which are populated by the backend (for example, a presence detail |
108 how or where a detail was derived. This is useful for things like presence information and avatars, |
120 which is linked to a particular online account detail of the contact). |
109 which are linked to a particular online account detail of the contact. |
121 |
110 |
|
111 When a QContactDetail has been retrieved in a QContact from a QContactManager, it may have certain |
|
112 access constraints provided with it, like \l ReadOnly or \l Irremovable. This might mean that the |
|
113 supplied detail is calculated or otherwise not modifiable by the user - presence information is a |
|
114 good example. Also, some details may be marked \l Irremovable. These are typically things that |
|
115 a contact has to have - like a QContactDisplayLabel or a QContactType. |
|
116 |
122 It is possible to inherit from QContactDetail to provide convenience or |
117 It is possible to inherit from QContactDetail to provide convenience or |
123 standardized access to values. For example, \l QContactPhoneNumber provides |
118 standardized access to values. For example, \l QContactPhoneNumber provides |
124 a convenient API for manipulating a QContactDetail as a phone number, according |
119 a convenient API for manipulating a QContactDetail as a phone number, according |
125 to the schema. |
120 to the schema. |
126 |
121 |
|
122 In general, QContactDetail and the built in subclasses (like \l QContactPhoneNumber) provide |
|
123 constants for the names of fields (like \l QContactPhoneNumber::FieldNumber), and for predefined |
|
124 common values like \l QContactDetail::ContextHome. Typically the constants for field names start |
|
125 with \c Field, and the constants for predefined values of a field start with the name of that field |
|
126 (e.g. \c ContextHome is a predefined constant for \c FieldContext). |
|
127 |
127 If you wish to create your own, customized contact detail, you should use |
128 If you wish to create your own, customized contact detail, you should use |
128 the \l Q_DECLARE_CUSTOM_CONTACT_DETAIL macro in order to ensure proper |
129 the \l Q_DECLARE_CUSTOM_CONTACT_DETAIL macro in order to ensure proper |
129 operation. See the predefined leaf classes (like \l QContactPhoneNumber, |
130 operation, and declare your own field constants with \l Q_DECLARE_LATIN1_CONSTANT. |
|
131 See the predefined detail subclasses (like \l QContactPhoneNumber, |
130 \l QContactAddress) for more information. |
132 \l QContactAddress) for more information. |
131 |
133 |
132 QContactDetail objects act like values. In general, you can assign them |
134 QContactDetail objects act like type checked values. In general, you can assign them |
133 to and fro and have reasonable behaviour, like the following example. |
135 to and fro and have reasonable behaviour, like the following example. |
134 |
136 |
135 \code |
137 \code |
136 |
138 |
137 QContactPhoneNumber number; |
139 QContactPhoneNumber number; |
138 number.setNumber("555-1212"); |
140 number.setNumber("555-1212"); |
139 // number.value(QContactPhoneNumber::FieldNumber) == "555-1212"; |
141 // number.value(QContactPhoneNumber::FieldNumber) == "555-1212"; |
140 // number.definitionName() == QContactPhoneNumber::staticType() |
142 // number.definitionName() == QContactPhoneNumber::DefinitionName |
141 |
143 |
142 QContactDetail detail = number; |
144 QContactDetail detail = number; |
143 // detail.value(QContactPhoneNumber::FieldNumber) == "555-1212"; |
145 // detail.value(QContactPhoneNumber::FieldNumber) == "555-1212"; |
144 // detail.definitionName() == QContactPhoneNumber::staticType() |
146 // detail.definitionName() == QContactPhoneNumber::DefinitionName |
145 |
147 |
146 QContactPhoneNumber otherNumber = detail; |
148 QContactPhoneNumber otherNumber = detail; |
147 // otherNumber.number() == "555-1212"; |
149 // otherNumber.number() == "555-1212"; |
148 // otherNumber.definitionName() == QContactPhoneNumber::staticType() |
150 // otherNumber.definitionName() == QContactPhoneNumber::DefinitionName |
149 |
151 |
150 QContactAddress address = detail; |
152 QContactAddress address = detail; |
151 // address is now a default constructed QContactAddress |
153 // address is now a default constructed QContactAddress |
152 // address.error() == QContactDetail::IncompatibleAssignmentError |
|
153 // address.value(QContactPhoneNumber::FieldNumber) is empty |
154 // address.value(QContactPhoneNumber::FieldNumber) is empty |
154 // address.definitionName() == QContactAddress::staticType() |
155 // address.definitionName() == QContactAddress::DefinitionName |
155 |
156 |
156 QContactAddress otherAddress = number; |
157 QContactAddress otherAddress = number; |
157 // otherAddress is now a default constructed QContactAddress |
158 // otherAddress is now a default constructed QContactAddress |
158 // otherAddress.error() == QContactDetail::IncompatibleAssignmentError |
|
159 // otherAddress.value(QContactPhoneNumber::FieldNumber) is empty |
159 // otherAddress.value(QContactPhoneNumber::FieldNumber) is empty |
160 // otherAddress.definitionName() == QContactAddress::staticType() |
160 // otherAddress.definitionName() == QContactAddress::DefinitionName |
161 \endcode |
161 \endcode |
162 |
162 |
163 \sa QContact, QContactDetailDefinition, QContactDetailFilter, QContactDetailRangeFilter, Q_DECLARE_CUSTOM_CONTACT_DETAIL |
163 \sa QContact, QContactDetailDefinition, QContactDetailFilter, QContactDetailRangeFilter, Q_DECLARE_CUSTOM_CONTACT_DETAIL |
164 */ |
164 */ |
165 |
165 |
166 /*! |
166 /*! |
167 \macro Q_DECLARE_CUSTOM_CONTACT_DETAIL |
167 \macro Q_DECLARE_CUSTOM_CONTACT_DETAIL |
168 \relates QContactDetail |
168 \relates QContactDetail |
169 |
169 |
170 Macro for simplifying declaring custom (leaf) detail classes. |
170 Macro for simplifying declaring custom (leaf) detail classes. |
|
171 |
|
172 The first argument is the name of the class, and the second argument |
|
173 is a Latin-1 string literal naming the detail type. |
171 |
174 |
172 If you are creating a convenience class for a type of QContactDetail, |
175 If you are creating a convenience class for a type of QContactDetail, |
173 you should use this macro when declaring your class to ensure that |
176 you should use this macro when declaring your class to ensure that |
174 it interoperates with other contact functionality. |
177 it interoperates with other contact functionality. |
175 |
178 |
180 |
183 |
181 \snippet ../../src/contacts/details/qcontactphonenumber.h 0 |
184 \snippet ../../src/contacts/details/qcontactphonenumber.h 0 |
182 */ |
185 */ |
183 |
186 |
184 /*! |
187 /*! |
|
188 \class QLatin1Constant |
|
189 \headerfile |
|
190 \brief The QLatin1Constant class holds a Latin 1 string constant |
|
191 |
|
192 */ |
|
193 |
|
194 /*! |
|
195 \fn QLatin1Constant::operator QString() const |
|
196 \internal |
|
197 */ |
|
198 /*! |
|
199 \fn QLatin1Constant::operator QLatin1String() const |
|
200 \internal |
|
201 */ |
|
202 /*! |
|
203 \fn QLatin1Constant::operator QVariant() const |
|
204 \internal |
|
205 */ |
|
206 /*! |
|
207 \fn bool QLatin1Constant::operator ==(const QLatin1Constant& other) const |
|
208 |
|
209 Returns true if this QLatin1Constant is the same as \a other (either same object or |
|
210 same string literal), and false otherwise. |
|
211 */ |
|
212 /*! |
|
213 \fn bool QLatin1Constant::operator !=(const QLatin1Constant& other) const |
|
214 |
|
215 Returns false if this QLatin1Constant is the same as \a other (either same object or |
|
216 same string literal), and true otherwise. |
|
217 */ |
|
218 /*! |
|
219 \fn inline const char * QLatin1Constant::latin1() const |
|
220 |
|
221 Returns the value of this literal as a C style string (null terminated). |
|
222 */ |
|
223 |
|
224 |
|
225 /*! |
|
226 \macro Q_DECLARE_LATIN1_CONSTANT |
|
227 \relates QLatin1Constant |
|
228 |
|
229 This macro, along with the related Q_DEFINE_LATIN1_CONSTANT macro, |
|
230 allows you to describe a "Latin 1 string constant". |
|
231 |
|
232 The resulting constant can be passed to functions accepting a |
|
233 QLatin1String, a QString, or a QVariant. |
|
234 |
|
235 The first parameter is the name of the variable to declare. The |
|
236 second parameter is the value of the constant, as a string literal. |
|
237 |
|
238 For example: |
|
239 \code |
|
240 // in a header file |
|
241 Q_DECLARE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT"); |
|
242 \endcode |
|
243 |
|
244 The declaration should be paired with a matching Q_DEFINE_LATIN1_CONSTANT |
|
245 with the same arguments to actually define the constant. |
|
246 |
|
247 \sa Q_DEFINE_LATIN1_CONSTANT |
|
248 */ |
|
249 |
|
250 /*! |
|
251 \macro Q_DEFINE_LATIN1_CONSTANT |
|
252 \relates QLatin1Constant |
|
253 |
|
254 This macro, along with the related Q_DECLARE_LATIN1_CONSTANT macro, |
|
255 allows you to describe a "Latin 1 string constant". |
|
256 |
|
257 The resulting constant can be passed to functions accepting a |
|
258 QLatin1String, a QString, or a QVariant. |
|
259 |
|
260 The first parameter is the name of the variable to define. The |
|
261 second parameter is the value of the constant, as a string literal. |
|
262 |
|
263 For example: |
|
264 \code |
|
265 // in a header file |
|
266 Q_DECLARE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT"); |
|
267 |
|
268 // in source file |
|
269 Q_DEFINE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT"); |
|
270 \endcode |
|
271 |
|
272 You can use this macro without the matching DECLARE macro if |
|
273 you are using the constant only in a single compilation unit. |
|
274 |
|
275 \sa Q_DECLARE_LATIN1_CONSTANT |
|
276 */ |
|
277 |
|
278 /*! |
185 \fn QContactDetail::operator!=(const QContactDetail& other) const |
279 \fn QContactDetail::operator!=(const QContactDetail& other) const |
186 Returns true if the values or id of this detail is different to those of the \a other detail |
280 Returns true if the values or id of this detail is different to those of the \a other detail |
187 */ |
281 */ |
188 |
282 |
189 /*! |
283 /*! |
373 /*! \overload |
507 /*! \overload |
374 Returns the value stored in this detail for the given \a key as a QString, or an empty QString if |
508 Returns the value stored in this detail for the given \a key as a QString, or an empty QString if |
375 no value for the given \a key exists */ |
509 no value for the given \a key exists */ |
376 QString QContactDetail::value(const QString& key) const |
510 QString QContactDetail::value(const QString& key) const |
377 { |
511 { |
378 return d.constData()->m_values.value(key.toLatin1().constData()).toString(); |
512 return d.constData()->m_values.value(QContactStringHolder(key)).toString(); |
379 } |
513 } |
380 |
514 |
381 |
515 /*! |
382 /*! \overload |
516 \internal |
383 Returns the value stored in this detail for the given \a key as a QString, or an empty QString if |
517 \overload |
384 no value for the given \a key exists */ |
518 Returns the value stored in this detail for the given \a key as a QString, or an empty QString if |
|
519 no value for the given \a key exists |
|
520 */ |
385 QString QContactDetail::value(const char* key) const |
521 QString QContactDetail::value(const char* key) const |
386 { |
522 { |
387 return d.constData()->m_values.value(key).toString(); |
523 return d.constData()->m_values.value(key).toString(); |
388 } |
524 } |
389 |
525 |
390 // A bug in qdoc means this comment needs to appear below the comment for the other value(). |
526 /*! |
391 /*! |
527 \fn T QContactDetail::value(const char* key) const |
392 \fn T QContactDetail::value(const QString& key) const |
528 \internal |
393 Returns the value of the template type associated with the given \a key |
529 \overload |
394 */ |
530 */ |
395 |
531 |
396 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */ |
532 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */ |
397 QVariant QContactDetail::variantValue(const QString& key) const |
533 QVariant QContactDetail::variantValue(const QString& key) const |
398 { |
534 { |
399 return d.constData()->m_values.value(key.toLatin1().constData()); |
535 return d.constData()->m_values.value(QContactStringHolder(key)); |
400 } |
536 } |
401 |
537 |
402 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */ |
538 /*! |
|
539 \internal |
|
540 Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists |
|
541 */ |
403 QVariant QContactDetail::variantValue(const char* key) const |
542 QVariant QContactDetail::variantValue(const char* key) const |
404 { |
543 { |
405 return d.constData()->m_values.value(key); |
544 return d.constData()->m_values.value(key); |
406 } |
545 } |
407 |
546 |
408 /*! |
547 /*! |
409 Returns true if this detail has a field with the given \a key, or false otherwise. |
548 Returns true if this detail has a field with the given \a key, or false otherwise. |
410 */ |
549 */ |
411 bool QContactDetail::hasValue(const QString& key) const |
550 bool QContactDetail::hasValue(const QString& key) const |
412 { |
551 { |
413 return d.constData()->m_values.contains(key.toLatin1().constData()); |
552 return d.constData()->m_values.contains(QContactStringHolder(key)); |
414 } |
553 } |
415 |
554 |
416 /*! |
555 /*! |
|
556 \internal |
417 Returns true if this detail has a field with the given \a key, or false otherwise. |
557 Returns true if this detail has a field with the given \a key, or false otherwise. |
418 */ |
558 */ |
419 bool QContactDetail::hasValue(const char * key) const |
559 bool QContactDetail::hasValue(const char * key) const |
420 { |
560 { |
421 return d.constData()->m_values.contains(key); |
561 return d.constData()->m_values.contains(key); |
432 |
572 |
433 d->m_values.insert(QContactStringHolder(key), value); |
573 d->m_values.insert(QContactStringHolder(key), value); |
434 return true; |
574 return true; |
435 } |
575 } |
436 |
576 |
437 /*! Inserts \a value into the detail for the given \a key if \a value is valid. If \a value is invalid, |
577 /*! |
|
578 \internal |
|
579 |
|
580 Inserts \a value into the detail for the given \a key if \a value is valid. If \a value is invalid, |
438 removes the field with the given \a key from the detail. Returns true if the given \a value was set |
581 removes the field with the given \a key from the detail. Returns true if the given \a value was set |
439 for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the |
582 for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the |
440 \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid) */ |
583 \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid) |
|
584 */ |
441 bool QContactDetail::setValue(const char* key, const QVariant& value) |
585 bool QContactDetail::setValue(const char* key, const QVariant& value) |
442 { |
586 { |
443 if (!value.isValid()) |
587 if (!value.isValid()) |
444 return removeValue(key); |
588 return removeValue(key); |
445 |
589 |
446 d->m_values.insert(key, value); |
590 d->m_values.insert(key, value); |
447 return true; |
591 return true; |
448 } |
592 } |
449 |
593 |
450 /*! Removes the value stored in this detail for the given \a key. Returns true if a value was stored for the given \a key and the operation succeeded, and false otherwise */ |
594 /*! |
|
595 Removes the value stored in this detail for the given \a key. Returns true if a value was stored |
|
596 for the given \a key and the operation succeeded, and false otherwise. |
|
597 */ |
451 bool QContactDetail::removeValue(const QString& key) |
598 bool QContactDetail::removeValue(const QString& key) |
452 { |
599 { |
453 if(d->m_values.remove(key.toLatin1().constData())) |
600 if(d->m_values.remove(QContactStringHolder(key))) |
454 return true; |
601 return true; |
455 return false; |
602 return false; |
456 } |
603 } |
457 /*! Removes the value stored in this detail for the given \a key. Returns true if a value was stored for the given \a key and the operation succeeded, and false otherwise */ |
604 |
|
605 /*! |
|
606 \internal |
|
607 Removes the value stored in this detail for the given \a key. Returns true if a value was stored |
|
608 for the given \a key and the operation succeeded, and false otherwise. |
|
609 */ |
458 bool QContactDetail::removeValue(const char * key) |
610 bool QContactDetail::removeValue(const char * key) |
459 { |
611 { |
460 if(d->m_values.remove(key)) |
612 if(d->m_values.remove(key)) |
461 return true; |
613 return true; |
462 return false; |
614 return false; |
468 QVariantMap QContactDetail::variantValues() const |
620 QVariantMap QContactDetail::variantValues() const |
469 { |
621 { |
470 QVariantMap ret; |
622 QVariantMap ret; |
471 QHash<QContactStringHolder, QVariant>::const_iterator it = d.constData()->m_values.constBegin(); |
623 QHash<QContactStringHolder, QVariant>::const_iterator it = d.constData()->m_values.constBegin(); |
472 while(it != d.constData()->m_values.constEnd()) { |
624 while(it != d.constData()->m_values.constEnd()) { |
473 ret.insert(it.key(), it.value()); |
625 ret.insert(it.key().toQString(), it.value()); |
474 ++it; |
626 ++it; |
475 } |
627 } |
476 |
628 |
477 return ret; |
629 return ret; |
478 } |
630 } |
|
631 |
|
632 |
|
633 /*! |
|
634 \fn bool QContactDetail::setValue(const QLatin1Constant& key, const QVariant& value) |
|
635 |
|
636 Inserts \a value into the detail for the given \a key if \a value is valid. If \a value is invalid, |
|
637 removes the field with the given \a key from the detail. Returns true if the given \a value was set |
|
638 for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the |
|
639 \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid) |
|
640 */ |
|
641 /*! |
|
642 \fn bool QContactDetail::removeValue(const QLatin1Constant& key) |
|
643 |
|
644 Removes the value stored in this detail for the given \a key. Returns true if a value was stored |
|
645 for the given \a key and the operation succeeded, and false otherwise. |
|
646 */ |
|
647 |
|
648 /*! |
|
649 \fn bool QContactDetail::hasValue(const QLatin1Constant& key) const |
|
650 Returns true if this detail has a field with the given \a key, or false otherwise. |
|
651 */ |
|
652 |
|
653 /*! |
|
654 \fn QVariant QContactDetail::variantValue(const QLatin1Constant& key) const |
|
655 Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists |
|
656 */ |
|
657 |
|
658 /*! |
|
659 \fn T QContactDetail::value(const QLatin1Constant& key) const |
|
660 \overload |
|
661 Returns the value of the template type associated with the given \a key |
|
662 */ |
|
663 /*! |
|
664 \fn QString QContactDetail::value(const QLatin1Constant& key) const |
|
665 Returns the value stored in this detail for the given \a key as a QString, or an empty QString if |
|
666 no value for the given \a key exists |
|
667 */ |
|
668 /*! |
|
669 \fn T QContactDetail::value(const QString& key) const |
|
670 Returns the value of the template type associated with the given \a key |
|
671 */ |
479 |
672 |
480 /*! |
673 /*! |
481 \enum QContactDetail::AccessConstraint |
674 \enum QContactDetail::AccessConstraint |
482 |
675 |
483 This enum defines the access constraints for a detail. This information is typically provided by |
676 This enum defines the access constraints for a detail. This information is typically provided by |