Qt 4.8
Public Functions | Protected Functions | Private Functions | Properties | List of all members
QDeclarativeContextScriptClass Class Reference

#include <qdeclarativecontextscriptclass_p.h>

Inheritance diagram for QDeclarativeContextScriptClass:
QScriptDeclarativeClass

Public Functions

QDeclarativeContextDatacontextFromValue (const QScriptValue &)
 
QScriptValue newContext (QDeclarativeContextData *, QObject *=0)
 
QScriptValue newSharedContext ()
 
QScriptValue newUrlContext (QDeclarativeContextData *, QObject *, const QString &)
 
QScriptValue newUrlContext (const QString &)
 
 QDeclarativeContextScriptClass (QDeclarativeEngine *)
 
QObjectsetOverrideObject (QScriptValue &, QObject *)
 
QUrl urlFromValue (const QScriptValue &)
 
 ~QDeclarativeContextScriptClass ()
 
- Public Functions inherited from QScriptDeclarativeClass
virtual Value call (Object *, QScriptContext *)
 
virtual bool compare (Object *, Object *)
 
QScriptContextcontext () const
 
PersistentIdentifier createPersistentIdentifier (const QString &)
 
PersistentIdentifier createPersistentIdentifier (const Identifier &)
 
QScriptEngineengine () const
 
virtual bool isQObject () const
 
virtual QScriptValue::PropertyFlags propertyFlags (Object *, const Identifier &)
 
virtual QStringList propertyNames (Object *)
 
 QScriptDeclarativeClass (QScriptEngine *engine)
 
void setSupportsCall (bool)
 
bool startsWithUpper (const Identifier &)
 
bool supportsCall () const
 
quint32 toArrayIndex (const Identifier &, bool *ok)
 
virtual QObjecttoQObject (Object *, bool *ok=0)
 
QString toString (const Identifier &)
 
virtual QVariant toVariant (Object *, bool *ok=0)
 
virtual ~QScriptDeclarativeClass ()
 

Protected Functions

virtual Value property (Object *, const Identifier &)
 
virtual QScriptClass::QueryFlags queryProperty (Object *, const Identifier &, QScriptClass::QueryFlags flags)
 
virtual void setProperty (Object *, const Identifier &name, const QScriptValue &)
 

Private Functions

QScriptClass::QueryFlags queryProperty (QDeclarativeContextData *, QObject *scopeObject, const Identifier &, QScriptClass::QueryFlags flags, bool includeTypes)
 

Properties

QDeclarativeEngineengine
 
QDeclarativeContextDatalastContext
 
QDeclarativeTypeNameCache::DatalastData
 
QScriptValue lastFunction
 
int lastPropertyIndex
 
QObjectlastScopeObject
 
uint m_id
 

Additional Inherited Members

- Public Types inherited from QScriptDeclarativeClass
typedef void * Identifier
 
- Static Public Functions inherited from QScriptDeclarativeClass
static QScriptValue function (const QScriptValue &, const Identifier &)
 
static Value functionValue (const QScriptValue &, const Identifier &)
 
