src/corelib/kernel/qvariant.cpp
changeset 30 5dc02b23752f
parent 19 fcece45ef507
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    44 #include "qbytearray.h"
    44 #include "qbytearray.h"
    45 #include "qdatastream.h"
    45 #include "qdatastream.h"
    46 #include "qdebug.h"
    46 #include "qdebug.h"
    47 #include "qmap.h"
    47 #include "qmap.h"
    48 #include "qdatetime.h"
    48 #include "qdatetime.h"
       
    49 #include "qeasingcurve.h"
    49 #include "qlist.h"
    50 #include "qlist.h"
    50 #include "qstring.h"
    51 #include "qstring.h"
    51 #include "qstringlist.h"
    52 #include "qstringlist.h"
    52 #include "qurl.h"
    53 #include "qurl.h"
    53 #include "qlocale.h"
    54 #include "qlocale.h"
   142         v_construct<QLocale>(x, copy);
   143         v_construct<QLocale>(x, copy);
   143         break;
   144         break;
   144 #ifndef QT_NO_REGEXP
   145 #ifndef QT_NO_REGEXP
   145     case QVariant::RegExp:
   146     case QVariant::RegExp:
   146         v_construct<QRegExp>(x, copy);
   147         v_construct<QRegExp>(x, copy);
       
   148         break;
       
   149 #endif
       
   150 #ifndef QT_BOOTSTRAPPED
       
   151     case QVariant::EasingCurve:
       
   152         v_construct<QEasingCurve>(x, copy);
   147         break;
   153         break;
   148 #endif
   154 #endif
   149     case QVariant::Int:
   155     case QVariant::Int:
   150         x->data.i = copy ? *static_cast<const int *>(copy) : 0;
   156         x->data.i = copy ? *static_cast<const int *>(copy) : 0;
   151         break;
   157         break;
   255         v_clear<QLocale>(d);
   261         v_clear<QLocale>(d);
   256         break;
   262         break;
   257 #ifndef QT_NO_REGEXP
   263 #ifndef QT_NO_REGEXP
   258     case QVariant::RegExp:
   264     case QVariant::RegExp:
   259         v_clear<QRegExp>(d);
   265         v_clear<QRegExp>(d);
       
   266         break;
       
   267 #endif
       
   268 #ifndef QT_BOOTSTRAPPED
       
   269     case QVariant::EasingCurve:
       
   270         v_clear<QEasingCurve>(d);
   260         break;
   271         break;
   261 #endif
   272 #endif
   262     case QVariant::LongLong:
   273     case QVariant::LongLong:
   263     case QVariant::ULongLong:
   274     case QVariant::ULongLong:
   264     case QVariant::Double:
   275     case QVariant::Double:
   315     case QVariant::Point:
   326     case QVariant::Point:
   316         return v_cast<QPoint>(d)->isNull();
   327         return v_cast<QPoint>(d)->isNull();
   317     case QVariant::PointF:
   328     case QVariant::PointF:
   318         return v_cast<QPointF>(d)->isNull();
   329         return v_cast<QPointF>(d)->isNull();
   319 #endif
   330 #endif
       
   331 #ifndef QT_BOOTSTRAPPED
       
   332     case QVariant::EasingCurve:
       
   333 #endif
   320     case QVariant::Url:
   334     case QVariant::Url:
   321     case QVariant::Locale:
   335     case QVariant::Locale:
   322     case QVariant::RegExp:
   336     case QVariant::RegExp:
   323     case QVariant::StringList:
   337     case QVariant::StringList:
   324     case QVariant::Map:
   338     case QVariant::Map:
   433         return *v_cast<QDate>(a) == *v_cast<QDate>(b);
   447         return *v_cast<QDate>(a) == *v_cast<QDate>(b);
   434     case QVariant::Time:
   448     case QVariant::Time:
   435         return *v_cast<QTime>(a) == *v_cast<QTime>(b);
   449         return *v_cast<QTime>(a) == *v_cast<QTime>(b);
   436     case QVariant::DateTime:
   450     case QVariant::DateTime:
   437         return *v_cast<QDateTime>(a) == *v_cast<QDateTime>(b);
   451         return *v_cast<QDateTime>(a) == *v_cast<QDateTime>(b);
       
   452 #ifndef QT_BOOTSTRAPPED
       
   453     case QVariant::EasingCurve:
       
   454         return *v_cast<QEasingCurve>(a) == *v_cast<QEasingCurve>(b);
       
   455 #endif
   438     case QVariant::ByteArray:
   456     case QVariant::ByteArray:
   439         return *v_cast<QByteArray>(a) == *v_cast<QByteArray>(b);
   457         return *v_cast<QByteArray>(a) == *v_cast<QByteArray>(b);
   440     case QVariant::BitArray:
   458     case QVariant::BitArray:
   441         return *v_cast<QBitArray>(a) == *v_cast<QBitArray>(b);
   459         return *v_cast<QBitArray>(a) == *v_cast<QBitArray>(b);
   442     case QVariant::Invalid:
   460     case QVariant::Invalid:
  1099         dbg.nospace() << v.toTime();
  1117         dbg.nospace() << v.toTime();
  1100         break;
  1118         break;
  1101     case QVariant::DateTime:
  1119     case QVariant::DateTime:
  1102         dbg.nospace() << v.toDateTime();
  1120         dbg.nospace() << v.toDateTime();
  1103         break;
  1121         break;
       
  1122 #ifndef QT_BOOTSTRAPPED
       
  1123     case QVariant::EasingCurve:
       
  1124         dbg.nospace() << v.toEasingCurve();
       
  1125         break;
       
  1126 #endif
  1104     case QVariant::ByteArray:
  1127     case QVariant::ByteArray:
  1105         dbg.nospace() << v.toByteArray();
  1128         dbg.nospace() << v.toByteArray();
  1106         break;
  1129         break;
  1107     case QVariant::Url:
  1130     case QVariant::Url:
  1108         dbg.nospace() << v.toUrl();
  1131         dbg.nospace() << v.toUrl();
  1267     \value Color  a QColor
  1290     \value Color  a QColor
  1268     \value Cursor  a QCursor
  1291     \value Cursor  a QCursor
  1269     \value Date  a QDate
  1292     \value Date  a QDate
  1270     \value DateTime  a QDateTime
  1293     \value DateTime  a QDateTime
  1271     \value Double  a double
  1294     \value Double  a double
       
  1295     \value EasingCurve a QEasingCurve
  1272     \value Font  a QFont
  1296     \value Font  a QFont
  1273     \value Hash a QVariantHash
  1297     \value Hash a QVariantHash
  1274     \value Icon  a QIcon
  1298     \value Icon  a QIcon
  1275     \value Image  a QImage
  1299     \value Image  a QImage
  1276     \value Int  an int
  1300     \value Int  an int
  1485 
  1509 
  1486     Constructs a new variant with a date/time value, \a val.
  1510     Constructs a new variant with a date/time value, \a val.
  1487 */
  1511 */
  1488 
  1512 
  1489 /*!
  1513 /*!
       
  1514     \since 4.7
       
  1515   \fn QVariant::QVariant(const QEasingCurve &val)
       
  1516 
       
  1517     Constructs a new variant with an easing curve value, \a val.
       
  1518 */
       
  1519 
       
  1520 /*!
  1490   \fn QVariant::QVariant(const QByteArray &val)
  1521   \fn QVariant::QVariant(const QByteArray &val)
  1491 
  1522 
  1492     Constructs a new variant with a bytearray value, \a val.
  1523     Constructs a new variant with a bytearray value, \a val.
  1493 */
  1524 */
  1494 
  1525 
  1683 { d.is_null = false; d.type = Date; v_construct<QDate>(&d, val); }
  1714 { d.is_null = false; d.type = Date; v_construct<QDate>(&d, val); }
  1684 QVariant::QVariant(const QTime &val)
  1715 QVariant::QVariant(const QTime &val)
  1685 { d.is_null = false; d.type = Time; v_construct<QTime>(&d, val); }
  1716 { d.is_null = false; d.type = Time; v_construct<QTime>(&d, val); }
  1686 QVariant::QVariant(const QDateTime &val)
  1717 QVariant::QVariant(const QDateTime &val)
  1687 { d.is_null = false; d.type = DateTime; v_construct<QDateTime>(&d, val); }
  1718 { d.is_null = false; d.type = DateTime; v_construct<QDateTime>(&d, val); }
       
  1719 #ifndef QT_BOOTSTRAPPED
       
  1720 QVariant::QVariant(const QEasingCurve &val)
       
  1721 { d.is_null = false; d.type = EasingCurve; v_construct<QEasingCurve>(&d, val); }
       
  1722 #endif
  1688 QVariant::QVariant(const QList<QVariant> &list)
  1723 QVariant::QVariant(const QList<QVariant> &list)
  1689 { d.is_null = false; d.type = List; v_construct<QVariantList>(&d, list); }
  1724 { d.is_null = false; d.type = List; v_construct<QVariantList>(&d, list); }
  1690 QVariant::QVariant(const QMap<QString, QVariant> &map)
  1725 QVariant::QVariant(const QMap<QString, QVariant> &map)
  1691 { d.is_null = false; d.type = Map; v_construct<QVariantMap>(&d, map); }
  1726 { d.is_null = false; d.type = Map; v_construct<QVariantMap>(&d, map); }
  1692 QVariant::QVariant(const QHash<QString, QVariant> &hash)
  1727 QVariant::QVariant(const QHash<QString, QVariant> &hash)
  1872     int metaType = QMetaType::type(name);
  1907     int metaType = QMetaType::type(name);
  1873     return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;
  1908     return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;
  1874 }
  1909 }
  1875 
  1910 
  1876 #ifndef QT_NO_DATASTREAM
  1911 #ifndef QT_NO_DATASTREAM
  1877 enum { MapFromThreeCount = 35 };
  1912 enum { MapFromThreeCount = 36 };
  1878 static const ushort map_from_three[MapFromThreeCount] =
  1913 static const ushort map_from_three[MapFromThreeCount] =
  1879 {
  1914 {
  1880     QVariant::Invalid,
  1915     QVariant::Invalid,
  1881     QVariant::Map,
  1916     QVariant::Map,
  1882     QVariant::List,
  1917     QVariant::List,
  1909     QVariant::ByteArray,
  1944     QVariant::ByteArray,
  1910     QVariant::BitArray,
  1945     QVariant::BitArray,
  1911     QVariant::KeySequence,
  1946     QVariant::KeySequence,
  1912     QVariant::Pen,
  1947     QVariant::Pen,
  1913     QVariant::LongLong,
  1948     QVariant::LongLong,
  1914     QVariant::ULongLong
  1949     QVariant::ULongLong,
       
  1950     QVariant::EasingCurve
  1915 };
  1951 };
  1916 
  1952 
  1917 /*!
  1953 /*!
  1918     Internal function for loading a variant from stream \a s. Use the
  1954     Internal function for loading a variant from stream \a s. Use the
  1919     stream operators instead.
  1955     stream operators instead.
  2167 {
  2203 {
  2168     return qVariantToHelper<QDateTime>(d, DateTime, handler);
  2204     return qVariantToHelper<QDateTime>(d, DateTime, handler);
  2169 }
  2205 }
  2170 
  2206 
  2171 /*!
  2207 /*!
       
  2208     \since 4.7
       
  2209     \fn QEasingCurve QVariant::toEasingCurve() const
       
  2210 
       
  2211     Returns the variant as a QEasingCurve if the variant has type() \l
       
  2212     EasingCurve; otherwise returns a default easing curve.
       
  2213 
       
  2214     \sa canConvert(), convert()
       
  2215 */
       
  2216 #ifndef QT_BOOTSTRAPPED
       
  2217 QEasingCurve QVariant::toEasingCurve() const
       
  2218 {
       
  2219     return qVariantToHelper<QEasingCurve>(d, EasingCurve, handler);
       
  2220 }
       
  2221 #endif
       
  2222 
       
  2223 /*!
  2172     \fn QByteArray QVariant::toByteArray() const
  2224     \fn QByteArray QVariant::toByteArray() const
  2173 
  2225 
  2174     Returns the variant as a QByteArray if the variant has type() \l
  2226     Returns the variant as a QByteArray if the variant has type() \l
  2175     ByteArray or \l String (converted using QString::fromAscii());
  2227     ByteArray or \l String (converted using QString::fromAscii());
  2176     otherwise returns an empty byte array.
  2228     otherwise returns an empty byte array.
  2607 
  2659 
  2608 /*QPointF*/       1 << QVariant::Point,
  2660 /*QPointF*/       1 << QVariant::Point,
  2609 
  2661 
  2610 /*QRegExp*/       0,
  2662 /*QRegExp*/       0,
  2611 
  2663 
  2612 /*QHash*/         0
  2664 /*QHash*/         0,
  2613 
  2665 
       
  2666 /*QEasingCurve*/  0
  2614 };
  2667 };
  2615 
  2668 
  2616 /*!
  2669 /*!
  2617     Returns true if the variant's type can be cast to the requested
  2670     Returns true if the variant's type can be cast to the requested
  2618     type, \a t. Such casting is done automatically when calling the
  2671     type, \a t. Such casting is done automatically when calling the