home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qvariant.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  10KB  |  370 lines

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