7#include <QtCore/qatomic.h>
8#include <QtCore/qcompare.h>
9#include <QtCore/qcontainerfwd.h>
10#include <QtCore/qmetatype.h>
11#ifndef QT_NO_DEBUG_STREAM
12#include <QtCore/qdebug.h>
16#include <QtCore/q20type_traits.h>
17#include <QtCore/q23utility.h>
20#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1
21# include <QtCore/qlist.h>
22# include <QtCore/qstringlist.h>
23# include <QtCore/qbytearraylist.h>
24# include <QtCore/qhash.h>
25# include <QtCore/qmap.h>
26# include <QtCore/qobject.h>
31QT_ENABLE_P0846_SEMANTICS_FOR(get_if)
32QT_ENABLE_P0846_SEMANTICS_FOR(
get)
62template<>
constexpr inline bool qIsRelocatable<QVariant> =
true;
66 template <
typename T,
typename... Args>
67 using if_constructible = std::enable_if_t<
69 std::is_copy_constructible<q20::remove_cvref_t<T>>,
70 std::is_destructible<q20::remove_cvref_t<T>>,
71 std::is_constructible<q20::remove_cvref_t<T>, Args...>
76 using if_rvalue = std::enable_if_t<!std::is_reference_v<T>,
bool>;
78 struct CborValueStandIn {
qint64 n;
void *
c;
int t; };
86 static size_t computeAllocationSize(
size_t size,
size_t align);
93 const void *
data()
const {
return reinterpret_cast<const uchar *
>(
this) +
offset; }
99 static constexpr size_t MaxInternalSize = 3 *
sizeof(
void *);
100 template <
size_t S>
static constexpr bool FitsInInternalSize = S <= MaxInternalSize;
101 template<
typename T>
static constexpr bool CanUseInternalSpace =
107 size_t(
type->size) <= MaxInternalSize && size_t(
type->alignment) <=
alignof(double);
120 constexpr Private() noexcept : is_shared(
false), is_null(true), packedType(0) {}
122 template <
typename T>
explicit Private(std::piecewise_construct_t,
const T &
t);
125 {
return is_shared ?
data.shared->data() : &
data.data; }
128 template<
typename T>
const T &
get()
const
129 {
return *
static_cast<const T *
>(CanUseInternalSpace<T> ? &
data.data :
data.shared->data()); }
142#if QT_DEPRECATED_SINCE(6, 0)
146 Bool = QMetaType::Bool,
147 Int = QMetaType::Int,
148 UInt = QMetaType::UInt,
149 LongLong = QMetaType::LongLong,
150 ULongLong = QMetaType::ULongLong,
151 Double = QMetaType::Double,
152 Char = QMetaType::QChar,
153 Map = QMetaType::QVariantMap,
154 List = QMetaType::QVariantList,
155 String = QMetaType::QString,
156 StringList = QMetaType::QStringList,
157 ByteArray = QMetaType::QByteArray,
158 BitArray = QMetaType::QBitArray,
159 Date = QMetaType::QDate,
160 Time = QMetaType::QTime,
161 DateTime = QMetaType::QDateTime,
162 Url = QMetaType::QUrl,
163 Locale = QMetaType::QLocale,
164 Rect = QMetaType::QRect,
165 RectF = QMetaType::QRectF,
166 Size = QMetaType::QSize,
167 SizeF = QMetaType::QSizeF,
168 Line = QMetaType::QLine,
169 LineF = QMetaType::QLineF,
170 Point = QMetaType::QPoint,
171 PointF = QMetaType::QPointF,
172#if QT_CONFIG(regularexpression)
175 Hash = QMetaType::QVariantHash,
176#if QT_CONFIG(easingcurve)
177 EasingCurve = QMetaType::QEasingCurve,
179 Uuid = QMetaType::QUuid,
180#if QT_CONFIG(itemmodel)
181 ModelIndex = QMetaType::QModelIndex,
182 PersistentModelIndex = QMetaType::QPersistentModelIndex,
186 Font = QMetaType::QFont,
187 Pixmap = QMetaType::QPixmap,
188 Brush = QMetaType::QBrush,
189 Color = QMetaType::QColor,
190 Palette = QMetaType::QPalette,
191 Image = QMetaType::QImage,
192 Polygon = QMetaType::QPolygon,
193 Region = QMetaType::QRegion,
194 Bitmap = QMetaType::QBitmap,
195 Cursor = QMetaType::QCursor,
196#if QT_CONFIG(shortcut)
197 KeySequence = QMetaType::QKeySequence,
199 Pen = QMetaType::QPen,
200 TextLength = QMetaType::QTextLength,
201 TextFormat = QMetaType::QTextFormat,
202 Transform = QMetaType::QTransform,
203 Matrix4x4 = QMetaType::QMatrix4x4,
204 Vector2D = QMetaType::QVector2D,
205 Vector3D = QMetaType::QVector3D,
206 Vector4D = QMetaType::QVector4D,
207 Quaternion = QMetaType::QQuaternion,
208 PolygonF = QMetaType::QPolygonF,
209 Icon = QMetaType::QIcon,
212 SizePolicy = QMetaType::QSizePolicy,
215 LastType = 0xffffffff
224 template <
typename T,
typename ...Args>
225 using is_noexcept_constructible = std::conjunction<
226 std::bool_constant<Private::CanUseInternalSpace<T>>,
227 std::is_nothrow_constructible<T, Args...>
231 template <
typename T,
typename... Args,
232 if_constructible<T, Args...> =
true>
234 noexcept(is_noexcept_constructible<q20::remove_cvref_t<T>, Args...>
::value)
237 void *
data =
const_cast<void *
>(constData());
238 new (
data) T(std::forward<Args>(
args)...);
241 template <
typename T,
typename U,
typename... Args,
242 if_constructible<T, std::initializer_list<U> &, Args...> =
true>
243 explicit QVariant(std::in_place_type_t<T>, std::initializer_list<U> il, Args&&...
args)
244 noexcept(is_noexcept_constructible<q20::remove_cvref_t<T>,
245 std::initializer_list<U> &,
250 char *
data =
static_cast<char *
>(
const_cast<void *
>(constData()));
251 new (
data) T(il, std::forward<Args>(
args)...);
267#ifndef QT_BOOTSTRAPPED
272 QVariant(
const QHash<QString, QVariant> &
hash)
noexcept;
277 QVariant(
const QMap<QString, QVariant> &
map)
noexcept;
285 QVariant(
const QJsonValue &jsonValue)
noexcept(Private::FitsInInternalSize<
sizeof(CborValueStandIn)>);
287 QVariant(
QUuid uuid)
noexcept(Private::FitsInInternalSize<16>);
288#ifndef QT_NO_GEOM_VARIANT
304#ifndef QT_NO_CAST_FROM_ASCII
311#if !defined(Q_CC_GHS)
313 template <
typename T,
314 std::enable_if_t<std::disjunction_v<std::is_pointer<T>, std::is_member_pointer<T>>,
bool> =
false>
317 QVariant(
const volatile void *) =
delete;
320#if QT_CORE_REMOVED_SINCE(6, 5)
335 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(
QVariant)
340 int typeId()
const {
return metaType().id(); }
352#if QT_DEPRECATED_SINCE(6, 0)
354 bool canConvert(
int targetTypeId)
const
361 inline bool isValid()
const;
367 inline bool isDetached()
const;
369 int toInt(
bool *
ok =
nullptr)
const;
370 uint toUInt(
bool *
ok =
nullptr)
const;
376 qreal toReal(
bool *
ok =
nullptr)
const;
378#ifndef QT_BOOTSTRAPPED
383 QChar toChar()
const;
387 QList<QVariant>
toList()
const;
388 QMap<QString, QVariant>
toMap()
const;
389 QHash<QString, QVariant> toHash()
const;
391#ifndef QT_NO_GEOM_VARIANT
394 QRect toRect()
const;
395 QSize toSize()
const;
397 QLine toLine()
const;
402#if QT_CONFIG(regularexpression)
405#if QT_CONFIG(easingcurve)
408 QUuid toUuid()
const;
409#ifndef QT_BOOTSTRAPPED
416#if QT_CONFIG(itemmodel)
421#ifndef QT_NO_DATASTREAM
425#if QT_DEPRECATED_SINCE(6, 0)
435 int type =
d.type().id();
439 static const char *typeToName(
int typeId)
442 static Type nameToType(
const char *
name)
445 return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
452 {
return d.storage(); }
453 inline const void *
data()
const {
return constData(); }
456 template <
typename T>
457 void verifySuitableForEmplace()
459 static_assert(!std::is_reference_v<T>,
460 "QVariant does not support reference types");
461 static_assert(!std::is_const_v<T>,
462 "QVariant does not support const types");
463 static_assert(std::is_copy_constructible_v<T>,
464 "QVariant requires that the type is copyable");
465 static_assert(std::is_destructible_v<T>,
466 "QVariant requires that the type is destructible");
469 template <
typename T,
typename... Args>
470 T &emplaceImpl(Args&&...
args)
472 verifySuitableForEmplace<T>();
473 auto data =
static_cast<T *
>(prepareForEmplace(QMetaType::fromType<T>()));
478 template <
typename T,
typename... Args,
479 if_constructible<T, Args...> =
true>
482 return emplaceImpl<T>(std::forward<Args>(
args)...);
485 template <
typename T,
typename U,
typename... Args,
486 if_constructible<T, std::initializer_list<U> &, Args...> =
true>
489 return emplaceImpl<T>(
list, std::forward<Args>(
args)...);
492 template<
typename T,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, QVariant>>>
495 using VT = std::decay_t<T>;
496 QMetaType metaType = QMetaType::fromType<VT>();
498 if (isDetached() &&
d.type() == metaType) {
499 *
reinterpret_cast<VT *
>(
const_cast<void *
>(constData())) = std::forward<T>(avalue);
501 *
this = QVariant::fromValue<VT>(std::forward<T>(avalue));
512 *
this = std::move(avalue);
517 {
return qvariant_cast<T>(*
this); }
529 {
return qvariant_cast<T>(std::move(*
this)); }
531 template<
typename T, if_rvalue<T> = true>
537 noexcept(std::is_nothrow_copy_constructible_v<T> && Private::CanUseInternalSpace<T>)
538 -> std::enable_if_t<std::conjunction_v<std::is_copy_constructible<T>,
545 using Type = std::remove_cv_t<T>;
546 if constexpr (std::is_null_pointer_v<Type>)
548 else if constexpr (std::is_same_v<Type, QVariant>)
549 return std::forward<T>(
value);
550 else if constexpr (std::is_same_v<Type, std::monostate>)
552 QMetaType mt = QMetaType::fromType<Type>();
558 if constexpr (std::conjunction_v<std::is_move_constructible<Type>, std::negation<std::is_const<T>>>)
559 return moveConstruct(QMetaType::fromType<Type>(), std::addressof(
value));
561 return copyConstruct(mt, std::addressof(
value));
567 noexcept(std::is_nothrow_copy_constructible_v<T> && Private::CanUseInternalSpace<T>)
568 -> std::enable_if_t<std::is_copy_constructible_v<T> && std::is_destructible_v<T>,
QVariant>
573 if constexpr (std::is_null_pointer_v<T>)
574 return QVariant(QMetaType::fromType<std::nullptr_t>());
575 else if constexpr (std::is_same_v<T, QVariant>)
577 else if constexpr (std::is_same_v<T, std::monostate>)
579 return QVariant(QMetaType::fromType<T>(), std::addressof(
value));
582 template<
typename... Types>
585 return fromStdVariantImpl(
value);
588 template<
typename... Types>
591 return fromStdVariantImpl(std::move(
value));
598 {
return canConvert(QMetaType::fromType<T>()); }
602 {
return canView(QMetaType::fromType<T>()); }
607 template <
typename StdVariant>
608 static QVariant fromStdVariantImpl(StdVariant &&
v)
612 auto visitor = [](
auto &&
arg) {
615 return std::visit(visitor, std::forward<StdVariant>(
v));
619 {
return a.equals(
b); }
622#ifndef QT_NO_DEBUG_STREAM
623 template <
typename T>
630 template <
typename T>
634 if (!
v ||
v->d.type() != QMetaType::fromType<T>())
636 return static_cast<T*
>(
v->data());
638 template <
typename T>
642 if (!
v ||
v->d.is_null ||
v->d.type() != QMetaType::fromType<T>())
644 return static_cast<const T*
>(
v->data());
647#define Q_MK_GET(cvref) \
648 template <typename T> \
649 friend T cvref get(QVariant cvref v) \
651 if constexpr (std::is_const_v<T cvref>) \
652 Q_ASSERT(!v.d.is_null); \
653 Q_ASSERT(v.d.type() == QMetaType::fromType<q20::remove_cvref_t<T>>()); \
654 return static_cast<T cvref>(*get_if<T>(&v)); \
704#ifdef QT_NO_CAST_FROM_ASCII
706 inline QVariant(
const char *) =
delete;
719#ifndef QT_NO_DATASTREAM
723#if QT_DEPRECATED_SINCE(6, 0)
731 p =
static_cast<QVariant::Type
>(u);
737 s << static_cast<quint32>(
p);
755 QMetaType targetType = QMetaType::fromType<T>();
756 if (
v.d.type() == targetType)
758 if constexpr (std::is_same_v<T,std::remove_const_t<std::remove_pointer_t<T>>
const *>) {
759 using nonConstT = std::remove_const_t<std::remove_pointer_t<T>> *;
760 QMetaType nonConstTargetType = QMetaType::fromType<nonConstT>();
761 if (
v.d.type() == nonConstTargetType)
762 return v.d.get<nonConstT>();
772 QMetaType targetType = QMetaType::fromType<T>();
773 if (
v.d.type() == targetType) {
774 if constexpr (QVariant::Private::CanUseInternalSpace<T>) {
775 return std::move(*
reinterpret_cast<T *
>(
v.d.data.data));
777 if (
v.d.data.shared->ref.loadRelaxed() == 1)
778 return std::move(*
reinterpret_cast<T *
>(
v.d.data.shared->data()));
783 if constexpr (std::is_same_v<T, QVariant>) {
786 }
if constexpr (std::is_same_v<T,std::remove_const_t<std::remove_pointer_t<T>>
const *>) {
788 using nonConstT = std::remove_const_t<std::remove_pointer_t<T>> *;
789 QMetaType nonConstTargetType = QMetaType::fromType<nonConstT>();
790 if (
v.d.type() == nonConstTargetType)
791 return v.d.get<nonConstT>();
799# ifndef QT_NO_VARIANT
803 return *
reinterpret_cast<const QVariant *
>(
v.constData());
810#ifndef QT_NO_DEBUG_STREAM
811#if QT_DEPRECATED_SINCE(6, 0)
833template<
typename Po
inter>
837 const Pointer *m_pointer =
nullptr;
870template<
typename Po
inter>
874 const Pointer *m_pointer =
nullptr;
878 QVariantRef<Pointer>
operator*()
const {
return QVariantRef<Pointer>(m_pointer); }
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
\inmodule QtCore\compares equality \compareswith equality QLineF \endcompareswith
\variable Qt::partial_ordering::less
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtCore \reentrant
Emulated const pointer to QVariant based on a pointer.
QVariantPointer is a template class that emulates a pointer to QVariant based on a pointer.
QVariantPointer(const Pointer *pointer)
Constructs a QVariantPointer from the given pointer.
Pointer operator->() const
Dereferences and returns the pointer.
QVariantRef< Pointer > operator*() const
Dereferences the QVariantPointer to a QVariantRef.
The QVariantRef acts as a non-const reference to a QVariant.
QVariantRef(const Pointer *reference)
Creates a QVariantRef from an pointer.
QVariantRef & operator=(const QVariantRef &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
QVariantRef(const QVariantRef &)=default
QVariantRef & operator=(QVariantRef &&value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
QVariantRef(QVariantRef &&)=default
friend void swap(QVariantRef a, QVariantRef b)
QVariantRef & operator=(const QVariant &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
bool canView(QMetaType targetType) const
friend const T * get_if(const QVariant *v) noexcept
static QVariant fromMetaType(QMetaType type, const void *copy=nullptr)
QVariant(const QPersistentModelIndex &modelIndex) noexcept(false)
const void * data() const
Returns a pointer to the contained object as a generic void* that cannot be written to.
QVariant() noexcept
Constructs an invalid variant.
QVariant(std::in_place_type_t< T >, Args &&... args) noexcept(is_noexcept_constructible< q20::remove_cvref_t< T >, Args... >::value)
T view()
Returns a mutable view of template type {T} on the stored value.
QVariant(const QRegularExpression &re) noexcept
QVariant(QVariant &&other) noexcept
Move-constructs a QVariant instance, making it point at the same object that other was pointing to.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
void setValue(T &&avalue)
const DataPtr & data_ptr() const
void setValue(QVariant &&avalue)
Moves value over this QVariant.
bool canConvert() const
Returns true if the variant can be converted to the template type {T}, otherwise false.
static QVariant fromStdVariant(const std::variant< Types... > &value)
friend T * get_if(QVariant *v) noexcept
If v contains an object of type T, returns a pointer to the contained object, otherwise returns \null...
QT_ASCII_CAST_WARN QVariant(const char *str) noexcept(false)
Constructs a new variant with a string value of val.
QVariant(const QModelIndex &modelIndex) noexcept(Private::FitsInInternalSize< 8+2 *sizeof(quintptr)>)
static auto fromValue(const T &value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::is_copy_constructible_v< T > &&std::is_destructible_v< T >, QVariant >
Returns a QVariant containing a copy of value.
friend auto operator<<(const QDebug &debug, const T &variant) -> std::enable_if_t< std::is_same_v< T, QVariant >, QDebug >
int typeId() const
Returns the storage type of the value stored in the variant.
void setValue(const QVariant &avalue)
Copies value over this QVariant.
static QVariant fromStdVariant(std::variant< Types... > &&value)
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
bool canConvert(QMetaType targetType) const
T & emplace(Args &&... args)
bool canView() const
Returns true if a mutable view of the template type {T} can be created on this variant,...
friend bool comparesEqual(const QVariant &a, const QVariant &b)
QVariant(std::in_place_type_t< T >, std::initializer_list< U > il, Args &&... args) noexcept(is_noexcept_constructible< q20::remove_cvref_t< T >, std::initializer_list< U > &, Args... >::value)
T & emplace(std::initializer_list< U > list, Args &&... args)
QVariant(const QEasingCurve &easing) noexcept(false)
const void * constData() const
QHash< int, QWidget * > hash
[35multi]
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< float > toFloat(QByteArrayView a) noexcept
T * construct_at(T *ptr, Args &&... args)
void toByteArray(QByteArray &)
static jboolean copy(JNIEnv *, jobject)
#define Q_DECLARE_EQUALITY_COMPARABLE(...)
#define QT_WARNING_DISABLE_DEPRECATED
constexpr timespec operator*(const timespec &t1, int mul)
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
void uint64_t uint64_t uint64_t value2
static ControlElement< T > * ptr(QWidget *widget)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLsizei const void * pointer
static ISC_DATE toDate(QDate t)
static QList< QVariant > toList(char **buf, int count)
static ISC_TIME toTime(QTime t)
#define QT_ASCII_CAST_WARN
#define QT_DEPRECATED_VERSION_X_6_0(text)
#define QT_DEPRECATED_VERSION_6_0
static QStringList toStringList(const QJsonArray &jsonArray)
static int compare(quint64 a, quint64 b)
static int toInt(const QChar &qc, int R)
static double toDouble(Value v)
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &s, QVariant &p)
QVariant qvariant_cast< QVariant >(const QVariant &v)
Q_CORE_EXPORT QDataStream & operator<<(QDataStream &s, const QVariant &p)
void swap(QVariant &value1, QVariant &value2) noexcept
T qvariant_cast(const QVariant &)
QUrl url("example.com")
[constructor-url-reference]
value toMap().value(key)
[3]
char * toString(const MyType &t)
[31]
const void * data() const
static constexpr bool canUseInternalSpace(const QtPrivate::QMetaTypeInterface *type)
const void * storage() const
const QtPrivate::QMetaTypeInterface * typeInterface() const
uchar data[MaxInternalSize]
constexpr Private() noexcept
QT_BEGIN_NAMESPACE bool toBool(const QString &str)