static QScriptValue newObject (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
static Value newObjectValue (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
static QScriptValue newStaticScopeObject (QScriptEngine *, int propertyCount, const QString *names, const QScriptValue *values, const QScriptValue::PropertyFlags *flags)
 Creates a scope object with a fixed set of undeletable properties. More...
 
static QScriptValue newStaticScopeObject (QScriptEngine *)
 Creates a static scope object that's initially empty, but to which new properties can be added. More...
 
static Objectobject (const QScriptValue &)
 
static QScriptValue property (const QScriptValue &, const Identifier &)
 
static Value propertyValue (const QScriptValue &, const Identifier &)
 
static QScriptContextpushCleanContext (QScriptEngine *)
 Enters a new execution context and returns the associated QScriptContext object. More...
 
static QScriptValue scopeChainValue (QScriptContext *, int index)
 
static QScriptDeclarativeClassscriptClass (const QScriptValue &)
 
- Protected Variables inherited from QScriptDeclarativeClass
QScopedPointer< QScriptDeclarativeClassPrivated_ptr
 

Detailed Description

Definition at line 64 of file qdeclarativecontextscriptclass_p.h.

Constructors and Destructors

◆ QDeclarativeContextScriptClass()

QDeclarativeContextScriptClass::QDeclarativeContextScriptClass ( QDeclarativeEngine bindEngine)

◆ ~QDeclarativeContextScriptClass()

QDeclarativeContextScriptClass::~QDeclarativeContextScriptClass ( )

Definition at line 101 of file qdeclarativecontextscriptclass.cpp.

102 {
103 }

Functions

◆ contextFromValue()

QDeclarativeContextData * QDeclarativeContextScriptClass::contextFromValue ( const QScriptValue v)

Definition at line 134 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeInclude::include(), QDeclarativeInclude::QDeclarativeInclude(), QDeclarativeObjectScriptClass::queryProperty(), and QDeclarativeObjectScriptClass::setProperty().

135 {
136  if (scriptClass(v) != this)
137  return 0;
138 
139  ContextData *data = (ContextData *)object(v);
140  return data->getContext(engine);
141 }
QDeclarativeContextData * getContext(QDeclarativeEngine *engine)
QScriptEngine * engine() const
static const char * data(const QByteArray &arr)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)

◆ newContext()

QScriptValue QDeclarativeContextScriptClass::newContext ( QDeclarativeContextData context,
QObject scopeObject = 0 
)

Definition at line 105 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeExpressionPrivate::evalInObjectScope(), and QDeclarativeExpressionPrivate::scriptValue().

106 {
108 
109  return newObject(scriptEngine, this, new ContextData(context, scopeObject));
110 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const

◆ newSharedContext()

QScriptValue QDeclarativeContextScriptClass::newSharedContext ( )

Definition at line 127 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeExpressionPrivate::init().

128 {
130 
131  return newObject(scriptEngine, this, new ContextData());
132 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const

◆ newUrlContext() [1/2]

QScriptValue QDeclarativeContextScriptClass::newUrlContext ( QDeclarativeContextData context,
QObject scopeObject,
const QString url 
)

Definition at line 112 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeContextData::addImportedScript(), QDeclarativeInclude::finished(), and QDeclarativeInclude::include().

114 {
116 
117  return newObject(scriptEngine, this, new UrlContextData(context, scopeObject, url));
118 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const

◆ newUrlContext() [2/2]

QScriptValue QDeclarativeContextScriptClass::newUrlContext ( const QString url)

Definition at line 120 of file qdeclarativecontextscriptclass.cpp.

121 {
123 
124  return newObject(scriptEngine, this, new UrlContextData(url));
125 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const

◆ property()

QDeclarativeContextScriptClass::Value QDeclarativeContextScriptClass::property ( Object object,
const Identifier name 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 262 of file qdeclarativecontextscriptclass.cpp.

263 {
264  Q_UNUSED(object);
265 
266  QDeclarativeContextData *bindContext = lastContext;
267  Q_ASSERT(bindContext);
268 
271 
272  if (lastData) {
273 
274  if (lastData->type) {
275  return Value(scriptEngine, ep->typeNameClass->newObject(lastScopeObject, lastData->type));
276  } else if (lastData->typeNamespace) {
277  return Value(scriptEngine, ep->typeNameClass->newObject(lastScopeObject, lastData->typeNamespace));
278  } else {
280  if (index < bindContext->importedScripts.count()) {
281  return Value(scriptEngine, bindContext->importedScripts.at(index));
282  } else {
283  return Value();
284  }
285  }
286 
287  } else if (lastScopeObject) {
288 
290 
291  } else if (lastPropertyIndex != -1) {
292 
293  QScriptValue rv;
294  if (lastPropertyIndex < bindContext->idValueCount) {
295  rv = ep->objectClass->newQObject(bindContext->idValues[lastPropertyIndex].data());
296 
297  if (ep->captureProperties)
299  } else {
301  const QVariant &value = cp->propertyValues.at(lastPropertyIndex);
302  if (value.userType() == qMetaTypeId<QList<QObject*> >()) {
304  } else {
305  rv = ep->scriptValueFromVariant(value);
306  }
307 
308  if (ep->captureProperties)
310  }
311 
312  return Value(scriptEngine, rv);
313 
314  } else {
315 
316  return Value(scriptEngine, lastFunction);
317 
318  }
319 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
QDeclarativeTypeNameScriptClass * typeNameClass
static int context_count(QDeclarativeListProperty< QObject > *)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QScriptValue newQObject(QObject *, int type=QMetaType::QObjectStar)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QDeclarativeContextPrivate * asQDeclarativeContextPrivate()
QScriptValue newObject(QObject *, QDeclarativeType *, TypeNameMode=IncludeEnums)
QDeclarativeTypeNameCache::Data * lastData
const char * name
QScriptEngine * engine() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue scriptValueFromVariant(const QVariant &)
QDeclarativeObjectScriptClass * objectClass
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QDeclarativeListScriptClass * listClass
QDeclarativeContext * asQDeclarativeContext()
QDeclarativeTypeNameCache * typeNamespace
quint16 index
static QObject * context_at(QDeclarativeListProperty< QObject > *, int)
QScriptValue newList(QObject *, int, int)
QList< QScriptValue > importedScripts
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Value property(QObject *, const Identifier &)
QPODVector< CapturedProperty, 16 > capturedProperties

◆ queryProperty() [1/2]

QScriptClass::QueryFlags QDeclarativeContextScriptClass::queryProperty ( Object object,
const Identifier name,
QScriptClass::QueryFlags  flags 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 168 of file qdeclarativecontextscriptclass.cpp.

170 {
171  Q_UNUSED(flags);
172 
173  lastScopeObject = 0;
174  lastContext = 0;
175  lastData = 0;
176  lastPropertyIndex = -1;
177 
178  QDeclarativeContextData *bindContext = ((ContextData *)object)->getContext(engine);
179  QObject *scopeObject = ((ContextData *)object)->getScope(engine);
180  if (!bindContext)
181  return 0;
182 
183  QObject *overrideObject = ((ContextData *)object)->overrideObject;
184  if (overrideObject) {
186  QScriptClass::QueryFlags rv =
187  ep->objectClass->queryProperty(overrideObject, name, flags, bindContext,
190  if (rv) {
191  lastScopeObject = overrideObject;
192  lastContext = bindContext;
193  return rv;
194  }
195  }
196 
197  bool includeTypes = true;
198  while (bindContext) {
199  QScriptClass::QueryFlags rv =
200  queryProperty(bindContext, scopeObject, name, flags, includeTypes);
201  scopeObject = 0; // Only applies to the first context
202  includeTypes = false; // Only applies to the first context
203  if (rv) return rv;
204  bindContext = bindContext->parent;
205  }
206 
207  return 0;
208 }
QScriptClass::QueryFlags queryProperty(QObject *, const Identifier &, QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext, QueryHints hints=0)
QDeclarativeContextData * parent
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeTypeNameCache::Data * lastData
const char * name
QScriptEngine * engine() const
virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags)
QDeclarativeObjectScriptClass * objectClass
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ queryProperty() [2/2]

QScriptClass::QueryFlags QDeclarativeContextScriptClass::queryProperty ( QDeclarativeContextData bindContext,
QObject scopeObject,
const Identifier name,
QScriptClass::QueryFlags  flags,
bool  includeTypes 
)
private

Definition at line 211 of file qdeclarativecontextscriptclass.cpp.

215 {
217 
218  lastPropertyIndex = bindContext->propertyNames?bindContext->propertyNames->value(name):-1;
219  if (lastPropertyIndex != -1) {
220  lastContext = bindContext;
222  }
223 
224  if (includeTypes && bindContext->imports) {
226 
227  if (data) {
228  lastData = data;
229  lastContext = bindContext;
230  lastScopeObject = scopeObject;
232  }
233  }
234 
235  if (scopeObject) {
236  QScriptClass::QueryFlags rv =
237  ep->objectClass->queryProperty(scopeObject, name, flags, bindContext,
239  if (rv) {
240  lastScopeObject = scopeObject;
241  lastContext = bindContext;
242  return rv;
243  }
244  }
245 
246  if (bindContext->contextObject) {
247  QScriptClass::QueryFlags rv =
248  ep->objectClass->queryProperty(bindContext->contextObject, name, flags, bindContext,
250 
251  if (rv) {
252  lastScopeObject = bindContext->contextObject;
253  lastContext = bindContext;
254  return rv;
255  }
256  }
257 
258  return 0;
259 }
QScriptClass::QueryFlags queryProperty(QObject *, const Identifier &, QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext, QueryHints hints=0)
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeTypeNameCache * imports
QDeclarativeTypeNameCache::Data * lastData
const char * name
QScriptEngine * engine() const
static const char * data(const QByteArray &arr)
QDeclarativeIntegerCache * propertyNames
QDeclarativeObjectScriptClass * objectClass
Data * data(const QString &) const

◆ setOverrideObject()

QObject * QDeclarativeContextScriptClass::setOverrideObject ( QScriptValue v,
QObject override 
)

Definition at line 156 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeQtScriptExpression::eval().

157 {
158  if (scriptClass(v) != this)
159  return 0;
160 
161  ContextData *data = (ContextData *)object(v);
162  QObject *rv = data->overrideObject;
163  data->overrideObject = override;
164  return rv;
165 }
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static const char * data(const QByteArray &arr)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)

◆ setProperty()

void QDeclarativeContextScriptClass::setProperty ( Object object,
const Identifier name,
const QScriptValue value 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 321 of file qdeclarativecontextscriptclass.cpp.

323 {
324  Q_UNUSED(object);
326 
327  QDeclarativeContextData *bindContext = lastContext;
328  Q_ASSERT(bindContext);
329 
331 
332  ep->objectClass->setProperty(lastScopeObject, name, value, context(), bindContext);
333 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
const char * name
QScriptEngine * engine() const
QDeclarativeObjectScriptClass * objectClass
void setProperty(QObject *, const Identifier &name, const QScriptValue &, QScriptContext *context, QDeclarativeContextData *evalContext=0)
QScriptContext * context() const
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ urlFromValue()

QUrl QDeclarativeContextScriptClass::urlFromValue ( const QScriptValue v)

Definition at line 143 of file qdeclarativecontextscriptclass.cpp.

Referenced by QDeclarativeInclude::include().

144 {
145  if (scriptClass(v) != this)
146  return QUrl();
147 
148  ContextData *data = (ContextData *)object(v);
149  if (data->isUrlContext) {
150  return QUrl(static_cast<UrlContextData *>(data)->url);
151  } else {
152  return QUrl();
153  }
154 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
static const char * data(const QByteArray &arr)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)

Properties

◆ engine

QDeclarativeEngine* QDeclarativeContextScriptClass::engine
private

Definition at line 92 of file qdeclarativecontextscriptclass_p.h.

◆ lastContext

QDeclarativeContextData* QDeclarativeContextScriptClass::lastContext
private

Definition at line 95 of file qdeclarativecontextscriptclass_p.h.

Referenced by property(), queryProperty(), and setProperty().

◆ lastData

QDeclarativeTypeNameCache::Data* QDeclarativeContextScriptClass::lastData
private

Definition at line 96 of file qdeclarativecontextscriptclass_p.h.

Referenced by property(), and queryProperty().

◆ lastFunction

QScriptValue QDeclarativeContextScriptClass::lastFunction
private

Definition at line 98 of file qdeclarativecontextscriptclass_p.h.

Referenced by property().

◆ lastPropertyIndex

int QDeclarativeContextScriptClass::lastPropertyIndex
private

Definition at line 97 of file qdeclarativecontextscriptclass_p.h.

Referenced by property(), and queryProperty().

◆ lastScopeObject

QObject* QDeclarativeContextScriptClass::lastScopeObject
private

Definition at line 94 of file qdeclarativecontextscriptclass_p.h.

Referenced by property(), queryProperty(), and setProperty().

◆ m_id

uint QDeclarativeContextScriptClass::m_id
private

Definition at line 100 of file qdeclarativecontextscriptclass_p.h.


The documentation for this class was generated from the following files: