1 | /****************************************************************************
|
---|
2 | ** $Id: qvariant.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition 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 | #ifndef QVARIANT_H
|
---|
39 | #define QVARIANT_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qstring.h"
|
---|
43 | #endif // QT_H
|
---|
44 |
|
---|
45 | #ifndef QT_NO_VARIANT
|
---|
46 | class QString;
|
---|
47 | class QCString;
|
---|
48 | class QFont;
|
---|
49 | class QPixmap;
|
---|
50 | class QBrush;
|
---|
51 | class QRect;
|
---|
52 | class QPoint;
|
---|
53 | class QImage;
|
---|
54 | class QSize;
|
---|
55 | class QColor;
|
---|
56 | class QPalette;
|
---|
57 | class QColorGroup;
|
---|
58 | class QIconSet;
|
---|
59 | class QDataStream;
|
---|
60 | class QPointArray;
|
---|
61 | class QRegion;
|
---|
62 | class QBitmap;
|
---|
63 | class QCursor;
|
---|
64 | class QStringList;
|
---|
65 | class QSizePolicy;
|
---|
66 | class QDate;
|
---|
67 | class QTime;
|
---|
68 | class QDateTime;
|
---|
69 | class QBitArray;
|
---|
70 | class QKeySequence;
|
---|
71 | class QPen;
|
---|
72 | // Some headers rejected after QVariant declaration for GCC 2.7.* compatibility
|
---|
73 | class QVariant;
|
---|
74 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
75 | template <class T> class QValueList;
|
---|
76 | template <class T> class QValueListConstIterator;
|
---|
77 | template <class T> class QValueListNode;
|
---|
78 | template <class Key, class T> class QMap;
|
---|
79 | template <class Key, class T> class QMapConstIterator;
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | class Q_EXPORT QVariant
|
---|
83 | {
|
---|
84 | public:
|
---|
85 | enum Type {
|
---|
86 | Invalid,
|
---|
87 | Map,
|
---|
88 | List,
|
---|
89 | String,
|
---|
90 | StringList,
|
---|
91 | Font,
|
---|
92 | Pixmap,
|
---|
93 | Brush,
|
---|
94 | Rect,
|
---|
95 | Size,
|
---|
96 | Color,
|
---|
97 | Palette,
|
---|
98 | ColorGroup,
|
---|
99 | IconSet,
|
---|
100 | Point,
|
---|
101 | Image,
|
---|
102 | Int,
|
---|
103 | UInt,
|
---|
104 | Bool,
|
---|
105 | Double,
|
---|
106 | CString,
|
---|
107 | PointArray,
|
---|
108 | Region,
|
---|
109 | Bitmap,
|
---|
110 | Cursor,
|
---|
111 | SizePolicy,
|
---|
112 | Date,
|
---|
113 | Time,
|
---|
114 | DateTime,
|
---|
115 | ByteArray,
|
---|
116 | BitArray,
|
---|
117 | KeySequence,
|
---|
118 | Pen,
|
---|
119 | LongLong,
|
---|
120 | ULongLong
|
---|
121 | };
|
---|
122 |
|
---|
123 | QVariant();
|
---|
124 | ~QVariant();
|
---|
125 | QVariant( const QVariant& );
|
---|
126 | #ifndef QT_NO_DATASTREAM
|
---|
127 | QVariant( QDataStream& s );
|
---|
128 | #endif
|
---|
129 | QVariant( const QString& );
|
---|
130 | QVariant( const QCString& );
|
---|
131 | QVariant( const char* );
|
---|
132 | #ifndef QT_NO_STRINGLIST
|
---|
133 | QVariant( const QStringList& );
|
---|
134 | #endif
|
---|
135 | QVariant( const QFont& );
|
---|
136 | QVariant( const QPixmap& );
|
---|
137 | QVariant( const QImage& );
|
---|
138 | QVariant( const QBrush& );
|
---|
139 | QVariant( const QPoint& );
|
---|
140 | QVariant( const QRect& );
|
---|
141 | QVariant( const QSize& );
|
---|
142 | QVariant( const QColor& );
|
---|
143 | QVariant( const QPalette& );
|
---|
144 | QVariant( const QColorGroup& );
|
---|
145 | QVariant( const QIconSet& );
|
---|
146 | QVariant( const QPointArray& );
|
---|
147 | QVariant( const QRegion& );
|
---|
148 | QVariant( const QBitmap& );
|
---|
149 | QVariant( const QCursor& );
|
---|
150 | QVariant( const QDate& );
|
---|
151 | QVariant( const QTime& );
|
---|
152 | QVariant( const QDateTime& );
|
---|
153 | QVariant( const QByteArray& );
|
---|
154 | QVariant( const QBitArray& );
|
---|
155 | #ifndef QT_NO_ACCEL
|
---|
156 | QVariant( const QKeySequence& );
|
---|
157 | #endif
|
---|
158 | QVariant( const QPen& );
|
---|
159 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
160 | QVariant( const QValueList<QVariant>& );
|
---|
161 | QVariant( const QMap<QString,QVariant>& );
|
---|
162 | #endif
|
---|
163 | QVariant( int );
|
---|
164 | QVariant( uint );
|
---|
165 | QVariant( Q_LLONG );
|
---|
166 | QVariant( Q_ULLONG );
|
---|
167 | // ### Problems on some compilers ?
|
---|
168 | QVariant( bool, int );
|
---|
169 | QVariant( double );
|
---|
170 | QVariant( QSizePolicy );
|
---|
171 |
|
---|
172 | QVariant& operator= ( const QVariant& );
|
---|
173 | bool operator==( const QVariant& ) const;
|
---|
174 | bool operator!=( const QVariant& ) const;
|
---|
175 |
|
---|
176 | Type type() const;
|
---|
177 | const char* typeName() const;
|
---|
178 |
|
---|
179 | bool canCast( Type ) const;
|
---|
180 | bool cast( Type );
|
---|
181 |
|
---|
182 | bool isValid() const;
|
---|
183 | bool isNull() const;
|
---|
184 |
|
---|
185 | void clear();
|
---|
186 |
|
---|
187 | const QString toString() const;
|
---|
188 | const QCString toCString() const;
|
---|
189 | #ifndef QT_NO_STRINGLIST
|
---|
190 | const QStringList toStringList() const;
|
---|
191 | #endif
|
---|
192 | const QFont toFont() const;
|
---|
193 | const QPixmap toPixmap() const;
|
---|
194 | const QImage toImage() const;
|
---|
195 | const QBrush toBrush() const;
|
---|
196 | const QPoint toPoint() const;
|
---|
197 | const QRect toRect() const;
|
---|
198 | const QSize toSize() const;
|
---|
199 | const QColor toColor() const;
|
---|
200 | const QPalette toPalette() const;
|
---|
201 | const QColorGroup toColorGroup() const;
|
---|
202 | const QIconSet toIconSet() const;
|
---|
203 | const QPointArray toPointArray() const;
|
---|
204 | const QBitmap toBitmap() const;
|
---|
205 | const QRegion toRegion() const;
|
---|
206 | const QCursor toCursor() const;
|
---|
207 | const QDate toDate() const;
|
---|
208 | const QTime toTime() const;
|
---|
209 | const QDateTime toDateTime() const;
|
---|
210 | const QByteArray toByteArray() const;
|
---|
211 | const QBitArray toBitArray() const;
|
---|
212 | #ifndef QT_NO_ACCEL
|
---|
213 | const QKeySequence toKeySequence() const;
|
---|
214 | #endif
|
---|
215 | const QPen toPen() const;
|
---|
216 | int toInt( bool * ok=0 ) const;
|
---|
217 | uint toUInt( bool * ok=0 ) const;
|
---|
218 | Q_LLONG toLongLong( bool * ok=0 ) const;
|
---|
219 | Q_ULLONG toULongLong( bool * ok=0 ) const;
|
---|
220 | bool toBool() const;
|
---|
221 | double toDouble( bool * ok=0 ) const;
|
---|
222 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
223 | const QValueList<QVariant> toList() const;
|
---|
224 | const QMap<QString,QVariant> toMap() const;
|
---|
225 | #endif
|
---|
226 | QSizePolicy toSizePolicy() const;
|
---|
227 |
|
---|
228 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
229 | QValueListConstIterator<QString> stringListBegin() const;
|
---|
230 | QValueListConstIterator<QString> stringListEnd() const;
|
---|
231 | QValueListConstIterator<QVariant> listBegin() const;
|
---|
232 | QValueListConstIterator<QVariant> listEnd() const;
|
---|
233 | QMapConstIterator<QString,QVariant> mapBegin() const;
|
---|
234 | QMapConstIterator<QString,QVariant> mapEnd() const;
|
---|
235 | QMapConstIterator<QString,QVariant> mapFind( const QString& ) const;
|
---|
236 | #endif
|
---|
237 | QString& asString();
|
---|
238 | QCString& asCString();
|
---|
239 | #ifndef QT_NO_STRINGLIST
|
---|
240 | QStringList& asStringList();
|
---|
241 | #endif
|
---|
242 | QFont& asFont();
|
---|
243 | QPixmap& asPixmap();
|
---|
244 | QImage& asImage();
|
---|
245 | QBrush& asBrush();
|
---|
246 | QPoint& asPoint();
|
---|
247 | QRect& asRect();
|
---|
248 | QSize& asSize();
|
---|
249 | QColor& asColor();
|
---|
250 | QPalette& asPalette();
|
---|
251 | QColorGroup& asColorGroup();
|
---|
252 | QIconSet& asIconSet();
|
---|
253 | QPointArray& asPointArray();
|
---|
254 | QBitmap& asBitmap();
|
---|
255 | QRegion& asRegion();
|
---|
256 | QCursor& asCursor();
|
---|
257 | QDate& asDate();
|
---|
258 | QTime& asTime();
|
---|
259 | QDateTime& asDateTime();
|
---|
260 | QByteArray& asByteArray();
|
---|
261 | QBitArray& asBitArray();
|
---|
262 | #ifndef QT_NO_ACCEL
|
---|
263 | QKeySequence& asKeySequence();
|
---|
264 | #endif
|
---|
265 | QPen& asPen();
|
---|
266 | int& asInt();
|
---|
267 | uint& asUInt();
|
---|
268 | Q_LLONG& asLongLong();
|
---|
269 | Q_ULLONG& asULongLong();
|
---|
270 | bool& asBool();
|
---|
271 | double& asDouble();
|
---|
272 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
273 | QValueList<QVariant>& asList();
|
---|
274 | QMap<QString,QVariant>& asMap();
|
---|
275 | #endif
|
---|
276 | QSizePolicy& asSizePolicy();
|
---|
277 |
|
---|
278 | #ifndef QT_NO_DATASTREAM
|
---|
279 | void load( QDataStream& );
|
---|
280 | void save( QDataStream& ) const;
|
---|
281 | #endif
|
---|
282 | static const char* typeToName( Type typ );
|
---|
283 | static Type nameToType( const char* name );
|
---|
284 |
|
---|
285 | private:
|
---|
286 | void detach();
|
---|
287 |
|
---|
288 | class Private : public QShared
|
---|
289 | {
|
---|
290 | public:
|
---|
291 | Private();
|
---|
292 | Private( Private* );
|
---|
293 | ~Private();
|
---|
294 |
|
---|
295 | void clear();
|
---|
296 |
|
---|
297 | Type typ;
|
---|
298 | union
|
---|
299 | {
|
---|
300 | uint u;
|
---|
301 | int i;
|
---|
302 | Q_LLONG ll;
|
---|
303 | Q_ULLONG ull;
|
---|
304 | bool b;
|
---|
305 | double d;
|
---|
306 | void *ptr;
|
---|
307 | } value;
|
---|
308 | uint is_null : 1; // ## 4.0 merge with typ
|
---|
309 | };
|
---|
310 |
|
---|
311 | Private* d;
|
---|
312 |
|
---|
313 | public:
|
---|
314 | void* rawAccess( void* ptr = 0, Type typ = Invalid, bool deepCopy = FALSE );
|
---|
315 | };
|
---|
316 |
|
---|
317 | // down here for GCC 2.7.* compatibility
|
---|
318 | #ifndef QT_H
|
---|
319 | #include "qvaluelist.h"
|
---|
320 | #include "qstringlist.h"
|
---|
321 | #include "qmap.h"
|
---|
322 | #endif // QT_H
|
---|
323 |
|
---|
324 | inline QVariant::Type QVariant::type() const
|
---|
325 | {
|
---|
326 | return d->typ;
|
---|
327 | }
|
---|
328 |
|
---|
329 | inline bool QVariant::isValid() const
|
---|
330 | {
|
---|
331 | return (d->typ != Invalid);
|
---|
332 | }
|
---|
333 |
|
---|
334 | #ifndef QT_NO_TEMPLATE_VARIANT
|
---|
335 | inline QValueListConstIterator<QString> QVariant::stringListBegin() const
|
---|
336 | {
|
---|
337 | if ( d->typ != StringList )
|
---|
338 | return QValueListConstIterator<QString>();
|
---|
339 | return ((const QStringList*)d->value.ptr)->begin();
|
---|
340 | }
|
---|
341 |
|
---|
342 | inline QValueListConstIterator<QString> QVariant::stringListEnd() const
|
---|
343 | {
|
---|
344 | if ( d->typ != StringList )
|
---|
345 | return QValueListConstIterator<QString>();
|
---|
346 | return ((const QStringList*)d->value.ptr)->end();
|
---|
347 | }
|
---|
348 |
|
---|
349 | inline QValueListConstIterator<QVariant> QVariant::listBegin() const
|
---|
350 | {
|
---|
351 | if ( d->typ != List )
|
---|
352 | return QValueListConstIterator<QVariant>();
|
---|
353 | return ((const QValueList<QVariant>*)d->value.ptr)->begin();
|
---|
354 | }
|
---|
355 |
|
---|
356 | inline QValueListConstIterator<QVariant> QVariant::listEnd() const
|
---|
357 | {
|
---|
358 | if ( d->typ != List )
|
---|
359 | return QValueListConstIterator<QVariant>();
|
---|
360 | return ((const QValueList<QVariant>*)d->value.ptr)->end();
|
---|
361 | }
|
---|
362 |
|
---|
363 | inline QMapConstIterator<QString,QVariant> QVariant::mapBegin() const
|
---|
364 | {
|
---|
365 | if ( d->typ != Map )
|
---|
366 | return QMapConstIterator<QString,QVariant>();
|
---|
367 | return ((const QMap<QString,QVariant>*)d->value.ptr)->begin();
|
---|
368 | }
|
---|
369 |
|
---|
370 | inline QMapConstIterator<QString,QVariant> QVariant::mapEnd() const
|
---|
371 | {
|
---|
372 | if ( d->typ != Map )
|
---|
373 | return QMapConstIterator<QString,QVariant>();
|
---|
374 | return ((const QMap<QString,QVariant>*)d->value.ptr)->end();
|
---|
375 | }
|
---|
376 |
|
---|
377 | inline QMapConstIterator<QString,QVariant> QVariant::mapFind( const QString& key ) const
|
---|
378 | {
|
---|
379 | if ( d->typ != Map )
|
---|
380 | return QMapConstIterator<QString,QVariant>();
|
---|
381 | return ((const QMap<QString,QVariant>*)d->value.ptr)->find( key );
|
---|
382 | }
|
---|
383 | #endif
|
---|
384 |
|
---|
385 | #ifndef QT_NO_DATASTREAM
|
---|
386 | Q_EXPORT QDataStream& operator>> ( QDataStream& s, QVariant& p );
|
---|
387 | Q_EXPORT QDataStream& operator<< ( QDataStream& s, const QVariant& p );
|
---|
388 | Q_EXPORT QDataStream& operator>> ( QDataStream& s, QVariant::Type& p );
|
---|
389 | Q_EXPORT QDataStream& operator<< ( QDataStream& s, const QVariant::Type p );
|
---|
390 | #endif
|
---|
391 |
|
---|
392 | #endif //QT_NO_VARIANT
|
---|
393 | #endif // QVARIANT_H
|
---|