15#include <QtCore/qvarlengtharray.h>
16#include <private/qmetaobject_p.h>
17#include <QtCore/qdebug.h>
134 d->m_data->clearPublicContext();
146 return d->m_data->isValid();
156 return d->m_data->engine();
167 if (QQmlRefPointer<QQmlContextData>
parent =
d->m_data->
parent())
168 return parent->asQQmlContext();
178 return d->m_data->contextObject();
191 QQmlRefPointer<QQmlContextData>
data =
d->m_data;
193 if (
data->isInternal()) {
194 qWarning(
"QQmlContext: Cannot set context object for internal context.");
198 if (!
data->isValid()) {
199 qWarning(
"QQmlContext: Cannot set context object on invalid context.");
203 data->setContextObject(
object);
204 data->refreshExpressions();
216 if (
d->notifyIndex() == -1)
219 QQmlRefPointer<QQmlContextData>
data =
d->m_data;
221 if (
data->isInternal()) {
222 qWarning(
"QQmlContext: Cannot set property on internal context.");
226 if (!
data->isValid()) {
227 qWarning(
"QQmlContext: Cannot set property on invalid context.");
232 qWarning(
"QQmlContext: Using numbers as context properties will be disallowed in a future Qt version.");
236 int idx =
data->propertyIndex(
name);
238 data->addPropertyNameAndIndex(
name,
data->numIdValues() +
d->numPropertyValues());
239 d->appendPropertyValue(
value);
240 data->refreshExpressions();
242 d->setPropertyValue(idx,
value);
246 if (
auto *
obj = qvariant_cast<QObject *>(
value)) {
284 QQmlRefPointer<QQmlContextData>
data =
d->m_data;
286 QQmlRefPointer<QQmlContextData> childContexts =
data->takeChildContexts();
291 data->setExpressions(expressions);
292 data->setChildContexts(childContexts);
293 data->refreshExpressions();
335 const QQmlRefPointer<QQmlContextData>
data =
d->m_data;
337 const int idx =
data->propertyIndex(
name);
348 if (idx >=
d->numPropertyValues())
351 return d->propertyValue(idx);
375 return d->m_data->findObjectId(
object);
395 QQmlRefPointer<QQmlContextData>
data =
d->m_data;
396 if (
const int propertyIndex =
data->propertyIndex(
name); propertyIndex >= 0) {
397 const int numPropertyValues =
d->numPropertyValues();
398 if (propertyIndex < numPropertyValues)
399 return qvariant_cast<QObject *>(
d->propertyValue(propertyIndex));
400 return data->idValue(propertyIndex - numPropertyValues);
406 return qvariant_cast<QObject *>(
result);
421 return d->m_data->resolvedUrl(
src);
446 return d->m_data->baseUrl();
467 int contextProperty = (int)(
quintptr)prop->data;
469 if (
d->propertyValue(contextProperty).userType() != qMetaTypeId<QList<QObject*> >())
472 return ((
const QList<QObject> *)
d->propertyValue(contextProperty).constData())->
size();
479 int contextProperty = (int)(
quintptr)prop->data;
481 if (
d->propertyValue(contextProperty).userType() != qMetaTypeId<QList<QObject*> >())
484 return ((
const QList<QObject*> *)
d->propertyValue(contextProperty).constData())->
at(
index);
494 if (qvariant_cast<QObject *>(
propertyValue(idx)) != destroyed)
509QQmlContextPrivate::QQmlContextPrivate(
510 QQmlContext *publicContext,
const QQmlRefPointer<QQmlContextData> &parent,
520#include "moc_qqmlcontext.cpp"
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
The QJSValue class acts as a container for Qt/JavaScript data types.
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
int propertyIndex(const QString &name) const
void dropDestroyedQObject(const QString &name, QObject *destroyed)
static qsizetype context_count(QQmlListProperty< QObject > *)
void setPropertyValue(int index, const QVariant &value)
static QQmlContextPrivate * get(QQmlContext *context)
QVariant propertyValue(int index) const
static QObject * context_at(QQmlListProperty< QObject > *, qsizetype)
The QQmlContext class defines a context within a QML engine.
QString nameForObject(const QObject *) const
Returns the name of object in this context, or an empty string if object is not named in the context.
bool isValid() const
Returns whether the context is valid.
void setBaseUrl(const QUrl &)
Explicitly sets the url resolvedUrl() will use for relative references to baseUrl.
QUrl baseUrl() const
Returns the base url of the component, or the containing component if none is set.
QQmlContext(QQmlEngine *parent, QObject *objParent=nullptr)
Create a new QQmlContext as a child of engine's root context, and the QObject parent.
QUrl resolvedUrl(const QUrl &) const
Resolves the URL src relative to the URL of the containing component.
QVariant contextProperty(const QString &) const
Returns the value of the name property for this context as a QVariant.
QJSValue importedScript(const QString &name) const
QQmlContext * parentContext() const
Return the context's parent QQmlContext, or \nullptr if this context has no parent or if the parent h...
QObject * objectForName(const QString &) const
QObject * contextObject() const
Return the context object, or \nullptr if there is no context object.
void setContextProperty(const QString &, QObject *)
Set the value of the name property on this context.
void setContextObject(QObject *)
Set the context object.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
~QQmlContext() override
Destroys the QQmlContext.
void setContextProperties(const QList< PropertyPair > &properties)
The QQmlEngine class provides an environment for instantiating QML components.
const QQmlPropertyData * property(const K &key, QObject *object, const QQmlRefPointer< QQmlContextData > &context) const
const QMetaObject * metaObject() const
static QQmlTypeLoader * get(Engine *engine)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
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 >
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool isNumber(char s)
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static bool readObjectProperty(const QQmlRefPointer< QQmlContextData > &data, QObject *object, const QString &name, QVariant *target)
ReturnedValue get(StringOrSymbol *name, bool *hasProperty=nullptr, const Value *receiver=nullptr) const