📄 qvariant.cpp
字号:
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.*/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); }QVariant::QVariant(const QRegExp ®Exp) { create(RegExp, ®Exp); }/*! 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*//*! 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;}/* Attention! For dependency reasons, this table is duplicated in moc's generator.cpp. If you change one, change both. (Search for the word 'Attention' in generator.cpp)*/enum { CoreTypeCount = QVariant::RegExp + 1 };static const char* const core_type_map[CoreTypeCount] ={ 0, "bool", "int", "uint", "qlonglong", "qulonglong", "double", "QChar", "QVariantMap", "QVariantList", "QString", "QStringList", "QByteArray", "QBitArray", "QDate", "QTime", "QDateTime", "QUrl", "QLocale", "QRect", "QRectF", "QSize", "QSizeF", "QLine", "QLineF", "QPoint", "QPointF", "QRegExp"};enum { GuiTypeCount = QVariant::TextFormat - QVariant::Font + 2 };static const char* const gui_type_map[GuiTypeCount] ={ "QColorGroup", "QFont", "QPixmap", "QBrush", "QColor", "QPalette", "QIcon", "QImage", "QPolygon", "QRegion", "QBitmap", "QCursor", "QSizePolicy", "QKeySequence", "QPen", "QTextLength", "QTextFormat"};/*! Converts the enum representation of the storage type, \a typ, to its string representation.*/const char *QVariant::typeToName(Type typ){ if (typ == UserType) return "UserType"; if (typ < int(CoreTypeCount)) return core_type_map[typ]; if (typ >= QVariant::Font - 1 && typ <= QVariant::TextFormat) return gui_type_map[int(typ) - QVariant::Font + 1]; if (typ > QVariant::UserType ) return QMetaType::typeName(typ); return 0;}/*! 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) return Invalid; if (name[0] == '\0') 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 i; for (i = 1; i < CoreTypeCount; ++i) { if (strcmp(core_type_map[i], name) == 0) return (Type)i; } for (i = 0; i < GuiTypeCount; ++i) { if (strcmp(gui_type_map[i], name) == 0) return (Type)(i + QVariant::Font - 1); } if (QMetaType::type(name)) return UserType; return Invalid;}#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]; } 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 = false; handler->load(&d, s);}/*! 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 (tp == QVariant::UserType) { s << QMetaType::typeName(userType()); } handler->save(&d, s);}/*!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -