Qt 4.8
Public Types | Public Functions | Protected Functions | Static Private Functions | Properties | Friends | List of all members
QDeclarativeObjectScriptClass Class Reference

#include <qdeclarativeobjectscriptclass_p.h>

Inheritance diagram for QDeclarativeObjectScriptClass:
QScriptDeclarativeClass

Public Types

enum  QueryHint { ImplicitObject = 0x01, SkipAttachedProperties = 0x02 }
 
- Public Types inherited from QScriptDeclarativeClass
typedef void * Identifier
 

Public Functions

virtual bool compare (Object *, Object *)
 
QScriptValue newQObject (QObject *, int type=QMetaType::QObjectStar)
 
int objectType (const QScriptValue &) const
 
Value property (QObject *, const Identifier &)
 
virtual QStringList propertyNames (Object *)
 
 QDeclarativeObjectScriptClass (QDeclarativeEngine *)
 
QScriptClass::QueryFlags queryProperty (QObject *, const Identifier &, QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext, QueryHints hints=0)
 
void setProperty (QObject *, const Identifier &name, const QScriptValue &, QScriptContext *context, QDeclarativeContextData *evalContext=0)
 
QObjecttoQObject (const QScriptValue &) const
 
 ~QDeclarativeObjectScriptClass ()
 
- Public Functions inherited from QScriptDeclarativeClass
virtual Value call (Object *, QScriptContext *)
 
QScriptContextcontext () const
 
PersistentIdentifier createPersistentIdentifier (const QString &)
 
PersistentIdentifier createPersistentIdentifier (const Identifier &)
 
QScriptEngineengine () const
 
virtual QScriptValue::PropertyFlags propertyFlags (Object *, const Identifier &)
 
 QScriptDeclarativeClass (QScriptEngine *engine)
 
void setSupportsCall (bool)
 
bool startsWithUpper (const Identifier &)
 
bool supportsCall () const
 
quint32 toArrayIndex (const Identifier &, bool *ok)
 
QString toString (const Identifier &)
 
virtual QVariant toVariant (Object *, bool *ok=0)
 
virtual ~QScriptDeclarativeClass ()
 

Protected Functions

virtual bool isQObject () const
 
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 &)
 
virtual QObjecttoQObject (Object *, bool *ok=0)
 

Static Private Functions

