Qt 4.8
Macros | Enumerations | Functions | Variables
qvariant.cpp File Reference
#include "qvariant.h"
#include "qbitarray.h"
#include "qbytearray.h"
#include "qdatastream.h"
#include "qdebug.h"
#include "qmap.h"
#include "qdatetime.h"
#include "qeasingcurve.h"
#include "qlist.h"
#include "qstring.h"
#include "qstringlist.h"
#include "qurl.h"
#include "qlocale.h"
#include "private/qvariant_p.h"
#include "qsize.h"
#include "qpoint.h"
#include "qrect.h"
#include "qline.h"
#include <float.h>

Go to the source code of this file.

Macros

#define DBL_DIG   10
 
#define FLT_DIG   6
 

Enumerations

enum  { MapFromThreeCount = 36 }
 

Functions

static void clear (QVariant::Private *d)
 
static bool compare (const QVariant::Private *a, const QVariant::Private *b)
 Compares a to b. More...
 
template<typename T >
bool compareNumericMetaType (const QVariant::Private *const a, const QVariant::Private *const b)
 
static void construct (QVariant::Private *x, const void *copy)
 
static bool convert (const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
 
static bool isNull (const QVariant::Private *d)
 
QDataStreamoperator<< (QDataStream &s, const QVariant &p)
 Writes a variant p to the stream s. More...
 
QDataStreamoperator<< (QDataStream &s, const QVariant::Type p)
 Writes a variant type p to the stream s. More...
 
QDebug operator<< (QDebug dbg, const QVariant &v)
 
QDebug operator<< (QDebug dbg, const QVariant::Type p)
 
QDataStreamoperator>> (QDataStream &s, QVariant &p)
 Reads a variant p from the stream s. More...
 
QDataStreamoperator>> (QDataStream &s, QVariant::Type &p)
 Reads a variant type p in enum representation from the stream s. More...
 
static qlonglong qConvertToNumber (const QVariant::Private *d, bool *ok)
 
static qulonglong qConvertToUnsignedNumber (const QVariant::Private *d, bool *ok)
 
Q_CORE_EXPORT const QVariant::Handler * qcoreVariantHandler ()
 
static bool qIsFloatingPoint (uint tp)
 
static bool qIsNumericType (uint tp)
 
static qlonglong qMetaTypeNumber (const QVariant::Private *d)
 
static qulonglong qMetaTypeUNumber (const QVariant::Private *d)
 
template<typename T >
qNumVariantToHelper (const QVariant::Private &d, const QVariant::Handler *handler, bool *ok, const T &val)
 
template<typename TInput , typename LiteralWrapper >
bool qt_convertToBool (const QVariant::Private *const d)
 
template<typename T >
qVariantToHelper (const QVariant::Private &d, QVariant::Type t, const QVariant::Handler *handler, T *=0)
 
static void streamDebug (QDebug dbg, const QVariant &v)
 

Variables

static const ushort map_from_three [MapFromThreeCount]
 
static const quint32 qCanConvertMatrix [QVariant::LastCoreType+1]
 
const QVariant::Handler qt_kernel_variant_handler
 

Macro Definition Documentation

◆ DBL_DIG

#define DBL_DIG   10

Definition at line 69 of file qvariant.cpp.

Referenced by convert(), qstrtod(), and QDoubleSpinBox::setDecimals().

◆ FLT_DIG

#define FLT_DIG   6

Definition at line 72 of file qvariant.cpp.

Referenced by convert().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MapFromThreeCount 

Definition at line 2046 of file qvariant.cpp.

Function Documentation

◆ clear()

static void clear ( QVariant::Private *  d)
static

Definition at line 197 of file qvariant.cpp.

Referenced by QHeaderViewPrivate::_q_sectionsRemoved(), QComboBox::addItems(), QListWidget::addItems(), QGL2PEXVertexArray::addVertex(), QContiguousCache< T >::available(), QBitmap::clear(), QDeclarativeEnginePrivate::SimpleList< T >::clear(), QVector< QPoint >::constData(), QDeclarativeCompiledBindingsPrivate::Binding::destroy(), QFileSystemMetaData::fillFromDirEnt(), QDeclarativeAbstractBinding::getPointer(), SurfaceCache::getSurface(), QDirModelPrivate::init(), QContiguousCache< T >::insert(), QAxBase::internalProperty(), QGraphicsScene::invalidate(), QToolBar::isAreaAllowed(), QLinkedList< JSC::Identifier >::isEmpty(), QList< QPostEvent >::isEmpty(), QString::isSharedWith(), QByteArray::isSharedWith(), QHash< QExplicitlySharedDataPointer, QHash >::isSharedWith(), QInt64Set::isValid(), QListModeViewBase::itemIndex(), QDeclarativeGridViewPrivate::layout(), QDeclarativeListViewPrivate::layout(), QByteArray::length(), QDomDocumentPrivate::nodeType(), QSqlRecord::operator!=(), QProcessEnvironment::operator!=(), QSslCertificate::operator!=(), QHostAddress::operator!=(), QDeclarativeGridViewPrivate::QDeclarativeGridViewPrivate(), QDeclarativeListViewPrivate::QDeclarativeListViewPrivate(), QInt64Set::QInt64Set(), QRBTree< int >::QRBTree(), QResourcePrivate::QResourcePrivate(), QDeclarativePathViewPrivate::regenerate(), QDeclarativeGridViewPrivate::regenerate(), QDeclarativeListViewPrivate::regenerate(), QInt64Set::rehash(), QPatternist::ResourceLoader::ResourceLoader(), QLineControl::selectAll(), QAxBase::setControl(), QGLTextureGlyphCache::setFilterMode(), QMap< int, QFrameInfo >::setInsertInOrder(), QDomNodePrivate::setNodeValue(), QSqlField::setRequired(), QUrl::swap(), QVariant::swap(), QTextControl::toHtml(), QPlainTextEdit::toPlainText(), QSqlField::value(), QHostInfoLookupManager::waitForThreadPoolDone(), QAbstractHostInfoLookupManager::~QAbstractHostInfoLookupManager(), QAxBase::~QAxBase(), QCommonListViewBase::~QCommonListViewBase(), QRBTree< int >::~QRBTree(), QResourcePrivate::~QResourcePrivate(), QSpanCollection::~QSpanCollection(), QTestEventList::~QTestEventList(), QXmlAttributes::~QXmlAttributes(), and SurfaceCache::~SurfaceCache().

198 {
199  switch (d->type) {
200  case QVariant::String:
201  v_clear<QString>(d);
202  break;
203  case QVariant::Char:
204  v_clear<QChar>(d);
205  break;
207  v_clear<QStringList>(d);
208  break;
209  case QVariant::Map:
210  v_clear<QVariantMap>(d);
211  break;
212  case QVariant::Hash:
213  v_clear<QVariantHash>(d);
214  break;
215  case QVariant::List:
216  v_clear<QVariantList>(d);
217  break;
218  case QVariant::Date:
219  v_clear<QDate>(d);
220  break;
221  case QVariant::Time:
222  v_clear<QTime>(d);
223  break;
224  case QVariant::DateTime:
225  v_clear<QDateTime>(d);
226  break;
227  case QVariant::ByteArray:
228  v_clear<QByteArray>(d);
229  break;
230  case QVariant::BitArray:
231  v_clear<QBitArray>(d);
232  break;
233 #ifndef QT_NO_GEOM_VARIANT
234  case QVariant::Point:
235  v_clear<QPoint>(d);
236  break;
237  case QVariant::PointF:
238  v_clear<QPointF>(d);
239  break;
240  case QVariant::Size:
241  v_clear<QSize>(d);
242  break;
243  case QVariant::SizeF:
244  v_clear<QSizeF>(d);
245  break;
246  case QVariant::Rect:
247  v_clear<QRect>(d);
248  break;
249  case QVariant::LineF:
250  v_clear<QLineF>(d);
251  break;
252  case QVariant::Line:
253  v_clear<QLine>(d);
254  break;
255  case QVariant::RectF:
256  v_clear<QRectF>(d);
257  break;
258 #endif
259 #ifndef QT_BOOTSTRAPPED
260  case QVariant::Url:
261  v_clear<QUrl>(d);
262  break;
263 #endif
264  case QVariant::Locale:
265  v_clear<QLocale>(d);
266  break;
267 #ifndef QT_NO_REGEXP
268  case QVariant::RegExp:
269  v_clear<QRegExp>(d);
270  break;
271 #endif
272 #ifndef QT_BOOTSTRAPPED
274  v_clear<QEasingCurve>(d);
275  break;
276 #endif
277  case QVariant::LongLong:
278  case QVariant::ULongLong:
279  case QVariant::Double:
280  case QMetaType::Float:
282  break;
283  case QVariant::Invalid:
284  case QVariant::UserType:
285  case QVariant::Int:
286  case QVariant::UInt:
287  case QVariant::Bool:
288  break;
289  default:
290  QMetaType::destroy(d->type, d->data.shared->ptr);
291  delete d->data.shared;
292  break;
293  }
294 
295  d->type = QVariant::Invalid;
296  d->is_null = true;
297  d->is_shared = false;
298 }
double d
Definition: qnumeric_p.h:62
static void destroy(int type, void *data)
Destroys the data, assuming it is of the type given.
Definition: qmetatype.cpp:1263

◆ compare()

static bool compare ( const QVariant::Private *  a,
const QVariant::Private *  b 
)
static

Compares a to b.

Warning
This function is not part of the public interface.

The caller guarantees that a and b are of the same type.

Definition at line 383 of file qvariant.cpp.

Referenced by QTestResult::compare(), QString::compare(), QPatternist::ComparisonFactory::constructAndCompare(), QPatternist::ComparisonPlatform< IndexOfIterator, false >::detailedFlexibleCompare(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QPatternist::ComparisonPlatform< IndexOfIterator, false >::flexibleCompare(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), QPatternist::XPath20CoreFunctions::retrieveExpression(), QListModel::sort(), QTableModel::sort(), QTreeModel::sortItems(), and QCss::Parser::testPrio().

384 {
385  switch(a->type) {
386  case QVariant::List:
387  return *v_cast<QVariantList>(a) == *v_cast<QVariantList>(b);
388  case QVariant::Map: {
389  const QVariantMap *m1 = v_cast<QVariantMap>(a);
390  const QVariantMap *m2 = v_cast<QVariantMap>(b);
391  if (m1->count() != m2->count())
392  return false;
394  QVariantMap::ConstIterator it2 = m2->constBegin();
395  while (it != m1->constEnd()) {
396  if (*it != *it2 || it.key() != it2.key())
397  return false;
398  ++it;
399  ++it2;
400  }
401  return true;
402  }
403  case QVariant::Hash:
404  return *v_cast<QVariantHash>(a) == *v_cast<QVariantHash>(b);
405  case QVariant::String:
406  return *v_cast<QString>(a) == *v_cast<QString>(b);
407  case QVariant::Char:
408  return *v_cast<QChar>(a) == *v_cast<QChar>(b);
410  return *v_cast<QStringList>(a) == *v_cast<QStringList>(b);
411 #ifndef QT_NO_GEOM_VARIANT
412  case QVariant::Size:
413  return *v_cast<QSize>(a) == *v_cast<QSize>(b);
414  case QVariant::SizeF:
415  return *v_cast<QSizeF>(a) == *v_cast<QSizeF>(b);
416  case QVariant::Rect:
417  return *v_cast<QRect>(a) == *v_cast<QRect>(b);
418  case QVariant::Line:
419  return *v_cast<QLine>(a) == *v_cast<QLine>(b);
420  case QVariant::LineF:
421  return *v_cast<QLineF>(a) == *v_cast<QLineF>(b);
422  case QVariant::RectF:
423  return *v_cast<QRectF>(a) == *v_cast<QRectF>(b);
424  case QVariant::Point:
425  return *v_cast<QPoint>(a) == *v_cast<QPoint>(b);
426  case QVariant::PointF:
427  return *v_cast<QPointF>(a) == *v_cast<QPointF>(b);
428 #endif
429 #ifndef QT_BOOTSTRAPPED
430  case QVariant::Url:
431  return *v_cast<QUrl>(a) == *v_cast<QUrl>(b);
432 #endif
433  case QVariant::Locale:
434  return *v_cast<QLocale>(a) == *v_cast<QLocale>(b);
435 #ifndef QT_NO_REGEXP
436  case QVariant::RegExp:
437  return *v_cast<QRegExp>(a) == *v_cast<QRegExp>(b);
438 #endif
439  case QVariant::Int:
440  return a->data.i == b->data.i;
441  case QVariant::UInt:
442  return a->data.u == b->data.u;
443  case QVariant::LongLong:
444  return a->data.ll == b->data.ll;
445  case QVariant::ULongLong:
446  return a->data.ull == b->data.ull;
447  case QVariant::Bool:
448  return a->data.b == b->data.b;
449  case QVariant::Double:
450  return a->data.d == b->data.d;
451  case QMetaType::Float:
452  return a->data.f == b->data.f;
454  return a->data.o == b->data.o;
455  case QVariant::Date:
456  return *v_cast<QDate>(a) == *v_cast<QDate>(b);
457  case QVariant::Time:
458  return *v_cast<QTime>(a) == *v_cast<QTime>(b);
459  case QVariant::DateTime:
460  return *v_cast<QDateTime>(a) == *v_cast<QDateTime>(b);
461 #ifndef QT_BOOTSTRAPPED
463  return *v_cast<QEasingCurve>(a) == *v_cast<QEasingCurve>(b);
464 #endif
465  case QVariant::ByteArray:
466  return *v_cast<QByteArray>(a) == *v_cast<QByteArray>(b);
467  case QVariant::BitArray:
468  return *v_cast<QBitArray>(a) == *v_cast<QBitArray>(b);
469  case QVariant::Invalid:
470  return true;
471  case QMetaType::Long:
472  return compareNumericMetaType<long>(a, b);
473  case QMetaType::ULong:
474  return compareNumericMetaType<ulong>(a, b);
475  case QMetaType::Short:
476  return compareNumericMetaType<short>(a, b);
477  case QMetaType::UShort:
478  return compareNumericMetaType<ushort>(a, b);
479  case QMetaType::UChar:
480  return compareNumericMetaType<uchar>(a, b);
481  case QMetaType::Char:
482  return compareNumericMetaType<char>(a, b);
483  default:
484  break;
485  }
486  if (!QMetaType::isRegistered(a->type))
487  qFatal("QVariant::compare: type %d unknown to QVariant.", a->type);
488 
489  const void *a_ptr = a->is_shared ? a->data.shared->ptr : &(a->data.ptr);
490  const void *b_ptr = b->is_shared ? b->data.shared->ptr : &(b->data.ptr);
491 
492  /* The reason we cannot place this test in a case branch above for the types
493  * QMetaType::VoidStar, QMetaType::QObjectStar and so forth, is that it wouldn't include
494  * user defined pointer types. */
495  const char *const typeName = QMetaType::typeName(a->type);
496  uint typeNameLen = qstrlen(typeName);
497  if (typeNameLen > 0 && typeName[typeNameLen - 1] == '*')
498  return *static_cast<void *const *>(a_ptr) == *static_cast<void *const *>(b_ptr);
499 
500  if (a->is_null && b->is_null)
501  return true;
502 
503  return a_ptr == b_ptr;
504 }
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int count(const Key &key) const
Returns the number of items associated with key key.
Definition: qmap.h:539
The QDate class provides date functions.
Definition: qdatetime.h:55
long ASN1_INTEGER_get ASN1_INTEGER * a
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
The QTime class provides clock time functions.
Definition: qdatetime.h:148
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const_iterator ConstIterator
Qt-style synonym for QMap::const_iterator.
Definition: qmap.h:389
const char * typeName
Definition: qmetatype.cpp:239
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
unsigned int uint
Definition: qglobal.h:996
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
Q_CORE_EXPORT void qFatal(const char *,...)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
uint qstrlen(const char *str)
Definition: qbytearray.h:79
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static bool isRegistered(int type)
Returns true if the datatype with ID type is registered; otherwise returns false. ...
Definition: qmetatype.cpp:590

◆ compareNumericMetaType()

template<typename T >
bool compareNumericMetaType ( const QVariant::Private *const  a,
const QVariant::Private *const  b 
)
inline

Definition at line 369 of file qvariant.cpp.

370 {
371  return *static_cast<const T *>(a->data.shared->ptr) == *static_cast<const T *>(b->data.shared->ptr);
372 }
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ construct()

static void construct ( QVariant::Private *  x,
const void *  copy 
)
static

Definition at line 75 of file qvariant.cpp.

Referenced by QScriptValue::construct(), QApplicationPrivate::graphicsSystem(), and QDeclarativeCompiledBindingsPrivate::run().

76 {
77  x->is_shared = false;
78 
79  switch (x->type) {
80  case QVariant::String:
81  v_construct<QString>(x, copy);
82  break;
83  case QVariant::Char:
84  v_construct<QChar>(x, copy);
85  break;
87  v_construct<QStringList>(x, copy);
88  break;
89  case QVariant::Map:
90  v_construct<QVariantMap>(x, copy);
91  break;
92  case QVariant::Hash:
93  v_construct<QVariantHash>(x, copy);
94  break;
95  case QVariant::List:
96  v_construct<QVariantList>(x, copy);
97  break;
98  case QVariant::Date:
99  v_construct<QDate>(x, copy);
100  break;
101  case QVariant::Time:
102  v_construct<QTime>(x, copy);
103  break;
104  case QVariant::DateTime:
105  v_construct<QDateTime>(x, copy);
106  break;
107  case QVariant::ByteArray:
108  v_construct<QByteArray>(x, copy);
109  break;
110  case QVariant::BitArray:
111  v_construct<QBitArray>(x, copy);
112  break;
113 #ifndef QT_NO_GEOM_VARIANT
114  case QVariant::Size:
115  v_construct<QSize>(x, copy);
116  break;
117  case QVariant::SizeF:
118  v_construct<QSizeF>(x, copy);
119  break;
120  case QVariant::Rect:
121  v_construct<QRect>(x, copy);
122  break;
123  case QVariant::LineF:
124  v_construct<QLineF>(x, copy);
125  break;
126  case QVariant::Line:
127  v_construct<QLine>(x, copy);
128  break;
129  case QVariant::RectF:
130  v_construct<QRectF>(x, copy);
131  break;
132  case QVariant::Point:
133  v_construct<QPoint>(x, copy);
134  break;
135  case QVariant::PointF:
136  v_construct<QPointF>(x, copy);
137  break;
138 #endif
139 #ifndef QT_BOOTSTRAPPED
140  case QVariant::Url:
141  v_construct<QUrl>(x, copy);
142  break;
143 #endif
144  case QVariant::Locale:
145  v_construct<QLocale>(x, copy);
146  break;
147 #ifndef QT_NO_REGEXP
148  case QVariant::RegExp:
149  v_construct<QRegExp>(x, copy);
150  break;
151 #endif
152 #ifndef QT_BOOTSTRAPPED
154  v_construct<QEasingCurve>(x, copy);
155  break;
156 #endif
157  case QVariant::Int:
158  x->data.i = copy ? *static_cast<const int *>(copy) : 0;
159  break;
160  case QVariant::UInt:
161  x->data.u = copy ? *static_cast<const uint *>(copy) : 0u;
162  break;
163  case QVariant::Bool:
164  x->data.b = copy ? *static_cast<const bool *>(copy) : false;
165  break;
166  case QVariant::Double:
167  x->data.d = copy ? *static_cast<const double*>(copy) : 0.0;
168  break;
169  case QMetaType::Float:
170  x->data.f = copy ? *static_cast<const float*>(copy) : 0.0f;
171  break;
173  x->data.o = copy ? *static_cast<QObject *const*>(copy) : 0;
174  break;
175  case QVariant::LongLong:
176  x->data.ll = copy ? *static_cast<const qlonglong *>(copy) : Q_INT64_C(0);
177  break;
178  case QVariant::ULongLong:
179  x->data.ull = copy ? *static_cast<const qulonglong *>(copy) : Q_UINT64_C(0);
180  break;
181  case QVariant::Invalid:
182  case QVariant::UserType:
183  break;
184  default:
185  void *ptr = QMetaType::construct(x->type, copy);
186  if (!ptr) {
187  x->type = QVariant::Invalid;
188  } else {
189  x->is_shared = true;
190  x->data.shared = new QVariant::PrivateShared(ptr);
191  }
192  break;
193  }
194  x->is_null = !copy;
195 }
quint16 u
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
#define Q_INT64_C(c)
Definition: qglobal.h:940
quint64 qulonglong
Definition: qglobal.h:952
#define Q_UINT64_C(c)
Definition: qglobal.h:941
qint64 qlonglong
Definition: qglobal.h:951

◆ convert()

static bool convert ( const QVariant::Private *  d,
QVariant::Type  t,
void *  result,
bool *  ok 
)
static
Warning
This function is not part of the public interface.

Converts d to type t, which is placed in result.

Definition at line 627 of file qvariant.cpp.

Referenced by QDeclarativeBindingCompilerPrivate::compile(), QPSQLResult::data(), QScriptEngine::fromScriptValue(), QDeclarativeBindingCompilerPrivate::numberArith(), QDeclarativeBindingCompilerPrivate::stringArith(), and QVariant::swap().

628 {
629  Q_ASSERT(d->type != uint(t));
630  Q_ASSERT(result);
631 
632  bool dummy;
633  if (!ok)
634  ok = &dummy;
635 
636  switch (uint(t)) {
637 #ifndef QT_BOOTSTRAPPED
638  case QVariant::Url:
639  switch (d->type) {
640  case QVariant::String:
641  *static_cast<QUrl *>(result) = QUrl(*v_cast<QString>(d));
642  break;
643  default:
644  return false;
645  }
646  break;
647 #endif
648  case QVariant::String: {
649  QString *str = static_cast<QString *>(result);
650  switch (d->type) {
651  case QVariant::Char:
652  *str = QString(*v_cast<QChar>(d));
653  break;
654  case QMetaType::Char:
655  case QMetaType::UChar:
656  *str = QChar::fromAscii(*static_cast<char *>(d->data.shared->ptr));
657  break;
658  case QMetaType::Short:
659  case QMetaType::Long:
660  case QVariant::Int:
661  case QVariant::LongLong:
663  break;
664  case QVariant::UInt:
665  case QVariant::ULongLong:
666  case QMetaType::UShort:
667  case QMetaType::ULong:
669  break;
670  case QMetaType::Float:
671  *str = QString::number(d->data.f, 'g', FLT_DIG);
672  break;
673  case QVariant::Double:
674  *str = QString::number(d->data.d, 'g', DBL_DIG);
675  break;
676 #if !defined(QT_NO_DATESTRING)
677  case QVariant::Date:
678  *str = v_cast<QDate>(d)->toString(Qt::ISODate);
679  break;
680  case QVariant::Time:
681  *str = v_cast<QTime>(d)->toString(Qt::ISODate);
682  break;
683  case QVariant::DateTime:
685  break;
686 #endif
687  case QVariant::Bool:
688  *str = QLatin1String(d->data.b ? "true" : "false");
689  break;
690  case QVariant::ByteArray:
691  *str = QString::fromAscii(v_cast<QByteArray>(d)->constData());
692  break;
694  if (v_cast<QStringList>(d)->count() == 1)
695  *str = v_cast<QStringList>(d)->at(0);
696  break;
697 #ifndef QT_BOOTSTRAPPED
698  case QVariant::Url:
699  *str = v_cast<QUrl>(d)->toString();
700  break;
701 #endif
702  default:
703  return false;
704  }
705  break;
706  }
707  case QVariant::Char: {
708  QChar *c = static_cast<QChar *>(result);
709  switch (d->type) {
710  case QVariant::Int:
711  case QVariant::LongLong:
712  case QMetaType::Char:
713  case QMetaType::Short:
714  case QMetaType::Long:
715  case QMetaType::Float:
716  *c = QChar(ushort(qMetaTypeNumber(d)));
717  break;
718  case QVariant::UInt:
719  case QVariant::ULongLong:
720  case QMetaType::UChar:
721  case QMetaType::UShort:
722  case QMetaType::ULong:
723  *c = QChar(ushort(qMetaTypeUNumber(d)));
724  break;
725  default:
726  return false;
727  }
728  break;
729  }
730 #ifndef QT_NO_GEOM_VARIANT
731  case QVariant::Size: {
732  QSize *s = static_cast<QSize *>(result);
733  switch (d->type) {
734  case QVariant::SizeF:
735  *s = v_cast<QSizeF>(d)->toSize();
736  break;
737  default:
738  return false;
739  }
740  break;
741  }
742 
743  case QVariant::SizeF: {
744  QSizeF *s = static_cast<QSizeF *>(result);
745  switch (d->type) {
746  case QVariant::Size:
747  *s = QSizeF(*(v_cast<QSize>(d)));
748  break;
749  default:
750  return false;
751  }
752  break;
753  }
754 
755  case QVariant::Line: {
756  QLine *s = static_cast<QLine *>(result);
757  switch (d->type) {
758  case QVariant::LineF:
759  *s = v_cast<QLineF>(d)->toLine();
760  break;
761  default:
762  return false;
763  }
764  break;
765  }
766 
767  case QVariant::LineF: {
768  QLineF *s = static_cast<QLineF *>(result);
769  switch (d->type) {
770  case QVariant::Line:
771  *s = QLineF(*(v_cast<QLine>(d)));
772  break;
773  default:
774  return false;
775  }
776  break;
777  }
778 #endif
780  if (d->type == QVariant::List) {
781  QStringList *slst = static_cast<QStringList *>(result);
782  const QVariantList *list = v_cast<QVariantList >(d);
783  for (int i = 0; i < list->size(); ++i)
784  slst->append(list->at(i).toString());
785  } else if (d->type == QVariant::String) {
786  QStringList *slst = static_cast<QStringList *>(result);
787  *slst = QStringList(*v_cast<QString>(d));
788  } else {
789  return false;
790  }
791  break;
792  case QVariant::Date: {
793  QDate *dt = static_cast<QDate *>(result);
794  if (d->type == QVariant::DateTime)
795  *dt = v_cast<QDateTime>(d)->date();
796 #ifndef QT_NO_DATESTRING
797  else if (d->type == QVariant::String)
798  *dt = QDate::fromString(*v_cast<QString>(d), Qt::ISODate);
799 #endif
800  else
801  return false;
802 
803  return dt->isValid();
804  }
805  case QVariant::Time: {
806  QTime *t = static_cast<QTime *>(result);
807  switch (d->type) {
808  case QVariant::DateTime:
809  *t = v_cast<QDateTime>(d)->time();
810  break;
811 #ifndef QT_NO_DATESTRING
812  case QVariant::String:
813  *t = QTime::fromString(*v_cast<QString>(d), Qt::ISODate);
814  break;
815 #endif
816  default:
817  return false;
818  }
819  return t->isValid();
820  }
821  case QVariant::DateTime: {
822  QDateTime *dt = static_cast<QDateTime *>(result);
823  switch (d->type) {
824 #ifndef QT_NO_DATESTRING
825  case QVariant::String:
826  *dt = QDateTime::fromString(*v_cast<QString>(d), Qt::ISODate);
827  break;
828 #endif
829  case QVariant::Date:
830  *dt = QDateTime(*v_cast<QDate>(d));
831  break;
832  default:
833  return false;
834  }
835  return dt->isValid();
836  }
837  case QVariant::ByteArray: {
838  QByteArray *ba = static_cast<QByteArray *>(result);
839  switch (d->type) {
840  case QVariant::String:
841  *ba = v_cast<QString>(d)->toAscii();
842  break;
843  case QVariant::Double:
844  *ba = QByteArray::number(d->data.d, 'g', DBL_DIG);
845  break;
846  case QMetaType::Float:
847  *ba = QByteArray::number(d->data.f, 'g', FLT_DIG);
848  break;
849  case QMetaType::Char:
850  case QMetaType::UChar:
851  *ba = QByteArray(1, *static_cast<char *>(d->data.shared->ptr));
852  break;
853  case QVariant::Int:
854  case QVariant::LongLong:
855  case QMetaType::Short:
856  case QMetaType::Long:
858  break;
859  case QVariant::UInt:
860  case QVariant::ULongLong:
861  case QMetaType::UShort:
862  case QMetaType::ULong:
864  break;
865  case QVariant::Bool:
866  *ba = QByteArray(d->data.b ? "true" : "false");
867  break;
868  default:
869  return false;
870  }
871  }
872  break;
873  case QMetaType::Short:
874  *static_cast<short *>(result) = short(qConvertToNumber(d, ok));
875  return *ok;
876  case QMetaType::Long:
877  *static_cast<long *>(result) = long(qConvertToNumber(d, ok));
878  return *ok;
879  case QMetaType::UShort:
880  *static_cast<ushort *>(result) = ushort(qConvertToUnsignedNumber(d, ok));
881  return *ok;
882  case QMetaType::ULong:
883  *static_cast<ulong *>(result) = ulong(qConvertToUnsignedNumber(d, ok));
884  return *ok;
885  case QVariant::Int:
886  *static_cast<int *>(result) = int(qConvertToNumber(d, ok));
887  return *ok;
888  case QVariant::UInt:
889  *static_cast<uint *>(result) = uint(qConvertToUnsignedNumber(d, ok));
890  return *ok;
891  case QVariant::LongLong:
892  *static_cast<qlonglong *>(result) = qConvertToNumber(d, ok);
893  return *ok;
894  case QVariant::ULongLong: {
895  *static_cast<qulonglong *>(result) = qConvertToUnsignedNumber(d, ok);
896  return *ok;
897  }
898  case QMetaType::UChar: {
899  *static_cast<uchar *>(result) = qConvertToUnsignedNumber(d, ok);
900  return *ok;
901  }
902  case QVariant::Bool: {
903  bool *b = static_cast<bool *>(result);
904  switch(d->type) {
905  case QVariant::ByteArray:
906  *b = qt_convertToBool<QByteArray, QByteArray>(d);
907  break;
908  case QVariant::String:
909  *b = qt_convertToBool<QString, QLatin1String>(d);
910  break;
911  case QVariant::Char:
912  *b = !v_cast<QChar>(d)->isNull();
913  break;
914  case QVariant::Double:
915  case QVariant::Int:
916  case QVariant::LongLong:
917  case QMetaType::Char:
918  case QMetaType::Short:
919  case QMetaType::Long:
920  case QMetaType::Float:
921  *b = qMetaTypeNumber(d) != Q_INT64_C(0);
922  break;
923  case QVariant::UInt:
924  case QVariant::ULongLong:
925  case QMetaType::UChar:
926  case QMetaType::UShort:
927  case QMetaType::ULong:
928  *b = qMetaTypeUNumber(d) != Q_UINT64_C(0);
929  break;
930  default:
931  *b = false;
932  return false;
933  }
934  break;
935  }
936  case QVariant::Double: {
937  double *f = static_cast<double *>(result);
938  switch (d->type) {
939  case QVariant::String:
940  *f = v_cast<QString>(d)->toDouble(ok);
941  break;
942  case QVariant::ByteArray:
943  *f = v_cast<QByteArray>(d)->toDouble(ok);
944  break;
945  case QVariant::Bool:
946  *f = double(d->data.b);
947  break;
948  case QMetaType::Float:
949  *f = double(d->data.f);
950  break;
951  case QVariant::LongLong:
952  case QVariant::Int:
953  case QMetaType::Char:
954  case QMetaType::Short:
955  case QMetaType::Long:
956  *f = double(qMetaTypeNumber(d));
957  break;
958  case QVariant::UInt:
959  case QVariant::ULongLong:
960  case QMetaType::UChar:
961  case QMetaType::UShort:
962  case QMetaType::ULong:
963  *f = double(qMetaTypeUNumber(d));
964  break;
965  default:
966  *f = 0.0;
967  return false;
968  }
969  break;
970  }
971  case QMetaType::Float: {
972  float *f = static_cast<float *>(result);
973  switch (d->type) {
974  case QVariant::String:
975  *f = v_cast<QString>(d)->toFloat(ok);
976  break;
977  case QVariant::ByteArray:
978  *f = v_cast<QByteArray>(d)->toFloat(ok);
979  break;
980  case QVariant::Bool:
981  *f = float(d->data.b);
982  break;
983  case QVariant::Double:
984  *f = float(d->data.d);
985  break;
986  case QVariant::LongLong:
987  case QVariant::Int:
988  case QMetaType::Char:
989  case QMetaType::Short:
990  case QMetaType::Long:
991  *f = float(qMetaTypeNumber(d));
992  break;
993  case QVariant::UInt:
994  case QVariant::ULongLong:
995  case QMetaType::UChar:
996  case QMetaType::UShort:
997  case QMetaType::ULong:
998  *f = float(qMetaTypeUNumber(d));
999  break;
1000  default:
1001  *f = 0.0f;
1002  return false;
1003  }
1004  break;
1005  }
1006  case QVariant::List:
1007  if (d->type == QVariant::StringList) {
1008  QVariantList *lst = static_cast<QVariantList *>(result);
1009  const QStringList *slist = v_cast<QStringList>(d);
1010  for (int i = 0; i < slist->size(); ++i)
1011  lst->append(QVariant(slist->at(i)));
1012  } else if (qstrcmp(QMetaType::typeName(d->type), "QList<QVariant>") == 0) {
1013  *static_cast<QVariantList *>(result) =
1014  *static_cast<QList<QVariant> *>(d->data.shared->ptr);
1015  } else {
1016  return false;
1017  }
1018  break;
1019  case QVariant::Map:
1020  if (qstrcmp(QMetaType::typeName(d->type), "QMap<QString, QVariant>") == 0) {
1021  *static_cast<QVariantMap *>(result) =
1022  *static_cast<QMap<QString, QVariant> *>(d->data.shared->ptr);
1023  } else {
1024  return false;
1025  }
1026  break;
1027  case QVariant::Hash:
1028  if (qstrcmp(QMetaType::typeName(d->type), "QHash<QString, QVariant>") == 0) {
1029  *static_cast<QVariantHash *>(result) =
1030  *static_cast<QHash<QString, QVariant> *>(d->data.shared->ptr);
1031  } else {
1032  return false;
1033  }
1034  break;
1035 #ifndef QT_NO_GEOM_VARIANT
1036  case QVariant::Rect:
1037  if (d->type == QVariant::RectF)
1038  *static_cast<QRect *>(result) = (v_cast<QRectF>(d))->toRect();
1039  else
1040  return false;
1041  break;
1042  case QVariant::RectF:
1043  if (d->type == QVariant::Rect)
1044  *static_cast<QRectF *>(result) = *v_cast<QRect>(d);
1045  else
1046  return false;
1047  break;
1048  case QVariant::PointF:
1049  if (d->type == QVariant::Point)
1050  *static_cast<QPointF *>(result) = *v_cast<QPoint>(d);
1051  else
1052  return false;
1053  break;
1054  case QVariant::Point:
1055  if (d->type == QVariant::PointF)
1056  *static_cast<QPoint *>(result) = (v_cast<QPointF>(d))->toPoint();
1057  else
1058  return false;
1059  break;
1060  case QMetaType::Char:
1061  {
1062  *static_cast<qint8 *>(result) = qint8(qConvertToNumber(d, ok));
1063  return *ok;
1064  }
1065 #endif
1066  default:
1067  return false;
1068  }
1069  return true;
1070 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
#define DBL_DIG
Definition: qvariant.cpp:69
#define at(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
signed char qint8
Definition: qglobal.h:933
unsigned char uchar
Definition: qglobal.h:994
static QString toString(Register *reg, int type, bool *ok=0)
static QDateTime fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if th...
Definition: qdatetime.cpp:3487
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QTime class provides clock time functions.
Definition: qdatetime.h:148
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define FLT_DIG
Definition: qvariant.cpp:72
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
unsigned int uint
Definition: qglobal.h:996
unsigned long ulong
Definition: qglobal.h:997
static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok)
Definition: qvariant.cpp:582
#define Q_INT64_C(c)
Definition: qglobal.h:940
static QTime fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the time represented in the string as a QTime using the format given, or an invalid time if t...
Definition: qdatetime.cpp:1928
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
unsigned short ushort
Definition: qglobal.h:995
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static QDate fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDate represented by the string, using the format given, or an invalid date if the string...
Definition: qdatetime.cpp:1203
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static qreal toDouble(const QChar *&str)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
quint64 qulonglong
Definition: qglobal.h:952
#define Q_UINT64_C(c)
Definition: qglobal.h:941
static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok)
Definition: qvariant.cpp:549
static qlonglong qMetaTypeNumber(const QVariant::Private *d)
Definition: qvariant.cpp:509
static QChar fromAscii(char c)
Converts the ASCII character c to its equivalent QChar.
Definition: qchar.cpp:1521
qint64 qlonglong
Definition: qglobal.h:951
static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
Definition: qvariant.cpp:531
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566

◆ isNull()

static bool isNull ( const QVariant::Private *  d)
static

Definition at line 300 of file qvariant.cpp.

Referenced by QMacStylePrivate::aquaSizeConstrain(), QPatternist::Item::asNode(), classIDL(), convert(), DumpIDL(), QAxBase::dynamicCallHelper(), QLabelPrivate::ensureTextPopulated(), QCss::ValueExtractor::extractImage(), QFileInfoPrivate::getFileName(), QFileInfoPrivate::getFileOwner(), QSqlRecord::isNull(), QAbstractXmlNodeModel::iterate(), QByteArray::length(), QPatternist::ReportContext::lookupSourceLocation(), QToolBoxButton::minimumSizeHint(), QWatermarkLabel::minimumSizeHint(), QScopedPointer< QXmlResultItemsPrivate >::operator bool(), QUuid::operator QString(), QPixmap::operator!(), QAuthenticator::operator!=(), QSqlRecord::operator!=(), QSslCipher::operator!=(), QSslConfiguration::operator!=(), QSslCertificate::operator!=(), QHostAddress::operator!=(), QIcon::paint(), QCommandLinkButton::paintEvent(), QDB2Driver::primaryIndex(), QGuiEventDispatcherWin32::processEvents(), QAxBase::propertyBag(), QGLGraphicsSystem::QGLGraphicsSystem(), qMakeFieldInfo(), QMdiSubWindow::QMdiSubWindow(), QRect::QRect(), qt_cleanup(), qt_getLprPrinters(), qt_init(), qt_message_output(), QAxBase::qt_metacall(), qt_wstate_iconified(), QAxBase::setControl(), QmlJSDebugger::LiveSelectionIndicator::setItems(), QAxBase::setPropertyBag(), QListView::setSelection(), QMdiSubWindow::setWidget(), QMdiSubWindow::showShaded(), QPushButton::sizeHint(), QToolBoxButton::sizeHint(), QDockWidgetTitleButton::sizeHint(), QRegion::swap(), QPixmap::swap(), QImage::swap(), QVariant::swap(), QDB2Driver::tables(), QComboBoxPrivate::updateLineEditGeometry(), QSqlField::value(), QPatternist::yyparse(), and QObject::~QObject().

301 {
302  switch(d->type) {
303  case QVariant::String:
304  return v_cast<QString>(d)->isNull();
305  case QVariant::Char:
306  return v_cast<QChar>(d)->isNull();
307  case QVariant::Date:
308  return v_cast<QDate>(d)->isNull();
309  case QVariant::Time:
310  return v_cast<QTime>(d)->isNull();
311  case QVariant::DateTime:
312  return v_cast<QDateTime>(d)->isNull();
313  case QVariant::ByteArray:
314  return v_cast<QByteArray>(d)->isNull();
315  case QVariant::BitArray:
316  return v_cast<QBitArray>(d)->isNull();
317 #ifndef QT_NO_GEOM_VARIANT
318  case QVariant::Size:
319  return v_cast<QSize>(d)->isNull();
320  case QVariant::SizeF:
321  return v_cast<QSizeF>(d)->isNull();
322  case QVariant::Rect:
323  return v_cast<QRect>(d)->isNull();
324  case QVariant::Line:
325  return v_cast<QLine>(d)->isNull();
326  case QVariant::LineF:
327  return v_cast<QLineF>(d)->isNull();
328  case QVariant::RectF:
329  return v_cast<QRectF>(d)->isNull();
330  case QVariant::Point:
331  return v_cast<QPoint>(d)->isNull();
332  case QVariant::PointF:
333  return v_cast<QPointF>(d)->isNull();
334 #endif
335 #ifndef QT_BOOTSTRAPPED
337  case QVariant::Url:
338 #endif
339  case QVariant::Locale:
340  case QVariant::RegExp:
342  case QVariant::Map:
343  case QVariant::Hash:
344  case QVariant::List:
345  case QVariant::Invalid:
346  case QVariant::UserType:
347  case QVariant::Int:
348  case QVariant::UInt:
349  case QVariant::LongLong:
350  case QVariant::ULongLong:
351  case QVariant::Bool:
352  case QVariant::Double:
353  case QMetaType::Float:
355  break;
356  }
357  return d->is_null;
358 }
double d
Definition: qnumeric_p.h:62
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QDate class provides date functions.
Definition: qdatetime.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
The QTime class provides clock time functions.
Definition: qdatetime.h:148
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ operator<<() [1/4]

QDataStream& operator<< ( QDataStream s,
const QVariant p 
)

Writes a variant p to the stream s.

See also
Format of the QDataStream operators

Definition at line 2195 of file qvariant.cpp.

Referenced by QVariant::operator!=(), qVariantCanConvert(), and QVariant::setValue().

2196 {
2197  p.save(s);
2198  return s;
2199 }
void save(QDataStream &ds) const
Internal function for saving a variant to the stream s.
Definition: qvariant.cpp:2140

◆ operator<<() [2/4]

QDataStream& operator<< ( QDataStream s,
const QVariant::Type  p 
)

Writes a variant type p to the stream s.

Definition at line 2216 of file qvariant.cpp.

2217 {
2218  s << static_cast<quint32>(p);
2219 
2220  return s;
2221 }

◆ operator<<() [3/4]

QDebug operator<< ( QDebug  dbg,
const QVariant v 
)

Definition at line 3108 of file qvariant.cpp.

3109 {
3110 #ifndef Q_BROKEN_DEBUG_STREAM
3111  dbg.nospace() << "QVariant(" << v.typeName() << ", ";
3112  QVariant::handler->debugStream(dbg, v);
3113  dbg.nospace() << ')';
3114  return dbg.space();
3115 #else
3116  qWarning("This compiler doesn't support streaming QVariant to QDebug");
3117  return dbg;
3118  Q_UNUSED(v);
3119 #endif
3120 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
static const Handler * handler
Definition: qvariant.h:419
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ operator<<() [4/4]

QDebug operator<< ( QDebug  dbg,
const QVariant::Type  p 
)

Definition at line 3122 of file qvariant.cpp.

3123 {
3124 #ifndef Q_BROKEN_DEBUG_STREAM
3125  dbg.nospace() << "QVariant::" << QVariant::typeToName(p);
3126  return dbg.space();
3127 #else
3128  qWarning("This compiler doesn't support streaming QVariant::Type to QDebug");
3129  return dbg;
3130  Q_UNUSED(p);
3131 #endif
3132 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
Q_CORE_EXPORT void qWarning(const char *,...)
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ operator>>() [1/2]

QDataStream& operator>> ( QDataStream s,
QVariant p 
)

Reads a variant p from the stream s.

Since
4.4
See also
Format of the QDataStream operators

Definition at line 2184 of file qvariant.cpp.

Referenced by QVariant::setValue().

2185 {
2186  p.load(s);
2187  return s;
2188 }
void load(QDataStream &ds)
Internal function for loading a variant from stream s.
Definition: qvariant.cpp:2093

◆ operator>>() [2/2]

QDataStream& operator>> ( QDataStream s,
QVariant::Type p 
)

Reads a variant type p in enum representation from the stream s.

Definition at line 2204 of file qvariant.cpp.

2205 {
2206  quint32 u;
2207  s >> u;
2208  p = (QVariant::Type)u;
2209 
2210  return s;
2211 }
quint16 u
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
unsigned int quint32
Definition: qglobal.h:938

◆ qConvertToNumber()

static qlonglong qConvertToNumber ( const QVariant::Private *  d,
bool *  ok 
)
static

Definition at line 549 of file qvariant.cpp.

Referenced by convert().

550 {
551  *ok = true;
552 
553  switch (uint(d->type)) {
554  case QVariant::String:
555  return v_cast<QString>(d)->toLongLong(ok);
556  case QVariant::Char:
557  return v_cast<QChar>(d)->unicode();
558  case QVariant::ByteArray:
559  return v_cast<QByteArray>(d)->toLongLong(ok);
560  case QVariant::Bool:
561  return qlonglong(d->data.b);
562  case QVariant::Double:
563  case QVariant::Int:
564  case QMetaType::Char:
565  case QMetaType::Short:
566  case QMetaType::Long:
567  case QMetaType::Float:
568  case QMetaType::LongLong:
569  return qMetaTypeNumber(d);
570  case QVariant::ULongLong:
571  case QVariant::UInt:
572  case QMetaType::UChar:
573  case QMetaType::UShort:
574  case QMetaType::ULong:
575  return qlonglong(qMetaTypeUNumber(d));
576  }
577 
578  *ok = false;
579  return Q_INT64_C(0);
580 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
unsigned int uint
Definition: qglobal.h:996
#define Q_INT64_C(c)
Definition: qglobal.h:940
static qlonglong qMetaTypeNumber(const QVariant::Private *d)
Definition: qvariant.cpp:509
qint64 qlonglong
Definition: qglobal.h:951
static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
Definition: qvariant.cpp:531

◆ qConvertToUnsignedNumber()

static qulonglong qConvertToUnsignedNumber ( const QVariant::Private *  d,
bool *  ok 
)
static

Definition at line 582 of file qvariant.cpp.

Referenced by convert().

583 {
584  *ok = true;
585 
586  switch (uint(d->type)) {
587  case QVariant::String:
588  return v_cast<QString>(d)->toULongLong(ok);
589  case QVariant::Char:
590  return v_cast<QChar>(d)->unicode();
591  case QVariant::ByteArray:
592  return v_cast<QByteArray>(d)->toULongLong(ok);
593  case QVariant::Bool:
594  return qulonglong(d->data.b);
595  case QVariant::Double:
596  case QVariant::Int:
597  case QMetaType::Char:
598  case QMetaType::Short:
599  case QMetaType::Long:
600  case QMetaType::Float:
601  case QMetaType::LongLong:
602  return qulonglong(qMetaTypeNumber(d));
603  case QVariant::ULongLong:
604  case QVariant::UInt:
605  case QMetaType::UChar:
606  case QMetaType::UShort:
607  case QMetaType::ULong:
608  return qMetaTypeUNumber(d);
609  }
610 
611  *ok = false;
612  return Q_UINT64_C(0);
613 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
unsigned int uint
Definition: qglobal.h:996
quint64 qulonglong
Definition: qglobal.h:952
#define Q_UINT64_C(c)
Definition: qglobal.h:941
static qlonglong qMetaTypeNumber(const QVariant::Private *d)
Definition: qvariant.cpp:509
static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
Definition: qvariant.cpp:531

◆ qcoreVariantHandler()

Q_CORE_EXPORT const QVariant::Handler* qcoreVariantHandler ( )

Definition at line 1193 of file qvariant.cpp.

Referenced by clear(), compare(), construct(), convert(), isNull(), streamDebug(), and v_clear().

1194 {
1195  return &qt_kernel_variant_handler;
1196 }
const QVariant::Handler qt_kernel_variant_handler
Definition: qvariant.cpp:1175

◆ qIsFloatingPoint()

static bool qIsFloatingPoint ( uint  tp)
static

Definition at line 3039 of file qvariant.cpp.

Referenced by QVariant::cmp().

3040 {
3041  return tp == QVariant::Double || tp == QMetaType::Float;
3042 }

◆ qIsNumericType()

static bool qIsNumericType ( uint  tp)
static

Definition at line 3033 of file qvariant.cpp.

Referenced by QVariant::cmp().

3034 {
3035  return (tp >= QVariant::Bool && tp <= QVariant::Double)
3036  || (tp >= QMetaType::Long && tp <= QMetaType::Float);
3037 }

◆ qMetaTypeNumber()

static qlonglong qMetaTypeNumber ( const QVariant::Private *  d)
static
Warning
This function is not part of the public interface.

Definition at line 509 of file qvariant.cpp.

Referenced by convert(), qConvertToNumber(), and qConvertToUnsignedNumber().

510 {
511  switch (d->type) {
512  case QMetaType::Int:
513  return d->data.i;
514  case QMetaType::LongLong:
515  return d->data.ll;
516  case QMetaType::Char:
517  return qlonglong(*static_cast<signed char *>(d->data.shared->ptr));
518  case QMetaType::Short:
519  return qlonglong(*static_cast<short *>(d->data.shared->ptr));
520  case QMetaType::Long:
521  return qlonglong(*static_cast<long *>(d->data.shared->ptr));
522  case QMetaType::Float:
523  return qRound64(d->data.f);
524  case QVariant::Double:
525  return qRound64(d->data.d);
526  }
527  Q_ASSERT(false);
528  return 0;
529 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR qint64 qRound64(qreal d)
Definition: qglobal.h:1210
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qint64 qlonglong
Definition: qglobal.h:951

◆ qMetaTypeUNumber()

static qulonglong qMetaTypeUNumber ( const QVariant::Private *  d)
static

Definition at line 531 of file qvariant.cpp.

Referenced by convert(), qConvertToNumber(), and qConvertToUnsignedNumber().

532 {
533  switch (d->type) {
534  case QVariant::UInt:
535  return d->data.u;
536  case QVariant::ULongLong:
537  return d->data.ull;
538  case QMetaType::UChar:
539  return qulonglong(*static_cast<unsigned char *>(d->data.shared->ptr));
540  case QMetaType::UShort:
541  return qulonglong(*static_cast<ushort *>(d->data.shared->ptr));
542  case QMetaType::ULong:
543  return qulonglong(*static_cast<ulong *>(d->data.shared->ptr));
544  }
545  Q_ASSERT(false);
546  return 0;
547 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
quint64 qulonglong
Definition: qglobal.h:952

◆ qNumVariantToHelper()

template<typename T >
T qNumVariantToHelper ( const QVariant::Private &  d,
const QVariant::Handler *  handler,
bool *  ok,
const T &  val 
)
inline

Definition at line 2596 of file qvariant.cpp.

2598 {
2599  uint t = qMetaTypeId<T>();
2600  if (ok)
2601  *ok = true;
2602  if (d.type == t)
2603  return val;
2604 
2605  T ret;
2606  if (!handler->convert(&d, QVariant::Type(t), &ret, ok) && ok)
2607  *ok = false;
2608  return ret;
2609 }
double d
Definition: qnumeric_p.h:62
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QImageIOHandler * handler

◆ qt_convertToBool()

template<typename TInput , typename LiteralWrapper >
bool qt_convertToBool ( const QVariant::Private *const  d)
inline

Definition at line 616 of file qvariant.cpp.

617 {
618  TInput str = v_cast<TInput>(d)->toLower();
619  return !(str == LiteralWrapper("0") || str == LiteralWrapper("false") || str.isEmpty());
620 }
double d
Definition: qnumeric_p.h:62
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78

◆ qVariantToHelper()

template<typename T >
T qVariantToHelper ( const QVariant::Private &  d,
QVariant::Type  t,
const QVariant::Handler *  handler,
T *  = 0 
)
inline

Definition at line 2236 of file qvariant.cpp.

2238 {
2239  if (d.type == t)
2240  return *v_cast<T>(&d);
2241 
2242  T ret;
2243  handler->convert(&d, t, &ret, 0);
2244  return ret;
2245 }
double d
Definition: qnumeric_p.h:62
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
QImageIOHandler * handler

◆ streamDebug()

static void streamDebug ( QDebug  dbg,
const QVariant v 
)
static

Definition at line 1073 of file qvariant.cpp.

1074 {
1075  switch (v.userType()) {
1076  case QVariant::Int:
1077  dbg.nospace() << v.toInt();
1078  break;
1079  case QVariant::UInt:
1080  dbg.nospace() << v.toUInt();
1081  break;
1082  case QVariant::LongLong:
1083  dbg.nospace() << v.toLongLong();
1084  break;
1085  case QVariant::ULongLong:
1086  dbg.nospace() << v.toULongLong();
1087  break;
1088  case QMetaType::Float:
1089  dbg.nospace() << v.toFloat();
1090  break;
1092  dbg.nospace() << qvariant_cast<QObject *>(v);
1093  break;
1094  case QVariant::Double:
1095  dbg.nospace() << v.toDouble();
1096  break;
1097  case QVariant::Bool:
1098  dbg.nospace() << v.toBool();
1099  break;
1100  case QVariant::String:
1101  dbg.nospace() << v.toString();
1102  break;
1103  case QVariant::Char:
1104  dbg.nospace() << v.toChar();
1105  break;
1106  case QVariant::StringList:
1107  dbg.nospace() << v.toStringList();
1108  break;
1109  case QVariant::Map:
1110  dbg.nospace() << v.toMap();
1111  break;
1112  case QVariant::Hash:
1113  dbg.nospace() << v.toHash();
1114  break;
1115  case QVariant::List:
1116  dbg.nospace() << v.toList();
1117  break;
1118  case QVariant::Date:
1119  dbg.nospace() << v.toDate();
1120  break;
1121  case QVariant::Time:
1122  dbg.nospace() << v.toTime();
1123  break;
1124  case QVariant::DateTime:
1125  dbg.nospace() << v.toDateTime();
1126  break;
1127 #ifndef QT_BOOTSTRAPPED
1128  case QVariant::EasingCurve:
1129  dbg.nospace() << v.toEasingCurve();
1130  break;
1131 #endif
1132  case QVariant::ByteArray:
1133  dbg.nospace() << v.toByteArray();
1134  break;
1135 #ifndef QT_BOOTSTRAPPED
1136  case QVariant::Url:
1137  dbg.nospace() << v.toUrl();
1138  break;
1139 #endif
1140 #ifndef QT_NO_GEOM_VARIANT
1141  case QVariant::Point:
1142  dbg.nospace() << v.toPoint();
1143  break;
1144  case QVariant::PointF:
1145  dbg.nospace() << v.toPointF();
1146  break;
1147  case QVariant::Rect:
1148  dbg.nospace() << v.toRect();
1149  break;
1150  case QVariant::Size:
1151  dbg.nospace() << v.toSize();
1152  break;
1153  case QVariant::SizeF:
1154  dbg.nospace() << v.toSizeF();
1155  break;
1156  case QVariant::Line:
1157  dbg.nospace() << v.toLine();
1158  break;
1159  case QVariant::LineF:
1160  dbg.nospace() << v.toLineF();
1161  break;
1162  case QVariant::RectF:
1163  dbg.nospace() << v.toRectF();
1164  break;
1165 #endif
1166  case QVariant::BitArray:
1167  //dbg.nospace() << v.toBitArray();
1168  break;
1169  default:
1170  break;
1171  }
1172 }
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
QLine toLine() const
Returns the variant as a QLine if the variant has type() Line ; otherwise returns an invalid QLine...
Definition: qvariant.cpp:2494
QMap< QString, QVariant > toMap() const
Returns the variant as a QMap<QString, QVariant> if the variant has type() Map ; otherwise returns an...
Definition: qvariant.cpp:2281
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
QHash< QString, QVariant > toHash() const
Returns the variant as a QHash<QString, QVariant> if the variant has type() Hash ; otherwise returns ...
Definition: qvariant.cpp:2292
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
QSize toSize() const
Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize...
Definition: qvariant.cpp:2432
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
Definition: qvariant.cpp:2447
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
QEasingCurve toEasingCurve() const
Returns the variant as a QEasingCurve if the variant has type() EasingCurve ; otherwise returns a def...
Definition: qvariant.cpp:2366
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QLineF toLineF() const
Returns the variant as a QLineF if the variant has type() LineF ; otherwise returns an invalid QLineF...
Definition: qvariant.cpp:2478
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2725
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330
QChar toChar() const
Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an ...
Definition: qvariant.cpp:2579
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

Variable Documentation

◆ map_from_three

const ushort map_from_three[MapFromThreeCount]
static

Definition at line 2047 of file qvariant.cpp.

Referenced by QVariant::load(), and QVariant::save().

◆ qCanConvertMatrix

const quint32 qCanConvertMatrix[QVariant::LastCoreType+1]
static

Definition at line 2771 of file qvariant.cpp.

Referenced by QVariant::canConvert().

◆ qt_kernel_variant_handler

const QVariant::Handler qt_kernel_variant_handler
Initial value:
= {
0,
0,
0,
}
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
static void streamDebug(QDebug dbg, const QVariant &v)
Definition: qvariant.cpp:1073
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
Definition: qvariant.cpp:383
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
Definition: qvariant.cpp:627
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

Definition at line 1175 of file qvariant.cpp.

Referenced by qcoreVariantHandler().