Qt 4.8
Classes | Public Types | Signals | Public Functions | Static Public Functions | Public Variables | Protected Functions | Private Functions | List of all members
QDeclarativeWorkerScriptEnginePrivate Class Reference
Inheritance diagram for QDeclarativeWorkerScriptEnginePrivate:
QObject

Classes

struct  ScriptEngine
 
struct  WorkerScript
 

Public Types

enum  WorkerEventTypes { WorkerDestroyEvent = QEvent::User + 100 }
 

Signals

void stopThread ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

QScriptValue getWorker (int)
 
 QDeclarativeWorkerScriptEnginePrivate (QDeclarativeEngine *eng)
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QDeclarativeWorkerScriptEnginePrivateget (QScriptEngine *e)
 
static QScriptValue onMessage (QScriptContext *ctxt, QScriptEngine *engine)
 
static QVariant scriptValueToVariant (const QScriptValue &)
 
static QScriptValue sendMessage (QScriptContext *ctxt, QScriptEngine *engine)
 
static QScriptValue variantToScriptValue (const QVariant &, QScriptEngine *)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Public Variables

QMutex m_lock
 
int m_nextId
 
QWaitCondition m_wait
 
QDeclarativeEngineqmlengine
 
ScriptEngineworkerEngine
 
QHash< int, WorkerScript * > workers
 

Protected Functions

virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

void processLoad (int, const QUrl &)
 
void processMessage (int, const QVariant &)
 
void reportScriptException (WorkerScript *)
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 121 of file qdeclarativeworkerscript.cpp.

Enumerations

◆ WorkerEventTypes

Enumerator
WorkerDestroyEvent 

Definition at line 125 of file qdeclarativeworkerscript.cpp.

Constructors and Destructors

◆ QDeclarativeWorkerScriptEnginePrivate()

QDeclarativeWorkerScriptEnginePrivate::QDeclarativeWorkerScriptEnginePrivate ( QDeclarativeEngine eng)

Functions

◆ event()

bool QDeclarativeWorkerScriptEnginePrivate::event ( QEvent e)
protectedvirtual

This virtual function receives events to an object and should return true if the event e was recognized and processed.

The event() function can be reimplemented to customize the behavior of an object.

See also
installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), QWidget::event()

Reimplemented from QObject.

Definition at line 263 of file qdeclarativeworkerscript.cpp.

264 {
266  WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
267  processMessage(workerEvent->workerId(), workerEvent->data());
268  return true;
269  } else if (event->type() == (QEvent::Type)WorkerLoadEvent::WorkerLoad) {
270  WorkerLoadEvent *workerEvent = static_cast<WorkerLoadEvent *>(event);
271  processLoad(workerEvent->workerId(), workerEvent->url());
272  return true;
273  } else if (event->type() == (QEvent::Type)WorkerDestroyEvent) {
274  emit stopThread();
275  return true;
276  } else {
277  return QObject::event(event);
278  }
279 }
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define emit
Definition: qobjectdefs.h:76
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62

◆ get()

static QDeclarativeWorkerScriptEnginePrivate* QDeclarativeWorkerScriptEnginePrivate::get ( QScriptEngine e)
inlinestatic

Definition at line 150 of file qdeclarativeworkerscript.cpp.

Referenced by onMessage(), reportScriptException(), and sendMessage().

150  {
151  return static_cast<ScriptEngine *>(e)->p;
152  }

◆ getWorker()

QScriptValue QDeclarativeWorkerScriptEnginePrivate::getWorker ( int  id)

Definition at line 237 of file qdeclarativeworkerscript.cpp.

Referenced by processLoad().

238 {
240 
241  if (iter == workers.end())
242  return workerEngine->nullValue();
243 
244  WorkerScript *script = *iter;
245  if (!script->initialized) {
246 
247  script->initialized = true;
248  script->object = workerEngine->newObject();
249 
251  api.setData(script->id);
252 
256 
257  script->object.setProperty(QLatin1String("WorkerScript"), api);
258  }
259 
260  return script->object;
261 }
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
The WorkerScript element enables the use of threads in QML.
static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QScriptValue newObject()
Creates a QtScript object of class Object.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine)
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.

◆ onMessage()

QScriptValue QDeclarativeWorkerScriptEnginePrivate::onMessage ( QScriptContext ctxt,
QScriptEngine engine 
)
static

Definition at line 199 of file qdeclarativeworkerscript.cpp.

Referenced by getWorker().

200 {
202 
203  int id = ctxt->thisObject().data().toVariant().toInt();
204 
205  WorkerScript *script = p->workers.value(id);
206  if (!script)
207  return engine->undefinedValue();
208 
209  if (ctxt->argumentCount() >= 1)
210  script->callback = ctxt->argument(0);
211 
212  return script->callback;
213 }
The WorkerScript element enables the use of threads in QML.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static QDeclarativeWorkerScriptEnginePrivate * get(QScriptEngine *e)
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ processLoad()

void QDeclarativeWorkerScriptEnginePrivate::processLoad ( int  id,
const QUrl url 
)
private

Definition at line 300 of file qdeclarativeworkerscript.cpp.

Referenced by event().

301 {
302  if (url.isRelative())
303  return;
304 
306 
307  QFile f(fileName);
308  if (f.open(QIODevice::ReadOnly)) {
309  QByteArray data = f.readAll();
310  QString sourceCode = QString::fromUtf8(data);
311 
312  QScriptValue activation = getWorker(id);
313 
315  QScriptValue urlContext = workerEngine->newObject();
316  urlContext.setData(QScriptValue(workerEngine, url.toString()));
317  ctxt->pushScope(urlContext);
318  ctxt->pushScope(activation);
319  ctxt->setActivationObject(activation);
321 
322  workerEngine->baseUrl = url;
323  workerEngine->evaluate(sourceCode);
324 
325  WorkerScript *script = workers.value(id);
326  if (script) {
327  script->source = url;
329  reportScriptException(script);
331  }
332  }
333 
335  } else {
336  qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString();
337  }
338 }
static QString urlToLocalFileOrQrc(const QUrl &url)
The QScriptContext class represents a Qt Script function invocation.
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
The WorkerScript element enables the use of threads in QML.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void popContext()
Pops the current execution context and restores the previous one.
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
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
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QScriptValue newObject()
Creates a QtScript object of class Object.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
void clearExceptions()
Clears any uncaught exceptions in this engine.
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QString fileName(const QString &fileUrl)
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.

◆ processMessage()

void QDeclarativeWorkerScriptEnginePrivate::processMessage ( int  id,
const QVariant data 
)
private

Definition at line 281 of file qdeclarativeworkerscript.cpp.

Referenced by event().

282 {
283  WorkerScript *script = workers.value(id);
284  if (!script)
285  return;
286 
287  if (script->callback.isFunction()) {
290 
291  script->callback.call(script->object, args);
292 
294  reportScriptException(script);
296  }
297  }
298 }
The WorkerScript element enables the use of threads in QML.
static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
void clearExceptions()
Clears any uncaught exceptions in this engine.
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ reportScriptException()

void QDeclarativeWorkerScriptEnginePrivate::reportScriptException ( WorkerScript script)
private

Definition at line 340 of file qdeclarativeworkerscript.cpp.

Referenced by processLoad(), and processMessage().

341 {
342  if (!script || !workerEngine->hasUncaughtException())
343  return;
344 
347  error.setUrl(script->source);
348 
350 
351  QMutexLocker(&p->m_lock);
352  if (script->owner)
353  QCoreApplication::postEvent(script->owner, new WorkerErrorEvent(error));
354 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
#define error(msg)
static QDeclarativeWorkerScriptEnginePrivate * get(QScriptEngine *e)
The QDeclarativeError class encapsulates a QML error.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...

◆ scriptValueToVariant()

QVariant QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant ( const QScriptValue value)
static

Definition at line 356 of file qdeclarativeworkerscript.cpp.

Referenced by QDeclarativeWorkerScript::sendMessage(), and sendMessage().

357 {
358  if (value.isBool()) {
359  return QVariant(value.toBool());
360  } else if (value.isString()) {
361  return QVariant(value.toString());
362  } else if (value.isNumber()) {
363  return QVariant((qreal)value.toNumber());
364  } else if (value.isDate()) {
365  return QVariant(value.toDateTime());
366 #ifndef QT_NO_REGEXP
367  } else if (value.isRegExp()) {
368  return QVariant(value.toRegExp());
369 #endif
370  } else if (value.isArray()) {
371  QVariantList list;
372 
373  quint32 length = (quint32)value.property(QLatin1String("length")).toNumber();
374 
375  for (quint32 ii = 0; ii < length; ++ii) {
376  QVariant v = scriptValueToVariant(value.property(ii));
377  list << v;
378  }
379 
380  return QVariant(list);
381  } else if (value.isQObject()) {
383  if (lm) {
385  if (agent) {
387  return QVariant::fromValue(v);
388  } else {
389  return QVariant();
390  }
391  } else {
392  // No other QObject's are allowed to be sent
393  return QVariant();
394  }
395  } else if (value.isObject()) {
397 
398  QScriptValueIterator iter(value);
399 
400  while (iter.hasNext()) {
401  iter.next();
402  hash.insert(iter.name(), scriptValueToVariant(iter.value()));
403  }
404 
405  return QVariant(hash);
406  }
407 
408  return QVariant();
409 
410 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
double qreal
Definition: qglobal.h:1193
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
QDeclarativeListModelWorkerAgent * agent()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
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 QScriptValueIterator class provides a Java-style iterator for QScriptValue.
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
unsigned int quint32
Definition: qglobal.h:938
QRegExp toRegExp() const
Returns the QRegExp representation of this value.
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
static QVariant scriptValueToVariant(const QScriptValue &)
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ sendMessage()

QScriptValue QDeclarativeWorkerScriptEnginePrivate::sendMessage ( QScriptContext ctxt,
QScriptEngine engine 
)
static

Definition at line 215 of file qdeclarativeworkerscript.cpp.

Referenced by getWorker().

216 {
217  if (!ctxt->argumentCount())
218  return engine->undefinedValue();
219 
221 
222  int id = ctxt->thisObject().data().toVariant().toInt();
223 
224  WorkerScript *script = p->workers.value(id);
225  if (!script)
226  return engine->undefinedValue();
227 
228  QMutexLocker(&p->m_lock);
229 
230  if (script->owner)
231  QCoreApplication::postEvent(script->owner,
232  new WorkerDataEvent(0, scriptValueToVariant(ctxt->argument(0))));
233 
234  return engine->undefinedValue();
235 }
The WorkerScript element enables the use of threads in QML.
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static QDeclarativeWorkerScriptEnginePrivate * get(QScriptEngine *e)
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QVariant scriptValueToVariant(const QScriptValue &)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ stopThread

void QDeclarativeWorkerScriptEnginePrivate::stopThread ( )
signal

Referenced by event().

◆ variantToScriptValue()

QScriptValue QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue ( const QVariant value,
QScriptEngine engine 
)
static

Definition at line 412 of file qdeclarativeworkerscript.cpp.

Referenced by QDeclarativeWorkerScript::event(), and processMessage().

413 {
414  if (value.userType() == QVariant::Bool) {
415  return QScriptValue(value.toBool());
416  } else if (value.userType() == QVariant::String) {
417  return QScriptValue(value.toString());
418  } else if (value.userType() == QMetaType::QReal) {
419  return QScriptValue(value.toReal());
420  } else if (value.userType() == QVariant::DateTime) {
421  return engine->newDate(value.toDateTime());
422 #ifndef QT_NO_REGEXP
423  } else if (value.userType() == QVariant::RegExp) {
424  return engine->newRegExp(value.toRegExp());
425 #endif
426  } else if (value.userType() == qMetaTypeId<QDeclarativeListModelWorkerAgent::VariantRef>()) {
428  if (vr.a->scriptEngine() == 0)
429  vr.a->setScriptEngine(engine);
430  else if (vr.a->scriptEngine() != engine)
431  return engine->nullValue();
432  QScriptValue o = engine->newQObject(vr.a);
433  o.setData(engine->newVariant(value)); // Keeps the agent ref so that it is cleaned up on gc
434  return o;
435  } else if (value.userType() == QMetaType::QVariantList) {
436  QVariantList list = qvariant_cast<QVariantList>(value);
437  QScriptValue rv = engine->newArray(list.count());
438 
439  for (quint32 ii = 0; ii < quint32(list.count()); ++ii)
440  rv.setProperty(ii, variantToScriptValue(list.at(ii), engine));
441 
442  return rv;
443  } else if (value.userType() == QMetaType::QVariantHash) {
444 
446 
447  QScriptValue rv = engine->newObject();
448 
449  for (QVariantHash::ConstIterator iter = hash.begin(); iter != hash.end(); ++iter)
450  rv.setProperty(iter.key(), variantToScriptValue(iter.value(), engine));
451 
452  return rv;
453  } else {
454  return engine->nullValue();
455  }
456 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
QRegExp toRegExp() const
Returns the variant as a QRegExp if the variant has type() RegExp ; otherwise returns an empty QRegEx...
Definition: qvariant.cpp:2562
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
QScriptValue newRegExp(const QRegExp &regexp)
Creates a QtScript object of class RegExp with the given regexp.
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue newObject()
Creates a QtScript object of class Object.
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
unsigned int quint32
Definition: qglobal.h:938
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QScriptValue newDate(qsreal value)
Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 Jan...
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.

Properties

◆ m_lock

QMutex QDeclarativeWorkerScriptEnginePrivate::m_lock

◆ m_nextId

int QDeclarativeWorkerScriptEnginePrivate::m_nextId

Definition at line 174 of file qdeclarativeworkerscript.cpp.

◆ m_wait

QWaitCondition QDeclarativeWorkerScriptEnginePrivate::m_wait

◆ qmlengine

QDeclarativeEngine* QDeclarativeWorkerScriptEnginePrivate::qmlengine

◆ workerEngine

ScriptEngine* QDeclarativeWorkerScriptEnginePrivate::workerEngine

◆ workers

QHash<int, WorkerScript *> QDeclarativeWorkerScriptEnginePrivate::workers

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