static QScriptValue destroy (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue tostring (QScriptContext *context, QScriptEngine *engine)
 

Properties

QDeclarativeEngineengine
 
QDeclarativePropertyCache::DatalastData
 
QDeclarativeTypeNameCache::DatalastTNData
 
QDeclarativePropertyCache::Data local
 
QScriptValue m_destroy
 
PersistentIdentifier m_destroyId
 
QScriptValue m_toString
 
PersistentIdentifier m_toStringId
 
QDeclarativeObjectMethodScriptClass methods
 

Friends

class QDeclarativeObjectMethodScriptClass
 

Additional Inherited Members

- 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 105 of file qdeclarativeobjectscriptclass_p.h.

Enumerations

◆ QueryHint

Constructors and Destructors

◆ QDeclarativeObjectScriptClass()

QDeclarativeObjectScriptClass::QDeclarativeObjectScriptClass ( QDeclarativeEngine bindEngine)

Definition at line 94 of file qdeclarativeobjectscriptclass.cpp.

96  methods(bindEngine), lastData(0), engine(bindEngine)
97 {
99 
100  m_destroy = scriptEngine->newFunction(destroy);
102  m_toString = scriptEngine->newFunction(tostring);
104 }
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue destroy(QScriptContext *context, QScriptEngine *engine)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QScriptValue tostring(QScriptContext *context, QScriptEngine *engine)
PersistentIdentifier createPersistentIdentifier(const QString &)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QDeclarativePropertyCache::Data * lastData
QScriptEngine * engine() const
QDeclarativeObjectMethodScriptClass methods
QScriptDeclarativeClass(QScriptEngine *engine)

◆ ~QDeclarativeObjectScriptClass()

QDeclarativeObjectScriptClass::~QDeclarativeObjectScriptClass ( )

Definition at line 106 of file qdeclarativeobjectscriptclass.cpp.

107 {
108 }

Functions

◆ compare()

bool QDeclarativeObjectScriptClass::compare ( Object o1,
Object o2 
)
virtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 556 of file qdeclarativeobjectscriptclass.cpp.

557 {
558  ObjectData *d1 = (ObjectData *)o1;
559  ObjectData *d2 = (ObjectData *)o2;
560 
561  return d1 == d2 || d1->object == d2->object;
562 }
QDeclarativeGuard< QObject > object

◆ destroy()

QScriptValue QDeclarativeObjectScriptClass::destroy ( QScriptContext context,
QScriptEngine engine 
)
staticprivate

Definition at line 496 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeObjectScriptClass().

497 {
499  QScriptValue that = context->thisObject();
500 
501  if (scriptClass(that) != p->objectClass)
502  return engine->undefinedValue();
503 
504  ObjectData *data = (ObjectData *)p->objectClass->object(that);
505  if (!data->object)
506  return engine->undefinedValue();
507 
508  QDeclarativeData *ddata = QDeclarativeData::get(data->object, false);
509  if (!ddata || ddata->indestructible)
510  return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object"));
511 
512  QObject *obj = data->object;
513  int delay = 0;
514  if (context->argumentCount() > 0)
515  delay = context->argument(0).toInt32();
516  if (delay > 0)
517  QTimer::singleShot(delay, obj, SLOT(deleteLater()));
518  else
519  obj->deleteLater();
520 
521  return engine->undefinedValue();
522 }
static QDeclarativeData * get(const QObject *object, bool create=false)
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
#define SLOT(a)
Definition: qobjectdefs.h:226
QDeclarativeGuard< QObject > object
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static Object * object(const QScriptValue &)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static const char * data(const QByteArray &arr)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QDeclarativeObjectScriptClass * objectClass
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
QScriptContext * currentContext() const
Returns the current context.
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ isQObject()

bool QDeclarativeObjectScriptClass::isQObject ( ) const
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 458 of file qdeclarativeobjectscriptclass.cpp.

459 {
460  return true;
461 }

◆ newQObject()

QScriptValue QDeclarativeObjectScriptClass::newQObject ( QObject object,
int  type = QMetaType::QObjectStar 
)

Definition at line 110 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeEnginePrivate::createComponent(), QDeclarativeComponentPrivate::createObject(), QDeclarativeEnginePrivate::createQmlObject(), QDeclarativeQtScriptExpression::eval(), QDeclarativeVMEMetaObject::metaCall(), QDeclarativeListScriptClass::property(), QDeclarativeObjectMethodScriptClass::property(), QDeclarativeContextScriptClass::property(), property(), QDeclarativeEnginePrivate::qmlScriptObject(), and QDeclarativeVMEMetaObject::readVarProperty().

111 {
113 
114  if (!object)
115  return scriptEngine->nullValue();
116 // return newObject(scriptEngine, this, new ObjectData(object, type));
117 
118  if (QObjectPrivate::get(object)->wasDeleted)
119  return scriptEngine->undefinedValue();
120 
121  QDeclarativeData *ddata = QDeclarativeData::get(object, true);
122 
123  if (!ddata) {
124  return scriptEngine->undefinedValue();
125  } else if (!ddata->indestructible && !object->parent()) {
126  return newObject(scriptEngine, this, new ObjectData(object, type));
127  } else if (!ddata->scriptValue) {
128  ddata->scriptValue = new QScriptValue(newObject(scriptEngine, this, new ObjectData(object, type)));
129  return *ddata->scriptValue;
131  return *ddata->scriptValue;
132  } else {
133  return newObject(scriptEngine, this, new ObjectData(object, type));
134  }
135 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QDeclarativeData * get(const QObject *object, bool create=false)
int type
Definition: qmetatype.cpp:239
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue * scriptValue
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.

◆ objectType()

int QDeclarativeObjectScriptClass::objectType ( const QScriptValue value) const

Definition at line 142 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeBinding::update().

143 {
144  if (scriptClass(value) != this)
145  return QVariant::Invalid;
146 
147  Object *o = object(value);
148  return ((ObjectData*)(o))->type;
149 }
static Object * object(const QScriptValue &)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)

◆ property() [1/2]

QDeclarativeObjectScriptClass::Value QDeclarativeObjectScriptClass::property ( QObject obj,
const Identifier name 
)

Definition at line 222 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeTypeNameScriptClass::property(), QDeclarativeContextScriptClass::property(), and property().

223 {
225 
226  if (name == m_destroyId.identifier)
227  return Value(scriptEngine, m_destroy);
228  else if (name == m_toStringId.identifier)
229  return Value(scriptEngine, m_toString);
230 
231  if (lastData && !lastData->isValid())
232  return Value();
233 
234  Q_ASSERT(obj);
235 
237 
238  if (lastTNData) {
239 
240  if (lastTNData->type)
241  return Value(scriptEngine, enginePriv->typeNameClass->newObject(obj, lastTNData->type));
242  else
243  return Value(scriptEngine, enginePriv->typeNameClass->newObject(obj, lastTNData->typeNamespace));
244 
247  return Value(scriptEngine, ((QDeclarativeVMEMetaObject *)(obj->metaObject()))->vmeMethod(lastData->coreIndex));
248  } else {
249  // Uncomment to use QtScript method call logic
250  // QScriptValue sobj = scriptEngine->newQObject(obj);
251  // return Value(scriptEngine, sobj.property(toString(name)));
252  return Value(scriptEngine, methods.newMethod(obj, lastData));
253  }
254  } else {
256  if (lastData->coreIndex == 0) {
257  enginePriv->capturedProperties <<
258  QDeclarativeEnginePrivate::CapturedProperty(QDeclarativeData::get(obj, true)->objectNameNotifier());
259  } else {
260  enginePriv->capturedProperties <<
262  }
263  }
264 
266  QDeclarativeValueType *valueType = enginePriv->valueTypes[lastData->propType];
267  if (valueType)
268  return Value(scriptEngine, enginePriv->valueTypeClass->newObject(obj, lastData->coreIndex, valueType));
269  }
270 
272  return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, lastData->propType));
274  QObject *rv = 0;
275  void *args[] = { &rv, 0 };
277  return Value(scriptEngine, newQObject(rv, lastData->propType));
279  QScriptValue rv = scriptEngine->nullValue();
280  void *args[] = { &rv, 0 };
282  return Value(scriptEngine, rv);
283  } else if (lastData->propType == QMetaType::QReal) {
284  qreal rv = 0;
285  void *args[] = { &rv, 0 };
287  return Value(scriptEngine, rv);
289  int rv = 0;
290  void *args[] = { &rv, 0 };
292  return Value(scriptEngine, rv);
293  } else if (lastData->propType == QMetaType::Bool) {
294  bool rv = false;
295  void *args[] = { &rv, 0 };
297  return Value(scriptEngine, rv);
298  } else if (lastData->propType == QMetaType::QString) {
299  QString rv;
300  void *args[] = { &rv, 0 };
302  return Value(scriptEngine, rv);
303  } else if (lastData->propType == QMetaType::UInt) {
304  uint rv = 0;
305  void *args[] = { &rv, 0 };
307  return Value(scriptEngine, rv);
308  } else if (lastData->propType == QMetaType::Float) {
309  float rv = 0;
310  void *args[] = { &rv, 0 };
312  return Value(scriptEngine, rv);
313  } else if (lastData->propType == QMetaType::Double) {
314  double rv = 0;
315  void *args[] = { &rv, 0 };
317  return Value(scriptEngine, rv);
318  } else {
319  QVariant var = obj->metaObject()->property(lastData->coreIndex).read(obj);
320  return Value(scriptEngine, enginePriv->scriptValueFromVariant(var));
321  }
322  }
323 }
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 QDeclarativeData * get(const QObject *object, bool create=false)
double qreal
Definition: qglobal.h:1193
static int metacall(QObject *, Call, int, void **)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QScriptValue newQObject(QObject *, int type=QMetaType::QObjectStar)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptValue newObject(QObject *, QDeclarativeType *, TypeNameMode=IncludeEnums)
QDeclarativePropertyCache::Data * lastData
const char * name
QScriptEngine * engine() const
QScriptValue scriptValueFromVariant(const QVariant &)
unsigned int uint
Definition: qglobal.h:996
QDeclarativeValueTypeScriptClass * valueTypeClass
QDeclarativeObjectMethodScriptClass methods
QScriptValue newObject(QObject *object, int coreIndex, QDeclarativeValueType *)
QDeclarativeTypeNameCache::Data * lastTNData
QDeclarativeListScriptClass * listClass
QDeclarativeValueTypeFactory valueTypes
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
QDeclarativeTypeNameCache * typeNamespace
QScriptValue newList(QObject *, int, int)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QPODVector< CapturedProperty, 16 > capturedProperties
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QScriptValue newMethod(QObject *, const QDeclarativePropertyCache::Data *)

◆ property() [2/2]

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

Reimplemented from QScriptDeclarativeClass.

Definition at line 216 of file qdeclarativeobjectscriptclass.cpp.

217 {
218  return property(toQObject(object), name);
219 }
QObject * toQObject(const QScriptValue &) const
const char * name
Value property(QObject *, const Identifier &)

◆ propertyNames()

QStringList QDeclarativeObjectScriptClass::propertyNames ( Object object)
virtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 524 of file qdeclarativeobjectscriptclass.cpp.

525 {
526  QObject *obj = toQObject(object);
527  if (!obj)
528  return QStringList();
529 
531 
532  QDeclarativePropertyCache *cache = 0;
534  if (ddata)
535  cache = ddata->propertyCache;
536  if (!cache) {
537  cache = enginePrivate->cache(obj);
538  if (cache) {
539  if (ddata) { cache->addref(); ddata->propertyCache = cache; }
540  } else {
541  // Not cachable - fall back to QMetaObject (eg. dynamic meta object)
542  // XXX QDeclarativeOpenMetaObject has a cache, so this is suboptimal.
543  // XXX This is a workaround for QTBUG-9420.
544  const QMetaObject *mo = obj->metaObject();
545  QStringList r;
546  int pc = mo->propertyCount();
547  int po = mo->propertyOffset();
548  for (int i=po; i<pc; ++i)
549  r += QString::fromUtf8(mo->property(i).name());
550  return r;
551  }
552  }
553  return cache->propertyNames();
554 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QDeclarativePropertyCache * propertyCache
static QDeclarativeData * get(const QObject *object, bool create=false)
QObject * toQObject(const QScriptValue &) const
QDeclarativePropertyCache * cache(QObject *obj)
Returns a QDeclarativePropertyCache for obj if one is available.
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QScriptEngine * engine() const
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
const char * name() const
Returns this property&#39;s name.
int propertyOffset() const
Returns the property offset for this class; i.e.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ queryProperty() [1/2]

QScriptClass::QueryFlags QDeclarativeObjectScriptClass::queryProperty ( QObject obj,
const Identifier name,
QScriptClass::QueryFlags  flags,
QDeclarativeContextData evalContext,
QueryHints  hints = 0 
)

Definition at line 159 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeTypeNameScriptClass::queryProperty(), QDeclarativeContextScriptClass::queryProperty(), and queryProperty().

162 {
163  Q_UNUSED(flags);
164  lastData = 0;
165  lastTNData = 0;
166 
167  if (name == m_destroyId.identifier ||
170 
171  if (!obj)
172  return 0;
173 
176  if ((hints & ImplicitObject) && lastData && lastData->revision != 0) {
177 
179  if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(lastData))
180  return 0;
181  }
182 
183  if (lastData)
185 
186  if (!(hints & SkipAttachedProperties)) {
187  if (!evalContext && context()) {
188  // Global object, QScriptContext activation object, QDeclarativeContext object
189  QScriptValue scopeNode = scopeChainValue(context(), -3);
190  if (scopeNode.isValid()) {
191  Q_ASSERT(scriptClass(scopeNode) == enginePrivate->contextClass);
192 
193  evalContext = enginePrivate->contextClass->contextFromValue(scopeNode);
194  }
195  }
196 
197  if (evalContext && evalContext->imports) {
199  if (data) {
200  lastTNData = data;
202  }
203  }
204  }
205 
206  if (!(hints & ImplicitObject)) {
207  local.coreIndex = -1;
208  lastData = &local;
210  }
211 
212  return 0;
213 }
QDeclarativePropertyCache * propertyCache
static QDeclarativeData * get(const QObject *object, bool create=false)
QDeclarativeContextData * contextFromValue(const QScriptValue &)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeTypeNameCache * imports
QDeclarativePropertyCache::Data local
QDeclarativePropertyCache::Data * lastData
const char * name
QScriptEngine * engine() const
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static const char * data(const QByteArray &arr)
QDeclarativeTypeNameCache::Data * lastTNData
static QScriptValue scopeChainValue(QScriptContext *, int index)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
Data * data(const QString &) const
QScriptContext * context() const
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
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
QDeclarativeContextScriptClass * contextClass

◆ queryProperty() [2/2]

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

Reimplemented from QScriptDeclarativeClass.

Definition at line 152 of file qdeclarativeobjectscriptclass.cpp.

154 {
155  return queryProperty(toQObject(object), name, flags, 0);
156 }
QScriptClass::QueryFlags queryProperty(QObject *, const Identifier &, QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext, QueryHints hints=0)
QObject * toQObject(const QScriptValue &) const
const char * name

◆ setProperty() [1/2]

void QDeclarativeObjectScriptClass::setProperty ( QObject obj,
const Identifier name,
const QScriptValue value,
QScriptContext context,
QDeclarativeContextData evalContext = 0 
)

Definition at line 337 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeTypeNameScriptClass::setProperty(), QDeclarativeContextScriptClass::setProperty(), and setProperty().

342 {
343  Q_UNUSED(name);
344 
345  Q_ASSERT(obj);
347  Q_ASSERT(context);
348 
349  if (!lastData->isValid()) {
350  QString error = QLatin1String("Cannot assign to non-existent property \"") +
351  toString(name) + QLatin1Char('\"');
352  context->throwError(error);
353  return;
354  }
355 
358  QString error = QLatin1String("Cannot assign to read-only property \"") +
359  toString(name) + QLatin1Char('\"');
360  context->throwError(error);
361  return;
362  }
363 
365 
366  if (!evalContext) {
367  // Global object, QScriptContext activation object, QDeclarativeContext object
368  QScriptValue scopeNode = scopeChainValue(context, -3);
369  if (scopeNode.isValid()) {
370  Q_ASSERT(scriptClass(scopeNode) == enginePriv->contextClass);
371 
372  evalContext = enginePriv->contextClass->contextFromValue(scopeNode);
373  }
374  }
375 
376  QDeclarativeBinding *newBinding = 0;
377  if (value.isFunction() && !value.isRegExp()) {
378  QScriptContextInfo ctxtInfo(context);
380 
381  newBinding = new QDeclarativeBinding(value, obj, evalContext);
382  newBinding->setSourceLocation(ctxtInfo.fileName(), ctxtInfo.functionStartLineNumber());
383  newBinding->setTarget(QDeclarativePropertyPrivate::restore(*lastData, valueTypeData, obj, evalContext));
384  if (newBinding->expression().contains(QLatin1String("this")))
386  }
387 
388  QDeclarativeAbstractBinding *delBinding =
390  if (delBinding)
391  delBinding->destroy();
392 
394  QObject *o = 0;
395  int status = -1;
396  int flags = 0;
397  void *argv[] = { &o, 0, &status, &flags };
400  void *a[] = { 0 };
402  } else if (value.isUndefined() && lastData->propType == qMetaTypeId<QVariant>()) {
404  } else if (value.isUndefined()) {
405  QString error = QLatin1String("Cannot assign [undefined] to ") +
407  context->throwError(error);
408  } else if (value.isFunction() && !value.isRegExp()) {
409  // this is handled by the binding creation above
410  } else {
411  //### expand optimization for other known types
412  if (lastData->propType == QMetaType::Int && value.isNumber()) {
413  int rawValue = qRoundDouble(value.toNumber());
414  int status = -1;
415  int flags = 0;
416  void *a[] = { (void *)&rawValue, 0, &status, &flags };
418  lastData->coreIndex, a);
419  return;
420  } else if (lastData->propType == QMetaType::QReal && value.isNumber()) {
421  qreal rawValue = qreal(value.toNumber());
422  int status = -1;
423  int flags = 0;
424  void *a[] = { (void *)&rawValue, 0, &status, &flags };
426  lastData->coreIndex, a);
427  return;
428  } else if (lastData->propType == QMetaType::QString && value.isString()) {
429  const QString &rawValue = value.toString();
430  int status = -1;
431  int flags = 0;
432  void *a[] = { (void *)&rawValue, 0, &status, &flags };
434  lastData->coreIndex, a);
435  return;
436  }
437 
438  QVariant v;
440  v = enginePriv->scriptValueToVariant(value, qMetaTypeId<QList<QObject *> >());
441  else
442  v = enginePriv->scriptValueToVariant(value, lastData->propType);
443 
444  if (!QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext)) {
445  const char *valueType = 0;
446  if (v.userType() == QVariant::Invalid) valueType = "null";
447  else valueType = QMetaType::typeName(v.userType());
448 
449  QString error = QLatin1String("Cannot assign ") +
450  QLatin1String(valueType) +
451  QLatin1String(" to ") +
453  context->throwError(error);
454  }
455  }
456 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
double qreal
Definition: qglobal.h:1193
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
static int metacall(QObject *, Call, int, void **)
#define error(msg)
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
void setTarget(const QDeclarativeProperty &)
virtual void destroy(DestroyMode mode=DisconnectBinding)
Destroy the binding.
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
int qMetaTypeId()
Definition: qmetatype.h:224
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
QDeclarativeContextData * contextFromValue(const QScriptValue &)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QVariant scriptValueToVariant(const QScriptValue &, int hint=QVariant::Invalid)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
QDeclarativePropertyCache::Data * lastData
const char * name
QScriptEngine * engine() const
static QDeclarativeAbstractBinding * setBinding(QObject *, int coreIndex, int valueTypeIndex, QDeclarativeAbstractBinding *, WriteFlags flags=DontRemoveBinding)
void setEvaluateFlags(EvaluateFlags flags)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
The QScriptContextInfo class provides additional information about a QScriptContext.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
static QDeclarativeProperty restore(const QByteArray &, QObject *, QDeclarativeContextData *)
virtual QString expression() const
static QScriptValue scopeChainValue(QScriptContext *, int index)
void setSourceLocation(const QString &fileName, int line)
Set the location of this expression to line of url.
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
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
QString toString(const Identifier &)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
EvaluateFlags evaluateFlags() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QDeclarativeContextScriptClass * contextClass
static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, QDeclarativeContextData *, WriteFlags flags=0)

◆ setProperty() [2/2]

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

Reimplemented from QScriptDeclarativeClass.

Definition at line 325 of file qdeclarativeobjectscriptclass.cpp.

328 {
329  return setProperty(toQObject(object), name, value, context());
330 }
QObject * toQObject(const QScriptValue &) const
const char * name
void setProperty(QObject *, const Identifier &name, const QScriptValue &, QScriptContext *context, QDeclarativeContextData *evalContext=0)
QScriptContext * context() const

◆ toQObject() [1/2]

QObject * QDeclarativeObjectScriptClass::toQObject ( const QScriptValue value) const

Definition at line 137 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeEnginePrivate::createQmlObject(), property(), propertyNames(), queryProperty(), and setProperty().

138 {
139  return value.toQObject();
140 }
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...

◆ toQObject() [2/2]

QObject * QDeclarativeObjectScriptClass::toQObject ( Object object,
bool *  ok = 0 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 463 of file qdeclarativeobjectscriptclass.cpp.

464 {
465  if (ok) *ok = true;
466 
467  ObjectData *data = (ObjectData*)object;
468  return data->object.data();
469 }
QDeclarativeGuard< QObject > object
static const char * data(const QByteArray &arr)

◆ tostring()

QScriptValue QDeclarativeObjectScriptClass::tostring ( QScriptContext context,
QScriptEngine engine 
)
staticprivate

Definition at line 471 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeObjectScriptClass().

472 {
473  QObject* obj = context->thisObject().toQObject();
474 
475  QString ret;
476  if(obj){
477  QString objectName = obj->objectName();
478 
479  ret += QString::fromUtf8(obj->metaObject()->className());
480  ret += QLatin1String("(0x");
481  ret += QString::number((quintptr)obj,16);
482 
483  if (!objectName.isEmpty()) {
484  ret += QLatin1String(", \"");
485  ret += objectName;
486  ret += QLatin1Char('\"');
487  }
488 
489  ret += QLatin1Char(')');
490  }else{
491  ret += QLatin1String("null");
492  }
493  return QScriptValue(ret);
494 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QString objectName
the name of this object
Definition: qobject.h:114
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

Friends and Related Functions

◆ QDeclarativeObjectMethodScriptClass

Definition at line 144 of file qdeclarativeobjectscriptclass_p.h.

Properties

◆ engine

QDeclarativeEngine* QDeclarativeObjectScriptClass::engine
private

Definition at line 159 of file qdeclarativeobjectscriptclass_p.h.

◆ lastData

QDeclarativePropertyCache::Data* QDeclarativeObjectScriptClass::lastData
private

Definition at line 148 of file qdeclarativeobjectscriptclass_p.h.

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

◆ lastTNData

QDeclarativeTypeNameCache::Data* QDeclarativeObjectScriptClass::lastTNData
private

Definition at line 147 of file qdeclarativeobjectscriptclass_p.h.

Referenced by property(), and queryProperty().

◆ local

QDeclarativePropertyCache::Data QDeclarativeObjectScriptClass::local
private

Definition at line 149 of file qdeclarativeobjectscriptclass_p.h.

Referenced by queryProperty().

◆ m_destroy

QScriptValue QDeclarativeObjectScriptClass::m_destroy
private

Definition at line 153 of file qdeclarativeobjectscriptclass_p.h.

Referenced by property(), and QDeclarativeObjectScriptClass().

◆ m_destroyId

PersistentIdentifier QDeclarativeObjectScriptClass::m_destroyId
private

◆ m_toString

QScriptValue QDeclarativeObjectScriptClass::m_toString
private

Definition at line 154 of file qdeclarativeobjectscriptclass_p.h.

Referenced by property(), and QDeclarativeObjectScriptClass().

◆ m_toStringId

PersistentIdentifier QDeclarativeObjectScriptClass::m_toStringId
private

◆ methods

QDeclarativeObjectMethodScriptClass QDeclarativeObjectScriptClass::methods
private

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