4#include <QtQml/private/qjsvalue_p.h>
5#include <QtQml/private/qqmlglobal_p.h>
6#include <QtQml/private/qqmlmetatype_p.h>
7#include <QtQml/qqmlengine.h>
9#include <QtCore/private/qvariant_p.h>
10#include <QtCore/qcoreapplication.h>
11#include <QtCore/qdebug.h>
12#include <QtCore/qstringlist.h>
19 switch (metaType.
id()) {
22 case QMetaType::Nullptr:
26 case QMetaType::LongLong:
27 case QMetaType::ULongLong:
28 case QMetaType::Float:
29 case QMetaType::Double:
31 case QMetaType::ULong:
32 case QMetaType::Short:
33 case QMetaType::UShort:
35 case QMetaType::SChar:
36 case QMetaType::UChar:
37 case QMetaType::QChar:
38 case QMetaType::QString:
40 case QMetaType::QDateTime:
41 case QMetaType::QDate:
42 case QMetaType::QTime:
44 case QMetaType::QRegularExpression:
45 case QMetaType::QByteArray:
46 case QMetaType::QLocale:
53 if (metaType == QMetaType::fromType<QJSValue>())
57 if (metaType.
flags() &
86 return d->data.shared->data();
96template<
typename Allocate>
98 const QMetaObject *targetMetaObject,
int ctorIndex,
void *
source, Allocate &&allocate)
101 Q_ASSERT_X(ctor.parameterCount() == 1,
"fromVerifiedType",
102 "Value type constructor must take exactly one argument");
107template<
typename Allocate,
typename Retrieve>
109 const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve)
113 if (ctor.parameterCount() != 1)
116 const QMetaType parameterType = ctor.parameterMetaType(0);
118 if (retrieve(parameterType, [&](
QMetaType sourceMetaType,
void *sourceData) {
119 if (sourceMetaType == parameterType) {
125 if (
const QMetaObject *sourceMetaObject = sourceMetaType.metaObject();
126 sourceMetaObject && sourceMetaObject->inherits(parameterMetaObject)) {
152template<
typename Allocate>
157 targetMetaObject, std::forward<Allocate>(allocate),
158 [&](
QMetaType parameterType,
auto callback) {
164template<
typename Allocate>
174template<
typename Allocate>
177 for (
int i = 0,
end =
mo->constructorCount();
i <
end; ++
i) {
179 if (ctor.parameterCount() != 1)
182 if (ctor.parameterMetaType(0) == QMetaType::fromType<QString>()) {
191template<
typename Get,
typename Convert>
197 if (
property.metaType() == propertyType) {
210 propertyType, converted.
data())) {
234 if (v4PropValue->isUndefined())
247 if (
property.metaType() == propertyType) {
260 propertyType, converted.
data())) {
266 <<
QLatin1String(
"Could not convert %1 to %2 for property %3")
275 if (!
source.isObject() || !targetMetaObject)
283template<
typename Read>
291 const int sourceProperty = sourceMetaObject->indexOfProperty(metaProperty.
name());
295 if (sourceProperty == -1)
299 QVariant property =
read(sourceMetaObject, sourceProperty);
300 if (
property.metaType() == propertyType) {
313 propertyType, converted.
data())) {
319 <<
QLatin1String(
"Could not convert %1 to %2 for property %3")
331 return sourceMetaObject->property(sourceProperty).read(source);
338 if (!
source || !targetMetaObject)
350 if (!
source || !sourceMetaObject || !targetMetaObject)
355 targetMetaObject,
result.data(), sourceMetaObject,
357 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
362template<
typename Map>
376 if (
property.metaType() == propertyType) {
389 propertyType, converted.
data())) {
395 <<
QLatin1String(
"Could not convert %1 to %2 for property %3")
401template<
typename Map>
413 if (!targetMetaObject)
416 if (
source.metaType() == QMetaType::fromType<QJSValue>()) {
422 if (
source.metaType() == QMetaType::fromType<QVariantMap>()) {
424 targetMetaObject, targetMetaType,
428 if (
source.metaType() == QMetaType::fromType<QVariantHash>()) {
430 targetMetaObject, targetMetaType,
438 return byProperties(targetMetaObject, targetMetaType, sourceMeta,
source.constData());
443template<
typename Allocate,
typename DefaultConstruct>
446 Allocate &&allocate, DefaultConstruct &&defaultConstruct)
448 const auto warn = [&](
const QMetaObject *targetMetaObject) {
450 <<
"Could not find any constructor for value type"
451 << targetMetaObject->className() <<
"to call with value"
452 <<
source.toQStringNoThrow();
464 warn(targetMetaObject);
471 warn(targetMetaObject);
479 if (resultType == targetType.
typeId()) {
488template<
typename Allocate,
typename DefaultConstruct>
491 Allocate &&allocate, DefaultConstruct &&defaultConstruct)
494 const auto warn = [&](
const QMetaObject *targetMetaObject) {
496 <<
"Could not find any constructor for value type"
497 << targetMetaObject->className() <<
"to call with value" <<
source;
505 targetMetaObject, defaultConstruct(), sourceMetaObject,
507 return sourceMetaObject->property(sourceProperty).readOnGadget(
source);
512 if (sourceMetaType == QMetaType::fromType<QVariantMap>()) {
514 targetMetaObject, defaultConstruct(),
519 if (sourceMetaType == QMetaType::fromType<QVariantHash>()) {
521 targetMetaObject, defaultConstruct(),
528 targetMetaObject, defaultConstruct(),
539 return callback(sourceMetaType,
source);
543 warn(targetMetaObject);
561 if (sourceMetaType == QMetaType::fromType<QJSValue>()) {
572 [targetMetaType,
target]() {
573 targetMetaType.destruct(
target);
596 targetMetaType.destruct(
target);
612 targetType,
source, [&]() {
615 target = align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
616 ?
operator new(metaType.
sizeOf(), std::align_val_t(align))
617 :
operator new(metaType.
sizeOf());
631 int ctorIndex,
void *ctorArg)
641 if (
const auto valueTypeFunction =
type.createValueTypeFunction()) {
643 if (
result.metaType() == metaType)
662 if (
type.canConstructValueType()) {
680 <<
"Could not find any constructor for value type"
681 <<
mo->className() <<
"to call with value" <<
s.toQStringNoThrow();
684 if (
type.canPopulateValueType()) {
689 if (
type.canConstructValueType()) {
695 }
else if (
type.canConstructValueType()) {
719 <<
"Could not find any constructor for value type"
720 <<
mo->className() <<
"to call with value" <<
s;
723 if (
type.canPopulateValueType()) {
728 if (
type.canConstructValueType()) {
734 }
else if (
type.canConstructValueType()) {
772 qWarning() <<
"Warning: QQml_colorProvider: no color provider has been set!";
914 return (ddata && ddata->propertyCache) ? ddata :
nullptr;
921 return ddata->propertyCache->firstCppMetaObject()->inherits(
mo);
922 return object->metaObject()->inherits(
mo);
936 for (
const QQmlPropertyCache *propertyCache = ddata->propertyCache.data(); propertyCache;
937 propertyCache = propertyCache->parent().data()) {
939 if (typeMetaObject) {
946 if (
const QMetaObject *objectMetaObject = propertyCache->metaObject())
947 return objectMetaObject->inherits(typeMetaObject);
953 if (propertyCache == typePropertyCache.
data())
961 return object->metaObject()->inherits(typeMetaObject
963 : (typePropertyCache ? typePropertyCache->createMetaObject() :
nullptr));
968#include "moc_qqmlglobal_p.cpp"
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static QStringList arguments()
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
static QV4::ReturnedValue asReturnedValue(const QJSValue *jsval)
The QJSValue class acts as a container for Qt/JavaScript data types.
QString arg(Args &&...args) const
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void setDomain(const QString &arg)
void setOrganization(const QString &arg)
void setVersion(const QString &arg)
void setName(const QString &arg)
void organizationChanged()
QQmlApplication(QObject *parent=nullptr)
virtual QVariant colorFromString(const QString &, bool *)
virtual QVariant lighter(const QVariant &, qreal)
virtual QVariant tint(const QVariant &, const QVariant &)
virtual QVariant fromRgbF(double, double, double, double)
virtual unsigned rgbaFromString(const QString &, bool *)
virtual QVariant fromHsvF(double, double, double, double)
virtual QVariant fromHslF(double, double, double, double)
virtual ~QQmlColorProvider()
virtual QVariant darker(const QVariant &, qreal)
virtual QVariant alpha(const QVariant &, qreal)
static QQmlData * get(QObjectPrivate *priv, bool create)
virtual ~QQmlGuiProvider()
virtual bool openUrlExternally(const QUrl &)
virtual QStringList fontFamilies()
virtual QQmlApplication * application(QObject *parent)
virtual QObject * styleHints()
virtual QString pluginName() const
virtual QObject * inputMethod()
const QMetaObject * metaObjectForValueType() const
bool canPopulateValueType() const
CreateValueTypeFunc createValueTypeFunction() const
bool canConstructValueType() const
static bool populateValueType(QMetaType targetMetaType, void *target, const QV4::Value &source)
static Q_QML_EXPORT void * heapCreateValueType(const QQmlType &targetType, const QV4::Value &source)
static QVariant constructValueType(QMetaType targetMetaType, const QMetaObject *targetMetaObject, int ctorIndex, void *ctorArg)
static QVariant createValueType(const QJSValue &, QMetaType)
const_iterator constEnd() const noexcept
const_iterator constFind(const T &value) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QMetaType metaType() const
QSet< QString >::iterator it
Combined button and popup list for selecting options.
Scoped< String > ScopedString
QList< QString > QStringList
Constructs a string list that contains the given string, str.
static QDBusError::ErrorType get(const char *name)
GLsizei GLsizei GLchar * source
static QQmlGuiProvider ** getGuiProvider(void)
Q_AUTOTEST_EXPORT QQmlGuiProvider * QQml_guiProvider(void)
static void callConstructor(const QMetaObject *targetMetaObject, int i, void *source, void *target)
static QQmlGuiProvider * guiProvider
static void fromVerifiedType(const QMetaObject *targetMetaObject, int ctorIndex, void *source, Allocate &&allocate)
static void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const QV4::Value &source)
static QVariant fromJSValue(const QQmlType &type, const QJSValue &s, QMetaType metaType)
Q_QML_EXPORT QQmlGuiProvider * QQml_setGuiProvider(QQmlGuiProvider *newProvider)
static bool doWriteProperty(const QMetaProperty &metaProperty, void *target, Get &&get, Convert &&convert)
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
Q_QML_EXPORT QQmlColorProvider * QQml_setColorProvider(QQmlColorProvider *newProvider)
static QQmlColorProvider * colorProvider
static QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType metaType, const QV4::Value &source)
Q_AUTOTEST_EXPORT QQmlColorProvider * QQml_colorProvider(void)
static QQmlColorProvider ** getColorProvider(void)
static bool fromMatchingType(const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve)
bool qmlobject_can_cpp_cast(QObject *object, const QMetaObject *mo)
static const QQmlData * ddata_for_cast(QObject *object)
bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type)
bool createOrConstructValueType(const QQmlType &targetType, const QV4::Value &source, Allocate &&allocate, DefaultConstruct &&defaultConstruct)
static void * createVariantData(QMetaType type, QVariant *variant)
static QT_BEGIN_NAMESPACE bool isConstructibleMetaType(const QMetaType metaType)
#define Q_ASSERT_X(cond, x, msg)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
#define Q_AUTOTEST_EXPORT
ReturnedValue read(const char *data)
Heap::String * newString(char16_t c)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
static PrivateShared * create(size_t size, size_t align)
static constexpr bool canUseInternalSpace(const QtPrivate::QMetaTypeInterface *type)