45 #include <QtCore/qatomic.h> 46 #include <QtCore/qbytearray.h> 47 #include <QtCore/qlist.h> 48 #include <QtCore/qmetatype.h> 49 #include <QtCore/qmap.h> 50 #include <QtCore/qhash.h> 51 #include <QtCore/qstring.h> 84 class QVariantComparisonHelper;
127 LastCoreType = EasingCurve,
156 LastGuiType = Quaternion,
162 PointArray = Polygon,
164 LastType = 0xffffffff
170 QVariant(
int typeOrUserType,
const void *copy);
171 QVariant(
int typeOrUserType,
const void *copy,
uint flags);
174 #ifndef QT_NO_DATASTREAM 185 #ifndef QT_NO_CAST_FROM_ASCII 191 QVariant(
const QString &
string);
194 QVariant(
const QChar &qchar);
195 QVariant(
const QDate &date);
196 QVariant(
const QTime &time);
201 #ifndef QT_NO_GEOM_VARIANT 202 QVariant(
const QSize &size);
203 QVariant(
const QSizeF &size);
204 QVariant(
const QPoint &pt);
206 QVariant(
const QLine &line);
207 QVariant(
const QLineF &line);
208 QVariant(
const QRect &rect);
209 QVariant(
const QRectF &rect);
211 QVariant(
const QUrl &url);
212 QVariant(
const QLocale &locale);
214 QVariant(
const QRegExp ®Exp);
216 #ifndef QT_BOOTSTRAPPED 221 QVariant& operator=(
const QVariant &other);
222 #ifdef Q_COMPILER_RVALUE_REFS 223 inline QVariant &operator=(QVariant &&other)
224 {
qSwap(
d, other.
d);
return *
this; }
230 int userType()
const;
233 bool canConvert(
Type t)
const;
237 inline QT3_SUPPORT
bool canCast(
Type t)
const 238 {
return canConvert(t); }
239 inline QT3_SUPPORT
bool cast(
Type t)
243 inline bool isValid()
const;
249 inline bool isDetached()
const;
251 int toInt(
bool *ok = 0)
const;
252 uint toUInt(
bool *ok = 0)
const;
253 qlonglong toLongLong(
bool *ok = 0)
const;
256 double toDouble(
bool *ok = 0)
const;
257 float toFloat(
bool *ok = 0)
const;
263 QChar toChar()
const;
271 #ifndef QT_NO_GEOM_VARIANT 274 QRect toRect()
const;
275 QSize toSize()
const;
277 QLine toLine()
const;
286 #ifndef QT_BOOTSTRAPPED 291 inline QT3_SUPPORT
int &asInt();
292 inline QT3_SUPPORT
uint &asUInt();
293 inline QT3_SUPPORT
qlonglong &asLongLong();
295 inline QT3_SUPPORT
bool &asBool();
296 inline QT3_SUPPORT
double &asDouble();
298 inline QT3_SUPPORT
QBitArray &asBitArray();
299 inline QT3_SUPPORT
QString &asString();
301 inline QT3_SUPPORT
QDate &asDate();
302 inline QT3_SUPPORT
QTime &asTime();
303 inline QT3_SUPPORT
QDateTime &asDateTime();
306 inline QT3_SUPPORT
QPoint &asPoint();
307 inline QT3_SUPPORT
QRect &asRect();
308 inline QT3_SUPPORT
QSize &asSize();
311 #ifndef QT_NO_DATASTREAM 315 static const char *typeToName(
Type type);
319 inline QT3_SUPPORT_CONSTRUCTOR QVariant(
bool val,
int) {
create(Bool, &val); }
320 inline QT3_SUPPORT
const QByteArray toCString()
const {
return toByteArray(); }
321 inline QT3_SUPPORT
QByteArray &asCString() {
return *
reinterpret_cast<QByteArray *
>(castOrDetach(ByteArray)); }
325 const void *constData()
const;
326 inline const void *
data()
const {
return constData(); }
329 inline void setValue(
const T &value);
341 {
return canConvert(
Type(qMetaTypeId<T>())); }
347 inline PrivateShared(
void *v) :
ptr(v), ref(1) { }
353 inline Private():
type(
Invalid), is_shared(
false), is_null(
true) { data.ptr = 0; }
354 inline Private(
const Private &other)
355 :
data(other.data),
type(other.type),
356 is_shared(other.is_shared), is_null(other.is_null)
371 PrivateShared *shared;
378 typedef void (*f_construct)(Private *,
const void *);
379 typedef void (*f_clear)(Private *);
380 typedef bool (*f_null)(
const Private *);
381 #ifndef QT_NO_DATASTREAM 383 typedef void (*f_save)(
const Private *,
QDataStream &);
385 typedef bool (*f_compare)(
const Private *,
const Private *);
386 typedef bool (*f_convert)(
const QVariant::Private *
d,
Type t,
void *,
bool *);
387 typedef bool (*f_canConvert)(
const QVariant::Private *
d,
Type t);
388 typedef void (*f_debugStream)(
QDebug,
const QVariant &);
393 #ifndef QT_NO_DATASTREAM 399 f_canConvert canConvert;
400 f_debugStream debugStream;
413 friend inline bool operator==(
const QVariant &,
const QVariantComparisonHelper &);
414 #ifndef QT_NO_DEBUG_STREAM 421 void create(
int type,
const void *copy);
423 void *castOrDetach(
Type t);
425 bool cmp(
const QVariant &other)
const;
430 #ifdef QT_NO_CAST_FROM_ASCII 432 inline QVariant(
const char *) {
Q_ASSERT(
false); }
450 template <
typename T>
459 template <
typename T>
463 const uint type = qMetaTypeId<T>(
reinterpret_cast<T *
>(0));
468 T *old =
reinterpret_cast<T*
>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
488 inline int &QVariant::asInt()
489 {
return *
reinterpret_cast<int *
>(castOrDetach(Int)); }
490 inline uint &QVariant::asUInt()
491 {
return *
reinterpret_cast<uint *
>(castOrDetach(UInt)); }
493 {
return *
reinterpret_cast<qlonglong *
>(castOrDetach(LongLong)); }
495 {
return *
reinterpret_cast<qulonglong *
>(castOrDetach(ULongLong)); }
496 inline bool &QVariant::asBool()
497 {
return *
reinterpret_cast<bool *
>(castOrDetach(Bool)); }
498 inline double &QVariant::asDouble()
499 {
return *
reinterpret_cast<double *
>(castOrDetach(
Double)); }
501 {
return *
reinterpret_cast<QByteArray *
>(castOrDetach(ByteArray)); }
503 {
return *
reinterpret_cast<QBitArray *
>(castOrDetach(BitArray)); }
504 inline QString& QVariant::asString()
505 {
return *
reinterpret_cast<QString *
>(castOrDetach(
String)); }
507 {
return *
reinterpret_cast<QStringList *
>(castOrDetach(StringList)); }
508 inline QDate& QVariant::asDate()
509 {
return *
reinterpret_cast<QDate *
>(castOrDetach(Date)); }
510 inline QTime& QVariant::asTime()
511 {
return *
reinterpret_cast<QTime *
>(castOrDetach(Time)); }
513 {
return *
reinterpret_cast<QDateTime *
>(castOrDetach(DateTime)); }
518 inline QPoint &QVariant::asPoint()
519 {
return *
reinterpret_cast<QPoint *
>(castOrDetach(Point)); }
520 inline QRect &QVariant::asRect()
521 {
return *
reinterpret_cast<QRect *
>(castOrDetach(Rect)); }
522 inline QSize &QVariant::asSize()
523 {
return *
reinterpret_cast<QSize *
>(castOrDetach(Size)); }
530 #ifndef QT_NO_DATASTREAM 538 {
return !
d.is_shared ||
d.data.shared->ref == 1; }
549 class QVariantComparisonHelper
552 inline QVariantComparisonHelper(
const QVariant &var)
561 return v1.
cmp(*v2.v);
573 const int vid = qMetaTypeId<T>(
static_cast<T *
>(0));
575 return *reinterpret_cast<const T *>(v.
constData());
587 return *reinterpret_cast<const QVariant *>(v.constData());
598 {
return variant.template canConvert<T>(); }
605 #ifndef QT_NO_DEBUG_STREAM The QVariant class acts like a union for the most common Qt data types.
The QDebug class provides an output stream for debugging information.
static uint hash(const uchar *p, int n)
int qUnregisterGuiVariant()
QHash< QString, QVariant > QVariantHash
#define QT_END_NAMESPACE
This macro expands to.
static ISC_DATE toDate(const QDate &t)
QVariant qVariantFromValue(const T &)
The QEasingCurve class provides easing curves for controlling animation.
The QLine class provides a two-dimensional vector using integer precision.
The QRegExp class provides pattern matching using regular expressions.
QVariant(float f)
Constructs a new variant with a floating point value, val.
The QMatrix class specifies 2D transformations of a coordinate system.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Q_CORE_EXPORT QDataStream & operator<<(QDataStream &s, const QVariant &p)
Writes a variant p to the stream s.
The QByteArray class provides an array of bytes.
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
The QPointF class defines a point in the plane using floating point precision.
void swap(QVariant &other)
Swaps variant other with this variant.
static void clear(QVariant::Private *d)
bool operator!=(const QVariant &v) const
Compares this QVariant with v and returns true if they are not equal; otherwise returns false...
The QDate class provides date functions.
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
QMap< QString, QVariant > QVariantMap
static QList< QVariant > toList(char **buf, int count, T *=0)
void setValue(const T &value)
Stores a copy of value.
The QObject class is the base class of all Qt objects.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
The QChar class provides a 16-bit Unicode character.
Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE)
bool canConvert() const
Returns true if the variant can be converted to the template type T, otherwise false.
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &s, QVariant &p)
Reads a variant p from the stream s.
The QLineF class provides a two-dimensional vector using floating point precision.
#define Q_DECLARE_SHARED(TYPE)
int qRegisterGuiVariant()
static bool toBool(Register *reg, int type, bool *ok=0)
static QString toString(Register *reg, int type, bool *ok=0)
The QTime class provides clock time functions.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
The QRectF class defines a rectangle in the plane using floating point precision. ...
void qVariantSetValue< QVariant >(QVariant &v, const QVariant &t)
static const Handler * handler
The QTextFormat class provides formatting information for a QTextDocument.
bool operator!=(const QVariant &v1, const QVariant &v2)
The QStringList class provides a list of strings.
static int toInt(const QByteArray &str)
QVariant()
Constructs an invalid variant.
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Type
This enum type defines the types of variable that a QVariant can contain.
void qVariantSetValue(QVariant &v, const T &t)
#define QT_ASCII_CAST_WARN_CONSTRUCTOR
const T * ptr(const T &t)
static int cmp(const ushort *s1, const ushort *s2, size_t len)
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
void qSwap(T &value1, T &value2)
The QBitArray class provides an array of bits.
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
bool qvariant_cast_helper(const QVariant &v, QVariant::Type tp, void *ptr)
static QVariant::Type nameToType(const QString &typeName)
int userType() const
Returns the storage type of the value stored in the variant.
The QDateTime class provides date and time functions.
static void construct(QVariant::Private *x, const void *copy)
QT_DEPRECATED bool qVariantCanConvert(const QVariant &variant)
const void * constData() const
bool operator==(const QVariant &v) const
Compares this QVariant with v and returns true if they are equal; otherwise returns false...
QList< QVariant > QVariantList
The QPoint class defines a point in the plane using integer precision.
QVariant(bool, int)
Use the QVariant(bool) constructor instead.
The QTextLength class encapsulates the different types of length used in a QTextDocument.
The QRect class defines a rectangle in the plane using integer precision.
QVariant qVariantFromValue(const T &value)
Returns a variant containing a copy of the given value with template type T.
T qvariant_cast(const QVariant &)
The Image element displays an image in a declarative user interface.
static ISC_TIME toTime(const QTime &t)
static qreal toDouble(const QChar *&str)
AbstractFloat< true > Double
An instantiation of AbsbstractFloat suitable for xs:double.
The QSize class defines the size of a two-dimensional object using integer point precision.
The QDataStream class provides serialization of binary data to a QIODevice.
bool cmp(const QVariant &other) const
T value() const
Returns the stored value converted to the template type T.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
static QUrl toUrl(Register *reg, int type, QDeclarativeContextData *context, bool *ok=0)
bool operator==(const QVariant &v1, const QVariant &v2)
static bool isNull(const QVariant::Private *d)
static qreal toReal(Register *reg, int type, bool *ok=0)
const void * data() const
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
QT_DEPRECATED T qVariantValue(const QVariant &variant)