📄 qvariant.cpp
字号:
\fn QVariant::QVariant(const QBitArray &val) Constructs a new variant with a bitarray value, \a val.*//*! \fn QVariant::QVariant(const QPoint &val) Constructs a new variant with a point value of \a val. *//*! \fn QVariant::QVariant(const QPointF &val) Constructs a new variant with a point value of \a val. *//*! \fn QVariant::QVariant(const QRectF &val) Constructs a new variant with a rect value of \a val. *//*! \fn QVariant::QVariant(const QLineF &val) Constructs a new variant with a line value of \a val. *//*! \fn QVariant::QVariant(const QLine &val) Constructs a new variant with a line value of \a val. *//*! \fn QVariant::QVariant(const QRect &val) Constructs a new variant with a rect value of \a val. *//*! \fn QVariant::QVariant(const QSize &val) Constructs a new variant with a size value of \a val. *//*! \fn QVariant::QVariant(const QSizeF &val) Constructs a new variant with a size value of \a val. *//*! \fn QVariant::QVariant(const QUrl &val) Constructs a new variant with a url value of \a val. *//*! \fn QVariant::QVariant(int val) Constructs a new variant with an integer value, \a val.*//*! \fn QVariant::QVariant(uint val) Constructs a new variant with an unsigned integer value, \a val.*//*! \fn QVariant::QVariant(qlonglong val) Constructs a new variant with a long long integer value, \a val.*//*! \fn QVariant::QVariant(qulonglong val) Constructs a new variant with an unsigned long long integer value, \a val.*//*! \fn QVariant::QVariant(bool val) Constructs a new variant with a boolean value, \a val. The integer argument is a dummy, necessary for compatibility with some compilers.*//*! \fn QVariant::QVariant(double val) Constructs a new variant with a floating point value, \a val.*//*! \fn QVariant::QVariant(const QList<QVariant> &val) Constructs a new variant with a list value, \a val.*//*! \fn QVariant::QVariant(const QChar &c) Constructs a new variant with a char value, \a c.*//*! \fn QVariant::QVariant(const QLocale &l) Constructs a new variant with a locale value, \a l.*//*! \fn QVariant::QVariant(const QRegExp ®Exp) Constructs a new variant with the regexp value \a regExp.*//*! \since 4.2 \fn QVariant::QVariant(Qt::GlobalColor color) Constructs a new variant of type QVariant::Color and initializes it with \a color. This is a convenience constructor that allows \c{QVariant(Qt::blue);} to create a valid QVariant storing a QColor. Note: This constructor will assert if the application does not link to the Qt GUI library. */QVariant::QVariant(Type type){ create(type, 0); }QVariant::QVariant(int typeOrUserType, const void *copy){ create(typeOrUserType, copy); d.is_null = false; }QVariant::QVariant(int val){ d.is_null = false; d.type = Int; d.data.i = val; }QVariant::QVariant(uint val){ d.is_null = false; d.type = UInt; d.data.u = val; }QVariant::QVariant(qlonglong val){ d.is_null = false; d.type = LongLong; d.data.ll = val; }QVariant::QVariant(qulonglong val){ d.is_null = false; d.type = ULongLong; d.data.ull = val; }QVariant::QVariant(bool val){ d.is_null = false; d.type = Bool; d.data.b = val; }QVariant::QVariant(double val){ d.is_null = false; d.type = Double; d.data.d = val; }QVariant::QVariant(const QByteArray &val){ create(ByteArray, &val); }QVariant::QVariant(const QBitArray &val){ create(BitArray, &val); }QVariant::QVariant(const QString &val){ create(String, &val); }QVariant::QVariant(const QChar &val){ create (Char, &val); }QVariant::QVariant(const QLatin1String &val){ QString str(val); create(String, &str); }QVariant::QVariant(const QStringList &val){ create(StringList, &val); }QVariant::QVariant(const QDate &val){ create(Date, &val); }QVariant::QVariant(const QTime &val){ create(Time, &val); }QVariant::QVariant(const QDateTime &val){ create(DateTime, &val); }QVariant::QVariant(const QList<QVariant> &list){ create(List, &list); }QVariant::QVariant(const QMap<QString, QVariant> &map){ create(Map, &map); }#ifndef QT_NO_GEOM_VARIANTQVariant::QVariant(const QPoint &pt) { create(Point, &pt); }QVariant::QVariant(const QPointF &pt) { create (PointF, &pt); }QVariant::QVariant(const QRectF &r) { create (RectF, &r); }QVariant::QVariant(const QLineF &l) { create (LineF, &l); }QVariant::QVariant(const QLine &l) { create (Line, &l); }QVariant::QVariant(const QRect &r) { create(Rect, &r); }QVariant::QVariant(const QSize &s) { create(Size, &s); }QVariant::QVariant(const QSizeF &s) { create(SizeF, &s); }#endifQVariant::QVariant(const QUrl &u) { create(Url, &u); }QVariant::QVariant(const QLocale &l) { create(Locale, &l); }#ifndef QT_NO_REGEXPQVariant::QVariant(const QRegExp ®Exp) { create(RegExp, ®Exp); }#endifQVariant::QVariant(Qt::GlobalColor color) { create(62, &color); }/*! Returns the storage type of the value stored in the variant. Usually it's best to test with canConvert() whether the variant can deliver the data type you are interested in.*/QVariant::Type QVariant::type() const{ return d.type >= QMetaType::User ? UserType : static_cast<Type>(d.type);}/*! Returns the storage type of the value stored in the variant. For non-user types, this is the same as type(). \sa type()*/int QVariant::userType() const{ return d.type;}/*! Assigns the value of the variant \a variant to this variant.*/QVariant& QVariant::operator=(const QVariant &variant){ if (this == &variant) return *this; clear(); if (variant.d.is_shared) { variant.d.data.shared->ref.ref(); d = variant.d; } else if (variant.d.type > Char) { d.type = variant.d.type; handler->construct(&d, variant.constData()); d.is_null = variant.d.is_null; } else { d = variant.d; } return *this;}/*! \fn void QVariant::detach() \internal*/void QVariant::detach(){ if (!d.is_shared || d.data.shared->ref == 1) return; Private dd; dd.type = d.type; handler->construct(&dd, constData()); dd.data.shared = qAtomicSetPtr(&d.data.shared, dd.data.shared); if (!dd.data.shared->ref.deref()) handler->clear(&dd);}/*! \fn bool QVariant::isDetached() const \internal*/// Qt 5 ###: change typeName()(and froends= to return a QString. Suggestion from Harald./*! Returns the name of the type stored in the variant. The returned strings describe the C++ datatype used to store the data: for example, "QFont", "QString", or "QVariantList". An Invalid variant returns 0.*/const char *QVariant::typeName() const{ return typeToName(Type(d.type));}/*! Convert this variant to type Invalid and free up any resources used.*/void QVariant::clear(){ if (!d.is_shared || !d.data.shared->ref.deref()) handler->clear(&d); d.type = Invalid; d.is_null = true; d.is_shared = false;}/*! Converts the enum representation of the storage type, \a typ, to its string representation. Returns a null pointer if the type is QVariant::Invalid or doesn't exist.*/const char *QVariant::typeToName(Type typ){ if (typ == Invalid) return 0; if (typ == UserType) return "UserType"; return QMetaType::typeName(typ);}/*! Converts the string representation of the storage type given in \a name, to its enum representation. If the string representation cannot be converted to any enum representation, the variant is set to \c Invalid.*/QVariant::Type QVariant::nameToType(const char *name){ if (!name || !*name) return Invalid; if (strcmp(name, "Q3CString") == 0) return ByteArray; if (strcmp(name, "Q_LLONG") == 0) return LongLong; if (strcmp(name, "Q_ULLONG") == 0) return ULongLong; if (strcmp(name, "QIconSet") == 0) return Icon; if (strcmp(name, "UserType") == 0) return UserType; int metaType = QMetaType::type(name); return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;}#ifndef QT_NO_DATASTREAMenum { MapFromThreeCount = 35 };static const uint map_from_three[MapFromThreeCount] ={ QVariant::Invalid, QVariant::Map, QVariant::List, QVariant::String, QVariant::StringList, QVariant::Font, QVariant::Pixmap, QVariant::Brush, QVariant::Rect, QVariant::Size, QVariant::Color, QVariant::Palette, 63, // ColorGroup QVariant::Icon, QVariant::Point, QVariant::Image, QVariant::Int, QVariant::UInt, QVariant::Bool, QVariant::Double, QVariant::ByteArray, QVariant::Polygon, QVariant::Region, QVariant::Bitmap, QVariant::Cursor, QVariant::SizePolicy, QVariant::Date, QVariant::Time, QVariant::DateTime, QVariant::ByteArray, QVariant::BitArray, QVariant::KeySequence, QVariant::Pen, QVariant::LongLong, QVariant::ULongLong};/*! Internal function for loading a variant from stream \a s. Use the stream operators instead. \internal*/void QVariant::load(QDataStream &s){ clear(); quint32 u; s >> u; if (s.version() < QDataStream::Qt_4_0) { if (u >= MapFromThreeCount) return; u = map_from_three[u]; } qint8 is_null = false; if (s.version() >= QDataStream::Qt_4_2) s >> is_null; if (u == QVariant::UserType) { QByteArray name; s >> name; u = QMetaType::type(name); if (!u) qFatal("QVariant::load(QDataStream &s): type %s unknown to QVariant.", name.data()); } create(static_cast<int>(u), 0); d.is_null = is_null; if (d.type == QVariant::Invalid) { // Since we wrote something, we should read something QString x; s >> x; d.is_null = true; return; } // const cast is save since we operate on a newly constructed variant if (!QMetaType::load(s, d.type, const_cast<void *>(::constData(d)))) { Q_ASSERT_X(false, "QVariant::load", "Invalid type to load"); qWarning("QVariant::load: unable to load type %d.", d.type); }}/*! Internal function for saving a variant to the stream \a s. Use the stream operators instead. \internal*/void QVariant::save(QDataStream &s) const{ quint32 tp = type(); if (s.version() < QDataStream::Qt_4_0) { int i; for (i = 0; i < MapFromThreeCount; ++i) { if (map_from_three[i] == tp) { tp = i; break; } } if (i == MapFromThreeCount) { s << QVariant(); return; } } s << tp; if (s.version() >= QDataStream::Qt_4_2) s << qint8(d.is_null); if (tp == QVariant::UserType) { s << QMetaType::typeName(userType()); } if (d.type == QVariant::Invalid) { s << QString(); return; } if (!QMetaType::save(s, d.type, ::constData(d))) { Q_ASSERT_X(false, "QVariant::save", "Invalid type to save"); qWarning("QVariant::save: unable to save type %d.", d.type); }}/*! Reads a variant \a p from the stream \a s. \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream& operator>>(QDataStream &s, QVariant &p){ p.load(s); return s;}/*! Writes a variant \a p to the stream \a s.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -