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