Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qjsmanagedvalue.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QJSMANAGEDVALUE_H
5#define QJSMANAGEDVALUE_H
6
7#include <QtQml/qtqmlglobal.h>
8#include <QtQml/qjsprimitivevalue.h>
9#include <QtQml/qjsvalue.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace QV4 {
14struct Value;
15struct ExecutionEngine;
16}
17
18class QJSEngine;
19class Q_QML_EXPORT QJSManagedValue
20{
21 Q_DISABLE_COPY(QJSManagedValue)
22public:
23 enum Type {
24 Undefined,
25 Boolean,
26 Number,
27 String,
28 Object,
29 Symbol,
30 Function
31 };
32
33 QJSManagedValue() = default;
34 QJSManagedValue(QJSValue value, QJSEngine *engine);
35 QJSManagedValue(const QJSPrimitiveValue &value, QJSEngine *engine);
36 QJSManagedValue(const QVariant &variant, QJSEngine *engine);
37 QJSManagedValue(const QString &string, QJSEngine *engine);
38
39 ~QJSManagedValue();
40 QJSManagedValue(QJSManagedValue &&other);
41 QJSManagedValue &operator=(QJSManagedValue &&other);
42
43 bool equals(const QJSManagedValue &other) const;
44 bool strictlyEquals(const QJSManagedValue &other) const;
45
46 QJSEngine *engine() const;
47
49 void setPrototype(const QJSManagedValue &prototype);
50
51 Type type() const;
52
53 // Compatibility with QJSValue
54 bool isUndefined() const { return type() == Undefined; }
55 bool isBoolean() const { return type() == Boolean; }
56 bool isNumber() const { return type() == Number; }
57 bool isString() const { return type() == String; }
58 bool isObject() const { return type() == Object; }
59 bool isSymbol() const { return type() == Symbol; }
60 bool isFunction() const { return type() == Function; }
61
62 // Special case of Number
63 bool isInteger() const;
64
65 // Selected special cases of Object
66 bool isNull() const;
67 bool isRegularExpression() const;
68 bool isArray() const;
69 bool isUrl() const;
70 bool isVariant() const;
71 bool isQObject() const;
72 bool isQMetaObject() const;
73 bool isDate() const;
74 bool isError() const;
75 bool isJsMetaType() const;
76
77 // Native type transformations
78 QString toString() const;
79 double toNumber() const;
80 bool toBoolean() const;
81
82 // Variant-like type transformations
84 QJSValue toJSValue() const;
85 QVariant toVariant() const;
86
87 // Special cases
88 int toInteger() const;
90 QUrl toUrl() const;
91 QObject *toQObject() const;
92 const QMetaObject *toQMetaObject() const;
93 QDateTime toDateTime() const;
94
95 // Properties of objects
96 bool hasProperty(const QString &name) const;
97 bool hasOwnProperty(const QString &name) const;
98 QJSValue property(const QString &name) const;
99 void setProperty(const QString &name, const QJSValue &value);
100 bool deleteProperty(const QString &name);
101
102 // ### Qt 7 use qsizetype instead.
103 // Array indexing
104 bool hasProperty(quint32 arrayIndex) const;
105 bool hasOwnProperty(quint32 arrayIndex) const;
106 QJSValue property(quint32 arrayIndex) const;
107 void setProperty(quint32 arrayIndex, const QJSValue &value);
108 bool deleteProperty(quint32 arrayIndex);
109
110 // Calling functions
111 QJSValue call(const QJSValueList &arguments = {}) const;
112 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments = {}) const;
113 QJSValue callAsConstructor(const QJSValueList &arguments = {}) const;
114
115 // JavaScript metatypes
118 QJSManagedValue jsMetaInstantiate(const QJSValueList &values = {}) const;
119
120private:
121 friend class QJSValue;
122 friend class QJSEngine;
124
125 QJSManagedValue(QV4::ExecutionEngine *engine);
126 QV4::Value *d = nullptr;
127};
128
129QT_END_NAMESPACE
130
131#endif
\inmodule QtQml
QJSManagedValue(QJSValue value, QJSEngine *engine)
Creates a QJSManagedValue from value, using the heap of engine.
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
bool deleteProperty(quint32 arrayIndex)
Deletes the value stored at arrayIndex from this QJSManagedValue.
QJSManagedValue()=default
Creates a QJSManagedValue that represents the JavaScript undefined value.
friend class QJSEngine
QJSValue toJSValue() const
Copies this QJSManagedValue into a new QJSValue.
QJSManagedValue jsMetaType() const
bool isBoolean() const
Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
const QMetaObject * toQMetaObject() const
If this QJSManagedValue holds a QMetaObject pointer, returns it.
QStringList jsMetaMembers() const
bool isArray() const
Returns true if this value represents a JavaScript Array object, or false otherwise.
bool strictlyEquals(const QJSManagedValue &other) const
Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
bool hasProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
QJSValue call(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments,...
QObject * toQObject() const
If this QJSManagedValue holds a QObject pointer, returns it.
bool isRegularExpression() const
Returns true if this value represents a JavaScript regular expression object, or false otherwise.
QJSValue property(const QString &name) const
Returns the property name of this QJSManagedValue.
QJSManagedValue jsMetaInstantiate(const QJSValueList &values={}) const
bool hasOwnProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
QVariant toVariant() const
Copies this QJSManagedValue into a new QVariant.
QJSManagedValue(const QJSPrimitiveValue &value, QJSEngine *engine)
Creates a QJSManagedValue from value using the heap of engine.
bool hasProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
double toNumber() const
Converts the manged value to a number.
QJSValue callAsConstructor(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the give...
bool isVariant() const
Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.
bool isFunction() const
Returns true if the type of this QJSManagedValue is function, false otherwise.
QRegularExpression toRegularExpression() const
If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularE...
QJSManagedValue prototype() const
Returns the prototype for this QJSManagedValue.
bool isUndefined() const
Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
bool isDate() const
Returns true if this value represents a JavaScript Date object, or false otherwise.
bool equals(const QJSManagedValue &other) const
Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
QJSPrimitiveValue toPrimitive() const
Converts the manged value to a QJSPrimitiveValue.
bool deleteProperty(const QString &name)
Deletes the property name from this QJSManagedValue.
bool isQMetaObject() const
Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap,...
QDateTime toDateTime() const
If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
int toInteger() const
Converts the manged value to an integer.
QString toString() const
Converts the manged value to a string.
QUrl toUrl() const
If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
bool isQObject() const
Returns true if this value represents a QObject pointer managed on the JavaScript heap,...
bool hasOwnProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
void setPrototype(const QJSManagedValue &prototype)
Sets the prototype of this QJSManagedValue to prototype.
bool isUrl() const
Returns true if this value represents a JavaScript Url object, or false otherwise.
bool isInteger() const
Returns true if this QJSManagedValue holds an integer value, or false otherwise.
bool isNumber() const
Returns true if the type of this QJSManagedValue is number, or false otherwise.
bool isSymbol() const
Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
bool isObject() const
Returns true if the type of this QJSManagedValue is object, or false otherwise.
void setProperty(const QString &name, const QJSValue &value)
Sets the property name to value on this QJSManagedValue.
bool toBoolean() const
Converts the manged value to a boolean.
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given a...
bool isJsMetaType() const
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const
virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value)
QQmlEngine * engine() const
Return the QQmlEngine this incubation controller is set on, or 0 if it has not been set on any engine...
bool isError() const
Returns true if the incubator's status() is Error.
bool isNull() const
Returns true if the incubator's status() is Null.
Method & operator=(Method &&) noexcept
Move-assigns other to this Method instance.
Definition qqmlsa.cpp:624
Definition qjsvalue.h:23