Registered QUuid in the metatype system as a builtin type.
[profile/ivi/qtbase.git] / src / corelib / kernel / qvariant.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qvariant.h"
43 #include "qbitarray.h"
44 #include "qbytearray.h"
45 #include "qdatastream.h"
46 #include "qdebug.h"
47 #include "qmap.h"
48 #include "qdatetime.h"
49 #include "qeasingcurve.h"
50 #include "qlist.h"
51 #include "qstring.h"
52 #include "qstringlist.h"
53 #include "qurl.h"
54 #include "qlocale.h"
55 #include "quuid.h"
56 #include "private/qvariant_p.h"
57 #include "qmetatype_p.h"
58
59 #ifndef QT_NO_GEOM_VARIANT
60 #include "qsize.h"
61 #include "qpoint.h"
62 #include "qrect.h"
63 #include "qline.h"
64 #endif
65
66 #include <float.h>
67
68 QT_BEGIN_NAMESPACE
69
70 #ifndef DBL_DIG
71 #  define DBL_DIG 10
72 #endif
73 #ifndef FLT_DIG
74 #  define FLT_DIG 6
75 #endif
76
77 namespace {
78 class HandlersManager
79 {
80     static const QVariant::Handler *Handlers[QModulesPrivate::ModulesCount];
81 public:
82     const QVariant::Handler *operator[] (const int typeId) const
83     {
84         return Handlers[QModulesPrivate::moduleForType(typeId)];
85     }
86
87     void registerHandler(const QModulesPrivate::Names name, const QVariant::Handler *handler)
88     {
89         Handlers[name] = handler;
90     }
91
92     inline void unregisterHandler(const QModulesPrivate::Names name);
93 };
94 }  // namespace
95
96 namespace {
97 template<typename T>
98 struct TypeDefiniton {
99     static const bool IsAvailable = true;
100 };
101
102 // Ignore these types, as incomplete
103 #ifdef QT_BOOTSTRAPPED
104 template<> struct TypeDefiniton<QEasingCurve> { static const bool IsAvailable = false; };
105 #endif
106 #ifdef QT_NO_GEOM_VARIANT
107 template<> struct TypeDefiniton<QRect> { static const bool IsAvailable = false; };
108 template<> struct TypeDefiniton<QRectF> { static const bool IsAvailable = false; };
109 template<> struct TypeDefiniton<QSize> { static const bool IsAvailable = false; };
110 template<> struct TypeDefiniton<QSizeF> { static const bool IsAvailable = false; };
111 template<> struct TypeDefiniton<QLine> { static const bool IsAvailable = false; };
112 template<> struct TypeDefiniton<QLineF> { static const bool IsAvailable = false; };
113 template<> struct TypeDefiniton<QPoint> { static const bool IsAvailable = false; };
114 template<> struct TypeDefiniton<QPointF> { static const bool IsAvailable = false; };
115 #endif
116
117 struct CoreTypesFilter {
118     template<typename T>
119     struct Acceptor {
120         static const bool IsAccepted = QTypeModuleInfo<T>::IsCore && TypeDefiniton<T>::IsAvailable;
121     };
122 };
123 } // annonymous used to hide TypeDefiniton
124
125 namespace { // annonymous used to hide QVariant handlers
126
127 static void construct(QVariant::Private *x, const void *copy)
128 {
129     QVariantConstructor<CoreTypesFilter> constructor(x, copy);
130     QMetaTypeSwitcher::switcher<void>(constructor, x->type, 0);
131 }
132
133 static void clear(QVariant::Private *d)
134 {
135     QVariantDestructor<CoreTypesFilter> cleaner(d);
136     QMetaTypeSwitcher::switcher<void>(cleaner, d->type, 0);
137 }
138
139 static bool isNull(const QVariant::Private *d)
140 {
141     QVariantIsNull<CoreTypesFilter> isNull(d);
142     return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, 0);
143 }
144
145 /*!
146   \internal
147
148   Compares \a a to \a b. The caller guarantees that \a a and \a b
149   are of the same type.
150  */
151 static bool compare(const QVariant::Private *a, const QVariant::Private *b)
152 {
153     QVariantComparator<CoreTypesFilter> comparator(a, b);
154     return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
155 }
156
157 /*!
158   \internal
159  */
160 static qlonglong qMetaTypeNumber(const QVariant::Private *d)
161 {
162     switch (d->type) {
163     case QMetaType::Int:
164         return d->data.i;
165     case QMetaType::LongLong:
166         return d->data.ll;
167     case QMetaType::Char:
168         return qlonglong(d->data.c);
169     case QMetaType::Short:
170         return qlonglong(d->data.s);
171     case QMetaType::Long:
172         return qlonglong(d->data.l);
173     case QMetaType::Float:
174         return qRound64(d->data.f);
175     case QVariant::Double:
176         return qRound64(d->data.d);
177     }
178     Q_ASSERT(false);
179     return 0;
180 }
181
182 static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
183 {
184     switch (d->type) {
185     case QVariant::UInt:
186         return d->data.u;
187     case QVariant::ULongLong:
188         return d->data.ull;
189     case QMetaType::UChar:
190         return d->data.uc;
191     case QMetaType::UShort:
192         return d->data.us;
193     case QMetaType::ULong:
194         return d->data.ul;
195     }
196     Q_ASSERT(false);
197     return 0;
198 }
199
200 static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok)
201 {
202     *ok = true;
203
204     switch (uint(d->type)) {
205     case QVariant::String:
206         return v_cast<QString>(d)->toLongLong(ok);
207     case QVariant::Char:
208         return v_cast<QChar>(d)->unicode();
209     case QVariant::ByteArray:
210         return v_cast<QByteArray>(d)->toLongLong(ok);
211     case QVariant::Bool:
212         return qlonglong(d->data.b);
213     case QVariant::Double:
214     case QVariant::Int:
215     case QMetaType::Char:
216     case QMetaType::Short:
217     case QMetaType::Long:
218     case QMetaType::Float:
219     case QMetaType::LongLong:
220         return qMetaTypeNumber(d);
221     case QVariant::ULongLong:
222     case QVariant::UInt:
223     case QMetaType::UChar:
224     case QMetaType::UShort:
225     case QMetaType::ULong:
226         return qlonglong(qMetaTypeUNumber(d));
227     }
228
229     *ok = false;
230     return Q_INT64_C(0);
231 }
232
233 static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok)
234 {
235     *ok = true;
236
237     switch (uint(d->type)) {
238     case QVariant::String:
239         return v_cast<QString>(d)->toULongLong(ok);
240     case QVariant::Char:
241         return v_cast<QChar>(d)->unicode();
242     case QVariant::ByteArray:
243         return v_cast<QByteArray>(d)->toULongLong(ok);
244     case QVariant::Bool:
245         return qulonglong(d->data.b);
246     case QVariant::Double:
247     case QVariant::Int:
248     case QMetaType::Char:
249     case QMetaType::Short:
250     case QMetaType::Long:
251     case QMetaType::Float:
252     case QMetaType::LongLong:
253         return qulonglong(qMetaTypeNumber(d));
254     case QVariant::ULongLong:
255     case QVariant::UInt:
256     case QMetaType::UChar:
257     case QMetaType::UShort:
258     case QMetaType::ULong:
259         return qMetaTypeUNumber(d);
260     }
261
262     *ok = false;
263     return Q_UINT64_C(0);
264 }
265
266 template<typename TInput, typename LiteralWrapper>
267 inline bool qt_convertToBool(const QVariant::Private *const d)
268 {
269     TInput str = v_cast<TInput>(d)->toLower();
270     return !(str == LiteralWrapper("0") || str == LiteralWrapper("false") || str.isEmpty());
271 }
272
273 /*!
274  \internal
275
276  Converts \a d to type \a t, which is placed in \a result.
277  */
278 static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
279 {
280     Q_ASSERT(d->type != uint(t));
281     Q_ASSERT(result);
282
283     bool dummy;
284     if (!ok)
285         ok = &dummy;
286
287     switch (uint(t)) {
288     case QVariant::Url:
289         switch (d->type) {
290         case QVariant::String:
291             *static_cast<QUrl *>(result) = QUrl(*v_cast<QString>(d));
292             break;
293         default:
294             return false;
295         }
296         break;
297     case QVariant::String: {
298         QString *str = static_cast<QString *>(result);
299         switch (d->type) {
300         case QVariant::Char:
301             *str = QString(*v_cast<QChar>(d));
302             break;
303         case QMetaType::Char:
304         case QMetaType::UChar:
305             *str = QChar::fromAscii(d->data.c);
306             break;
307         case QMetaType::Short:
308         case QMetaType::Long:
309         case QVariant::Int:
310         case QVariant::LongLong:
311             *str = QString::number(qMetaTypeNumber(d));
312             break;
313         case QVariant::UInt:
314         case QVariant::ULongLong:
315         case QMetaType::UShort:
316         case QMetaType::ULong:
317             *str = QString::number(qMetaTypeUNumber(d));
318             break;
319         case QMetaType::Float:
320             *str = QString::number(d->data.f, 'g', FLT_DIG);
321             break;
322         case QVariant::Double:
323             *str = QString::number(d->data.d, 'g', DBL_DIG);
324             break;
325 #if !defined(QT_NO_DATESTRING)
326         case QVariant::Date:
327             *str = v_cast<QDate>(d)->toString(Qt::ISODate);
328             break;
329         case QVariant::Time:
330             *str = v_cast<QTime>(d)->toString(Qt::ISODate);
331             break;
332         case QVariant::DateTime:
333             *str = v_cast<QDateTime>(d)->toString(Qt::ISODate);
334             break;
335 #endif
336         case QVariant::Bool:
337             *str = QLatin1String(d->data.b ? "true" : "false");
338             break;
339         case QVariant::ByteArray:
340             *str = QString::fromAscii(v_cast<QByteArray>(d)->constData());
341             break;
342         case QVariant::StringList:
343             if (v_cast<QStringList>(d)->count() == 1)
344                 *str = v_cast<QStringList>(d)->at(0);
345             break;
346         case QVariant::Url:
347             *str = v_cast<QUrl>(d)->toString();
348             break;
349         case QVariant::Uuid:
350             *str = v_cast<QUuid>(d)->toString();
351             break;
352         default:
353             return false;
354         }
355         break;
356     }
357     case QVariant::Char: {
358         QChar *c = static_cast<QChar *>(result);
359         switch (d->type) {
360         case QVariant::Int:
361         case QVariant::LongLong:
362         case QMetaType::Char:
363         case QMetaType::Short:
364         case QMetaType::Long:
365         case QMetaType::Float:
366             *c = QChar(ushort(qMetaTypeNumber(d)));
367             break;
368         case QVariant::UInt:
369         case QVariant::ULongLong:
370         case QMetaType::UChar:
371         case QMetaType::UShort:
372         case QMetaType::ULong:
373             *c = QChar(ushort(qMetaTypeUNumber(d)));
374             break;
375         default:
376             return false;
377         }
378         break;
379     }
380 #ifndef QT_NO_GEOM_VARIANT
381     case QVariant::Size: {
382         QSize *s = static_cast<QSize *>(result);
383         switch (d->type) {
384         case QVariant::SizeF:
385             *s = v_cast<QSizeF>(d)->toSize();
386             break;
387         default:
388             return false;
389         }
390         break;
391     }
392
393     case QVariant::SizeF: {
394         QSizeF *s = static_cast<QSizeF *>(result);
395         switch (d->type) {
396         case QVariant::Size:
397             *s = QSizeF(*(v_cast<QSize>(d)));
398             break;
399         default:
400             return false;
401         }
402         break;
403     }
404
405     case QVariant::Line: {
406         QLine *s = static_cast<QLine *>(result);
407         switch (d->type) {
408         case QVariant::LineF:
409             *s = v_cast<QLineF>(d)->toLine();
410             break;
411         default:
412             return false;
413         }
414         break;
415     }
416
417     case QVariant::LineF: {
418         QLineF *s = static_cast<QLineF *>(result);
419         switch (d->type) {
420         case QVariant::Line:
421             *s = QLineF(*(v_cast<QLine>(d)));
422             break;
423         default:
424             return false;
425         }
426         break;
427     }
428 #endif
429     case QVariant::StringList:
430         if (d->type == QVariant::List) {
431             QStringList *slst = static_cast<QStringList *>(result);
432             const QVariantList *list = v_cast<QVariantList >(d);
433             for (int i = 0; i < list->size(); ++i)
434                 slst->append(list->at(i).toString());
435         } else if (d->type == QVariant::String) {
436             QStringList *slst = static_cast<QStringList *>(result);
437             *slst = QStringList(*v_cast<QString>(d));
438         } else {
439             return false;
440         }
441         break;
442     case QVariant::Date: {
443         QDate *dt = static_cast<QDate *>(result);
444         if (d->type == QVariant::DateTime)
445             *dt = v_cast<QDateTime>(d)->date();
446 #ifndef QT_NO_DATESTRING
447         else if (d->type == QVariant::String)
448             *dt = QDate::fromString(*v_cast<QString>(d), Qt::ISODate);
449 #endif
450         else
451             return false;
452
453         return dt->isValid();
454     }
455     case QVariant::Time: {
456         QTime *t = static_cast<QTime *>(result);
457         switch (d->type) {
458         case QVariant::DateTime:
459             *t = v_cast<QDateTime>(d)->time();
460             break;
461 #ifndef QT_NO_DATESTRING
462         case QVariant::String:
463             *t = QTime::fromString(*v_cast<QString>(d), Qt::ISODate);
464             break;
465 #endif
466         default:
467             return false;
468         }
469         return t->isValid();
470     }
471     case QVariant::DateTime: {
472         QDateTime *dt = static_cast<QDateTime *>(result);
473         switch (d->type) {
474 #ifndef QT_NO_DATESTRING
475         case QVariant::String:
476             *dt = QDateTime::fromString(*v_cast<QString>(d), Qt::ISODate);
477             break;
478 #endif
479         case QVariant::Date:
480             *dt = QDateTime(*v_cast<QDate>(d));
481             break;
482         default:
483             return false;
484         }
485         return dt->isValid();
486     }
487     case QVariant::ByteArray: {
488         QByteArray *ba = static_cast<QByteArray *>(result);
489         switch (d->type) {
490         case QVariant::String:
491             *ba = v_cast<QString>(d)->toAscii();
492             break;
493         case QVariant::Double:
494             *ba = QByteArray::number(d->data.d, 'g', DBL_DIG);
495             break;
496         case QMetaType::Float:
497             *ba = QByteArray::number(d->data.f, 'g', FLT_DIG);
498             break;
499         case QMetaType::Char:
500         case QMetaType::UChar:
501             *ba = QByteArray(1, d->data.c);
502             break;
503         case QVariant::Int:
504         case QVariant::LongLong:
505         case QMetaType::Short:
506         case QMetaType::Long:
507             *ba = QByteArray::number(qMetaTypeNumber(d));
508             break;
509         case QVariant::UInt:
510         case QVariant::ULongLong:
511         case QMetaType::UShort:
512         case QMetaType::ULong:
513             *ba = QByteArray::number(qMetaTypeUNumber(d));
514             break;
515         case QVariant::Bool:
516             *ba = QByteArray(d->data.b ? "true" : "false");
517             break;
518         default:
519             return false;
520         }
521     }
522     break;
523     case QMetaType::Short:
524         *static_cast<short *>(result) = short(qConvertToNumber(d, ok));
525         return *ok;
526     case QMetaType::Long:
527         *static_cast<long *>(result) = long(qConvertToNumber(d, ok));
528         return *ok;
529     case QMetaType::UShort:
530         *static_cast<ushort *>(result) = ushort(qConvertToUnsignedNumber(d, ok));
531         return *ok;
532     case QMetaType::ULong:
533         *static_cast<ulong *>(result) = ulong(qConvertToUnsignedNumber(d, ok));
534         return *ok;
535     case QVariant::Int:
536         *static_cast<int *>(result) = int(qConvertToNumber(d, ok));
537         return *ok;
538     case QVariant::UInt:
539         *static_cast<uint *>(result) = uint(qConvertToUnsignedNumber(d, ok));
540         return *ok;
541     case QVariant::LongLong:
542         *static_cast<qlonglong *>(result) = qConvertToNumber(d, ok);
543         return *ok;
544     case QVariant::ULongLong: {
545         *static_cast<qulonglong *>(result) = qConvertToUnsignedNumber(d, ok);
546         return *ok;
547     }
548     case QMetaType::UChar: {
549         *static_cast<uchar *>(result) = qConvertToUnsignedNumber(d, ok);
550         return *ok;
551     }
552     case QVariant::Bool: {
553         bool *b = static_cast<bool *>(result);
554         switch(d->type) {
555         case QVariant::ByteArray:
556             *b = qt_convertToBool<QByteArray, QByteArray>(d);
557             break;
558         case QVariant::String:
559             *b = qt_convertToBool<QString, QLatin1String>(d);
560             break;
561         case QVariant::Char:
562             *b = !v_cast<QChar>(d)->isNull();
563             break;
564         case QVariant::Double:
565         case QVariant::Int:
566         case QVariant::LongLong:
567         case QMetaType::Char:
568         case QMetaType::Short:
569         case QMetaType::Long:
570         case QMetaType::Float:
571             *b = qMetaTypeNumber(d) != Q_INT64_C(0);
572             break;
573         case QVariant::UInt:
574         case QVariant::ULongLong:
575         case QMetaType::UChar:
576         case QMetaType::UShort:
577         case QMetaType::ULong:
578             *b = qMetaTypeUNumber(d) != Q_UINT64_C(0);
579             break;
580         default:
581             *b = false;
582             return false;
583         }
584         break;
585     }
586     case QVariant::Double: {
587         double *f = static_cast<double *>(result);
588         switch (d->type) {
589         case QVariant::String:
590             *f = v_cast<QString>(d)->toDouble(ok);
591             break;
592         case QVariant::ByteArray:
593             *f = v_cast<QByteArray>(d)->toDouble(ok);
594             break;
595         case QVariant::Bool:
596             *f = double(d->data.b);
597             break;
598         case QMetaType::Float:
599             *f = double(d->data.f);
600             break;
601         case QVariant::LongLong:
602         case QVariant::Int:
603         case QMetaType::Char:
604         case QMetaType::Short:
605         case QMetaType::Long:
606             *f = double(qMetaTypeNumber(d));
607             break;
608         case QVariant::UInt:
609         case QVariant::ULongLong:
610         case QMetaType::UChar:
611         case QMetaType::UShort:
612         case QMetaType::ULong:
613             *f = double(qMetaTypeUNumber(d));
614             break;
615         default:
616             *f = 0.0;
617             return false;
618         }
619         break;
620     }
621     case QMetaType::Float: {
622         float *f = static_cast<float *>(result);
623         switch (d->type) {
624         case QVariant::String:
625             *f = v_cast<QString>(d)->toFloat(ok);
626             break;
627         case QVariant::ByteArray:
628             *f = v_cast<QByteArray>(d)->toFloat(ok);
629             break;
630         case QVariant::Bool:
631             *f = float(d->data.b);
632             break;
633         case QVariant::Double:
634             *f = float(d->data.d);
635             break;
636         case QVariant::LongLong:
637         case QVariant::Int:
638         case QMetaType::Char:
639         case QMetaType::Short:
640         case QMetaType::Long:
641             *f = float(qMetaTypeNumber(d));
642             break;
643         case QVariant::UInt:
644         case QVariant::ULongLong:
645         case QMetaType::UChar:
646         case QMetaType::UShort:
647         case QMetaType::ULong:
648             *f = float(qMetaTypeUNumber(d));
649             break;
650         default:
651             *f = 0.0f;
652             return false;
653         }
654         break;
655     }
656     case QVariant::List:
657         if (d->type == QVariant::StringList) {
658             QVariantList *lst = static_cast<QVariantList *>(result);
659             const QStringList *slist = v_cast<QStringList>(d);
660             for (int i = 0; i < slist->size(); ++i)
661                 lst->append(QVariant(slist->at(i)));
662         } else if (qstrcmp(QMetaType::typeName(d->type), "QList<QVariant>") == 0) {
663             *static_cast<QVariantList *>(result) =
664                 *static_cast<QList<QVariant> *>(d->data.shared->ptr);
665         } else {
666             return false;
667         }
668         break;
669     case QVariant::Map:
670         if (qstrcmp(QMetaType::typeName(d->type), "QMap<QString, QVariant>") == 0) {
671             *static_cast<QVariantMap *>(result) =
672                 *static_cast<QMap<QString, QVariant> *>(d->data.shared->ptr);
673         } else {
674             return false;
675         }
676         break;
677     case QVariant::Hash:
678         if (qstrcmp(QMetaType::typeName(d->type), "QHash<QString, QVariant>") == 0) {
679             *static_cast<QVariantHash *>(result) =
680                 *static_cast<QHash<QString, QVariant> *>(d->data.shared->ptr);
681         } else {
682             return false;
683         }
684         break;
685 #ifndef QT_NO_GEOM_VARIANT
686     case QVariant::Rect:
687         if (d->type == QVariant::RectF)
688             *static_cast<QRect *>(result) = (v_cast<QRectF>(d))->toRect();
689         else
690             return false;
691         break;
692     case QVariant::RectF:
693         if (d->type == QVariant::Rect)
694             *static_cast<QRectF *>(result) = *v_cast<QRect>(d);
695         else
696             return false;
697         break;
698     case QVariant::PointF:
699         if (d->type == QVariant::Point)
700             *static_cast<QPointF *>(result) = *v_cast<QPoint>(d);
701         else
702             return false;
703         break;
704     case QVariant::Point:
705         if (d->type == QVariant::PointF)
706             *static_cast<QPoint *>(result) = (v_cast<QPointF>(d))->toPoint();
707         else
708             return false;
709         break;
710     case QMetaType::Char:
711     {
712         *static_cast<qint8 *>(result) = qint8(qConvertToNumber(d, ok));
713         return *ok;
714     }
715 #endif
716     case QVariant::Uuid:
717         switch (d->type) {
718         case QVariant::String:
719             *static_cast<QUuid *>(result) = QUuid(*v_cast<QString>(d));
720             break;
721         default:
722             return false;
723         }
724         break;
725     default:
726         return false;
727     }
728     return true;
729 }
730
731 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
732 static void streamDebug(QDebug dbg, const QVariant &v)
733 {
734     switch (v.userType()) {
735     case QVariant::Int:
736         dbg.nospace() << v.toInt();
737         break;
738     case QVariant::UInt:
739         dbg.nospace() << v.toUInt();
740         break;
741     case QVariant::LongLong:
742         dbg.nospace() << v.toLongLong();
743         break;
744     case QVariant::ULongLong:
745         dbg.nospace() << v.toULongLong();
746         break;
747     case QMetaType::Float:
748         dbg.nospace() << v.toFloat();
749         break;
750     case QMetaType::QObjectStar:
751         dbg.nospace() << qvariant_cast<QObject *>(v);
752         break;
753     case QVariant::Double:
754         dbg.nospace() << v.toDouble();
755         break;
756     case QVariant::Bool:
757         dbg.nospace() << v.toBool();
758         break;
759     case QVariant::String:
760         dbg.nospace() << v.toString();
761         break;
762     case QVariant::Char:
763         dbg.nospace() << v.toChar();
764         break;
765     case QVariant::StringList:
766         dbg.nospace() << v.toStringList();
767         break;
768     case QVariant::Map:
769         dbg.nospace() << v.toMap();
770         break;
771     case QVariant::Hash:
772         dbg.nospace() << v.toHash();
773         break;
774     case QVariant::List:
775         dbg.nospace() << v.toList();
776         break;
777     case QVariant::Date:
778         dbg.nospace() << v.toDate();
779         break;
780     case QVariant::Time:
781         dbg.nospace() << v.toTime();
782         break;
783     case QVariant::DateTime:
784         dbg.nospace() << v.toDateTime();
785         break;
786 #ifndef QT_BOOTSTRAPPED
787     case QVariant::EasingCurve:
788         dbg.nospace() << v.toEasingCurve();
789         break;
790 #endif
791     case QVariant::ByteArray:
792         dbg.nospace() << v.toByteArray();
793         break;
794     case QVariant::Url:
795         dbg.nospace() << v.toUrl();
796         break;
797 #ifndef QT_NO_GEOM_VARIANT
798     case QVariant::Point:
799         dbg.nospace() << v.toPoint();
800         break;
801     case QVariant::PointF:
802         dbg.nospace() << v.toPointF();
803         break;
804     case QVariant::Rect:
805         dbg.nospace() << v.toRect();
806         break;
807     case QVariant::Size:
808         dbg.nospace() << v.toSize();
809         break;
810     case QVariant::SizeF:
811         dbg.nospace() << v.toSizeF();
812         break;
813     case QVariant::Line:
814         dbg.nospace() << v.toLine();
815         break;
816     case QVariant::LineF:
817         dbg.nospace() << v.toLineF();
818         break;
819     case QVariant::RectF:
820         dbg.nospace() << v.toRectF();
821         break;
822 #endif
823     case QVariant::Uuid:
824         dbg.nospace() << v.value<QUuid>().toString();
825         break;
826     case QVariant::BitArray:
827         //dbg.nospace() << v.toBitArray();
828         break;
829     default:
830         break;
831     }
832 }
833 #endif
834
835 const QVariant::Handler qt_kernel_variant_handler = {
836     construct,
837     clear,
838     isNull,
839 #ifndef QT_NO_DATASTREAM
840     0,
841     0,
842 #endif
843     compare,
844     convert,
845     0,
846 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
847     streamDebug
848 #else
849     0
850 #endif
851 };
852
853 static void dummyConstruct(QVariant::Private *, const void *) { Q_ASSERT_X(false, "QVariant", "Trying to construct an unknown type"); }
854 static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to clear an unknown type"); }
855 static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; }
856 static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; }
857 static bool dummyConvert(const QVariant::Private *, QVariant::Type , void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
858 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
859 static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); }
860 #endif
861 const QVariant::Handler qt_dummy_variant_handler = {
862     dummyConstruct,
863     dummyClear,
864     dummyIsNull,
865 #ifndef QT_NO_DATASTREAM
866     0,
867     0,
868 #endif
869     dummyCompare,
870     dummyConvert,
871     0,
872 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
873     dummyStreamDebug
874 #else
875     0
876 #endif
877 };
878
879 static void customConstruct(QVariant::Private *d, const void *copy)
880 {
881     const uint size = QMetaType::sizeOf(d->type);
882     if (!size) {
883         d->type = QVariant::Invalid;
884         return;
885     }
886
887     // this logic should match with QVariantIntegrator::CanUseInternalSpace
888     if (size <= sizeof(QVariant::Private::Data)
889             && (QMetaType::typeFlags(d->type) & QMetaType::MovableType)) {
890         QMetaType::construct(d->type, &d->data.ptr, copy);
891         d->is_shared = false;
892     } else {
893         void *ptr = QMetaType::create(d->type, copy);
894         d->is_shared = true;
895         d->data.shared = new QVariant::PrivateShared(ptr);
896     }
897 }
898
899 static void customClear(QVariant::Private *d)
900 {
901     if (!d->is_shared) {
902         QMetaType::destruct(d->type, &d->data.ptr);
903     } else {
904         QMetaType::destroy(d->type, d->data.shared->ptr);
905         delete d->data.shared;
906     }
907 }
908
909 static bool customIsNull(const QVariant::Private *d)
910 {
911     return d->is_null;
912 }
913
914 static bool customCompare(const QVariant::Private *a, const QVariant::Private *b)
915 {
916     const char *const typeName = QMetaType::typeName(a->type);
917     if (Q_UNLIKELY(!typeName) && Q_LIKELY(!QMetaType::isRegistered(a->type)))
918         qFatal("QVariant::compare: type %d unknown to QVariant.", a->type);
919
920     const void *a_ptr = a->is_shared ? a->data.shared->ptr : &(a->data.ptr);
921     const void *b_ptr = b->is_shared ? b->data.shared->ptr : &(b->data.ptr);
922
923     uint typeNameLen = qstrlen(typeName);
924     if (typeNameLen > 0 && typeName[typeNameLen - 1] == '*')
925         return *static_cast<void *const *>(a_ptr) == *static_cast<void *const *>(b_ptr);
926
927     if (a->is_null && b->is_null)
928         return true;
929
930     return !memcmp(a_ptr, b_ptr, QMetaType::sizeOf(a->type));
931 }
932
933 static bool customConvert(const QVariant::Private *, QVariant::Type, void *, bool *ok)
934 {
935     if (ok)
936         *ok = false;
937     return false;
938 }
939
940 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
941 static void customStreamDebug(QDebug, const QVariant &) {}
942 #endif
943
944 const QVariant::Handler qt_custom_variant_handler = {
945     customConstruct,
946     customClear,
947     customIsNull,
948 #ifndef QT_NO_DATASTREAM
949     0,
950     0,
951 #endif
952     customCompare,
953     customConvert,
954     0,
955 #if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
956     customStreamDebug
957 #else
958     0
959 #endif
960 };
961
962 } // annonymous used to hide QVariant handlers
963
964 static HandlersManager handlerManager;
965 Q_STATIC_ASSERT_X(!QModulesPrivate::Core, "Initialization assumes that ModulesNames::Core is 0");
966 const QVariant::Handler *HandlersManager::Handlers[QModulesPrivate::ModulesCount]
967                                         = { &qt_kernel_variant_handler, &qt_dummy_variant_handler,
968                                             &qt_dummy_variant_handler, &qt_custom_variant_handler };
969
970 Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler()
971 {
972     return &qt_kernel_variant_handler;
973 }
974
975 inline void HandlersManager::unregisterHandler(const QModulesPrivate::Names name)
976 {
977     Handlers[name] = &qt_dummy_variant_handler;
978 }
979
980 Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names */name, const QVariant::Handler *handler)
981 {
982     handlerManager.registerHandler(static_cast<QModulesPrivate::Names>(name), handler);
983 }
984
985 Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Names */ name)
986 {
987     handlerManager.unregisterHandler(static_cast<QModulesPrivate::Names>(name));
988 }
989
990 /*!
991     \class QVariant
992     \brief The QVariant class acts like a union for the most common Qt data types.
993
994     \ingroup objectmodel
995     \ingroup shared
996
997
998     Because C++ forbids unions from including types that have
999     non-default constructors or destructors, most interesting Qt
1000     classes cannot be used in unions. Without QVariant, this would be
1001     a problem for QObject::property() and for database work, etc.
1002
1003     A QVariant object holds a single value of a single type() at a
1004     time. (Some type()s are multi-valued, for example a string list.)
1005     You can find out what type, T, the variant holds, convert it to a
1006     different type using convert(), get its value using one of the
1007     toT() functions (e.g., toSize()) and check whether the type can
1008     be converted to a particular type using canConvert().
1009
1010     The methods named toT() (e.g., toInt(), toString()) are const. If
1011     you ask for the stored type, they return a copy of the stored
1012     object. If you ask for a type that can be generated from the
1013     stored type, toT() copies and converts and leaves the object
1014     itself unchanged. If you ask for a type that cannot be generated
1015     from the stored type, the result depends on the type; see the
1016     function documentation for details.
1017
1018     Here is some example code to demonstrate the use of QVariant:
1019
1020     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 0
1021
1022     You can even store QList<QVariant> and QMap<QString, QVariant>
1023     values in a variant, so you can easily construct arbitrarily
1024     complex data structures of arbitrary types. This is very powerful
1025     and versatile, but may prove less memory and speed efficient than
1026     storing specific types in standard data structures.
1027
1028     QVariant also supports the notion of null values, where you can
1029     have a defined type with no value set. However, note that QVariant
1030     types can only be cast when they have had a value set.
1031
1032     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 1
1033
1034     QVariant can be extended to support other types than those
1035     mentioned in the \l Type enum. See the \l QMetaType documentation
1036     for details.
1037
1038     \section1 A Note on GUI Types
1039
1040     Because QVariant is part of the QtCore library, it cannot provide
1041     conversion functions to data types defined in QtGui, such as
1042     QColor, QImage, and QPixmap. In other words, there is no \c
1043     toColor() function. Instead, you can use the QVariant::value() or
1044     the qvariant_cast() template function. For example:
1045
1046     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 2
1047
1048     The inverse conversion (e.g., from QColor to QVariant) is
1049     automatic for all data types supported by QVariant, including
1050     GUI-related types:
1051
1052     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 3
1053
1054     \section1 Using canConvert() and convert() Consecutively
1055
1056     When using canConvert() and convert() consecutively, it is possible for
1057     canConvert() to return true, but convert() to return false. This
1058     is typically because canConvert() only reports the general ability of
1059     QVariant to convert between types given suitable data; it is still
1060     possible to supply data which cannot actually be converted.
1061
1062     For example, canConvert() would return true when called on a variant
1063     containing a string because, in principle, QVariant is able to convert
1064     strings of numbers to integers.
1065     However, if the string contains non-numeric characters, it cannot be
1066     converted to an integer, and any attempt to convert it will fail.
1067     Hence, it is important to have both functions return true for a
1068     successful conversion.
1069
1070     \sa QMetaType
1071 */
1072
1073 /*!
1074     \enum QVariant::Type
1075
1076     This enum type defines the types of variable that a QVariant can
1077     contain.
1078
1079     \value Invalid  no type
1080     \value BitArray  a QBitArray
1081     \value Bitmap  a QBitmap
1082     \value Bool  a bool
1083     \value Brush  a QBrush
1084     \value ByteArray  a QByteArray
1085     \value Char  a QChar
1086     \value Color  a QColor
1087     \value Cursor  a QCursor
1088     \value Date  a QDate
1089     \value DateTime  a QDateTime
1090     \value Double  a double
1091     \value EasingCurve a QEasingCurve
1092     \value Uuid a QUuid
1093     \value Font  a QFont
1094     \value Hash a QVariantHash
1095     \value Icon  a QIcon
1096     \value Image  a QImage
1097     \value Int  an int
1098     \value KeySequence  a QKeySequence
1099     \value Line  a QLine
1100     \value LineF  a QLineF
1101     \value List  a QVariantList
1102     \value Locale  a QLocale
1103     \value LongLong a \l qlonglong
1104     \value Map  a QVariantMap
1105     \value Matrix  a QMatrix
1106     \value Transform  a QTransform
1107     \value Matrix4x4  a QMatrix4x4
1108     \value Palette  a QPalette
1109     \value Pen  a QPen
1110     \value Pixmap  a QPixmap
1111     \value Point  a QPoint
1112     \value PointF  a QPointF
1113     \value Polygon a QPolygon
1114     \value PolygonF a QPolygonF
1115     \value Quaternion  a QQuaternion
1116     \value Rect  a QRect
1117     \value RectF  a QRectF
1118     \value RegExp  a QRegExp
1119     \value Region  a QRegion
1120     \value Size  a QSize
1121     \value SizeF  a QSizeF
1122     \value SizePolicy  a QSizePolicy
1123     \value String  a QString
1124     \value StringList  a QStringList
1125     \value TextFormat  a QTextFormat
1126     \value TextLength  a QTextLength
1127     \value Time  a QTime
1128     \value UInt  a \l uint
1129     \value ULongLong a \l qulonglong
1130     \value Url  a QUrl
1131     \value Vector2D  a QVector2D
1132     \value Vector3D  a QVector3D
1133     \value Vector4D  a QVector4D
1134
1135     \value UserType Base value for user-defined types.
1136
1137     \omitvalue CString
1138     \omitvalue ColorGroup
1139     \omitvalue IconSet
1140     \omitvalue LastGuiType
1141     \omitvalue LastCoreType
1142     \omitvalue LastType
1143 */
1144
1145 /*!
1146     \fn QVariant::QVariant()
1147
1148     Constructs an invalid variant.
1149 */
1150
1151
1152 /*!
1153     \fn QVariant::QVariant(int typeOrUserType, const void *copy)
1154
1155     Constructs variant of type \a typeOrUserType, and initializes with
1156     \a copy if \a copy is not 0.
1157
1158     Note that you have to pass the address of the variable you want stored.
1159
1160     Usually, you never have to use this constructor, use QVariant::fromValue()
1161     instead to construct variants from the pointer types represented by
1162     \c QMetaType::VoidStar, \c QMetaType::QObjectStar and
1163     \c QMetaType::QWidgetStar.
1164
1165     \sa QVariant::fromValue(), Type
1166 */
1167
1168 /*!
1169     \fn QVariant::QVariant(Type type)
1170
1171     Constructs a null variant of type \a type.
1172 */
1173
1174
1175
1176 /*!
1177     \fn QVariant::create(int type, const void *copy)
1178
1179     \internal
1180
1181     Constructs a variant private of type \a type, and initializes with \a copy if
1182     \a copy is not 0.
1183 */
1184
1185 void QVariant::create(int type, const void *copy)
1186 {
1187     d.type = type;
1188     handlerManager[type]->construct(&d, copy);
1189 }
1190
1191 /*!
1192     \fn QVariant::~QVariant()
1193
1194     Destroys the QVariant and the contained object.
1195
1196     Note that subclasses that reimplement clear() should reimplement
1197     the destructor to call clear(). This destructor calls clear(), but
1198     because it is the destructor, QVariant::clear() is called rather
1199     than a subclass's clear().
1200 */
1201
1202 QVariant::~QVariant()
1203 {
1204     if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared && d.type > Char))
1205         handlerManager[d.type]->clear(&d);
1206 }
1207
1208 /*!
1209   \fn QVariant::QVariant(const QVariant &p)
1210
1211     Constructs a copy of the variant, \a p, passed as the argument to
1212     this constructor.
1213 */
1214
1215 QVariant::QVariant(const QVariant &p)
1216     : d(p.d)
1217 {
1218     if (d.is_shared) {
1219         d.data.shared->ref.ref();
1220     } else if (p.d.type > Char) {
1221         handlerManager[d.type]->construct(&d, p.constData());
1222         d.is_null = p.d.is_null;
1223     }
1224 }
1225
1226 #ifndef QT_NO_DATASTREAM
1227 /*!
1228     Reads the variant from the data stream, \a s.
1229 */
1230 QVariant::QVariant(QDataStream &s)
1231 {
1232     d.is_null = true;
1233     s >> *this;
1234 }
1235 #endif //QT_NO_DATASTREAM
1236
1237 /*!
1238   \fn QVariant::QVariant(const QString &val)
1239
1240     Constructs a new variant with a string value, \a val.
1241 */
1242
1243 /*!
1244   \fn QVariant::QVariant(const QLatin1String &val)
1245
1246     Constructs a new variant with a string value, \a val.
1247 */
1248
1249 /*!
1250   \fn QVariant::QVariant(const char *val)
1251
1252     Constructs a new variant with a string value of \a val.
1253     The variant creates a deep copy of \a val, using the encoding
1254     set by QTextCodec::setCodecForCStrings().
1255
1256     Note that \a val is converted to a QString for storing in the
1257     variant and QVariant::type() will return QMetaType::QString for
1258     the variant.
1259
1260     You can disable this operator by defining \c
1261     QT_NO_CAST_FROM_ASCII when you compile your applications.
1262
1263     \sa QTextCodec::setCodecForCStrings()
1264 */
1265
1266 #ifndef QT_NO_CAST_FROM_ASCII
1267 QVariant::QVariant(const char *val)
1268 {
1269     QString s = QString::fromAscii(val);
1270     create(String, &s);
1271 }
1272 #endif
1273
1274 /*!
1275   \fn QVariant::QVariant(const QStringList &val)
1276
1277     Constructs a new variant with a string list value, \a val.
1278 */
1279
1280 /*!
1281   \fn QVariant::QVariant(const QMap<QString, QVariant> &val)
1282
1283     Constructs a new variant with a map of QVariants, \a val.
1284 */
1285
1286 /*!
1287   \fn QVariant::QVariant(const QHash<QString, QVariant> &val)
1288
1289     Constructs a new variant with a hash of QVariants, \a val.
1290 */
1291
1292 /*!
1293   \fn QVariant::QVariant(const QDate &val)
1294
1295     Constructs a new variant with a date value, \a val.
1296 */
1297
1298 /*!
1299   \fn QVariant::QVariant(const QTime &val)
1300
1301     Constructs a new variant with a time value, \a val.
1302 */
1303
1304 /*!
1305   \fn QVariant::QVariant(const QDateTime &val)
1306
1307     Constructs a new variant with a date/time value, \a val.
1308 */
1309
1310 /*!
1311     \since 4.7
1312   \fn QVariant::QVariant(const QEasingCurve &val)
1313
1314     Constructs a new variant with an easing curve value, \a val.
1315 */
1316
1317 /*!
1318   \fn QVariant::QVariant(const QByteArray &val)
1319
1320     Constructs a new variant with a bytearray value, \a val.
1321 */
1322
1323 /*!
1324   \fn QVariant::QVariant(const QBitArray &val)
1325
1326     Constructs a new variant with a bitarray value, \a val.
1327 */
1328
1329 /*!
1330   \fn QVariant::QVariant(const QPoint &val)
1331
1332   Constructs a new variant with a point value of \a val.
1333  */
1334
1335 /*!
1336   \fn QVariant::QVariant(const QPointF &val)
1337
1338   Constructs a new variant with a point value of \a val.
1339  */
1340
1341 /*!
1342   \fn QVariant::QVariant(const QRectF &val)
1343
1344   Constructs a new variant with a rect value of \a val.
1345  */
1346
1347 /*!
1348   \fn QVariant::QVariant(const QLineF &val)
1349
1350   Constructs a new variant with a line value of \a val.
1351  */
1352
1353 /*!
1354   \fn QVariant::QVariant(const QLine &val)
1355
1356   Constructs a new variant with a line value of \a val.
1357  */
1358
1359 /*!
1360   \fn QVariant::QVariant(const QRect &val)
1361
1362   Constructs a new variant with a rect value of \a val.
1363  */
1364
1365 /*!
1366   \fn QVariant::QVariant(const QSize &val)
1367
1368   Constructs a new variant with a size value of \a val.
1369  */
1370
1371 /*!
1372   \fn QVariant::QVariant(const QSizeF &val)
1373
1374   Constructs a new variant with a size value of \a val.
1375  */
1376
1377 /*!
1378   \fn QVariant::QVariant(const QUrl &val)
1379
1380   Constructs a new variant with a url value of \a val.
1381  */
1382
1383 /*!
1384   \fn QVariant::QVariant(int val)
1385
1386     Constructs a new variant with an integer value, \a val.
1387 */
1388
1389 /*!
1390   \fn QVariant::QVariant(uint val)
1391
1392     Constructs a new variant with an unsigned integer value, \a val.
1393 */
1394
1395 /*!
1396   \fn QVariant::QVariant(qlonglong val)
1397
1398     Constructs a new variant with a long long integer value, \a val.
1399 */
1400
1401 /*!
1402   \fn QVariant::QVariant(qulonglong val)
1403
1404     Constructs a new variant with an unsigned long long integer value, \a val.
1405 */
1406
1407
1408 /*!
1409   \fn QVariant::QVariant(bool val)
1410
1411     Constructs a new variant with a boolean value, \a val.
1412 */
1413
1414 /*!
1415   \fn QVariant::QVariant(double val)
1416
1417     Constructs a new variant with a floating point value, \a val.
1418 */
1419
1420 /*!
1421   \fn QVariant::QVariant(float val)
1422
1423     Constructs a new variant with a floating point value, \a val.
1424     \since 4.6
1425 */
1426
1427 /*!
1428     \fn QVariant::QVariant(const QList<QVariant> &val)
1429
1430     Constructs a new variant with a list value, \a val.
1431 */
1432
1433 /*!
1434   \fn QVariant::QVariant(const QChar &c)
1435
1436   Constructs a new variant with a char value, \a c.
1437 */
1438
1439 /*!
1440   \fn QVariant::QVariant(const QLocale &l)
1441
1442   Constructs a new variant with a locale value, \a l.
1443 */
1444
1445 /*!
1446   \fn QVariant::QVariant(const QRegExp &regExp)
1447
1448   Constructs a new variant with the regexp value \a regExp.
1449 */
1450
1451 /*! \since 4.2
1452   \fn QVariant::QVariant(Qt::GlobalColor color)
1453
1454   Constructs a new variant of type QVariant::Color and initializes
1455   it with \a color.
1456
1457   This is a convenience constructor that allows \c{QVariant(Qt::blue);}
1458   to create a valid QVariant storing a QColor.
1459
1460   Note: This constructor will assert if the application does not link
1461   to the Qt GUI library.
1462  */
1463
1464 QVariant::QVariant(Type type)
1465 { create(type, 0); }
1466 QVariant::QVariant(int typeOrUserType, const void *copy)
1467 { create(typeOrUserType, copy); d.is_null = false; }
1468
1469 /*! \internal
1470     flags is true if it is a pointer type
1471  */
1472 QVariant::QVariant(int typeOrUserType, const void *copy, uint flags)
1473 {
1474     if (flags) { //type is a pointer type
1475         d.type = typeOrUserType;
1476         d.data.ptr = *reinterpret_cast<void *const*>(copy);
1477     } else {
1478         create(typeOrUserType, copy);
1479     }
1480     d.is_null = false;
1481 }
1482
1483 QVariant::QVariant(int val)
1484 { d.is_null = false; d.type = Int; d.data.i = val; }
1485 QVariant::QVariant(uint val)
1486 { d.is_null = false; d.type = UInt; d.data.u = val; }
1487 QVariant::QVariant(qlonglong val)
1488 { d.is_null = false; d.type = LongLong; d.data.ll = val; }
1489 QVariant::QVariant(qulonglong val)
1490 { d.is_null = false; d.type = ULongLong; d.data.ull = val; }
1491 QVariant::QVariant(bool val)
1492 { d.is_null = false; d.type = Bool; d.data.b = val; }
1493 QVariant::QVariant(double val)
1494 { d.is_null = false; d.type = Double; d.data.d = val; }
1495
1496 QVariant::QVariant(const QByteArray &val)
1497 { d.is_null = false; d.type = ByteArray; v_construct<QByteArray>(&d, val); }
1498 QVariant::QVariant(const QBitArray &val)
1499 { d.is_null = false; d.type = BitArray; v_construct<QBitArray>(&d, val);  }
1500 QVariant::QVariant(const QString &val)
1501 { d.is_null = false; d.type = String; v_construct<QString>(&d, val);  }
1502 QVariant::QVariant(const QChar &val)
1503 { d.is_null = false; d.type = Char; v_construct<QChar>(&d, val);  }
1504 QVariant::QVariant(const QLatin1String &val)
1505 { QString str(val); d.is_null = false; d.type = String; v_construct<QString>(&d, str); }
1506 QVariant::QVariant(const QStringList &val)
1507 { d.is_null = false; d.type = StringList; v_construct<QStringList>(&d, val); }
1508
1509 QVariant::QVariant(const QDate &val)
1510 { d.is_null = false; d.type = Date; v_construct<QDate>(&d, val); }
1511 QVariant::QVariant(const QTime &val)
1512 { d.is_null = false; d.type = Time; v_construct<QTime>(&d, val); }
1513 QVariant::QVariant(const QDateTime &val)
1514 { d.is_null = false; d.type = DateTime; v_construct<QDateTime>(&d, val); }
1515 #ifndef QT_BOOTSTRAPPED
1516 QVariant::QVariant(const QEasingCurve &val)
1517 { d.is_null = false; d.type = EasingCurve; v_construct<QEasingCurve>(&d, val); }
1518 #endif
1519 QVariant::QVariant(const QList<QVariant> &list)
1520 { d.is_null = false; d.type = List; v_construct<QVariantList>(&d, list); }
1521 QVariant::QVariant(const QMap<QString, QVariant> &map)
1522 { d.is_null = false; d.type = Map; v_construct<QVariantMap>(&d, map); }
1523 QVariant::QVariant(const QHash<QString, QVariant> &hash)
1524 { d.is_null = false; d.type = Hash; v_construct<QVariantHash>(&d, hash); }
1525 #ifndef QT_NO_GEOM_VARIANT
1526 QVariant::QVariant(const QPoint &pt) { d.is_null = false; d.type = Point; v_construct<QPoint>(&d, pt); }
1527 QVariant::QVariant(const QPointF &pt) { d.is_null = false; d.type = PointF; v_construct<QPointF>(&d, pt); }
1528 QVariant::QVariant(const QRectF &r) { d.is_null = false; d.type = RectF; v_construct<QRectF>(&d, r); }
1529 QVariant::QVariant(const QLineF &l) { d.is_null = false; d.type = LineF; v_construct<QLineF>(&d, l); }
1530 QVariant::QVariant(const QLine &l) { d.is_null = false; d.type = Line; v_construct<QLine>(&d, l); }
1531 QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_construct<QRect>(&d, r); }
1532 QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct<QSize>(&d, s); }
1533 QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct<QSizeF>(&d, s); }
1534 #endif
1535 QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct<QUrl>(&d, u); }
1536 QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct<QLocale>(&d, l); }
1537 #ifndef QT_NO_REGEXP
1538 QVariant::QVariant(const QRegExp &regExp) { d.is_null = false; d.type = RegExp; v_construct<QRegExp>(&d, regExp); }
1539 #endif
1540 QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); }
1541
1542 /*!
1543     Returns the storage type of the value stored in the variant.
1544     Although this function is declared as returning QVariant::Type,
1545     the return value should be interpreted as QMetaType::Type. In
1546     particular, QVariant::UserType is returned here only if the value
1547     is equal or greater than QMetaType::User.
1548
1549     Note that return values in the ranges QVariant::Char through
1550     QVariant::RegExp and QVariant::Font through QVariant::Transform
1551     correspond to the values in the ranges QMetaType::QChar through
1552     QMetaType::QRegExp and QMetaType::QFont through QMetaType::QQuaternion.
1553
1554     Pay particular attention when working with char and QChar
1555     variants.  Note that there is no QVariant constructor specifically
1556     for type char, but there is one for QChar. For a variant of type
1557     QChar, this function returns QVariant::Char, which is the same as
1558     QMetaType::QChar, but for a variant of type \c char, this function
1559     returns QMetaType::Char, which is \e not the same as
1560     QVariant::Char.
1561
1562     Also note that the types \c void*, \c long, \c short, \c unsigned
1563     \c long, \c unsigned \c short, \c unsigned \c char, \c float, \c
1564     QObject*, and \c QWidget* are represented in QMetaType::Type but
1565     not in QVariant::Type, and they can be returned by this function.
1566     However, they are considered to be user defined types when tested
1567     against QVariant::Type.
1568
1569     To test whether an instance of QVariant contains a data type that
1570     is compatible with the data type you are interested in, use
1571     canConvert().
1572 */
1573
1574 QVariant::Type QVariant::type() const
1575 {
1576     return d.type >= QMetaType::User ? UserType : static_cast<Type>(d.type);
1577 }
1578
1579 /*!
1580     Returns the storage type of the value stored in the variant. For
1581     non-user types, this is the same as type().
1582
1583     \sa type()
1584 */
1585
1586 int QVariant::userType() const
1587 {
1588     return d.type;
1589 }
1590
1591 /*!
1592     Assigns the value of the variant \a variant to this variant.
1593 */
1594 QVariant& QVariant::operator=(const QVariant &variant)
1595 {
1596     if (this == &variant)
1597         return *this;
1598
1599     clear();
1600     if (variant.d.is_shared) {
1601         variant.d.data.shared->ref.ref();
1602         d = variant.d;
1603     } else if (variant.d.type > Char) {
1604         d.type = variant.d.type;
1605         handlerManager[d.type]->construct(&d, variant.constData());
1606         d.is_null = variant.d.is_null;
1607     } else {
1608         d = variant.d;
1609     }
1610
1611     return *this;
1612 }
1613
1614 /*!
1615     \fn void QVariant::swap(QVariant &other)
1616     \since 4.8
1617
1618     Swaps variant \a other with this variant. This operation is very
1619     fast and never fails.
1620 */
1621
1622 /*!
1623     \fn void QVariant::detach()
1624
1625     \internal
1626 */
1627
1628 void QVariant::detach()
1629 {
1630     if (!d.is_shared || d.data.shared->ref.load() == 1)
1631         return;
1632
1633     Private dd;
1634     dd.type = d.type;
1635     handlerManager[d.type]->construct(&dd, constData());
1636     if (!d.data.shared->ref.deref())
1637         handlerManager[d.type]->clear(&d);
1638     d.data.shared = dd.data.shared;
1639 }
1640
1641 /*!
1642     \fn bool QVariant::isDetached() const
1643
1644     \internal
1645 */
1646
1647 // ### Qt 5: change typeName()(and froends= to return a QString. Suggestion from Harald.
1648 /*!
1649     Returns the name of the type stored in the variant. The returned
1650     strings describe the C++ datatype used to store the data: for
1651     example, "QFont", "QString", or "QVariantList". An Invalid
1652     variant returns 0.
1653 */
1654 const char *QVariant::typeName() const
1655 {
1656     return typeToName(Type(d.type));
1657 }
1658
1659 /*!
1660     Convert this variant to type Invalid and free up any resources
1661     used.
1662 */
1663 void QVariant::clear()
1664 {
1665     if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared && d.type > Char))
1666         handlerManager[d.type]->clear(&d);
1667     d.type = Invalid;
1668     d.is_null = true;
1669     d.is_shared = false;
1670 }
1671
1672 /*!
1673     Converts the enum representation of the storage type, \a typ, to
1674     its string representation.
1675
1676     Returns a null pointer if the type is QVariant::Invalid or doesn't exist.
1677 */
1678 const char *QVariant::typeToName(Type typ)
1679 {
1680     if (typ == Invalid)
1681         return 0;
1682     if (typ == UserType)
1683         return "UserType";
1684
1685     return QMetaType::typeName(typ);
1686 }
1687
1688
1689 /*!
1690     Converts the string representation of the storage type given in \a
1691     name, to its enum representation.
1692
1693     If the string representation cannot be converted to any enum
1694     representation, the variant is set to \c Invalid.
1695 */
1696 QVariant::Type QVariant::nameToType(const char *name)
1697 {
1698     if (!name || !*name)
1699         return Invalid;
1700     if (strcmp(name, "Q3CString") == 0)
1701         return ByteArray;
1702     if (strcmp(name, "Q_LLONG") == 0)
1703         return LongLong;
1704     if (strcmp(name, "Q_ULLONG") == 0)
1705         return ULongLong;
1706     if (strcmp(name, "QIconSet") == 0)
1707         return Icon;
1708     if (strcmp(name, "UserType") == 0)
1709         return UserType;
1710
1711     int metaType = QMetaType::type(name);
1712     return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;
1713 }
1714
1715 #ifndef QT_NO_DATASTREAM
1716 enum { MapFromThreeCount = 36 };
1717 static const ushort map_from_three[MapFromThreeCount] =
1718 {
1719     QVariant::Invalid,
1720     QVariant::Map,
1721     QVariant::List,
1722     QVariant::String,
1723     QVariant::StringList,
1724     QVariant::Font,
1725     QVariant::Pixmap,
1726     QVariant::Brush,
1727     QVariant::Rect,
1728     QVariant::Size,
1729     QVariant::Color,
1730     QVariant::Palette,
1731     63, // ColorGroup
1732     QVariant::Icon,
1733     QVariant::Point,
1734     QVariant::Image,
1735     QVariant::Int,
1736     QVariant::UInt,
1737     QVariant::Bool,
1738     QVariant::Double,
1739     QVariant::ByteArray,
1740     QVariant::Polygon,
1741     QVariant::Region,
1742     QVariant::Bitmap,
1743     QVariant::Cursor,
1744     QVariant::SizePolicy,
1745     QVariant::Date,
1746     QVariant::Time,
1747     QVariant::DateTime,
1748     QVariant::ByteArray,
1749     QVariant::BitArray,
1750     QVariant::KeySequence,
1751     QVariant::Pen,
1752     QVariant::LongLong,
1753     QVariant::ULongLong,
1754     QVariant::EasingCurve
1755 };
1756
1757 /*!
1758     Internal function for loading a variant from stream \a s. Use the
1759     stream operators instead.
1760
1761     \internal
1762 */
1763 void QVariant::load(QDataStream &s)
1764 {
1765     clear();
1766
1767     quint32 u;
1768     s >> u;
1769     if (s.version() < QDataStream::Qt_4_0) {
1770         if (u >= MapFromThreeCount)
1771             return;
1772         u = map_from_three[u];
1773     }
1774     qint8 is_null = false;
1775     if (s.version() >= QDataStream::Qt_4_2)
1776         s >> is_null;
1777     if (u == QVariant::UserType) {
1778         QByteArray name;
1779         s >> name;
1780         u = QMetaType::type(name);
1781         if (!u) {
1782             s.setStatus(QDataStream::ReadCorruptData);
1783             return;
1784         }
1785     }
1786     create(static_cast<int>(u), 0);
1787     d.is_null = is_null;
1788
1789     if (!isValid()) {
1790         // Since we wrote something, we should read something
1791         QString x;
1792         s >> x;
1793         d.is_null = true;
1794         return;
1795     }
1796
1797     // const cast is safe since we operate on a newly constructed variant
1798     if (!QMetaType::load(s, d.type, const_cast<void *>(constData()))) {
1799         s.setStatus(QDataStream::ReadCorruptData);
1800         qWarning("QVariant::load: unable to load type %d.", d.type);
1801     }
1802 }
1803
1804 /*!
1805     Internal function for saving a variant to the stream \a s. Use the
1806     stream operators instead.
1807
1808     \internal
1809 */
1810 void QVariant::save(QDataStream &s) const
1811 {
1812     quint32 tp = type();
1813     if (s.version() < QDataStream::Qt_4_0) {
1814         int i;
1815         for (i = MapFromThreeCount - 1; i >= 0; i--) {
1816             if (map_from_three[i] == tp) {
1817                 tp = i;
1818                 break;
1819             }
1820         }
1821         if (i == -1) {
1822             s << QVariant();
1823             return;
1824         }
1825     }
1826     s << tp;
1827     if (s.version() >= QDataStream::Qt_4_2)
1828         s << qint8(d.is_null);
1829     if (tp == QVariant::UserType) {
1830         s << QMetaType::typeName(userType());
1831     }
1832
1833     if (!isValid()) {
1834         s << QString();
1835         return;
1836     }
1837
1838     if (!QMetaType::save(s, d.type, constData())) {
1839         Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
1840         qWarning("QVariant::save: unable to save type %d.", d.type);
1841     }
1842 }
1843
1844 /*!
1845     \since 4.4
1846
1847     Reads a variant \a p from the stream \a s.
1848
1849     \sa \link datastreamformat.html Format of the QDataStream
1850     operators \endlink
1851 */
1852 QDataStream& operator>>(QDataStream &s, QVariant &p)
1853 {
1854     p.load(s);
1855     return s;
1856 }
1857
1858 /*!
1859     Writes a variant \a p to the stream \a s.
1860
1861     \sa \link datastreamformat.html Format of the QDataStream
1862     operators \endlink
1863 */
1864 QDataStream& operator<<(QDataStream &s, const QVariant &p)
1865 {
1866     p.save(s);
1867     return s;
1868 }
1869
1870 /*!
1871     Reads a variant type \a p in enum representation from the stream \a s.
1872 */
1873 QDataStream& operator>>(QDataStream &s, QVariant::Type &p)
1874 {
1875     quint32 u;
1876     s >> u;
1877     p = (QVariant::Type)u;
1878
1879     return s;
1880 }
1881
1882 /*!
1883     Writes a variant type \a p to the stream \a s.
1884 */
1885 QDataStream& operator<<(QDataStream &s, const QVariant::Type p)
1886 {
1887     s << static_cast<quint32>(p);
1888
1889     return s;
1890 }
1891
1892 #endif //QT_NO_DATASTREAM
1893
1894 /*!
1895     \fn bool QVariant::isValid() const
1896
1897     Returns true if the storage type of this variant is not
1898     QVariant::Invalid; otherwise returns false.
1899 */
1900
1901 template <typename T>
1902 inline T qVariantToHelper(const QVariant::Private &d, QVariant::Type t, const HandlersManager &handler)
1903 {
1904     if (d.type == t)
1905         return *v_cast<T>(&d);
1906
1907     T ret;
1908     handler[d.type]->convert(&d, t, &ret, 0);
1909     return ret;
1910 }
1911
1912 /*!
1913     \fn QStringList QVariant::toStringList() const
1914
1915     Returns the variant as a QStringList if the variant has type()
1916     StringList, \l String, or \l List of a type that can be converted
1917     to QString; otherwise returns an empty list.
1918
1919     \sa canConvert(), convert()
1920 */
1921 QStringList QVariant::toStringList() const
1922 {
1923     return qVariantToHelper<QStringList>(d, StringList, handlerManager);
1924 }
1925
1926 /*!
1927     Returns the variant as a QString if the variant has type() \l
1928     String, \l Bool, \l ByteArray, \l Char, \l Date, \l DateTime, \l
1929     Double, \l Int, \l LongLong, \l StringList, \l Time, \l UInt, or
1930     \l ULongLong; otherwise returns an empty string.
1931
1932     \sa canConvert(), convert()
1933 */
1934 QString QVariant::toString() const
1935 {
1936     return qVariantToHelper<QString>(d, String, handlerManager);
1937 }
1938
1939 /*!
1940     Returns the variant as a QMap<QString, QVariant> if the variant
1941     has type() \l Map; otherwise returns an empty map.
1942
1943     \sa canConvert(), convert()
1944 */
1945 QVariantMap QVariant::toMap() const
1946 {
1947     return qVariantToHelper<QVariantMap>(d, Map, handlerManager);
1948 }
1949
1950 /*!
1951     Returns the variant as a QHash<QString, QVariant> if the variant
1952     has type() \l Hash; otherwise returns an empty map.
1953
1954     \sa canConvert(), convert()
1955 */
1956 QVariantHash QVariant::toHash() const
1957 {
1958     return qVariantToHelper<QVariantHash>(d, Hash, handlerManager);
1959 }
1960
1961 /*!
1962     \fn QDate QVariant::toDate() const
1963
1964     Returns the variant as a QDate if the variant has type() \l Date,
1965     \l DateTime, or \l String; otherwise returns an invalid date.
1966
1967     If the type() is \l String, an invalid date will be returned if the
1968     string cannot be parsed as a Qt::ISODate format date.
1969
1970     \sa canConvert(), convert()
1971 */
1972 QDate QVariant::toDate() const
1973 {
1974     return qVariantToHelper<QDate>(d, Date, handlerManager);
1975 }
1976
1977 /*!
1978     \fn QTime QVariant::toTime() const
1979
1980     Returns the variant as a QTime if the variant has type() \l Time,
1981     \l DateTime, or \l String; otherwise returns an invalid time.
1982
1983     If the type() is \l String, an invalid time will be returned if
1984     the string cannot be parsed as a Qt::ISODate format time.
1985
1986     \sa canConvert(), convert()
1987 */
1988 QTime QVariant::toTime() const
1989 {
1990     return qVariantToHelper<QTime>(d, Time, handlerManager);
1991 }
1992
1993 /*!
1994     \fn QDateTime QVariant::toDateTime() const
1995
1996     Returns the variant as a QDateTime if the variant has type() \l
1997     DateTime, \l Date, or \l String; otherwise returns an invalid
1998     date/time.
1999
2000     If the type() is \l String, an invalid date/time will be returned
2001     if the string cannot be parsed as a Qt::ISODate format date/time.
2002
2003     \sa canConvert(), convert()
2004 */
2005 QDateTime QVariant::toDateTime() const
2006 {
2007     return qVariantToHelper<QDateTime>(d, DateTime, handlerManager);
2008 }
2009
2010 /*!
2011     \since 4.7
2012     \fn QEasingCurve QVariant::toEasingCurve() const
2013
2014     Returns the variant as a QEasingCurve if the variant has type() \l
2015     EasingCurve; otherwise returns a default easing curve.
2016
2017     \sa canConvert(), convert()
2018 */
2019 #ifndef QT_BOOTSTRAPPED
2020 QEasingCurve QVariant::toEasingCurve() const
2021 {
2022     return qVariantToHelper<QEasingCurve>(d, EasingCurve, handlerManager);
2023 }
2024 #endif
2025
2026 /*!
2027     \fn QByteArray QVariant::toByteArray() const
2028
2029     Returns the variant as a QByteArray if the variant has type() \l
2030     ByteArray or \l String (converted using QString::fromAscii());
2031     otherwise returns an empty byte array.
2032
2033     \sa canConvert(), convert()
2034 */
2035 QByteArray QVariant::toByteArray() const
2036 {
2037     return qVariantToHelper<QByteArray>(d, ByteArray, handlerManager);
2038 }
2039
2040 #ifndef QT_NO_GEOM_VARIANT
2041 /*!
2042     \fn QPoint QVariant::toPoint() const
2043
2044     Returns the variant as a QPoint if the variant has type()
2045     \l Point or \l PointF; otherwise returns a null QPoint.
2046
2047     \sa canConvert(), convert()
2048 */
2049 QPoint QVariant::toPoint() const
2050 {
2051     return qVariantToHelper<QPoint>(d, Point, handlerManager);
2052 }
2053
2054 /*!
2055     \fn QRect QVariant::toRect() const
2056
2057     Returns the variant as a QRect if the variant has type() \l Rect;
2058     otherwise returns an invalid QRect.
2059
2060     \sa canConvert(), convert()
2061 */
2062 QRect QVariant::toRect() const
2063 {
2064     return qVariantToHelper<QRect>(d, Rect, handlerManager);
2065 }
2066
2067 /*!
2068     \fn QSize QVariant::toSize() const
2069
2070     Returns the variant as a QSize if the variant has type() \l Size;
2071     otherwise returns an invalid QSize.
2072
2073     \sa canConvert(), convert()
2074 */
2075 QSize QVariant::toSize() const
2076 {
2077     return qVariantToHelper<QSize>(d, Size, handlerManager);
2078 }
2079
2080 /*!
2081     \fn QSizeF QVariant::toSizeF() const
2082
2083     Returns the variant as a QSizeF if the variant has type() \l
2084     SizeF; otherwise returns an invalid QSizeF.
2085
2086     \sa canConvert(), convert()
2087 */
2088 QSizeF QVariant::toSizeF() const
2089 {
2090     return qVariantToHelper<QSizeF>(d, SizeF, handlerManager);
2091 }
2092
2093 /*!
2094     \fn QRectF QVariant::toRectF() const
2095
2096     Returns the variant as a QRectF if the variant has type() \l Rect
2097     or \l RectF; otherwise returns an invalid QRectF.
2098
2099     \sa canConvert(), convert()
2100 */
2101 QRectF QVariant::toRectF() const
2102 {
2103     return qVariantToHelper<QRectF>(d, RectF, handlerManager);
2104 }
2105
2106 /*!
2107     \fn QLineF QVariant::toLineF() const
2108
2109     Returns the variant as a QLineF if the variant has type() \l
2110     LineF; otherwise returns an invalid QLineF.
2111
2112     \sa canConvert(), convert()
2113 */
2114 QLineF QVariant::toLineF() const
2115 {
2116     return qVariantToHelper<QLineF>(d, LineF, handlerManager);
2117 }
2118
2119 /*!
2120     \fn QLine QVariant::toLine() const
2121
2122     Returns the variant as a QLine if the variant has type() \l Line;
2123     otherwise returns an invalid QLine.
2124
2125     \sa canConvert(), convert()
2126 */
2127 QLine QVariant::toLine() const
2128 {
2129     return qVariantToHelper<QLine>(d, Line, handlerManager);
2130 }
2131
2132 /*!
2133     \fn QPointF QVariant::toPointF() const
2134
2135     Returns the variant as a QPointF if the variant has type() \l
2136     Point or \l PointF; otherwise returns a null QPointF.
2137
2138     \sa canConvert(), convert()
2139 */
2140 QPointF QVariant::toPointF() const
2141 {
2142     return qVariantToHelper<QPointF>(d, PointF, handlerManager);
2143 }
2144
2145 #endif // QT_NO_GEOM_VARIANT
2146
2147 /*!
2148     \fn QUrl QVariant::toUrl() const
2149
2150     Returns the variant as a QUrl if the variant has type()
2151     \l Url; otherwise returns an invalid QUrl.
2152
2153     \sa canConvert(), convert()
2154 */
2155 QUrl QVariant::toUrl() const
2156 {
2157     return qVariantToHelper<QUrl>(d, Url, handlerManager);
2158 }
2159
2160 /*!
2161     \fn QLocale QVariant::toLocale() const
2162
2163     Returns the variant as a QLocale if the variant has type()
2164     \l Locale; otherwise returns an invalid QLocale.
2165
2166     \sa canConvert(), convert()
2167 */
2168 QLocale QVariant::toLocale() const
2169 {
2170     return qVariantToHelper<QLocale>(d, Locale, handlerManager);
2171 }
2172
2173 /*!
2174     \fn QRegExp QVariant::toRegExp() const
2175     \since 4.1
2176
2177     Returns the variant as a QRegExp if the variant has type() \l
2178     RegExp; otherwise returns an empty QRegExp.
2179
2180     \sa canConvert(), convert()
2181 */
2182 #ifndef QT_NO_REGEXP
2183 QRegExp QVariant::toRegExp() const
2184 {
2185     return qVariantToHelper<QRegExp>(d, RegExp, handlerManager);
2186 }
2187 #endif
2188
2189 /*!
2190     \fn QChar QVariant::toChar() const
2191
2192     Returns the variant as a QChar if the variant has type() \l Char,
2193     \l Int, or \l UInt; otherwise returns an invalid QChar.
2194
2195     \sa canConvert(), convert()
2196 */
2197 QChar QVariant::toChar() const
2198 {
2199     return qVariantToHelper<QChar>(d, Char, handlerManager);
2200 }
2201
2202 /*!
2203     Returns the variant as a QBitArray if the variant has type()
2204     \l BitArray; otherwise returns an empty bit array.
2205
2206     \sa canConvert(), convert()
2207 */
2208 QBitArray QVariant::toBitArray() const
2209 {
2210     return qVariantToHelper<QBitArray>(d, BitArray, handlerManager);
2211 }
2212
2213 template <typename T>
2214 inline T qNumVariantToHelper(const QVariant::Private &d,
2215                              const HandlersManager &handler, bool *ok, const T& val)
2216 {
2217     uint t = qMetaTypeId<T>();
2218     if (ok)
2219         *ok = true;
2220     if (d.type == t)
2221         return val;
2222
2223     T ret = 0;
2224     if (!handler[d.type]->convert(&d, QVariant::Type(t), &ret, ok) && ok)
2225         *ok = false;
2226     return ret;
2227 }
2228
2229 /*!
2230     Returns the variant as an int if the variant has type() \l Int,
2231     \l Bool, \l ByteArray, \l Char, \l Double, \l LongLong, \l
2232     String, \l UInt, or \l ULongLong; otherwise returns 0.
2233
2234     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2235     converted to an int; otherwise \c{*}\a{ok} is set to false.
2236
2237     \bold{Warning:} If the value is convertible to a \l LongLong but is too
2238     large to be represented in an int, the resulting arithmetic overflow will
2239     not be reflected in \a ok. A simple workaround is to use QString::toInt().
2240     Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.
2241
2242     \sa canConvert(), convert()
2243 */
2244 int QVariant::toInt(bool *ok) const
2245 {
2246     return qNumVariantToHelper<int>(d, handlerManager, ok, d.data.i);
2247 }
2248
2249 /*!
2250     Returns the variant as an unsigned int if the variant has type()
2251     \l UInt,  \l Bool, \l ByteArray, \l Char, \l Double, \l Int, \l
2252     LongLong, \l String, or \l ULongLong; otherwise returns 0.
2253
2254     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2255     converted to an unsigned int; otherwise \c{*}\a{ok} is set to false.
2256
2257     \bold{Warning:} If the value is convertible to a \l ULongLong but is too
2258     large to be represented in an unsigned int, the resulting arithmetic overflow will
2259     not be reflected in \a ok. A simple workaround is to use QString::toUInt().
2260     Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.
2261
2262     \sa canConvert(), convert()
2263 */
2264 uint QVariant::toUInt(bool *ok) const
2265 {
2266     return qNumVariantToHelper<uint>(d, handlerManager, ok, d.data.u);
2267 }
2268
2269 /*!
2270     Returns the variant as a long long int if the variant has type()
2271     \l LongLong, \l Bool, \l ByteArray, \l Char, \l Double, \l Int,
2272     \l String, \l UInt, or \l ULongLong; otherwise returns 0.
2273
2274     If \a ok is non-null: \c{*}\c{ok} is set to true if the value could be
2275     converted to an int; otherwise \c{*}\c{ok} is set to false.
2276
2277     \sa canConvert(), convert()
2278 */
2279 qlonglong QVariant::toLongLong(bool *ok) const
2280 {
2281     return qNumVariantToHelper<qlonglong>(d, handlerManager, ok, d.data.ll);
2282 }
2283
2284 /*!
2285     Returns the variant as as an unsigned long long int if the
2286     variant has type() \l ULongLong, \l Bool, \l ByteArray, \l Char,
2287     \l Double, \l Int, \l LongLong, \l String, or \l UInt; otherwise
2288     returns 0.
2289
2290     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2291     converted to an int; otherwise \c{*}\a{ok} is set to false.
2292
2293     \sa canConvert(), convert()
2294 */
2295 qulonglong QVariant::toULongLong(bool *ok) const
2296 {
2297     return qNumVariantToHelper<qulonglong>(d, handlerManager, ok, d.data.ull);
2298 }
2299
2300 /*!
2301     Returns the variant as a bool if the variant has type() Bool.
2302
2303     Returns true if the variant has type() \l Bool, \l Char, \l Double,
2304     \l Int, \l LongLong, \l UInt, or \l ULongLong and the value is
2305     non-zero, or if the variant has type \l String or \l ByteArray and
2306     its lower-case content is not empty, "0" or "false"; otherwise
2307     returns false.
2308
2309     \sa canConvert(), convert()
2310 */
2311 bool QVariant::toBool() const
2312 {
2313     if (d.type == Bool)
2314         return d.data.b;
2315
2316     bool res = false;
2317     handlerManager[d.type]->convert(&d, Bool, &res, 0);
2318
2319     return res;
2320 }
2321
2322 /*!
2323     Returns the variant as a double if the variant has type() \l
2324     Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
2325     UInt, or \l ULongLong; otherwise returns 0.0.
2326
2327     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2328     converted to a double; otherwise \c{*}\a{ok} is set to false.
2329
2330     \sa canConvert(), convert()
2331 */
2332 double QVariant::toDouble(bool *ok) const
2333 {
2334     return qNumVariantToHelper<double>(d, handlerManager, ok, d.data.d);
2335 }
2336
2337 /*!
2338     Returns the variant as a float if the variant has type() \l
2339     Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
2340     UInt, or \l ULongLong; otherwise returns 0.0.
2341
2342     \since 4.6
2343
2344     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2345     converted to a double; otherwise \c{*}\a{ok} is set to false.
2346
2347     \sa canConvert(), convert()
2348 */
2349 float QVariant::toFloat(bool *ok) const
2350 {
2351     return qNumVariantToHelper<float>(d, handlerManager, ok, d.data.f);
2352 }
2353
2354 /*!
2355     Returns the variant as a qreal if the variant has type() \l
2356     Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
2357     UInt, or \l ULongLong; otherwise returns 0.0.
2358
2359     \since 4.6
2360
2361     If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
2362     converted to a double; otherwise \c{*}\a{ok} is set to false.
2363
2364     \sa canConvert(), convert()
2365 */
2366 qreal QVariant::toReal(bool *ok) const
2367 {
2368     return qNumVariantToHelper<qreal>(d, handlerManager, ok, d.data.real);
2369 }
2370
2371 /*!
2372     Returns the variant as a QVariantList if the variant has type()
2373     \l List or \l StringList; otherwise returns an empty list.
2374
2375     \sa canConvert(), convert()
2376 */
2377 QVariantList QVariant::toList() const
2378 {
2379     return qVariantToHelper<QVariantList>(d, List, handlerManager);
2380 }
2381
2382
2383 static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
2384 {
2385 /*Invalid*/     0,
2386
2387 /*Bool*/          1 << QVariant::Double     | 1 << QVariant::Int        | 1 << QVariant::UInt
2388                 | 1 << QVariant::LongLong   | 1 << QVariant::ULongLong  | 1 << QVariant::ByteArray
2389                 | 1 << QVariant::String     | 1 << QVariant::Char,
2390
2391 /*Int*/           1 << QVariant::UInt       | 1 << QVariant::String     | 1 << QVariant::Double
2392                 | 1 << QVariant::Bool       | 1 << QVariant::LongLong   | 1 << QVariant::ULongLong
2393                 | 1 << QVariant::Char       | 1 << QVariant::ByteArray,
2394
2395 /*UInt*/          1 << QVariant::Int        | 1 << QVariant::String     | 1 << QVariant::Double
2396                 | 1 << QVariant::Bool       | 1 << QVariant::LongLong   | 1 << QVariant::ULongLong
2397                 | 1 << QVariant::Char       | 1 << QVariant::ByteArray,
2398
2399 /*LLong*/         1 << QVariant::Int        | 1 << QVariant::String     | 1 << QVariant::Double
2400                 | 1 << QVariant::Bool       | 1 << QVariant::UInt       | 1 << QVariant::ULongLong
2401                 | 1 << QVariant::Char       | 1 << QVariant::ByteArray,
2402
2403 /*ULlong*/        1 << QVariant::Int        | 1 << QVariant::String     | 1 << QVariant::Double
2404                 | 1 << QVariant::Bool       | 1 << QVariant::UInt       | 1 << QVariant::LongLong
2405                 | 1 << QVariant::Char       | 1 << QVariant::ByteArray,
2406
2407 /*double*/        1 << QVariant::Int        | 1 << QVariant::String     | 1 << QVariant::ULongLong
2408                 | 1 << QVariant::Bool       | 1 << QVariant::UInt       | 1 << QVariant::LongLong
2409                 | 1 << QVariant::ByteArray,
2410
2411 /*QChar*/         1 << QVariant::Int        | 1 << QVariant::UInt       | 1 << QVariant::LongLong
2412                 | 1 << QVariant::ULongLong,
2413
2414 /*QMap*/          0,
2415
2416 /*QList*/         1 << QVariant::StringList,
2417
2418 /*QString*/       1 << QVariant::StringList | 1 << QVariant::ByteArray  | 1 << QVariant::Int
2419                 | 1 << QVariant::UInt       | 1 << QVariant::Bool       | 1 << QVariant::Double
2420                 | 1 << QVariant::Date       | 1 << QVariant::Time       | 1 << QVariant::DateTime
2421                 | 1 << QVariant::LongLong   | 1 << QVariant::ULongLong  | 1 << QVariant::Char
2422                 | 1 << QVariant::Url        | 1 << QVariant::Uuid,
2423
2424 /*QStringList*/   1 << QVariant::List       | 1 << QVariant::String,
2425
2426 /*QByteArray*/    1 << QVariant::String     | 1 << QVariant::Int        | 1 << QVariant::UInt | 1 << QVariant::Bool
2427                 | 1 << QVariant::Double     | 1 << QVariant::LongLong   | 1 << QVariant::ULongLong,
2428
2429 /*QBitArray*/     0,
2430
2431 /*QDate*/         1 << QVariant::String     | 1 << QVariant::DateTime,
2432
2433 /*QTime*/         1 << QVariant::String     | 1 << QVariant::DateTime,
2434
2435 /*QDateTime*/     1 << QVariant::String     | 1 << QVariant::Date,
2436
2437 /*QUrl*/          1 << QVariant::String,
2438
2439 /*QLocale*/       0,
2440
2441 /*QRect*/         1 << QVariant::RectF,
2442
2443 /*QRectF*/        1 << QVariant::Rect,
2444
2445 /*QSize*/         1 << QVariant::SizeF,
2446
2447 /*QSizeF*/        1 << QVariant::Size,
2448
2449 /*QLine*/         1 << QVariant::LineF,
2450
2451 /*QLineF*/        1 << QVariant::Line,
2452
2453 /*QPoint*/        1 << QVariant::PointF,
2454
2455 /*QPointF*/       1 << QVariant::Point,
2456
2457 /*QRegExp*/       0,
2458
2459 /*QHash*/         0,
2460
2461 /*QEasingCurve*/  0,
2462
2463 /*QUuid*/         1 << QVariant::String
2464 };
2465
2466 /*!
2467     Returns true if the variant's type can be cast to the requested
2468     type, \a t. Such casting is done automatically when calling the
2469     toInt(), toBool(), ... methods.
2470
2471     The following casts are done automatically:
2472
2473     \table
2474     \header \o Type \o Automatically Cast To
2475     \row \o \l Bool \o \l Char, \l Double, \l Int, \l LongLong, \l String, \l UInt, \l ULongLong
2476     \row \o \l ByteArray \o \l Double, \l Int, \l LongLong, \l String, \l UInt, \l ULongLong
2477     \row \o \l Char \o \l Bool, \l Int, \l UInt, \l LongLong, \l ULongLong
2478     \row \o \l Color \o \l String
2479     \row \o \l Date \o \l DateTime, \l String
2480     \row \o \l DateTime \o \l Date, \l String, \l Time
2481     \row \o \l Double \o \l Bool, \l Int, \l LongLong, \l String, \l UInt, \l ULongLong
2482     \row \o \l Font \o \l String
2483     \row \o \l Int \o \l Bool, \l Char, \l Double, \l LongLong, \l String, \l UInt, \l ULongLong
2484     \row \o \l KeySequence \o \l Int, \l String
2485     \row \o \l List \o \l StringList (if the list's items can be converted to strings)
2486     \row \o \l LongLong \o \l Bool, \l ByteArray, \l Char, \l Double, \l Int, \l String, \l UInt, \l ULongLong
2487     \row \o \l Point \o PointF
2488     \row \o \l Rect \o RectF
2489     \row \o \l String \o \l Bool, \l ByteArray, \l Char, \l Color, \l Date, \l DateTime, \l Double,
2490                          \l Font, \l Int, \l KeySequence, \l LongLong, \l StringList, \l Time, \l UInt,
2491                          \l ULongLong
2492     \row \o \l StringList \o \l List, \l String (if the list contains exactly one item)
2493     \row \o \l Time \o \l String
2494     \row \o \l UInt \o \l Bool, \l Char, \l Double, \l Int, \l LongLong, \l String, \l ULongLong
2495     \row \o \l ULongLong \o \l Bool, \l Char, \l Double, \l Int, \l LongLong, \l String, \l UInt
2496     \endtable
2497
2498     \sa convert()
2499 */
2500 bool QVariant::canConvert(Type t) const
2501 {
2502     //we can treat floats as double
2503     //the reason for not doing it the "proper" way is that QMetaType::Float's value is 135,
2504     //which can't be handled by qCanConvertMatrix
2505     //In addition QVariant::Type doesn't have a Float value, so we're using QMetaType::Float
2506     const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
2507     if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double;
2508
2509     if (currentType == uint(t))
2510         return true;
2511
2512     if (currentType > QVariant::LastCoreType || t > QVariant::LastCoreType) {
2513         switch (uint(t)) {
2514         case QVariant::Int:
2515             return currentType == QVariant::KeySequence
2516                    || currentType == QMetaType::ULong
2517                    || currentType == QMetaType::Long
2518                    || currentType == QMetaType::UShort
2519                    || currentType == QMetaType::UChar
2520                    || currentType == QMetaType::Char
2521                    || currentType == QMetaType::Short;
2522         case QVariant::Image:
2523             return currentType == QVariant::Pixmap || currentType == QVariant::Bitmap;
2524         case QVariant::Pixmap:
2525             return currentType == QVariant::Image || currentType == QVariant::Bitmap
2526                               || currentType == QVariant::Brush;
2527         case QVariant::Bitmap:
2528             return currentType == QVariant::Pixmap || currentType == QVariant::Image;
2529         case QVariant::ByteArray:
2530             return currentType == QVariant::Color;
2531         case QVariant::String:
2532             return currentType == QVariant::KeySequence || currentType == QVariant::Font
2533                               || currentType == QVariant::Color;
2534         case QVariant::KeySequence:
2535             return currentType == QVariant::String || currentType == QVariant::Int;
2536         case QVariant::Font:
2537             return currentType == QVariant::String;
2538         case QVariant::Color:
2539             return currentType == QVariant::String || currentType == QVariant::ByteArray
2540                               || currentType == QVariant::Brush;
2541         case QVariant::Brush:
2542             return currentType == QVariant::Color || currentType == QVariant::Pixmap;
2543         case QMetaType::Long:
2544         case QMetaType::Char:
2545         case QMetaType::UChar:
2546         case QMetaType::ULong:
2547         case QMetaType::Short:
2548         case QMetaType::UShort:
2549             return qCanConvertMatrix[QVariant::Int] & (1 << currentType) || currentType == QVariant::Int;
2550         default:
2551             return false;
2552         }
2553     }
2554
2555     if(t == String && currentType == StringList)
2556         return v_cast<QStringList>(&d)->count() == 1;
2557     else
2558         return qCanConvertMatrix[t] & (1 << currentType);
2559 }
2560
2561 /*!
2562     Casts the variant to the requested type, \a t. If the cast cannot be
2563     done, the variant is cleared. Returns true if the current type of
2564     the variant was successfully cast; otherwise returns false.
2565
2566     \warning For historical reasons, converting a null QVariant results
2567     in a null value of the desired type (e.g., an empty string for
2568     QString) and a result of false.
2569
2570     \sa canConvert(), clear()
2571 */
2572
2573 bool QVariant::convert(Type t)
2574 {
2575     if (d.type == uint(t))
2576         return true;
2577
2578     QVariant oldValue = *this;
2579
2580     clear();
2581     if (!oldValue.canConvert(t))
2582         return false;
2583
2584     create(t, 0);
2585     if (oldValue.isNull())
2586         return false;
2587
2588     bool isOk = true;
2589     if (!handlerManager[d.type]->convert(&oldValue.d, t, data(), &isOk))
2590         isOk = false;
2591     d.is_null = !isOk;
2592     return isOk;
2593 }
2594
2595 /*!
2596   \fn convert(const int type, void *ptr) const
2597   \internal
2598   Created for qvariant_cast() usage
2599 */
2600 bool QVariant::convert(const int type, void *ptr) const
2601 {
2602     Q_ASSERT(type < int(QMetaType::User));
2603     return handlerManager[type]->convert(&d, QVariant::Type(type), ptr, 0);
2604 }
2605
2606
2607 /*!
2608     \fn bool operator==(const QVariant &v1, const QVariant &v2)
2609
2610     \relates QVariant
2611
2612     Returns true if \a v1 and \a v2 are equal; otherwise returns false.
2613
2614     \warning This function doesn't support custom types registered
2615     with qRegisterMetaType().
2616 */
2617 /*!
2618     \fn bool operator!=(const QVariant &v1, const QVariant &v2)
2619
2620     \relates QVariant
2621
2622     Returns false if \a v1 and \a v2 are equal; otherwise returns true.
2623
2624     \warning This function doesn't support custom types registered
2625     with qRegisterMetaType().
2626 */
2627
2628 /*! \fn bool QVariant::operator==(const QVariant &v) const
2629
2630     Compares this QVariant with \a v and returns true if they are
2631     equal; otherwise returns false.
2632
2633     In the case of custom types, their equalness operators are not called.
2634     Instead the values' addresses are compared.
2635 */
2636
2637 /*!
2638     \fn bool QVariant::operator!=(const QVariant &v) const
2639
2640     Compares this QVariant with \a v and returns true if they are not
2641     equal; otherwise returns false.
2642
2643     \warning This function doesn't support custom types registered
2644     with qRegisterMetaType().
2645 */
2646
2647 static bool qIsNumericType(uint tp)
2648 {
2649     return (tp >= QVariant::Bool && tp <= QVariant::Double)
2650            || (tp >= QMetaType::Long && tp <= QMetaType::Float);
2651 }
2652
2653 static bool qIsFloatingPoint(uint tp)
2654 {
2655     return tp == QVariant::Double || tp == QMetaType::Float;
2656 }
2657
2658 /*! \internal
2659  */
2660 bool QVariant::cmp(const QVariant &v) const
2661 {
2662     QVariant v2 = v;
2663     if (d.type != v2.d.type) {
2664         if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) {
2665             if (qIsFloatingPoint(d.type) || qIsFloatingPoint(v.d.type))
2666                 return qFuzzyCompare(toReal(), v.toReal());
2667             else
2668                 return toLongLong() == v.toLongLong();
2669         }
2670         if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type)))
2671             return false;
2672     }
2673     return handlerManager[d.type]->compare(&d, &v2.d);
2674 }
2675
2676 /*! \internal
2677  */
2678
2679 const void *QVariant::constData() const
2680 {
2681     return d.is_shared ? d.data.shared->ptr : reinterpret_cast<const void *>(&d.data.ptr);
2682 }
2683
2684 /*!
2685     \fn const void* QVariant::data() const
2686
2687     \internal
2688 */
2689
2690 /*! \internal */
2691 void* QVariant::data()
2692 {
2693     detach();
2694     return const_cast<void *>(constData());
2695 }
2696
2697
2698 /*!
2699   Returns true if this is a NULL variant, false otherwise.
2700 */
2701 bool QVariant::isNull() const
2702 {
2703     return handlerManager[d.type]->isNull(&d);
2704 }
2705
2706 #ifndef QT_NO_DEBUG_STREAM
2707 QDebug operator<<(QDebug dbg, const QVariant &v)
2708 {
2709 #ifndef Q_BROKEN_DEBUG_STREAM
2710     dbg.nospace() << "QVariant(" << v.typeName() << ", ";
2711     handlerManager[v.d.type]->debugStream(dbg, v);
2712     dbg.nospace() << ')';
2713     return dbg.space();
2714 #else
2715     qWarning("This compiler doesn't support streaming QVariant to QDebug");
2716     return dbg;
2717     Q_UNUSED(v);
2718 #endif
2719 }
2720
2721 QDebug operator<<(QDebug dbg, const QVariant::Type p)
2722 {
2723 #ifndef Q_BROKEN_DEBUG_STREAM
2724     dbg.nospace() << "QVariant::" << QVariant::typeToName(p);
2725     return dbg.space();
2726 #else
2727     qWarning("This compiler doesn't support streaming QVariant::Type to QDebug");
2728     return dbg;
2729     Q_UNUSED(p);
2730 #endif
2731 }
2732 #endif
2733
2734
2735 /*! \fn void QVariant::setValue(const T &value)
2736
2737     Stores a copy of \a value. If \c{T} is a type that QVariant
2738     doesn't support, QMetaType is used to store the value. A compile
2739     error will occur if QMetaType doesn't handle the type.
2740
2741     Example:
2742
2743     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 4
2744
2745     \sa value(), fromValue(), canConvert()
2746  */
2747
2748 /*! \fn T QVariant::value() const
2749
2750     Returns the stored value converted to the template type \c{T}.
2751     Call canConvert() to find out whether a type can be converted.
2752     If the value cannot be converted, \l{default-constructed value}
2753     will be returned.
2754
2755     If the type \c{T} is supported by QVariant, this function behaves
2756     exactly as toString(), toInt() etc.
2757
2758     Example:
2759
2760     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 5
2761
2762     \sa setValue(), fromValue(), canConvert()
2763 */
2764
2765 /*! \fn bool QVariant::canConvert() const
2766
2767     Returns true if the variant can be converted to the template type \c{T},
2768     otherwise false.
2769
2770     Example:
2771
2772     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 6
2773
2774     \sa convert()
2775 */
2776
2777 /*! \fn static QVariant QVariant::fromValue(const T &value)
2778
2779     Returns a QVariant containing a copy of \a value. Behaves
2780     exactly like setValue() otherwise.
2781
2782     Example:
2783
2784     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 7
2785
2786     \note If you are working with custom types, you should use
2787     the Q_DECLARE_METATYPE() macro to register your custom type.
2788
2789     \sa setValue(), value()
2790 */
2791
2792 /*!
2793     \fn QVariant qVariantFromValue(const T &value)
2794     \relates QVariant
2795     \obsolete
2796
2797     Returns a variant containing a copy of the given \a value
2798     with template type \c{T}.
2799
2800     This function is equivalent to QVariant::fromValue(\a value).
2801
2802     \note This function was provided as a workaround for MSVC 6
2803     which did not support member template functions. It is advised
2804     to use the other form in new code.
2805
2806     For example, a QObject pointer can be stored in a variant with the
2807     following code:
2808
2809     \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 8
2810
2811     \sa QVariant::fromValue()
2812 */
2813
2814 /*! \fn void qVariantSetValue(QVariant &variant, const T &value)
2815     \relates QVariant
2816     \obsolete
2817
2818     Sets the contents of the given \a variant to a copy of the
2819     \a value with the specified template type \c{T}.
2820
2821     This function is equivalent to QVariant::setValue(\a value).
2822
2823     \note This function was provided as a workaround for MSVC 6
2824     which did not support member template functions. It is advised
2825     to use the other form in new code.
2826
2827     \sa QVariant::setValue()
2828 */
2829
2830 /*!
2831     \fn T qvariant_cast(const QVariant &value)
2832     \relates QVariant
2833
2834     Returns the given \a value converted to the template type \c{T}.
2835
2836     This function is equivalent to QVariant::value().
2837
2838     \sa QVariant::value()
2839 */
2840
2841 /*! \fn T qVariantValue(const QVariant &value)
2842     \relates QVariant
2843     \obsolete
2844
2845     Returns the given \a value converted to the template type \c{T}.
2846
2847     This function is equivalent to
2848     \l{QVariant::value()}{QVariant::value}<T>(\a value).
2849
2850     \note This function was provided as a workaround for MSVC 6
2851     which did not support member template functions. It is advised
2852     to use the other form in new code.
2853
2854     \sa QVariant::value(), qvariant_cast()
2855 */
2856
2857 /*! \fn bool qVariantCanConvert(const QVariant &value)
2858     \relates QVariant
2859     \obsolete
2860
2861     Returns true if the given \a value can be converted to the
2862     template type specified; otherwise returns false.
2863
2864     This function is equivalent to QVariant::canConvert(\a value).
2865
2866     \note This function was provided as a workaround for MSVC 6
2867     which did not support member template functions. It is advised
2868     to use the other form in new code.
2869
2870     \sa QVariant::canConvert()
2871 */
2872
2873 /*!
2874     \typedef QVariantList
2875     \relates QVariant
2876
2877     Synonym for QList<QVariant>.
2878 */
2879
2880 /*!
2881     \typedef QVariantMap
2882     \relates QVariant
2883
2884     Synonym for QMap<QString, QVariant>.
2885 */
2886
2887 /*!
2888     \typedef QVariantHash
2889     \relates QVariant
2890     \since 4.5
2891
2892     Synonym for QHash<QString, QVariant>.
2893 */
2894
2895 /*!
2896     \typedef QVariant::DataPtr
2897     \internal
2898 */
2899
2900 /*!
2901     \fn DataPtr &QVariant::data_ptr()
2902     \internal
2903 */
2904
2905 QT_END_NAMESPACE