source: vendor/trolltech/current/src/kernel/qvariant.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 78.2 KB
Line 
1/****************************************************************************
2** $Id: qvariant.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of QVariant class
5**
6** Created : 990414
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include <float.h>
39
40#include "qvariant.h"
41#ifndef QT_NO_VARIANT
42#include "qstring.h"
43#include "qcstring.h"
44#include "qfont.h"
45#include "qpixmap.h"
46#include "qimage.h"
47#include "qbrush.h"
48#include "qpoint.h"
49#include "qrect.h"
50#include "qsize.h"
51#include "qcolor.h"
52#include "qpalette.h"
53#include "qiconset.h"
54#include "qdatastream.h"
55#include "qregion.h"
56#include "qpointarray.h"
57#include "qbitmap.h"
58#include "qcursor.h"
59#include "qdatetime.h"
60#include "qsizepolicy.h"
61#include "qshared.h"
62#include "qbitarray.h"
63#include "qkeysequence.h"
64#include "qpen.h"
65
66#ifndef DBL_DIG
67#define DBL_DIG 10
68#endif //DBL_DIG
69
70// Uncomment to test for memory leaks or to run qt/test/qvariant/main.cpp
71// #define QVARIANT_DEBUG
72
73
74static bool isNumeric(QVariant::Type type)
75{
76 return (type == QVariant::Int || type == QVariant::UInt
77 || type == QVariant::Double || type == QVariant::LongLong
78 || type == QVariant::ULongLong || type == QVariant::Bool);
79}
80
81
82#ifdef QVARIANT_DEBUG
83int qv_count = 0;
84int get_qv_count() { return qv_count; }
85#endif
86
87QVariant::Private::Private()
88{
89#ifdef QVARIANT_DEBUG
90 qv_count++;
91#endif
92 typ = QVariant::Invalid;
93 is_null = TRUE;
94}
95
96QVariant::Private::Private( Private* d )
97{
98#ifdef QVARIANT_DEBUG
99 qv_count++;
100#endif
101
102 switch( d->typ )
103 {
104 case QVariant::Invalid:
105 break;
106 case QVariant::Bitmap:
107 value.ptr = new QBitmap( *((QBitmap*)d->value.ptr) );
108 break;
109 case QVariant::Region:
110 value.ptr = new QRegion( *((QRegion*)d->value.ptr) );
111 // ## Force a detach
112 // ((QRegion*)value.ptr)->translate( 0, 0 );
113 break;
114 case QVariant::PointArray:
115 // QPointArray is explicit shared
116 value.ptr = new QPointArray( *((QPointArray*)d->value.ptr) );
117 break;
118 case QVariant::String:
119 value.ptr = new QString( *((QString*)d->value.ptr) );
120 break;
121 case QVariant::CString:
122 // QCString is explicit shared
123 value.ptr = new QCString( *((QCString*)d->value.ptr) );
124 break;
125#ifndef QT_NO_STRINGLIST
126 case QVariant::StringList:
127 value.ptr = new QStringList( *((QStringList*)d->value.ptr) );
128 break;
129#endif //QT_NO_STRINGLIST
130 case QVariant::Font:
131 value.ptr = new QFont( *((QFont*)d->value.ptr) );
132 break;
133 case QVariant::Pixmap:
134 value.ptr = new QPixmap( *((QPixmap*)d->value.ptr) );
135 break;
136 case QVariant::Image:
137 // QImage is explicit shared
138 value.ptr = new QImage( *((QImage*)d->value.ptr) );
139 break;
140 case QVariant::Brush:
141 value.ptr = new QBrush( *((QBrush*)d->value.ptr) );
142 // ## Force a detach
143 // ((QBrush*)value.ptr)->setColor( ((QBrush*)value.ptr)->color() );
144 break;
145 case QVariant::Point:
146 value.ptr = new QPoint( *((QPoint*)d->value.ptr) );
147 break;
148 case QVariant::Rect:
149 value.ptr = new QRect( *((QRect*)d->value.ptr) );
150 break;
151 case QVariant::Size:
152 value.ptr = new QSize( *((QSize*)d->value.ptr) );
153 break;
154 case QVariant::Color:
155 value.ptr = new QColor( *((QColor*)d->value.ptr) );
156 break;
157#ifndef QT_NO_PALETTE
158 case QVariant::Palette:
159 value.ptr = new QPalette( *((QPalette*)d->value.ptr) );
160 break;
161 case QVariant::ColorGroup:
162 value.ptr = new QColorGroup( *((QColorGroup*)d->value.ptr) );
163 break;
164#endif
165#ifndef QT_NO_ICONSET
166 case QVariant::IconSet:
167 value.ptr = new QIconSet( *((QIconSet*)d->value.ptr) );
168 break;
169#endif
170#ifndef QT_NO_TEMPLATE_VARIANT
171 case QVariant::Map:
172 value.ptr = new QMap<QString,QVariant>( *((QMap<QString,QVariant>*)d->value.ptr) );
173 break;
174 case QVariant::List:
175 value.ptr = new QValueList<QVariant>( *((QValueList<QVariant>*)d->value.ptr) );
176 break;
177#endif
178 case QVariant::Date:
179 value.ptr = new QDate( *((QDate*)d->value.ptr) );
180 break;
181 case QVariant::Time:
182 value.ptr = new QTime( *((QTime*)d->value.ptr) );
183 break;
184 case QVariant::DateTime:
185 value.ptr = new QDateTime( *((QDateTime*)d->value.ptr) );
186 break;
187 case QVariant::ByteArray:
188 value.ptr = new QByteArray( *((QByteArray*)d->value.ptr) );
189 break;
190 case QVariant::BitArray:
191 value.ptr = new QBitArray( *((QBitArray*)d->value.ptr) );
192 break;
193#ifndef QT_NO_ACCEL
194 case QVariant::KeySequence:
195 value.ptr = new QKeySequence( *((QKeySequence*)d->value.ptr) );
196 break;
197#endif
198 case QVariant::Pen:
199 value.ptr = new QPen( *((QPen*)d->value.ptr) );
200 break;
201 case QVariant::Int:
202 value.i = d->value.i;
203 break;
204 case QVariant::UInt:
205 value.u = d->value.u;
206 break;
207 case QVariant::Bool:
208 value.b = d->value.b;
209 break;
210 case QVariant::Double:
211 value.d = d->value.d;
212 break;
213 case QVariant::SizePolicy:
214 value.ptr = new QSizePolicy( *((QSizePolicy*)d->value.ptr) );
215 break;
216 case QVariant::Cursor:
217 value.ptr = new QCursor( *((QCursor*)d->value.ptr) );
218 break;
219 default:
220 Q_ASSERT( 0 );
221 }
222
223 typ = d->typ;
224 is_null = d->is_null;
225}
226
227QVariant::Private::~Private()
228{
229#ifdef QVARIANT_DEBUG
230 qv_count--;
231#endif
232 clear();
233}
234
235void QVariant::Private::clear()
236{
237 switch( typ )
238 {
239 case QVariant::Bitmap:
240 delete (QBitmap*)value.ptr;
241 break;
242 case QVariant::Cursor:
243 delete (QCursor*)value.ptr;
244 break;
245 case QVariant::Region:
246 delete (QRegion*)value.ptr;
247 break;
248 case QVariant::PointArray:
249 delete (QPointArray*)value.ptr;
250 break;
251 case QVariant::String:
252 delete (QString*)value.ptr;
253 break;
254 case QVariant::CString:
255 delete (QCString*)value.ptr;
256 break;
257#ifndef QT_NO_STRINGLIST
258 case QVariant::StringList:
259 delete (QStringList*)value.ptr;
260 break;
261#endif //QT_NO_STRINGLIST
262 case QVariant::Font:
263 delete (QFont*)value.ptr;
264 break;
265 case QVariant::Pixmap:
266 delete (QPixmap*)value.ptr;
267 break;
268 case QVariant::Image:
269 delete (QImage*)value.ptr;
270 break;
271 case QVariant::Brush:
272 delete (QBrush*)value.ptr;
273 break;
274 case QVariant::Point:
275 delete (QPoint*)value.ptr;
276 break;
277 case QVariant::Rect:
278 delete (QRect*)value.ptr;
279 break;
280 case QVariant::Size:
281 delete (QSize*)value.ptr;
282 break;
283 case QVariant::Color:
284 delete (QColor*)value.ptr;
285 break;
286#ifndef QT_NO_PALETTE
287 case QVariant::Palette:
288 delete (QPalette*)value.ptr;
289 break;
290 case QVariant::ColorGroup:
291 delete (QColorGroup*)value.ptr;
292 break;
293#endif
294#ifndef QT_NO_ICONSET
295 case QVariant::IconSet:
296 delete (QIconSet*)value.ptr;
297 break;
298#endif
299#ifndef QT_NO_TEMPLATE_VARIANT
300 case QVariant::Map:
301 delete (QMap<QString,QVariant>*)value.ptr;
302 break;
303 case QVariant::List:
304 delete (QValueList<QVariant>*)value.ptr;
305 break;
306#endif
307 case QVariant::SizePolicy:
308 delete (QSizePolicy*)value.ptr;
309 break;
310 case QVariant::Date:
311 delete (QDate*)value.ptr;
312 break;
313 case QVariant::Time:
314 delete (QTime*)value.ptr;
315 break;
316 case QVariant::DateTime:
317 delete (QDateTime*)value.ptr;
318 break;
319 case QVariant::ByteArray:
320 delete (QByteArray*)value.ptr;
321 break;
322 case QVariant::BitArray:
323 delete (QBitArray*)value.ptr;
324 break;
325#ifndef QT_NO_ACCEL
326 case QVariant::KeySequence:
327 delete (QKeySequence*)value.ptr;
328 break;
329#endif
330 case QVariant::Pen:
331 delete (QPen*)value.ptr;
332 break;
333 case QVariant::Invalid:
334 case QVariant::Int:
335 case QVariant::UInt:
336 case QVariant::LongLong:
337 case QVariant::ULongLong:
338 case QVariant::Bool:
339 case QVariant::Double:
340 break;
341 }
342
343 typ = QVariant::Invalid;
344 is_null = TRUE;
345}
346
347/*!
348 \class QVariant qvariant.h
349 \brief The QVariant class acts like a union for the most common Qt data types.
350
351 \ingroup objectmodel
352 \ingroup misc
353 \mainclass
354
355 Because C++ forbids unions from including types that have
356 non-default constructors or destructors, most interesting Qt
357 classes cannot be used in unions. Without QVariant, this would be
358 a problem for QObject::property() and for database work, etc.
359
360 A QVariant object holds a single value of a single type() at a
361 time. (Some type()s are multi-valued, for example a string list.)
362 You can find out what type, T, the variant holds, convert it to a
363 different type using one of the asT() functions, e.g. asSize(),
364 get its value using one of the toT() functions, e.g. toSize(), and
365 check whether the type can be converted to a particular type using
366 canCast().
367
368 The methods named toT() (for any supported T, see the \c Type
369 documentation for a list) are const. If you ask for the stored
370 type, they return a copy of the stored object. If you ask for a
371 type that can be generated from the stored type, toT() copies and
372 converts and leaves the object itself unchanged. If you ask for a
373 type that cannot be generated from the stored type, the result
374 depends on the type (see the function documentation for details).
375
376 Note that three data types supported by QVariant are explicitly
377 shared, namely QImage, QPointArray, and QCString, and in these
378 cases the toT() methods return a shallow copy. In almost all cases
379 you must make a deep copy of the returned values before modifying
380 them.
381
382 The asT() functions are not const. They do conversion like the
383 toT() methods, set the variant to hold the converted value, and
384 return a reference to the new contents of the variant.
385
386 Here is some example code to demonstrate the use of QVariant:
387
388 \code
389 QDataStream out(...);
390 QVariant v(123); // The variant now contains an int
391 int x = v.toInt(); // x = 123
392 out << v; // Writes a type tag and an int to out
393 v = QVariant("hello"); // The variant now contains a QCString
394 v = QVariant(tr("hello"));// The variant now contains a QString
395 int y = v.toInt(); // y = 0 since v cannot be converted to an int
396 QString s = v.toString(); // s = tr("hello") (see QObject::tr())
397 out << v; // Writes a type tag and a QString to out
398 ...
399 QDataStream in(...); // (opening the previously written stream)
400 in >> v; // Reads an Int variant
401 int z = v.toInt(); // z = 123
402 qDebug("Type is %s", // prints "Type is int"
403 v.typeName());
404 v.asInt() += 100; // The variant now hold the value 223.
405 v = QVariant( QStringList() );
406 v.asStringList().append( "Hello" );
407 \endcode
408
409 You can even store QValueList<QVariant>s and
410 QMap<QString,QVariant>s in a variant, so you can easily construct
411 arbitrarily complex data structures of arbitrary types. This is
412 very powerful and versatile, but may prove less memory and speed
413 efficient than storing specific types in standard data structures.
414
415 QVariant also supports the notion of NULL values, where you have a
416 defined type with no value set.
417 \code
418 QVariant x, y( QString() ), z( QString("") );
419 x.asInt();
420 // x.isNull() == TRUE, y.isNull() == TRUE, z.isNull() == FALSE
421 \endcode
422
423 See the \link collection.html Collection Classes\endlink.
424*/
425
426/*!
427 \enum QVariant::Type
428
429 This enum type defines the types of variable that a QVariant can
430 contain.
431
432 \value Invalid no type
433 \value BitArray a QBitArray
434 \value ByteArray a QByteArray
435 \value Bitmap a QBitmap
436 \value Bool a bool
437 \value Brush a QBrush
438 \value Color a QColor
439 \value ColorGroup a QColorGroup
440 \value Cursor a QCursor
441 \value Date a QDate
442 \value DateTime a QDateTime
443 \value Double a double
444 \value Font a QFont
445 \value IconSet a QIconSet
446 \value Image a QImage
447 \value Int an int
448 \value KeySequence a QKeySequence
449 \value List a QValueList<QVariant>
450 \value LongLong a long long
451 \value ULongLong an unsigned long long
452 \value Map a QMap<QString,QVariant>
453 \value Palette a QPalette
454 \value Pen a QPen
455 \value Pixmap a QPixmap
456 \value Point a QPoint
457 \value PointArray a QPointArray
458 \value Rect a QRect
459 \value Region a QRegion
460 \value Size a QSize
461 \value SizePolicy a QSizePolicy
462 \value String a QString
463 \value CString a QCString
464 \value StringList a QStringList
465 \value Time a QTime
466 \value UInt an unsigned int
467
468 Note that Qt's definition of bool depends on the compiler.
469 \c qglobal.h has the system-dependent definition of bool.
470*/
471
472/*!
473 Constructs an invalid variant.
474*/
475QVariant::QVariant()
476{
477 d = new Private;
478}
479
480/*!
481 Destroys the QVariant and the contained object.
482
483 Note that subclasses that reimplement clear() should reimplement
484 the destructor to call clear(). This destructor calls clear(), but
485 because it is the destructor, QVariant::clear() is called rather
486 than a subclass's clear().
487*/
488QVariant::~QVariant()
489{
490 if ( d->deref() )
491 delete d;
492}
493
494/*!
495 Constructs a copy of the variant, \a p, passed as the argument to
496 this constructor. Usually this is a deep copy, but a shallow copy
497 is made if the stored data type is explicitly shared, as e.g.
498 QImage is.
499*/
500QVariant::QVariant( const QVariant& p )
501{
502 p.d->ref();
503 d = p.d;
504}
505
506#ifndef QT_NO_DATASTREAM
507/*!
508 Reads the variant from the data stream, \a s.
509*/
510QVariant::QVariant( QDataStream& s )
511{
512 d = new Private;
513 s >> *this;
514}
515#endif //QT_NO_DATASTREAM
516
517/*!
518 Constructs a new variant with a string value, \a val.
519*/
520QVariant::QVariant( const QString& val )
521{
522 d = new Private;
523 d->typ = String;
524 d->value.ptr = new QString( val );
525}
526
527/*!
528 Constructs a new variant with a C-string value, \a val.
529
530 If you want to modify the QCString after you've passed it to this
531 constructor, we recommend passing a deep copy (see
532 QCString::copy()).
533*/
534QVariant::QVariant( const QCString& val )
535{
536 d = new Private;
537 d->typ = CString;
538 d->value.ptr = new QCString( val );
539}
540
541/*!
542 Constructs a new variant with a C-string value of \a val if \a val
543 is non-null. The variant creates a deep copy of \a val.
544
545 If \a val is null, the resulting variant has type Invalid.
546*/
547QVariant::QVariant( const char* val )
548{
549 d = new Private;
550 if ( val == 0 )
551 return;
552 d->typ = CString;
553 d->value.ptr = new QCString( val );
554}
555
556#ifndef QT_NO_STRINGLIST
557/*!
558 Constructs a new variant with a string list value, \a val.
559*/
560QVariant::QVariant( const QStringList& val )
561{
562 d = new Private;
563 d->typ = StringList;
564 d->value.ptr = new QStringList( val );
565 d->is_null = FALSE;
566}
567#endif // QT_NO_STRINGLIST
568
569#ifndef QT_NO_TEMPLATE_VARIANT
570/*!
571 Constructs a new variant with a map of QVariants, \a val.
572*/
573QVariant::QVariant( const QMap<QString,QVariant>& val )
574{
575 d = new Private;
576 d->typ = Map;
577 d->value.ptr = new QMap<QString,QVariant>( val );
578 d->is_null = FALSE;
579}
580#endif
581/*!
582 Constructs a new variant with a font value, \a val.
583*/
584QVariant::QVariant( const QFont& val )
585{
586 d = new Private;
587 d->typ = Font;
588 d->value.ptr = new QFont( val );
589 d->is_null = FALSE;
590}
591
592/*!
593 Constructs a new variant with a pixmap value, \a val.
594*/
595QVariant::QVariant( const QPixmap& val )
596{
597 d = new Private;
598 d->typ = Pixmap;
599 d->value.ptr = new QPixmap( val );
600}
601
602
603/*!
604 Constructs a new variant with an image value, \a val.
605
606 Because QImage is explicitly shared, you may need to pass a deep
607 copy to the variant using QImage::copy(), e.g. if you intend
608 changing the image you've passed later on.
609*/
610QVariant::QVariant( const QImage& val )
611{
612 d = new Private;
613 d->typ = Image;
614 d->value.ptr = new QImage( val );
615}
616
617/*!
618 Constructs a new variant with a brush value, \a val.
619*/
620QVariant::QVariant( const QBrush& val )
621{
622 d = new Private;
623 d->typ = Brush;
624 d->value.ptr = new QBrush( val );
625 d->is_null = FALSE;
626}
627
628/*!
629 Constructs a new variant with a point value, \a val.
630*/
631QVariant::QVariant( const QPoint& val )
632{
633 d = new Private;
634 d->typ = Point;
635 d->value.ptr = new QPoint( val );
636}
637
638/*!
639 Constructs a new variant with a rect value, \a val.
640*/
641QVariant::QVariant( const QRect& val )
642{
643 d = new Private;
644 d->typ = Rect;
645 d->value.ptr = new QRect( val );
646}
647
648/*!
649 Constructs a new variant with a size value, \a val.
650*/
651QVariant::QVariant( const QSize& val )
652{
653 d = new Private;
654 d->typ = Size;
655 d->value.ptr = new QSize( val );
656}
657
658/*!
659 Constructs a new variant with a color value, \a val.
660*/
661QVariant::QVariant( const QColor& val )
662{
663 d = new Private;
664 d->typ = Color;
665 d->value.ptr = new QColor( val );
666 d->is_null = FALSE;
667}
668
669#ifndef QT_NO_PALETTE
670/*!
671 Constructs a new variant with a color palette value, \a val.
672*/
673QVariant::QVariant( const QPalette& val )
674{
675 d = new Private;
676 d->typ = Palette;
677 d->value.ptr = new QPalette( val );
678 d->is_null = FALSE;
679}
680
681/*!
682 Constructs a new variant with a color group value, \a val.
683*/
684QVariant::QVariant( const QColorGroup& val )
685{
686 d = new Private;
687 d->typ = ColorGroup;
688 d->value.ptr = new QColorGroup( val );
689 d->is_null = FALSE;
690}
691#endif //QT_NO_PALETTE
692#ifndef QT_NO_ICONSET
693/*!
694 Constructs a new variant with an icon set value, \a val.
695*/
696QVariant::QVariant( const QIconSet& val )
697{
698 d = new Private;
699 d->typ = IconSet;
700 d->value.ptr = new QIconSet( val );
701}
702#endif //QT_NO_ICONSET
703/*!
704 Constructs a new variant with a region value, \a val.
705*/
706QVariant::QVariant( const QRegion& val )
707{
708 d = new Private;
709 d->typ = Region;
710 // ## Force a detach
711 d->value.ptr = new QRegion( val );
712 ((QRegion*)d->value.ptr)->translate( 0, 0 );
713}
714
715/*!
716 Constructs a new variant with a bitmap value, \a val.
717*/
718QVariant::QVariant( const QBitmap& val )
719{
720 d = new Private;
721 d->typ = Bitmap;
722 d->value.ptr = new QBitmap( val );
723}
724
725/*!
726 Constructs a new variant with a cursor value, \a val.
727*/
728QVariant::QVariant( const QCursor& val )
729{
730 d = new Private;
731 d->typ = Cursor;
732 d->value.ptr = new QCursor( val );
733 d->is_null = FALSE;
734}
735
736/*!
737 Constructs a new variant with a point array value, \a val.
738
739 Because QPointArray is explicitly shared, you may need to pass a
740 deep copy to the variant using QPointArray::copy(), e.g. if you
741 intend changing the point array you've passed later on.
742*/
743QVariant::QVariant( const QPointArray& val )
744{
745 d = new Private;
746 d->typ = PointArray;
747 d->value.ptr = new QPointArray( val );
748}
749
750/*!
751 Constructs a new variant with a date value, \a val.
752*/
753QVariant::QVariant( const QDate& val )
754{
755 d = new Private;
756 d->typ = Date;
757 d->value.ptr = new QDate( val );
758}
759
760/*!
761 Constructs a new variant with a time value, \a val.
762*/
763QVariant::QVariant( const QTime& val )
764{
765 d = new Private;
766 d->typ = Time;
767 d->value.ptr = new QTime( val );
768}
769
770/*!
771 Constructs a new variant with a date/time value, \a val.
772*/
773QVariant::QVariant( const QDateTime& val )
774{
775 d = new Private;
776 d->typ = DateTime;
777 d->value.ptr = new QDateTime( val );
778}
779
780/*!
781 Constructs a new variant with a bytearray value, \a val.
782*/
783QVariant::QVariant( const QByteArray& val )
784{
785 d = new Private;
786 d->typ = ByteArray;
787 d->value.ptr = new QByteArray( val );
788}
789
790/*!
791 Constructs a new variant with a bitarray value, \a val.
792*/
793QVariant::QVariant( const QBitArray& val )
794{
795 d = new Private;
796 d->typ = BitArray;
797 d->value.ptr = new QBitArray( val );
798}
799
800#ifndef QT_NO_ACCEL
801
802/*!
803 Constructs a new variant with a key sequence value, \a val.
804*/
805QVariant::QVariant( const QKeySequence& val )
806{
807 d = new Private;
808 d->typ = KeySequence;
809 d->value.ptr = new QKeySequence( val );
810 d->is_null = FALSE;
811}
812
813#endif
814
815/*!
816 Constructs a new variant with a pen value, \a val.
817*/
818QVariant::QVariant( const QPen& val )
819{
820 d = new Private;
821 d->typ = Pen;
822 d->value.ptr = new QPen( val );
823}
824
825/*!
826 Constructs a new variant with an integer value, \a val.
827*/
828QVariant::QVariant( int val )
829{
830 d = new Private;
831 d->typ = Int;
832 d->value.i = val;
833 d->is_null = FALSE;
834}
835
836/*!
837 Constructs a new variant with an unsigned integer value, \a val.
838*/
839QVariant::QVariant( uint val )
840{
841 d = new Private;
842 d->typ = UInt;
843 d->value.u = val;
844 d->is_null = FALSE;
845}
846
847/*!
848 Constructs a new variant with a long long integer value, \a val.
849*/
850QVariant::QVariant( Q_LLONG val )
851{
852 d = new Private;
853 d->typ = LongLong;
854 d->value.ll = val;
855 d->is_null = FALSE;
856}
857
858/*!
859 Constructs a new variant with an unsigned long long integer value, \a val.
860*/
861
862QVariant::QVariant( Q_ULLONG val )
863{
864 d = new Private;
865 d->typ = ULongLong;
866 d->value.ull = val;
867 d->is_null = FALSE;
868}
869
870/*!
871 Constructs a new variant with a boolean value, \a val. The integer
872 argument is a dummy, necessary for compatibility with some
873 compilers.
874*/
875QVariant::QVariant( bool val, int )
876{ // this is the comment that does NOT name said compiler.
877 d = new Private;
878 d->typ = Bool;
879 d->value.b = val;
880 d->is_null = FALSE;
881}
882
883
884/*!
885 Constructs a new variant with a floating point value, \a val.
886*/
887QVariant::QVariant( double val )
888{
889 d = new Private;
890 d->typ = Double;
891 d->value.d = val;
892 d->is_null = FALSE;
893}
894
895#ifndef QT_NO_TEMPLATE_VARIANT
896/*!
897 Constructs a new variant with a list value, \a val.
898*/
899QVariant::QVariant( const QValueList<QVariant>& val )
900{
901 d = new Private;
902 d->typ = List;
903 d->value.ptr = new QValueList<QVariant>( val );
904 d->is_null = FALSE;
905}
906#endif
907
908/*!
909 Constructs a new variant with a size policy value, \a val.
910*/
911QVariant::QVariant( QSizePolicy val )
912{
913 d = new Private;
914 d->typ = SizePolicy;
915 d->value.ptr = new QSizePolicy( val );
916 d->is_null = FALSE;
917}
918
919/*!
920 Assigns the value of the variant \a variant to this variant.
921
922 This is a deep copy of the variant, but note that if the variant
923 holds an explicitly shared type such as QImage, a shallow copy is
924 performed.
925*/
926QVariant& QVariant::operator= ( const QVariant& variant )
927{
928 QVariant& other = (QVariant&)variant;
929
930 other.d->ref();
931 if ( d->deref() )
932 delete d;
933
934 d = other.d;
935
936 return *this;
937}
938
939/*!
940 \internal
941*/
942void QVariant::detach()
943{
944 if ( d->count == 1 )
945 return;
946
947 d->deref();
948 d = new Private( d );
949}
950
951/*!
952 Returns the name of the type stored in the variant. The returned
953 strings describe the C++ datatype used to store the data: for
954 example, "QFont", "QString", or "QValueList<QVariant>". An Invalid
955 variant returns 0.
956*/
957const char* QVariant::typeName() const
958{
959 return typeToName( (Type) d->typ );
960}
961
962/*!
963 Convert this variant to type Invalid and free up any resources
964 used.
965*/
966void QVariant::clear()
967{
968 if ( d->count > 1 )
969 {
970 d->deref();
971 d = new Private;
972 return;
973 }
974
975 d->clear();
976}
977
978/* Attention!
979
980 For dependency reasons, this table is duplicated in moc.y. If you
981 change one, change both.
982
983 (Search for the word 'Attention' in moc.y.)
984*/
985static const int ntypes = 35;
986static const char* const type_map[ntypes] =
987{
988 0,
989 "QMap<QString,QVariant>",
990 "QValueList<QVariant>",
991 "QString",
992 "QStringList",
993 "QFont",
994 "QPixmap",
995 "QBrush",
996 "QRect",
997 "QSize",
998 "QColor",
999 "QPalette",
1000 "QColorGroup",
1001 "QIconSet",
1002 "QPoint",
1003 "QImage",
1004 "int",
1005 "uint",
1006 "bool",
1007 "double",
1008 "QCString",
1009 "QPointArray",
1010 "QRegion",
1011 "QBitmap",
1012 "QCursor",
1013 "QSizePolicy",
1014 "QDate",
1015 "QTime",
1016 "QDateTime",
1017 "QByteArray",
1018 "QBitArray",
1019 "QKeySequence",
1020 "QPen",
1021 "Q_LLONG",
1022 "Q_ULLONG"
1023};
1024
1025
1026/*!
1027 Converts the enum representation of the storage type, \a typ, to
1028 its string representation.
1029*/
1030const char* QVariant::typeToName( Type typ )
1031{
1032 if ( typ >= ntypes )
1033 return 0;
1034 return type_map[typ];
1035}
1036
1037
1038/*!
1039 Converts the string representation of the storage type gven in \a
1040 name, to its enum representation.
1041
1042 If the string representation cannot be converted to any enum
1043 representation, the variant is set to \c Invalid.
1044*/
1045QVariant::Type QVariant::nameToType( const char* name )
1046{
1047 for ( int i = 0; i < ntypes; i++ ) {
1048 if ( !qstrcmp( type_map[i], name ) )
1049 return (Type) i;
1050 }
1051 return Invalid;
1052}
1053
1054#ifndef QT_NO_DATASTREAM
1055/*!
1056 Internal function for loading a variant from stream \a s. Use the
1057 stream operators instead.
1058
1059 \internal
1060*/
1061void QVariant::load( QDataStream& s )
1062{
1063 Q_UINT32 u;
1064 s >> u;
1065 Type t = (Type)u;
1066
1067 switch( t ) {
1068 case Invalid:
1069 {
1070 // Since we wrote something, we should read something
1071 QString x;
1072 s >> x;
1073 d->typ = t;
1074 d->is_null = TRUE;
1075 }
1076 break;
1077#ifndef QT_NO_TEMPLATE_VARIANT
1078 case Map:
1079 {
1080 QMap<QString,QVariant>* x = new QMap<QString,QVariant>;
1081 s >> *x;
1082 d->value.ptr = x;
1083 d->is_null = FALSE;
1084 }
1085 break;
1086 case List:
1087 {
1088 QValueList<QVariant>* x = new QValueList<QVariant>;
1089 s >> *x;
1090 d->value.ptr = x;
1091 d->is_null = FALSE;
1092 }
1093 break;
1094#endif
1095 case Cursor:
1096 {
1097#ifndef QT_NO_CURSOR
1098 QCursor* x = new QCursor;
1099 s >> *x;
1100 d->value.ptr = x;
1101 d->is_null = FALSE;
1102#endif
1103 }
1104 break;
1105 case Bitmap:
1106 {
1107 QBitmap* x = new QBitmap;
1108#ifndef QT_NO_IMAGEIO
1109 s >> *x;
1110#endif
1111 d->value.ptr = x;
1112 }
1113 break;
1114 case Region:
1115 {
1116 QRegion* x = new QRegion;
1117 s >> *x;
1118 d->value.ptr = x;
1119 }
1120 break;
1121 case PointArray:
1122 {
1123 QPointArray* x = new QPointArray;
1124 s >> *x;
1125 d->value.ptr = x;
1126 }
1127 break;
1128 case String:
1129 {
1130 QString* x = new QString;
1131 s >> *x;
1132 d->value.ptr = x;
1133 }
1134 break;
1135 case CString:
1136 {
1137 QCString* x = new QCString;
1138 s >> *x;
1139 d->value.ptr = x;
1140 }
1141 break;
1142#ifndef QT_NO_STRINGLIST
1143 case StringList:
1144 {
1145 QStringList* x = new QStringList;
1146 s >> *x;
1147 d->value.ptr = x;
1148 d->is_null = FALSE;
1149 }
1150 break;
1151#endif // QT_NO_STRINGLIST
1152 case Font:
1153 {
1154 QFont* x = new QFont;
1155 s >> *x;
1156 d->value.ptr = x;
1157 d->is_null = FALSE;
1158 }
1159 break;
1160 case Pixmap:
1161 {
1162 QPixmap* x = new QPixmap;
1163#ifndef QT_NO_IMAGEIO
1164 s >> *x;
1165#endif
1166 d->value.ptr = x;
1167 }
1168 break;
1169 case Image:
1170 {
1171 QImage* x = new QImage;
1172#ifndef QT_NO_IMAGEIO
1173 s >> *x;
1174#endif
1175 d->value.ptr = x;
1176 }
1177 break;
1178 case Brush:
1179 {
1180 QBrush* x = new QBrush;
1181 s >> *x;
1182 d->value.ptr = x;
1183 d->is_null = FALSE;
1184 }
1185 break;
1186 case Rect:
1187 {
1188 QRect* x = new QRect;
1189 s >> *x;
1190 d->value.ptr = x;
1191 }
1192 break;
1193 case Point:
1194 {
1195 QPoint* x = new QPoint;
1196 s >> *x;
1197 d->value.ptr = x;
1198 }
1199 break;
1200 case Size:
1201 {
1202 QSize* x = new QSize;
1203 s >> *x;
1204 d->value.ptr = x;
1205 }
1206 break;
1207 case Color:
1208 {
1209 QColor* x = new QColor;
1210 s >> *x;
1211 d->value.ptr = x;
1212 d->is_null = FALSE;
1213 }
1214 break;
1215#ifndef QT_NO_PALETTE
1216 case Palette:
1217 {
1218 QPalette* x = new QPalette;
1219 s >> *x;
1220 d->value.ptr = x;
1221 d->is_null = FALSE;
1222 }
1223 break;
1224 case ColorGroup:
1225 {
1226 QColorGroup* x = new QColorGroup;
1227 s >> *x;
1228 d->value.ptr = x;
1229 d->is_null = FALSE;
1230 }
1231 break;
1232#endif
1233#ifndef QT_NO_ICONSET
1234 case IconSet:
1235 {
1236 QPixmap x;
1237 s >> x;
1238 d->value.ptr = new QIconSet( x );
1239 }
1240 break;
1241#endif
1242 case Int:
1243 {
1244 int x;
1245 s >> x;
1246 d->value.i = x;
1247 d->is_null = FALSE;
1248 }
1249 break;
1250 case UInt:
1251 {
1252 uint x;
1253 s >> x;
1254 d->value.u = x;
1255 d->is_null = FALSE;
1256 }
1257 break;
1258 case LongLong:
1259 {
1260 Q_LLONG x;
1261 s >> x;
1262 d->value.ll = x;
1263 }
1264 break;
1265 case ULongLong:
1266 {
1267 Q_ULLONG x;
1268 s >> x;
1269 d->value.ull = x;
1270 }
1271 break;
1272 case Bool:
1273 {
1274 Q_INT8 x;
1275 s >> x;
1276 d->value.b = x;
1277 d->is_null = FALSE;
1278 }
1279 break;
1280 case Double:
1281 {
1282 double x;
1283 s >> x;
1284 d->value.d = x;
1285 d->is_null = FALSE;
1286 }
1287 break;
1288 case SizePolicy:
1289 {
1290 int h,v;
1291 Q_INT8 hfw;
1292 s >> h >> v >> hfw;
1293 d->value.ptr = new QSizePolicy( (QSizePolicy::SizeType)h,
1294 (QSizePolicy::SizeType)v,
1295 (bool) hfw);
1296 d->is_null = FALSE;
1297 }
1298 break;
1299 case Date:
1300 {
1301 QDate* x = new QDate;
1302 s >> *x;
1303 d->value.ptr = x;
1304 }
1305 break;
1306 case Time:
1307 {
1308 QTime* x = new QTime;
1309 s >> *x;
1310 d->value.ptr = x;
1311 }
1312 break;
1313 case DateTime:
1314 {
1315 QDateTime* x = new QDateTime;
1316 s >> *x;
1317 d->value.ptr = x;
1318 }
1319 break;
1320 case ByteArray:
1321 {
1322 QByteArray* x = new QByteArray;
1323 s >> *x;
1324 d->value.ptr = x;
1325 }
1326 break;
1327 case BitArray:
1328 {
1329 QBitArray* x = new QBitArray;
1330 s >> *x;
1331 d->value.ptr = x;
1332 }
1333 break;
1334#ifndef QT_NO_ACCEL
1335 case KeySequence:
1336 {
1337 QKeySequence* x = new QKeySequence;
1338 s >> *x;
1339 d->value.ptr = x;
1340 d->is_null = FALSE;
1341 }
1342 break;
1343#endif // QT_NO_ACCEL
1344 case Pen:
1345 {
1346 QPen* x = new QPen;
1347 s >> *x;
1348 d->value.ptr = x;
1349 d->is_null = FALSE;
1350 }
1351 break;
1352 }
1353 d->typ = t;
1354}
1355
1356/*!
1357 Internal function for saving a variant to the stream \a s. Use the
1358 stream operators instead.
1359
1360 \internal
1361*/
1362void QVariant::save( QDataStream& s ) const
1363{
1364 s << (Q_UINT32)type();
1365
1366 switch( d->typ ) {
1367 case Cursor:
1368 s << *((QCursor*)d->value.ptr);
1369 break;
1370 case Bitmap:
1371#ifndef QT_NO_IMAGEIO
1372 s << *((QBitmap*)d->value.ptr);
1373#endif
1374 break;
1375 case PointArray:
1376 s << *((QPointArray*)d->value.ptr);
1377 break;
1378 case Region:
1379 s << *((QRegion*)d->value.ptr);
1380 break;
1381#ifndef QT_NO_TEMPLATE_VARIANT
1382 case List:
1383 s << *((QValueList<QVariant>*)d->value.ptr);
1384 break;
1385 case Map:
1386 s << *((QMap<QString,QVariant>*)d->value.ptr);
1387 break;
1388#endif
1389 case String:
1390 s << *((QString*)d->value.ptr);
1391 break;
1392 case CString:
1393 s << *((QCString*)d->value.ptr);
1394 break;
1395#ifndef QT_NO_STRINGLIST
1396 case StringList:
1397 s << *((QStringList*)d->value.ptr);
1398 break;
1399#endif
1400 case Font:
1401 s << *((QFont*)d->value.ptr);
1402 break;
1403 case Pixmap:
1404#ifndef QT_NO_IMAGEIO
1405 s << *((QPixmap*)d->value.ptr);
1406#endif
1407 break;
1408 case Image:
1409#ifndef QT_NO_IMAGEIO
1410 s << *((QImage*)d->value.ptr);
1411#endif
1412 break;
1413 case Brush:
1414 s << *((QBrush*)d->value.ptr);
1415 break;
1416 case Point:
1417 s << *((QPoint*)d->value.ptr);
1418 break;
1419 case Rect:
1420 s << *((QRect*)d->value.ptr);
1421 break;
1422 case Size:
1423 s << *((QSize*)d->value.ptr);
1424 break;
1425 case Color:
1426 s << *((QColor*)d->value.ptr);
1427 break;
1428#ifndef QT_NO_PALETTE
1429 case Palette:
1430 s << *((QPalette*)d->value.ptr);
1431 break;
1432 case ColorGroup:
1433 s << *((QColorGroup*)d->value.ptr);
1434 break;
1435#endif
1436#ifndef QT_NO_ICONSET
1437 case IconSet:
1438 //### add stream operator to iconset
1439 s << ((QIconSet*)d->value.ptr)->pixmap();
1440 break;
1441#endif
1442 case Int:
1443 s << d->value.i;
1444 break;
1445 case UInt:
1446 s << d->value.u;
1447 break;
1448 case LongLong:
1449 s << d->value.ll;
1450 break;
1451 case ULongLong:
1452 s << d->value.ull;
1453 break;
1454 case Bool:
1455 s << (Q_INT8)d->value.b;
1456 break;
1457 case Double:
1458 s << d->value.d;
1459 break;
1460 case SizePolicy:
1461 {
1462 QSizePolicy p = toSizePolicy();
1463 s << (int) p.horData() << (int) p.verData()
1464 << (Q_INT8) p.hasHeightForWidth();
1465 }
1466 break;
1467 case Date:
1468 s << *((QDate*)d->value.ptr);
1469 break;
1470 case Time:
1471 s << *((QTime*)d->value.ptr);
1472 break;
1473 case DateTime:
1474 s << *((QDateTime*)d->value.ptr);
1475 break;
1476 case ByteArray:
1477 s << *((QByteArray*)d->value.ptr);
1478 break;
1479 case BitArray:
1480 s << *((QBitArray*)d->value.ptr);
1481 break;
1482#ifndef QT_NO_ACCEL
1483 case KeySequence:
1484 s << *((QKeySequence*)d->value.ptr);
1485 break;
1486#endif
1487 case Pen:
1488 s << *((QPen*)d->value.ptr);
1489 break;
1490 case Invalid:
1491 s << QString(); // ### looks wrong.
1492 break;
1493 }
1494}
1495
1496/*!
1497 Reads a variant \a p from the stream \a s.
1498
1499 \sa \link datastreamformat.html Format of the QDataStream
1500 operators \endlink
1501*/
1502QDataStream& operator>> ( QDataStream& s, QVariant& p )
1503{
1504 p.load( s );
1505 return s;
1506}
1507
1508/*!
1509 Writes a variant \a p to the stream \a s.
1510
1511 \sa \link datastreamformat.html Format of the QDataStream
1512 operators \endlink
1513*/
1514QDataStream& operator<< ( QDataStream& s, const QVariant& p )
1515{
1516 p.save( s );
1517 return s;
1518}
1519
1520/*!
1521 Reads a variant type \a p in enum representation from the stream \a s.
1522*/
1523QDataStream& operator>> ( QDataStream& s, QVariant::Type& p )
1524{
1525 Q_UINT32 u;
1526 s >> u;
1527 p = (QVariant::Type) u;
1528
1529 return s;
1530}
1531
1532/*!
1533 Writes a variant type \a p to the stream \a s.
1534*/
1535QDataStream& operator<< ( QDataStream& s, const QVariant::Type p )
1536{
1537 s << (Q_UINT32)p;
1538
1539 return s;
1540}
1541
1542#endif //QT_NO_DATASTREAM
1543
1544/*!
1545 \fn Type QVariant::type() const
1546
1547 Returns the storage type of the value stored in the variant.
1548 Usually it's best to test with canCast() whether the variant can
1549 deliver the data type you are interested in.
1550*/
1551
1552/*!
1553 \fn bool QVariant::isValid() const
1554
1555 Returns TRUE if the storage type of this variant is not
1556 QVariant::Invalid; otherwise returns FALSE.
1557*/
1558
1559/*!
1560 \fn QValueListConstIterator<QString> QVariant::stringListBegin() const
1561 \obsolete
1562
1563 Returns an iterator to the first string in the list if the
1564 variant's type is StringList; otherwise returns a null iterator.
1565*/
1566
1567/*!
1568 \fn QValueListConstIterator<QString> QVariant::stringListEnd() const
1569 \obsolete
1570
1571 Returns the end iterator for the list if the variant's type is
1572 StringList; otherwise returns a null iterator.
1573*/
1574
1575/*!
1576 \fn QValueListConstIterator<QVariant> QVariant::listBegin() const
1577 \obsolete
1578
1579 Returns an iterator to the first item in the list if the variant's
1580 type is appropriate; otherwise returns a null iterator.
1581*/
1582
1583/*!
1584 \fn QValueListConstIterator<QVariant> QVariant::listEnd() const
1585 \obsolete
1586
1587 Returns the end iterator for the list if the variant's type is
1588 appropriate; otherwise returns a null iterator.
1589*/
1590
1591/*!
1592 \fn QMapConstIterator<QString, QVariant> QVariant::mapBegin() const
1593 \obsolete
1594
1595 Returns an iterator to the first item in the map, if the variant's
1596 type is appropriate; otherwise returns a null iterator.
1597*/
1598
1599/*!
1600 \fn QMapConstIterator<QString, QVariant> QVariant::mapEnd() const
1601 \obsolete
1602
1603 Returns the end iterator for the map, if the variant's type is
1604 appropriate; otherwise returns a null iterator.
1605*/
1606
1607/*!
1608 \fn QMapConstIterator<QString, QVariant> QVariant::mapFind( const QString& key ) const
1609 \obsolete
1610
1611 Returns an iterator to the item in the map with \a key as key, if
1612 the variant's type is appropriate and \a key is a valid key;
1613 otherwise returns a null iterator.
1614*/
1615
1616/*!
1617 Returns the variant as a QString if the variant can be cast to
1618 String, otherwise returns QString::null.
1619
1620 \sa asString(), canCast()
1621*/
1622const QString QVariant::toString() const
1623{
1624 switch( d->typ ) {
1625 case CString:
1626 return QString::fromLatin1( toCString() );
1627 case Int:
1628 return QString::number( toInt() );
1629 case UInt:
1630 return QString::number( toUInt() );
1631 case LongLong:
1632 return QString::number( toLongLong() );
1633 case ULongLong:
1634 return QString::number( toULongLong() );
1635 case Double:
1636 return QString::number( toDouble(), 'g', DBL_DIG );
1637#if !defined(QT_NO_SPRINTF) && !defined(QT_NO_DATESTRING)
1638 case Date:
1639 return toDate().toString( Qt::ISODate );
1640 case Time:
1641 return toTime().toString( Qt::ISODate );
1642 case DateTime:
1643 return toDateTime().toString( Qt::ISODate );
1644#endif
1645 case Bool:
1646 return toInt() ? "true" : "false";
1647#ifndef QT_NO_ACCEL
1648 case KeySequence:
1649 return (QString) *( (QKeySequence*)d->value.ptr );
1650#endif
1651 case ByteArray:
1652 return QString( *((QByteArray*)d->value.ptr) );
1653 case Font:
1654 return toFont().toString();
1655 case Color:
1656 return toColor().name();
1657 case String:
1658 return *((QString*)d->value.ptr);
1659 default:
1660 return QString::null;
1661 }
1662}
1663/*!
1664 Returns the variant as a QCString if the variant can be cast to a
1665 CString; otherwise returns 0.
1666
1667 \sa asCString(), canCast()
1668*/
1669const QCString QVariant::toCString() const
1670{
1671 switch( d->typ ) {
1672 case CString: return *((QCString*)d->value.ptr);
1673 case String: return ((QString*)d->value.ptr)->latin1();
1674 default: {
1675 if (!canCast(String))
1676 return 0;
1677 QString c = toString();
1678 return QCString(c.latin1());
1679 }
1680 }
1681}
1682
1683
1684#ifndef QT_NO_STRINGLIST
1685/*!
1686 Returns the variant as a QStringList if the variant has type()
1687 StringList or List of a type that can be converted to QString;
1688 otherwise returns an empty list.
1689
1690 Note that if you want to iterate over the list, you should iterate
1691 over a copy, e.g.
1692 \code
1693 QStringList list = myVariant.toStringList();
1694 QStringList::Iterator it = list.begin();
1695 while( it != list.end() ) {
1696 myProcessing( *it );
1697 ++it;
1698 }
1699 \endcode
1700
1701 \sa asStringList()
1702*/
1703const QStringList QVariant::toStringList() const
1704{
1705 switch ( d->typ ) {
1706 case StringList:
1707 return *((QStringList*)d->value.ptr);
1708#ifndef QT_NO_TEMPLATE_VARIANT
1709 case List:
1710 {
1711 QStringList lst;
1712 QValueList<QVariant>::ConstIterator it = listBegin();
1713 QValueList<QVariant>::ConstIterator end = listEnd();
1714 while( it != end ) {
1715 QString tmp = (*it).toString();
1716 ++it;
1717 lst.append( tmp );
1718 }
1719 return lst;
1720 }
1721#endif
1722 default:
1723 return QStringList();
1724 }
1725}
1726#endif //QT_NO_STRINGLIST
1727
1728#ifndef QT_NO_TEMPLATE_VARIANT
1729/*!
1730 Returns the variant as a QMap<QString,QVariant> if the variant has
1731 type() Map; otherwise returns an empty map.
1732
1733 Note that if you want to iterate over the map, you should iterate
1734 over a copy, e.g.
1735 \code
1736 QMap<QString, QVariant> map = myVariant.toMap();
1737 QMap<QString, QVariant>::Iterator it = map.begin();
1738 while( it != map.end() ) {
1739 myProcessing( *it );
1740 ++it;
1741 }
1742 \endcode
1743
1744 \sa asMap()
1745*/
1746const QMap<QString, QVariant> QVariant::toMap() const
1747{
1748 if ( d->typ != Map )
1749 return QMap<QString,QVariant>();
1750
1751 return *((QMap<QString,QVariant>*)d->value.ptr);
1752}
1753#endif
1754/*!
1755 Returns the variant as a QFont if the variant can be cast to Font;
1756 otherwise returns the application's default font.
1757
1758 \sa asFont(), canCast()
1759*/
1760const QFont QVariant::toFont() const
1761{
1762 switch ( d->typ ) {
1763 case CString:
1764 case ByteArray:
1765 case String:
1766 {
1767 QFont fnt;
1768 fnt.fromString( toString() );
1769 return fnt;
1770 }
1771 case Font:
1772 return *((QFont*)d->value.ptr);
1773 default:
1774 return QFont();
1775 }
1776}
1777
1778/*!
1779 Returns the variant as a QPixmap if the variant has type() Pixmap;
1780 otherwise returns a null pixmap.
1781
1782 \sa asPixmap()
1783*/
1784const QPixmap QVariant::toPixmap() const
1785{
1786 if ( d->typ != Pixmap )
1787 return QPixmap();
1788
1789 return *((QPixmap*)d->value.ptr);
1790}
1791
1792/*!
1793 Returns the variant as a QImage if the variant has type() Image;
1794 otherwise returns a null image.
1795
1796 \sa asImage()
1797*/
1798const QImage QVariant::toImage() const
1799{
1800 if ( d->typ != Image )
1801 return QImage();
1802
1803 return *((QImage*)d->value.ptr);
1804}
1805
1806/*!
1807 Returns the variant as a QBrush if the variant has type() Brush;
1808 otherwise returns a default brush (with all black colors).
1809
1810 \sa asBrush()
1811*/
1812const QBrush QVariant::toBrush() const
1813{
1814 if( d->typ != Brush )
1815 return QBrush();
1816
1817 return *((QBrush*)d->value.ptr);
1818}
1819
1820/*!
1821 Returns the variant as a QPoint if the variant has type() Point;
1822 otherwise returns a point (0, 0).
1823
1824 \sa asPoint()
1825*/
1826const QPoint QVariant::toPoint() const
1827{
1828 if ( d->typ != Point )
1829 return QPoint();
1830
1831 return *((QPoint*)d->value.ptr);
1832}
1833
1834/*!
1835 Returns the variant as a QRect if the variant has type() Rect;
1836 otherwise returns an empty rectangle.
1837
1838 \sa asRect()
1839*/
1840const QRect QVariant::toRect() const
1841{
1842 if ( d->typ != Rect )
1843 return QRect();
1844
1845 return *((QRect*)d->value.ptr);
1846}
1847
1848/*!
1849 Returns the variant as a QSize if the variant has type() Size;
1850 otherwise returns an invalid size.
1851
1852 \sa asSize()
1853*/
1854const QSize QVariant::toSize() const
1855{
1856 if ( d->typ != Size )
1857 return QSize();
1858
1859 return *((QSize*)d->value.ptr);
1860}
1861
1862/*!
1863 Returns the variant as a QColor if the variant can be cast to Color;
1864 otherwise returns an invalid color.
1865
1866 \sa asColor(), canCast()
1867*/
1868const QColor QVariant::toColor() const
1869{
1870 switch ( d->typ ) {
1871 case ByteArray:
1872 case CString:
1873 case String:
1874 {
1875 QColor col;
1876 col.setNamedColor( toString() );
1877 return col;
1878 }
1879 case Color:
1880 return *((QColor*)d->value.ptr);
1881 default:
1882 return QColor();
1883 }
1884}
1885#ifndef QT_NO_PALETTE
1886/*!
1887 Returns the variant as a QPalette if the variant has type()
1888 Palette; otherwise returns a completely black palette.
1889
1890 \sa asPalette()
1891*/
1892const QPalette QVariant::toPalette() const
1893{
1894 if ( d->typ != Palette )
1895 return QPalette();
1896
1897 return *((QPalette*)d->value.ptr);
1898}
1899
1900/*!
1901 Returns the variant as a QColorGroup if the variant has type()
1902 ColorGroup; otherwise returns a completely black color group.
1903
1904 \sa asColorGroup()
1905*/
1906const QColorGroup QVariant::toColorGroup() const
1907{
1908 if ( d->typ != ColorGroup )
1909 return QColorGroup();
1910
1911 return *((QColorGroup*)d->value.ptr);
1912}
1913#endif //QT_NO_PALETTE
1914#ifndef QT_NO_ICONSET
1915/*!
1916 Returns the variant as a QIconSet if the variant has type()
1917 IconSet; otherwise returns an icon set of null pixmaps.
1918
1919 \sa asIconSet()
1920*/
1921const QIconSet QVariant::toIconSet() const
1922{
1923 if ( d->typ != IconSet )
1924 return QIconSet();
1925
1926 return *((QIconSet*)d->value.ptr);
1927}
1928#endif //QT_NO_ICONSET
1929/*!
1930 Returns the variant as a QPointArray if the variant has type()
1931 PointArray; otherwise returns an empty QPointArray.
1932
1933 \sa asPointArray()
1934*/
1935const QPointArray QVariant::toPointArray() const
1936{
1937 if ( d->typ != PointArray )
1938 return QPointArray();
1939
1940 return *((QPointArray*)d->value.ptr);
1941}
1942
1943/*!
1944 Returns the variant as a QBitmap if the variant has type() Bitmap;
1945 otherwise returns a null QBitmap.
1946
1947 \sa asBitmap()
1948*/
1949const QBitmap QVariant::toBitmap() const
1950{
1951 if ( d->typ != Bitmap )
1952 return QBitmap();
1953
1954 return *((QBitmap*)d->value.ptr);
1955}
1956
1957/*!
1958 Returns the variant as a QRegion if the variant has type() Region;
1959 otherwise returns an empty QRegion.
1960
1961 \sa asRegion()
1962*/
1963const QRegion QVariant::toRegion() const
1964{
1965 if ( d->typ != Region )
1966 return QRegion();
1967
1968 return *((QRegion*)d->value.ptr);
1969}
1970
1971/*!
1972 Returns the variant as a QCursor if the variant has type() Cursor;
1973 otherwise returns the default arrow cursor.
1974
1975 \sa asCursor()
1976*/
1977const QCursor QVariant::toCursor() const
1978{
1979#ifndef QT_NO_CURSOR
1980 if ( d->typ != Cursor )
1981 return QCursor();
1982#endif
1983
1984 return *((QCursor*)d->value.ptr);
1985}
1986
1987/*!
1988 Returns the variant as a QDate if the variant can be cast to Date;
1989 otherwise returns an invalid date.
1990
1991 Note that if the type() is String, CString or ByteArray an invalid
1992 date will be returned if the string cannot be parsed as a
1993 Qt::ISODate format date.
1994
1995 \sa asDate(), canCast()
1996*/
1997const QDate QVariant::toDate() const
1998{
1999 switch ( d->typ ) {
2000 case Date:
2001 return *((QDate*)d->value.ptr);
2002 case DateTime:
2003 return ((QDateTime*)d->value.ptr)->date();
2004#ifndef QT_NO_DATESTRING
2005 case String:
2006 return QDate::fromString( *((QString*)d->value.ptr), Qt::ISODate );
2007 case CString:
2008 case ByteArray:
2009 return QDate::fromString(toString(), Qt::ISODate);
2010#endif
2011 default:
2012 return QDate();
2013 }
2014}
2015
2016/*!
2017 Returns the variant as a QTime if the variant can be cast to Time;
2018 otherwise returns an invalid date.
2019
2020 Note that if the type() is String, CString or ByteArray an invalid
2021 time will be returned if the string cannot be parsed as a
2022 Qt::ISODate format time.
2023
2024 \sa asTime()
2025*/
2026const QTime QVariant::toTime() const
2027{
2028 switch ( d->typ ) {
2029 case Time:
2030 return *((QTime*)d->value.ptr);
2031 case DateTime:
2032 return ((QDateTime*)d->value.ptr)->time();
2033#ifndef QT_NO_DATESTRING
2034 case String:
2035 return QTime::fromString( *((QString*)d->value.ptr), Qt::ISODate );
2036 case CString:
2037 case ByteArray:
2038 return QTime::fromString(toString(), Qt::ISODate);
2039#endif
2040 default:
2041 return QTime();
2042 }
2043}
2044
2045/*!
2046 Returns the variant as a QDateTime if the variant can be cast to
2047 DateTime; otherwise returns an invalid QDateTime.
2048
2049 Note that if the type() is String, CString or ByteArray an invalid
2050 QDateTime will be returned if the string cannot be parsed as a
2051 Qt::ISODate format date/time.
2052
2053 \sa asDateTime()
2054*/
2055const QDateTime QVariant::toDateTime() const
2056{
2057 switch ( d->typ ) {
2058 case DateTime:
2059 return *((QDateTime*)d->value.ptr);
2060#ifndef QT_NO_DATESTRING
2061 case String:
2062 return QDateTime::fromString( *((QString*)d->value.ptr), Qt::ISODate );
2063 case CString:
2064 case ByteArray:
2065 return QDateTime::fromString(toString(), Qt::ISODate);
2066#endif
2067 case Date:
2068 return QDateTime( *((QDate*)d->value.ptr) );
2069 default:
2070 return QDateTime();
2071 }
2072}
2073
2074/*!
2075 Returns the variant as a QByteArray if the variant can be cast to
2076 a ByteArray; otherwise returns an empty bytearray.
2077
2078 \sa asByteArray(), canCast()
2079*/
2080const QByteArray QVariant::toByteArray() const
2081{
2082 switch(d->typ) {
2083 case ByteArray: return *((QByteArray*)d->value.ptr);
2084 case CString: return *((QByteArray*)d->value.ptr);
2085 default: {
2086 QByteArray ret;
2087 if (canCast(String)) {
2088 QString c = toString();
2089 ret.duplicate(c.latin1(), c.length());
2090 }
2091 return ret;
2092 }
2093 }
2094}
2095
2096/*!
2097 Returns the variant as a QBitArray if the variant has type()
2098 BitArray; otherwise returns an empty bitarray.
2099
2100 \sa asBitArray()
2101*/
2102const QBitArray QVariant::toBitArray() const
2103{
2104 if ( d->typ == BitArray )
2105 return *((QBitArray*)d->value.ptr);
2106 return QBitArray();
2107}
2108
2109#ifndef QT_NO_ACCEL
2110
2111/*!
2112 Returns the variant as a QKeySequence if the variant can be cast
2113 to a KeySequence; otherwise returns an empty key sequence.
2114
2115 \sa asKeySequence(), canCast()
2116*/
2117const QKeySequence QVariant::toKeySequence() const
2118{
2119 switch ( d->typ ) {
2120 case KeySequence:
2121 return *((QKeySequence*)d->value.ptr);
2122 case String:
2123 case ByteArray:
2124 case CString:
2125 return QKeySequence( toString() );
2126 case Int:
2127 case UInt:
2128 case Double:
2129 case ULongLong:
2130 case LongLong:
2131 return QKeySequence( toInt() );
2132 default:
2133 return QKeySequence();
2134 }
2135}
2136
2137#endif // QT_NO_ACCEL
2138
2139/*!
2140 Returns the variant as a QPen if the variant has type()
2141 Pen; otherwise returns an empty QPen.
2142
2143 \sa asPen()
2144*/
2145const QPen QVariant::toPen() const
2146{
2147 if ( d->typ != Pen )
2148 return QPen();
2149
2150 return *((QPen*)d->value.ptr);
2151}
2152
2153/*!
2154 Returns the variant as an int if the variant can be cast to Int;
2155 otherwise returns 0.
2156
2157 If \a ok is non-null: \a *ok is set to TRUE if the value could be
2158 converted to an int; otherwise \a *ok is set to FALSE.
2159
2160 \sa asInt(), canCast()
2161*/
2162int QVariant::toInt( bool * ok ) const
2163{
2164 if ( ok )
2165 *ok = canCast( Int );
2166
2167 switch ( d->typ ) {
2168 case String:
2169 return ((QString*)d->value.ptr)->toInt( ok );
2170 case CString:
2171 case ByteArray:
2172 return ((QCString*)d->value.ptr)->toInt( ok );
2173 case Int:
2174 return d->value.i;
2175 case UInt:
2176 return (int)d->value.u;
2177 case LongLong:
2178 return (int)d->value.ll;
2179 case ULongLong:
2180 return (int)d->value.ull;
2181 case Double:
2182 return (int)d->value.d;
2183 case Bool:
2184 return (int)d->value.b;
2185#ifndef QT_NO_ACCEL
2186 case KeySequence:
2187 return (int) *( (QKeySequence*)d->value.ptr );
2188#endif
2189 default:
2190 return 0;
2191 }
2192}
2193
2194/*!
2195 Returns the variant as an unsigned int if the variant can be cast
2196 to UInt; otherwise returns 0.
2197
2198 If \a ok is non-null: \a *ok is set to TRUE if the value could be
2199 converted to an unsigned int; otherwise \a *ok is set to FALSE.
2200
2201 \sa asUInt(), canCast()
2202*/
2203uint QVariant::toUInt( bool * ok ) const
2204{
2205 if ( ok )
2206 *ok = canCast( UInt );
2207
2208 switch( d->typ ) {
2209 case String:
2210 return ((QString*)d->value.ptr)->toUInt( ok );
2211 case CString:
2212 case ByteArray:
2213 return ((QCString*)d->value.ptr)->toUInt( ok );
2214 case Int:
2215 return (uint)d->value.i;
2216 case UInt:
2217 return d->value.u;
2218 case LongLong:
2219 return (uint)d->value.ll;
2220 case ULongLong:
2221 return (uint)d->value.ull;
2222 case Double:
2223 return (uint)d->value.d;
2224 case Bool:
2225 return (uint)d->value.b;
2226 default:
2227 return 0;
2228 }
2229}
2230
2231/*!
2232 Returns the variant as a long long int if the variant can be cast
2233 to LongLong; otherwise returns 0.
2234
2235 If \a ok is non-null: \a *ok is set to TRUE if the value could be
2236 converted to an int; otherwise \a *ok is set to FALSE.
2237
2238 \sa asLongLong(), canCast()
2239*/
2240Q_LLONG QVariant::toLongLong( bool * ok ) const
2241{
2242 if ( ok )
2243 *ok = canCast( LongLong );
2244
2245 switch ( d->typ ) {
2246 case String:
2247 return ((QString*)d->value.ptr)->toLongLong( ok );
2248 case CString:
2249 case ByteArray:
2250 return QString(*(QCString*)d->value.ptr).toLongLong(ok);
2251 case Int:
2252 return (Q_LLONG)d->value.i;
2253 case UInt:
2254 return (Q_LLONG)d->value.u;
2255 case LongLong:
2256 return d->value.ll;
2257 case ULongLong:
2258 return (Q_LLONG)d->value.ull;
2259 case Double:
2260 return (Q_LLONG)d->value.d;
2261 case Bool:
2262 return (Q_LLONG)d->value.b;
2263 default:
2264 return 0;
2265 }
2266}
2267
2268/*!
2269 Returns the variant as as an unsigned long long int if the variant
2270 can be cast to ULongLong; otherwise returns 0.
2271
2272 If \a ok is non-null: \a *ok is set to TRUE if the value could be
2273 converted to an int; otherwise \a *ok is set to FALSE.
2274
2275 \sa asULongLong(), canCast()
2276*/
2277Q_ULLONG QVariant::toULongLong( bool * ok ) const
2278{
2279 if ( ok )
2280 *ok = canCast( ULongLong );
2281
2282 switch ( d->typ ) {
2283 case Int:
2284 return (Q_ULLONG)d->value.i;
2285 case UInt:
2286 return (Q_ULLONG)d->value.u;
2287 case LongLong:
2288 return (Q_ULLONG)d->value.ll;
2289 case ULongLong:
2290 return d->value.ull;
2291 case Double:
2292 return (Q_ULLONG)d->value.d;
2293 case Bool:
2294 return (Q_ULLONG)d->value.b;
2295 case String:
2296 return ((QString*)d->value.ptr)->toULongLong( ok );
2297 case CString:
2298 case ByteArray:
2299 return QString(*(QCString*)d->value.ptr).toULongLong(ok);
2300 default:
2301 return 0;
2302 }
2303}
2304
2305/*!
2306 Returns the variant as a bool if the variant can be cast to Bool;
2307 otherWise returns FALSE.
2308
2309 Returns TRUE if the variant has a numeric type and its value is
2310 non-zero, or if the variant has type String, ByteArray or CString
2311 and its lower-case content is not empty, "0" or "false"; otherwise
2312 returns FALSE.
2313
2314 \sa asBool(), canCast()
2315*/
2316bool QVariant::toBool() const
2317{
2318 switch( d->typ ) {
2319 case Bool:
2320 return d->value.b;
2321 case Double:
2322 return d->value.d != 0.0;
2323 case Int:
2324 return d->value.i != 0;
2325 case UInt:
2326 return d->value.u != 0;
2327 case LongLong:
2328 return d->value.ll != 0;
2329 case ULongLong:
2330 return d->value.ull != 0;
2331 case String:
2332 case CString:
2333 case ByteArray:
2334 {
2335 QString str = toString().lower();
2336 return !(str == "0" || str == "false" || str.isEmpty() );
2337 }
2338 default:
2339 return FALSE;
2340 }
2341}
2342
2343/*!
2344 Returns the variant as a double if the variant can be cast to
2345 Double; otherwise returns 0.0.
2346
2347 If \a ok is non-null: \a *ok is set to TRUE if the value could be
2348 converted to a double; otherwise \a *ok is set to FALSE.
2349
2350 \sa asDouble(), canCast()
2351*/
2352double QVariant::toDouble( bool * ok ) const
2353{
2354 if ( ok )
2355 *ok = canCast( Double );
2356
2357 switch ( d->typ ) {
2358 case String:
2359 return ((QString*)d->value.ptr)->toDouble( ok );
2360 case CString:
2361 case ByteArray:
2362 return ((QCString*)d->value.ptr)->toDouble( ok );
2363 case Double:
2364 return d->value.d;
2365 case Int:
2366 return (double)d->value.i;
2367 case Bool:
2368 return (double)d->value.b;
2369 case UInt:
2370 return (double)d->value.u;
2371 case LongLong:
2372 return (double)d->value.ll;
2373 case ULongLong:
2374#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET)
2375 return (double)(Q_LLONG)d->value.ull;
2376#else
2377 return (double)d->value.ull;
2378#endif
2379 default:
2380 return 0.0;
2381 }
2382}
2383
2384#ifndef QT_NO_TEMPLATE_VARIANT
2385/*!
2386 Returns the variant as a QValueList<QVariant> if the variant has
2387 type() List or StringList; otherwise returns an empty list.
2388
2389 Note that if you want to iterate over the list, you should iterate
2390 over a copy, e.g.
2391 \code
2392 QValueList<QVariant> list = myVariant.toList();
2393 QValueList<QVariant>::Iterator it = list.begin();
2394 while( it != list.end() ) {
2395 myProcessing( *it );
2396 ++it;
2397 }
2398 \endcode
2399
2400 \sa asList()
2401*/
2402const QValueList<QVariant> QVariant::toList() const
2403{
2404 if ( d->typ == List )
2405 return *((QValueList<QVariant>*)d->value.ptr);
2406#ifndef QT_NO_STRINGLIST
2407 if ( d->typ == StringList ) {
2408 QValueList<QVariant> lst;
2409 QStringList::ConstIterator it = stringListBegin();
2410 QStringList::ConstIterator end = stringListEnd();
2411 for( ; it != end; ++it )
2412 lst.append( QVariant( *it ) );
2413 return lst;
2414 }
2415#endif //QT_NO_STRINGLIST
2416 return QValueList<QVariant>();
2417}
2418#endif
2419
2420/*!
2421 Returns the variant as a QSizePolicy if the variant has type()
2422 SizePolicy; otherwise returns an undefined (but legal) size
2423 policy.
2424*/
2425
2426QSizePolicy QVariant::toSizePolicy() const
2427{
2428 if ( d->typ == SizePolicy )
2429 return *((QSizePolicy*)d->value.ptr);
2430
2431 return QSizePolicy();
2432}
2433
2434
2435#define Q_VARIANT_AS( f ) Q##f& QVariant::as##f() \
2436{ \
2437 bool b = isNull(); \
2438 if ( d->typ != f ) \
2439 *this = QVariant( to##f() ); \
2440 else \
2441 detach(); \
2442 d->is_null = b; \
2443 return *((Q##f*)d->value.ptr); \
2444}
2445
2446Q_VARIANT_AS(String)
2447Q_VARIANT_AS(CString)
2448#ifndef QT_NO_STRINGLIST
2449Q_VARIANT_AS(StringList)
2450#endif
2451Q_VARIANT_AS(Font)
2452Q_VARIANT_AS(Pixmap)
2453Q_VARIANT_AS(Image)
2454Q_VARIANT_AS(Brush)
2455Q_VARIANT_AS(Point)
2456Q_VARIANT_AS(Rect)
2457Q_VARIANT_AS(Size)
2458Q_VARIANT_AS(Color)
2459#ifndef QT_NO_PALETTE
2460Q_VARIANT_AS(Palette)
2461Q_VARIANT_AS(ColorGroup)
2462#endif
2463#ifndef QT_NO_ICONSET
2464Q_VARIANT_AS(IconSet)
2465#endif
2466Q_VARIANT_AS(PointArray)
2467Q_VARIANT_AS(Bitmap)
2468Q_VARIANT_AS(Region)
2469Q_VARIANT_AS(Cursor)
2470Q_VARIANT_AS(SizePolicy)
2471Q_VARIANT_AS(Date)
2472Q_VARIANT_AS(Time)
2473Q_VARIANT_AS(DateTime)
2474Q_VARIANT_AS(ByteArray)
2475Q_VARIANT_AS(BitArray)
2476#ifndef QT_NO_ACCEL
2477Q_VARIANT_AS(KeySequence)
2478#endif
2479Q_VARIANT_AS(Pen)
2480
2481/*!
2482 \fn QString& QVariant::asString()
2483
2484 Tries to convert the variant to hold a string value. If that is
2485 not possible the variant is set to an empty string.
2486
2487 Returns a reference to the stored string.
2488
2489 \sa toString()
2490*/
2491
2492/*!
2493 \fn QCString& QVariant::asCString()
2494
2495 Tries to convert the variant to hold a string value. If that is
2496 not possible the variant is set to an empty string.
2497
2498 Returns a reference to the stored string.
2499
2500 \sa toCString()
2501*/
2502
2503/*!
2504 \fn QStringList& QVariant::asStringList()
2505
2506 Tries to convert the variant to hold a QStringList value. If that
2507 is not possible the variant is set to an empty string list.
2508
2509 Returns a reference to the stored string list.
2510
2511 Note that if you want to iterate over the list, you should
2512 iterate over a copy, e.g.
2513 \code
2514 QStringList list = myVariant.asStringList();
2515 QStringList::Iterator it = list.begin();
2516 while( it != list.end() ) {
2517 myProcessing( *it );
2518 ++it;
2519 }
2520 \endcode
2521
2522 \sa toStringList()
2523*/
2524
2525/*!
2526 \fn QFont& QVariant::asFont()
2527
2528 Tries to convert the variant to hold a QFont. If that is not
2529 possible the variant is set to the application's default font.
2530
2531 Returns a reference to the stored font.
2532
2533 \sa toFont()
2534*/
2535
2536/*!
2537 \fn QPixmap& QVariant::asPixmap()
2538
2539 Tries to convert the variant to hold a pixmap value. If that is
2540 not possible the variant is set to a null pixmap.
2541
2542 Returns a reference to the stored pixmap.
2543
2544 \sa toPixmap()
2545*/
2546
2547/*!
2548 \fn QImage& QVariant::asImage()
2549
2550 Tries to convert the variant to hold an image value. If that is
2551 not possible the variant is set to a null image.
2552
2553 Returns a reference to the stored image.
2554
2555 \sa toImage()
2556*/
2557
2558/*!
2559 \fn QBrush& QVariant::asBrush()
2560
2561 Tries to convert the variant to hold a brush value. If that is not
2562 possible the variant is set to a default black brush.
2563
2564 Returns a reference to the stored brush.
2565
2566 \sa toBrush()
2567*/
2568
2569/*!
2570 \fn QPoint& QVariant::asPoint()
2571
2572 Tries to convert the variant to hold a point value. If that is not
2573 possible the variant is set to a (0, 0) point.
2574
2575 Returns a reference to the stored point.
2576
2577 \sa toPoint()
2578*/
2579
2580/*!
2581 \fn QRect& QVariant::asRect()
2582
2583 Tries to convert the variant to hold a rectangle value. If that is
2584 not possible the variant is set to an empty rectangle.
2585
2586 Returns a reference to the stored rectangle.
2587
2588 \sa toRect()
2589*/
2590
2591/*!
2592 \fn QSize& QVariant::asSize()
2593
2594 Tries to convert the variant to hold a QSize value. If that is not
2595 possible the variant is set to an invalid size.
2596
2597 Returns a reference to the stored size.
2598
2599 \sa toSize() QSize::isValid()
2600*/
2601
2602/*!
2603 \fn QSizePolicy& QVariant::asSizePolicy()
2604
2605 Tries to convert the variant to hold a QSizePolicy value. If that
2606 fails, the variant is set to an arbitrary (valid) size policy.
2607*/
2608
2609
2610/*!
2611 \fn QColor& QVariant::asColor()
2612
2613 Tries to convert the variant to hold a QColor value. If that is
2614 not possible the variant is set to an invalid color.
2615
2616 Returns a reference to the stored color.
2617
2618 \sa toColor() QColor::isValid()
2619*/
2620
2621/*!
2622 \fn QPalette& QVariant::asPalette()
2623
2624 Tries to convert the variant to hold a QPalette value. If that is
2625 not possible the variant is set to a palette of black colors.
2626
2627 Returns a reference to the stored palette.
2628
2629 \sa toString()
2630*/
2631
2632/*!
2633 \fn QColorGroup& QVariant::asColorGroup()
2634
2635 Tries to convert the variant to hold a QColorGroup value. If that
2636 is not possible the variant is set to a color group of all black
2637 colors.
2638
2639 Returns a reference to the stored color group.
2640
2641 \sa toColorGroup()
2642*/
2643
2644/*!
2645 \fn QIconSet& QVariant::asIconSet()
2646
2647 Tries to convert the variant to hold a QIconSet value. If that is
2648 not possible the variant is set to an empty iconset.
2649
2650 Returns a reference to the stored iconset.
2651
2652 \sa toIconSet()
2653*/
2654
2655/*!
2656 \fn QPointArray& QVariant::asPointArray()
2657
2658 Tries to convert the variant to hold a QPointArray value. If that
2659 is not possible the variant is set to an empty point array.
2660
2661 Returns a reference to the stored point array.
2662
2663 \sa toPointArray()
2664*/
2665
2666/*!
2667 \fn QBitmap& QVariant::asBitmap()
2668
2669 Tries to convert the variant to hold a bitmap value. If that is
2670 not possible the variant is set to a null bitmap.
2671
2672 Returns a reference to the stored bitmap.
2673
2674 \sa toBitmap()
2675*/
2676
2677/*!
2678 \fn QRegion& QVariant::asRegion()
2679
2680 Tries to convert the variant to hold a QRegion value. If that is
2681 not possible the variant is set to a null region.
2682
2683 Returns a reference to the stored region.
2684
2685 \sa toRegion()
2686*/
2687
2688/*!
2689 \fn QCursor& QVariant::asCursor()
2690
2691 Tries to convert the variant to hold a QCursor value. If that is
2692 not possible the variant is set to a default arrow cursor.
2693
2694 Returns a reference to the stored cursor.
2695
2696 \sa toCursor()
2697*/
2698
2699/*!
2700 \fn QDate& QVariant::asDate()
2701
2702 Tries to convert the variant to hold a QDate value. If that is not
2703 possible then the variant is set to an invalid date.
2704
2705 Returns a reference to the stored date.
2706
2707 \sa toDate()
2708*/
2709
2710/*!
2711 \fn QTime& QVariant::asTime()
2712
2713 Tries to convert the variant to hold a QTime value. If that is not
2714 possible then the variant is set to an invalid time.
2715
2716 Returns a reference to the stored time.
2717
2718 \sa toTime()
2719*/
2720
2721/*!
2722 \fn QDateTime& QVariant::asDateTime()
2723
2724 Tries to convert the variant to hold a QDateTime value. If that is
2725 not possible then the variant is set to an invalid date/time.
2726
2727 Returns a reference to the stored date/time.
2728
2729 \sa toDateTime()
2730*/
2731
2732/*!
2733 \fn QByteArray& QVariant::asByteArray()
2734
2735 Tries to convert the variant to hold a QByteArray value. If that
2736 is not possible then the variant is set to an empty bytearray.
2737
2738 Returns a reference to the stored bytearray.
2739
2740 \sa toByteArray()
2741*/
2742
2743/*!
2744 \fn QBitArray& QVariant::asBitArray()
2745
2746 Tries to convert the variant to hold a QBitArray value. If that is
2747 not possible then the variant is set to an empty bitarray.
2748
2749 Returns a reference to the stored bitarray.
2750
2751 \sa toBitArray()
2752*/
2753
2754/*!
2755 \fn QKeySequence& QVariant::asKeySequence()
2756
2757 Tries to convert the variant to hold a QKeySequence value. If that
2758 is not possible then the variant is set to an empty key sequence.
2759
2760 Returns a reference to the stored key sequence.
2761
2762 \sa toKeySequence()
2763*/
2764
2765/*! \fn QPen& QVariant::asPen()
2766
2767 Tries to convert the variant to hold a QPen value. If that
2768 is not possible then the variant is set to an empty pen.
2769
2770 Returns a reference to the stored pen.
2771
2772 \sa toPen()
2773*/
2774
2775/*!
2776 Returns the variant's value as int reference.
2777*/
2778int& QVariant::asInt()
2779{
2780 detach();
2781 if ( d->typ != Int ) {
2782 int i = toInt();
2783 bool b = isNull();
2784 d->clear();
2785 d->value.i = i;
2786 d->typ = Int;
2787 d->is_null = b;
2788 }
2789 return d->value.i;
2790}
2791
2792/*!
2793 Returns the variant's value as unsigned int reference.
2794*/
2795uint& QVariant::asUInt()
2796{
2797 detach();
2798 if ( d->typ != UInt ) {
2799 uint u = toUInt();
2800 bool b = isNull();
2801 d->clear();
2802 d->value.u = u;
2803 d->typ = UInt;
2804 d->is_null = b;
2805 }
2806 return d->value.u;
2807}
2808
2809/*!
2810 Returns the variant's value as long long reference.
2811*/
2812Q_LLONG& QVariant::asLongLong()
2813{
2814 detach();
2815 if ( d->typ != LongLong ) {
2816 Q_LLONG ll = toLongLong();
2817 bool b = isNull();
2818 d->clear();
2819 d->value.ll = ll;
2820 d->typ = LongLong;
2821 d->is_null = b;
2822 }
2823 return d->value.ll;
2824}
2825
2826/*!
2827 Returns the variant's value as unsigned long long reference.
2828*/
2829Q_ULLONG& QVariant::asULongLong()
2830{
2831 detach();
2832 if ( d->typ != ULongLong ) {
2833 Q_ULLONG ull = toULongLong();
2834 bool b = isNull();
2835 d->clear();
2836 d->value.ull = ull;
2837 d->typ = ULongLong;
2838 d->is_null = b;
2839 }
2840 return d->value.ull;
2841}
2842
2843/*!
2844 Returns the variant's value as bool reference.
2845*/
2846bool& QVariant::asBool()
2847{
2848 detach();
2849 if ( d->typ != Bool ) {
2850 bool b = toBool();
2851 bool nb = isNull();
2852 d->clear();
2853 d->value.b = b;
2854 d->typ = Bool;
2855 d->is_null = nb;
2856 }
2857 return d->value.b;
2858}
2859
2860/*!
2861 Returns the variant's value as double reference.
2862*/
2863double& QVariant::asDouble()
2864{
2865 detach();
2866 if ( d->typ != Double ) {
2867 double dbl = toDouble();
2868 bool b = isNull();
2869 d->clear();
2870 d->value.d = dbl;
2871 d->typ = Double;
2872 d->is_null = b;
2873 }
2874 return d->value.d;
2875}
2876
2877#ifndef QT_NO_TEMPLATE_VARIANT
2878/*!
2879 Returns the variant's value as variant list reference.
2880
2881 Note that if you want to iterate over the list, you should iterate
2882 over a copy, e.g.
2883 \code
2884 QValueList<QVariant> list = myVariant.asList();
2885 QValueList<QVariant>::Iterator it = list.begin();
2886 while( it != list.end() ) {
2887 myProcessing( *it );
2888 ++it;
2889 }
2890 \endcode
2891*/
2892QValueList<QVariant>& QVariant::asList()
2893{
2894 bool b = isNull();
2895 if ( d->typ != List )
2896 *this = QVariant( toList() );
2897 else
2898 detach();
2899 d->is_null = b;
2900 return *((QValueList<QVariant>*)d->value.ptr);
2901}
2902
2903/*!
2904 Returns the variant's value as variant map reference.
2905
2906 Note that if you want to iterate over the map, you should iterate
2907 over a copy, e.g.
2908 \code
2909 QMap<QString, QVariant> map = myVariant.asMap();
2910 QMap<QString, QVariant>::Iterator it = map.begin();
2911 while( it != map.end() ) {
2912 myProcessing( *it );
2913 ++it;
2914 }
2915 \endcode
2916*/
2917QMap<QString, QVariant>& QVariant::asMap()
2918{
2919 bool b = isNull();
2920 if ( d->typ != Map )
2921 *this = QVariant( toMap() );
2922 else
2923 detach();
2924 d->is_null = b;
2925 return *((QMap<QString,QVariant>*)d->value.ptr);
2926}
2927#endif
2928
2929/*!
2930 Returns TRUE if the variant's type can be cast to the requested
2931 type, \a t. Such casting is done automatically when calling the
2932 toInt(), toBool(), ... or asInt(), asBool(), ... methods.
2933
2934 The following casts are done automatically:
2935 \table
2936 \header \i Type \i Automatically Cast To
2937 \row \i Bool \i Double, Int, UInt, LongLong, ULongLong, String, CString, ByteArray
2938 \row \i Color \i String. CString. ByteArray
2939 \row \i Date \i String, CString, ByteArray, DateTime
2940 \row \i DateTime \i String, CString, ByteArray, Date, Time
2941 \row \i Double \i String, CString, ByteArray, Int, Bool, UInt, LongLong, ULongLong
2942 \row \i Font \i String, CString, ByteArray
2943 \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
2944 \row \i LongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
2945 \row \i ULongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
2946 \row \i List \i StringList (if the list contains only strings or
2947 something that can be cast to a string)
2948 \row \i String \i CString, ByteArray, CString, Int, UInt, Bool, Double, Date,
2949 Time, DateTime, KeySequence, Font, Color
2950 \row \i CString \i String, ByteArray, Int, UInt, Bool, Double, Date, ULongLong, LongLong
2951 \row \i ByteArray \i String, CString, Int, UInt, Bool, Double, Date, ULongLong, LongLong
2952 \row \i StringList \i List
2953 \row \i Time \i String
2954 \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
2955 \row \i KeySequence \i String, CString, ByteArray, Int, UInt, LongLong, ULongLong
2956 \endtable
2957*/
2958bool QVariant::canCast( Type t ) const
2959{
2960 if ( Type( d->typ ) == t )
2961 return TRUE;
2962
2963 switch ( t ) {
2964 case Bool:
2965 case Double:
2966 if (d->typ == KeySequence)
2967 break;
2968 case Int:
2969 case UInt:
2970 case LongLong:
2971 case ULongLong:
2972 switch(d->typ) {
2973 case Bool:
2974 case ByteArray:
2975 case CString:
2976 case Double:
2977 case Int:
2978 case KeySequence:
2979 case LongLong:
2980 case String:
2981 case UInt:
2982 case ULongLong:
2983 return TRUE;
2984 default: break;
2985 }
2986 break;
2987
2988 case CString:
2989 case ByteArray:
2990 case String:
2991 switch(d->typ) {
2992 case Bool:
2993 case ByteArray:
2994 case CString:
2995 case Color:
2996 case Date:
2997 case DateTime:
2998 case Double:
2999 case Font:
3000 case Int:
3001 case KeySequence:
3002 case LongLong:
3003 case String:
3004 case Time:
3005 case UInt:
3006 case ULongLong:
3007 return TRUE;
3008 default: break;
3009 }
3010 break;
3011
3012 case Time:
3013 if (d->typ == Date)
3014 break;
3015 case Date:
3016 case DateTime:
3017 switch(d->typ) {
3018 case ByteArray:
3019 case CString:
3020 case Date:
3021 case DateTime:
3022 case String:
3023 return TRUE;
3024 default: break;
3025 }
3026 break;
3027
3028 case KeySequence:
3029 switch(d->typ) {
3030 case ByteArray:
3031 case CString:
3032 case Int:
3033 case UInt:
3034 case LongLong:
3035 case ULongLong:
3036 case Double:
3037 case String:
3038 return TRUE;
3039 default: break;
3040 }
3041 break;
3042
3043 case Font:
3044 case Color:
3045 switch(d->typ) {
3046 case ByteArray:
3047 case CString:
3048 case String:
3049 return TRUE;
3050 default: break;
3051 }
3052 break;
3053
3054#ifndef QT_NO_STRINGLIST
3055 case List:
3056 return d->typ == StringList;
3057#endif
3058#ifndef QT_NO_TEMPLATE_VARIANT
3059 case StringList:
3060 if ( d->typ == List ) {
3061 QValueList<QVariant>::ConstIterator it = listBegin();
3062 QValueList<QVariant>::ConstIterator end = listEnd();
3063 for( ; it != end; ++it ) {
3064 if ( !(*it).canCast( String ) )
3065 return FALSE;
3066 }
3067 return TRUE;
3068 }
3069#endif
3070 case Invalid:
3071 case Map:
3072 case Pixmap:
3073 case Brush:
3074 case Rect:
3075 case Size:
3076 case Palette:
3077 case ColorGroup:
3078 case IconSet:
3079 case Point:
3080 case Image:
3081 case PointArray:
3082 case Region:
3083 case Bitmap:
3084 case Cursor:
3085 case SizePolicy:
3086 case BitArray:
3087 case Pen:
3088 break;
3089 }
3090 return FALSE;
3091}
3092
3093/*!
3094 Casts the variant to the requested type. If the cast cannot be
3095 done, the variant is set to the default value of the requested
3096 type (e.g. an empty string if the requested type \a t is
3097 QVariant::String, an empty point array if the requested type \a t
3098 is QVariant::PointArray, etc). Returns TRUE if the current type of
3099 the variant was successfully cast; otherwise returns FALSE.
3100
3101 \sa canCast()
3102*/
3103
3104bool QVariant::cast( Type t )
3105{
3106 switch ( t ) {
3107#ifndef QT_NO_TEMPLATE_VARIANT
3108 case QVariant::Map:
3109 asMap();
3110 break;
3111 case QVariant::List:
3112 asList();
3113 break;
3114#endif
3115 case QVariant::String:
3116 asString();
3117 break;
3118#ifndef QT_NO_STRINGLIST
3119 case QVariant::StringList:
3120 asStringList();
3121 break;
3122#endif
3123 case QVariant::Font:
3124 asFont();
3125 break;
3126 case QVariant::Pixmap:
3127 asPixmap();
3128 break;
3129 case QVariant::Brush:
3130 asBrush();
3131 break;
3132 case QVariant::Rect:
3133 asRect();
3134 break;
3135 case QVariant::Size:
3136 asSize();
3137 break;
3138 case QVariant::Color:
3139 asColor();
3140 break;
3141#ifndef QT_NO_PALETTE
3142 case QVariant::Palette:
3143 asPalette();
3144 break;
3145 case QVariant::ColorGroup:
3146 asColorGroup();
3147 break;
3148#endif
3149#ifndef QT_NO_ICONSET
3150 case QVariant::IconSet:
3151 asIconSet();
3152 break;
3153#endif
3154 case QVariant::Point:
3155 asPoint();
3156 break;
3157 case QVariant::Image:
3158 asImage();
3159 break;
3160 case QVariant::Int:
3161 asInt();
3162 break;
3163 case QVariant::UInt:
3164 asUInt();
3165 break;
3166 case QVariant::Bool:
3167 asBool();
3168 break;
3169 case QVariant::Double:
3170 asDouble();
3171 break;
3172 case QVariant::CString:
3173 asCString();
3174 break;
3175 case QVariant::PointArray:
3176 asPointArray();
3177 break;
3178 case QVariant::Region:
3179 asRegion();
3180 break;
3181 case QVariant::Bitmap:
3182 asBitmap();
3183 break;
3184 case QVariant::Cursor:
3185 asCursor();
3186 break;
3187 case QVariant::SizePolicy:
3188 asSizePolicy();
3189 break;
3190 case QVariant::Date:
3191 asDate();
3192 break;
3193 case QVariant::Time:
3194 asTime();
3195 break;
3196 case QVariant::DateTime:
3197 asDateTime();
3198 break;
3199 case QVariant::ByteArray:
3200 asByteArray();
3201 break;
3202 case QVariant::BitArray:
3203 asBitArray();
3204 break;
3205#ifndef QT_NO_ACCEL
3206 case QVariant::KeySequence:
3207 asKeySequence();
3208 break;
3209#endif
3210 case QVariant::Pen:
3211 asPen();
3212 break;
3213 case QVariant::LongLong:
3214 asLongLong();
3215 break;
3216 case QVariant::ULongLong:
3217 asULongLong();
3218 break;
3219 default:
3220 case QVariant::Invalid:
3221 (*this) = QVariant();
3222 }
3223 return canCast( t );
3224}
3225
3226/*!
3227 Compares this QVariant with \a v and returns TRUE if they are
3228 equal; otherwise returns FALSE.
3229*/
3230
3231bool QVariant::operator==( const QVariant &v ) const
3232{
3233 if (isNumeric(v.type()) && canCast(v.type())) {
3234 bool ok;
3235 switch(v.type()) {
3236 case Bool:
3237 return toBool() == v.toBool();
3238 case Int:
3239 {
3240 int val = toInt(&ok);
3241 return (ok && val == v.toInt());
3242 }
3243 case UInt:
3244 {
3245 uint val = toUInt(&ok);
3246 return (ok && val == v.toUInt());
3247 }
3248
3249 case Double:
3250 {
3251 double val = toDouble(&ok);
3252 return (ok && val == v.toDouble());
3253 }
3254
3255 case LongLong:
3256 {
3257 Q_LLONG val = toLongLong(&ok);
3258 return (ok && val == v.toLongLong());
3259 }
3260
3261 case ULongLong:
3262 {
3263 Q_ULLONG val = toULongLong(&ok);
3264 return (ok && val == v.toULongLong());
3265 }
3266
3267 default:
3268 Q_ASSERT(FALSE);
3269 }
3270 }
3271
3272 if (!v.canCast(d->typ)) {
3273 return FALSE;
3274 }
3275
3276 switch( d->typ ) {
3277 case Cursor:
3278#ifndef QT_NO_CURSOR
3279 return v.toCursor().shape() == toCursor().shape();
3280#endif
3281 case Bitmap:
3282 return v.toBitmap().serialNumber() == toBitmap().serialNumber();
3283 case PointArray:
3284 return v.toPointArray() == toPointArray();
3285 case Region:
3286 return v.toRegion() == toRegion();
3287#ifndef QT_NO_TEMPLATE_VARIANT
3288 case List:
3289 return v.toList() == toList();
3290 case Map: {
3291 if ( v.toMap().count() != toMap().count() )
3292 return FALSE;
3293 QMap<QString, QVariant>::ConstIterator it = v.toMap().begin();
3294 QMap<QString, QVariant>::ConstIterator it2 = toMap().begin();
3295 while ( it != v.toMap().end() ) {
3296 if ( *it != *it2 )
3297 return FALSE;
3298 ++it;
3299 ++it2;
3300 }
3301 return TRUE;
3302 }
3303#endif
3304 case String:
3305 return v.toString() == toString();
3306 case CString:
3307 return v.toCString() == toCString();
3308#ifndef QT_NO_STRINGLIST
3309 case StringList:
3310 return v.toStringList() == toStringList();
3311#endif
3312 case Font:
3313 return v.toFont() == toFont();
3314 case Pixmap:
3315 return v.toPixmap().serialNumber() == toPixmap().serialNumber();
3316 case Image:
3317 return v.toImage() == toImage();
3318 case Brush:
3319 return v.toBrush() == toBrush();
3320 case Point:
3321 return v.toPoint() == toPoint();
3322 case Rect:
3323 return v.toRect() == toRect();
3324 case Size:
3325 return v.toSize() == toSize();
3326 case Color:
3327 return v.toColor() == toColor();
3328#ifndef QT_NO_PALETTE
3329 case Palette:
3330 return v.toPalette() == toPalette();
3331 case ColorGroup:
3332 return v.toColorGroup() == toColorGroup();
3333#endif
3334#ifndef QT_NO_ICONSET
3335 case IconSet:
3336 return v.toIconSet().pixmap().serialNumber()
3337 == toIconSet().pixmap().serialNumber();
3338#endif
3339 case Int:
3340 return v.toInt() == toInt();
3341 case UInt:
3342 return v.toUInt() == toUInt();
3343 case LongLong:
3344 return v.toLongLong() == toLongLong();
3345 case ULongLong:
3346 return v.toULongLong() == toULongLong();
3347 case Bool:
3348 return v.toBool() == toBool();
3349 case Double:
3350 return v.toDouble() == toDouble();
3351 case SizePolicy:
3352 return v.toSizePolicy() == toSizePolicy();
3353 case Date:
3354 return v.toDate() == toDate();
3355 case Time:
3356 return v.toTime() == toTime();
3357 case DateTime:
3358 return v.toDateTime() == toDateTime();
3359 case ByteArray:
3360 return v.toByteArray() == toByteArray();
3361 case BitArray:
3362 return v.toBitArray() == toBitArray();
3363#ifndef QT_NO_ACCEL
3364 case KeySequence:
3365 return v.toKeySequence() == toKeySequence();
3366#endif
3367 case Pen:
3368 return v.toPen() == toPen();
3369 case Invalid:
3370 break;
3371 }
3372 return FALSE;
3373}
3374
3375/*!
3376 Compares this QVariant with \a v and returns TRUE if they are not
3377 equal; otherwise returns FALSE.
3378*/
3379
3380bool QVariant::operator!=( const QVariant &v ) const
3381{
3382 return !( v == *this );
3383}
3384
3385
3386/*! \internal
3387
3388 Reads or sets the variant type and ptr
3389 */
3390void* QVariant::rawAccess( void* ptr, Type typ, bool deepCopy )
3391{
3392 if ( ptr ) {
3393 clear();
3394 d->typ = typ;
3395 d->value.ptr = ptr;
3396 d->is_null = FALSE;
3397 if ( deepCopy ) {
3398 QVariant::Private* p = new Private( d );
3399 d->typ = Invalid;
3400 delete d;
3401 d = p;
3402 }
3403 }
3404
3405 if ( !deepCopy )
3406 return d->value.ptr;
3407 QVariant::Private* p = new Private( d );
3408 void *ret = (void*)p->value.ptr;
3409 p->typ = Invalid;
3410 delete p;
3411 return ret;
3412}
3413
3414/*!
3415 Returns TRUE if this is a NULL variant, FALSE otherwise.
3416*/
3417bool QVariant::isNull() const
3418{
3419 switch( d->typ )
3420 {
3421 case QVariant::Bitmap:
3422 return ((QBitmap*) d->value.ptr)->isNull();
3423 case QVariant::Region:
3424 return ((QRegion*) d->value.ptr)->isNull();
3425 case QVariant::PointArray:
3426 return ((QPointArray*) d->value.ptr)->isNull();
3427 case QVariant::String:
3428 return ((QString*) d->value.ptr)->isNull();
3429 case QVariant::CString:
3430 return ((QCString*) d->value.ptr)->isNull();
3431 case QVariant::Pixmap:
3432 return ((QPixmap*) d->value.ptr)->isNull();
3433 case QVariant::Image:
3434 return ((QImage*) d->value.ptr)->isNull();
3435 case QVariant::Point:
3436 return ((QPoint*) d->value.ptr)->isNull();
3437 case QVariant::Rect:
3438 return ((QRect*) d->value.ptr)->isNull();
3439 case QVariant::Size:
3440 return ((QSize*) d->value.ptr)->isNull();
3441#ifndef QT_NO_ICONSET
3442 case QVariant::IconSet:
3443 return ((QIconSet*) d->value.ptr)->isNull();
3444#endif
3445 case QVariant::Date:
3446 return ((QDate*) d->value.ptr)->isNull();
3447 case QVariant::Time:
3448 return ((QTime*) d->value.ptr)->isNull();
3449 case QVariant::DateTime:
3450 return ((QDateTime*) d->value.ptr)->isNull();
3451 case QVariant::ByteArray:
3452 return ((QByteArray*) d->value.ptr)->isNull();
3453 case QVariant::BitArray:
3454 return ((QBitArray*) d->value.ptr)->isNull();
3455 case QVariant::Cursor:
3456#ifndef QT_NO_STRINGLIST
3457 case QVariant::StringList:
3458#endif //QT_NO_STRINGLIST
3459 case QVariant::Font:
3460 case QVariant::Brush:
3461 case QVariant::Color:
3462#ifndef QT_NO_PALETTE
3463 case QVariant::Palette:
3464 case QVariant::ColorGroup:
3465#endif
3466#ifndef QT_NO_TEMPLATE_VARIANT
3467 case QVariant::Map:
3468 case QVariant::List:
3469#endif
3470 case QVariant::SizePolicy:
3471#ifndef QT_NO_ACCEL
3472 case QVariant::KeySequence:
3473#endif
3474 case QVariant::Pen:
3475 case QVariant::Invalid:
3476 case QVariant::Int:
3477 case QVariant::UInt:
3478 case QVariant::LongLong:
3479 case QVariant::ULongLong:
3480 case QVariant::Bool:
3481 case QVariant::Double:
3482 break;
3483 }
3484 return d->is_null;
3485}
3486#endif //QT_NO_VARIANT
Note: See TracBrowser for help on using the repository browser.