Eneboo - Documentación para desarrolladores
src/qt/src/kernel/qvariant.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qvariant.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QVariant class
00005 **
00006 ** Created : 990414
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QVARIANT_H
00039 #define QVARIANT_H
00040 
00041 #ifndef QT_H
00042 #include "qstring.h"
00043 #endif // QT_H
00044 
00045 #ifndef QT_NO_VARIANT
00046 class QString;
00047 class QCString;
00048 class QFont;
00049 class QPixmap;
00050 class QBrush;
00051 class QRect;
00052 class QPoint;
00053 class QImage;
00054 class QSize;
00055 class QColor;
00056 class QPalette;
00057 class QColorGroup;
00058 class QIconSet;
00059 class QDataStream;
00060 class QPointArray;
00061 class QRegion;
00062 class QBitmap;
00063 class QCursor;
00064 class QStringList;
00065 class QSizePolicy;
00066 class QDate;
00067 class QTime;
00068 class QDateTime;
00069 class QBitArray;
00070 class QKeySequence;
00071 class QPen;
00072 // Some headers rejected after QVariant declaration for GCC 2.7.* compatibility
00073 class QVariant;
00074 #ifndef QT_NO_TEMPLATE_VARIANT
00075 template <class T> class QValueList;
00076 template <class T> class QValueListConstIterator;
00077 template <class T> class QValueListNode;
00078 template <class Key, class T> class QMap;
00079 template <class Key, class T> class QMapConstIterator;
00080 #endif
00081 
00082 class Q_EXPORT QVariant
00083 {
00084 public:
00085     enum Type {
00086         Invalid,
00087         Map,
00088         List,
00089         String,
00090         StringList,
00091         Font,
00092         Pixmap,
00093         Brush,
00094         Rect,
00095         Size,
00096         Color,
00097         Palette,
00098         ColorGroup,
00099         IconSet,
00100         Point,
00101         Image,
00102         Int,
00103         UInt,
00104         Bool,
00105         Double,
00106         CString,
00107         PointArray,
00108         Region,
00109         Bitmap,
00110         Cursor,
00111         SizePolicy,
00112         Date,
00113         Time,
00114         DateTime,
00115         ByteArray,
00116         BitArray,
00117         KeySequence,
00118         Pen,
00119         LongLong,
00120         ULongLong
00121     };
00122 
00123     QVariant();
00124     ~QVariant();
00125     QVariant( const QVariant& );
00126 #ifndef QT_NO_DATASTREAM
00127     QVariant( QDataStream& s );
00128 #endif
00129     QVariant( const QString& );
00130     QVariant( const QCString& );
00131     QVariant( const char* );
00132 #ifndef QT_NO_STRINGLIST
00133     QVariant( const QStringList& );
00134 #endif
00135     QVariant( const QFont& );
00136     QVariant( const QPixmap& );
00137     QVariant( const QImage& );
00138     QVariant( const QBrush& );
00139     QVariant( const QPoint& );
00140     QVariant( const QRect& );
00141     QVariant( const QSize& );
00142     QVariant( const QColor& );
00143     QVariant( const QPalette& );
00144     QVariant( const QColorGroup& );
00145     QVariant( const QIconSet& );
00146     QVariant( const QPointArray& );
00147     QVariant( const QRegion& );
00148     QVariant( const QBitmap& );
00149     QVariant( const QCursor& );
00150     QVariant( const QDate& );
00151     QVariant( const QTime& );
00152     QVariant( const QDateTime& );
00153     QVariant( const QByteArray& );
00154     QVariant( const QBitArray& );
00155 #ifndef QT_NO_ACCEL
00156     QVariant( const QKeySequence& );
00157 #endif
00158     QVariant( const QPen& );
00159 #ifndef QT_NO_TEMPLATE_VARIANT
00160     QVariant( const QValueList<QVariant>& );
00161     QVariant( const QMap<QString,QVariant>& );
00162 #endif
00163     QVariant( int );
00164     QVariant( uint );
00165     QVariant( Q_LLONG );
00166     QVariant( Q_ULLONG );
00167     // ### Problems on some compilers ?
00168     QVariant( bool, int );
00169     QVariant( double );
00170     QVariant( QSizePolicy );
00171 
00172     QVariant& operator= ( const QVariant& );
00173     bool operator==( const QVariant& ) const;
00174     bool operator!=( const QVariant& ) const;
00175 
00176     Type type() const;
00177     const char* typeName() const;
00178 
00179     bool canCast( Type ) const;
00180     bool cast( Type );
00181 
00182     bool isValid() const;
00183     bool isNull() const;
00184 
00185     void clear();
00186 
00187     const QString toString() const;
00188     const QCString toCString() const;
00189 #ifndef QT_NO_STRINGLIST
00190     const QStringList toStringList() const;
00191 #endif
00192     const QFont toFont() const;
00193     const QPixmap toPixmap() const;
00194     const QImage toImage() const;
00195     const QBrush toBrush() const;
00196     const QPoint toPoint() const;
00197     const QRect toRect() const;
00198     const QSize toSize() const;
00199     const QColor toColor() const;
00200     const QPalette toPalette() const;
00201     const QColorGroup toColorGroup() const;
00202     const QIconSet toIconSet() const;
00203     const QPointArray toPointArray() const;
00204     const QBitmap toBitmap() const;
00205     const QRegion toRegion() const;
00206     const QCursor toCursor() const;
00207     const QDate toDate() const;
00208     const QTime toTime() const;
00209     const QDateTime toDateTime() const;
00210     const QByteArray toByteArray() const;
00211     const QBitArray toBitArray() const;
00212 #ifndef QT_NO_ACCEL
00213     const QKeySequence toKeySequence() const;
00214 #endif
00215     const QPen toPen() const;
00216     int toInt( bool * ok=0 ) const;
00217     uint toUInt( bool * ok=0 ) const;
00218     Q_LLONG toLongLong( bool * ok=0 ) const;
00219     Q_ULLONG toULongLong( bool * ok=0 ) const;
00220     bool toBool() const;
00221     double toDouble( bool * ok=0 ) const;
00222 #ifndef QT_NO_TEMPLATE_VARIANT
00223     const QValueList<QVariant> toList() const;
00224     const QMap<QString,QVariant> toMap() const;
00225 #endif
00226     QSizePolicy toSizePolicy() const;
00227 
00228 #ifndef QT_NO_TEMPLATE_VARIANT
00229     QValueListConstIterator<QString> stringListBegin() const;
00230     QValueListConstIterator<QString> stringListEnd() const;
00231     QValueListConstIterator<QVariant> listBegin() const;
00232     QValueListConstIterator<QVariant> listEnd() const;
00233     QMapConstIterator<QString,QVariant> mapBegin() const;
00234     QMapConstIterator<QString,QVariant> mapEnd() const;
00235     QMapConstIterator<QString,QVariant> mapFind( const QString& ) const;
00236 #endif
00237     QString& asString();
00238     QCString& asCString();
00239 #ifndef QT_NO_STRINGLIST
00240     QStringList& asStringList();
00241 #endif
00242     QFont& asFont();
00243     QPixmap& asPixmap();
00244     QImage& asImage();
00245     QBrush& asBrush();
00246     QPoint& asPoint();
00247     QRect& asRect();
00248     QSize& asSize();
00249     QColor& asColor();
00250     QPalette& asPalette();
00251     QColorGroup& asColorGroup();
00252     QIconSet& asIconSet();
00253     QPointArray& asPointArray();
00254     QBitmap& asBitmap();
00255     QRegion& asRegion();
00256     QCursor& asCursor();
00257     QDate& asDate();
00258     QTime& asTime();
00259     QDateTime& asDateTime();
00260     QByteArray& asByteArray();
00261     QBitArray& asBitArray();
00262 #ifndef QT_NO_ACCEL
00263     QKeySequence& asKeySequence();
00264 #endif
00265     QPen& asPen();
00266     int& asInt();
00267     uint& asUInt();
00268     Q_LLONG& asLongLong();
00269     Q_ULLONG& asULongLong();
00270     bool& asBool();
00271     double& asDouble();
00272 #ifndef QT_NO_TEMPLATE_VARIANT
00273     QValueList<QVariant>& asList();
00274     QMap<QString,QVariant>& asMap();
00275 #endif
00276     QSizePolicy& asSizePolicy();
00277 
00278 #ifndef QT_NO_DATASTREAM
00279     void load( QDataStream& );
00280     void save( QDataStream& ) const;
00281 #endif
00282     static const char* typeToName( Type typ );
00283     static Type nameToType( const char* name );
00284 
00285 private:
00286     void detach();
00287 
00288     class Private : public QShared
00289     {
00290     public:
00291         Private();
00292         Private( Private* );
00293         ~Private();
00294 
00295         void clear();
00296 
00297         Type typ;
00298         union
00299         {
00300             uint u;
00301             int i;
00302             Q_LLONG ll;
00303             Q_ULLONG ull;
00304             bool b;
00305             double d;
00306             void *ptr;
00307         } value;
00308         uint is_null : 1; // ## 4.0 merge with typ
00309     };
00310 
00311     Private* d;
00312 
00313 public:
00314     void* rawAccess( void* ptr = 0, Type typ = Invalid, bool deepCopy = FALSE );
00315 };
00316 
00317 // down here for GCC 2.7.* compatibility
00318 #ifndef QT_H
00319 #include "qvaluelist.h"
00320 #include "qstringlist.h"
00321 #include "qmap.h"
00322 #endif // QT_H
00323 
00324 inline QVariant::Type QVariant::type() const
00325 {
00326     return d->typ;
00327 }
00328 
00329 inline bool QVariant::isValid() const
00330 {
00331     return (d->typ != Invalid);
00332 }
00333 
00334 #ifndef QT_NO_TEMPLATE_VARIANT
00335 inline QValueListConstIterator<QString> QVariant::stringListBegin() const
00336 {
00337     if ( d->typ != StringList )
00338         return QValueListConstIterator<QString>();
00339     return ((const QStringList*)d->value.ptr)->begin();
00340 }
00341 
00342 inline QValueListConstIterator<QString> QVariant::stringListEnd() const
00343 {
00344     if ( d->typ != StringList )
00345         return QValueListConstIterator<QString>();
00346     return ((const QStringList*)d->value.ptr)->end();
00347 }
00348 
00349 inline QValueListConstIterator<QVariant> QVariant::listBegin() const
00350 {
00351     if ( d->typ != List )
00352         return QValueListConstIterator<QVariant>();
00353     return ((const QValueList<QVariant>*)d->value.ptr)->begin();
00354 }
00355 
00356 inline QValueListConstIterator<QVariant> QVariant::listEnd() const
00357 {
00358     if ( d->typ != List )
00359         return QValueListConstIterator<QVariant>();
00360     return ((const QValueList<QVariant>*)d->value.ptr)->end();
00361 }
00362 
00363 inline QMapConstIterator<QString,QVariant> QVariant::mapBegin() const
00364 {
00365     if ( d->typ != Map )
00366         return QMapConstIterator<QString,QVariant>();
00367     return ((const QMap<QString,QVariant>*)d->value.ptr)->begin();
00368 }
00369 
00370 inline QMapConstIterator<QString,QVariant> QVariant::mapEnd() const
00371 {
00372     if ( d->typ != Map )
00373         return QMapConstIterator<QString,QVariant>();
00374     return ((const QMap<QString,QVariant>*)d->value.ptr)->end();
00375 }
00376 
00377 inline QMapConstIterator<QString,QVariant> QVariant::mapFind( const QString& key ) const
00378 {
00379     if ( d->typ != Map )
00380         return QMapConstIterator<QString,QVariant>();
00381     return ((const QMap<QString,QVariant>*)d->value.ptr)->find( key );
00382 }
00383 #endif
00384 
00385 #ifndef QT_NO_DATASTREAM
00386 Q_EXPORT QDataStream& operator>> ( QDataStream& s, QVariant& p );
00387 Q_EXPORT QDataStream& operator<< ( QDataStream& s, const QVariant& p );
00388 Q_EXPORT QDataStream& operator>> ( QDataStream& s, QVariant::Type& p );
00389 Q_EXPORT QDataStream& operator<< ( QDataStream& s, const QVariant::Type p );
00390 #endif
00391 
00392 #endif //QT_NO_VARIANT
00393 #endif // QVARIANT_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'