Qt 4.8
Classes | Public Types | Public Functions | Public Variables | Private Functions | Properties | List of all members
QDeclarativeQtScriptExpression Class Reference

#include <qdeclarativeexpression_p.h>

Inheritance diagram for QDeclarativeQtScriptExpression:
QDeclarativeAbstractExpression QDeclarativeDelayedError QDeclarativeExpressionPrivate QDeclarativeBindingPrivate

Classes

class  DeleteWatcher
 

Public Types

enum  EvaluateFlag { RequiresThisObject = 0x01 }
 
enum  Mode { SharedContext, ExplicitContext }
 

Public Functions

EvaluateFlags evaluateFlags () const
 
bool notifyOnValueChange () const
 
 QDeclarativeQtScriptExpression ()
 
void resetNotifyOnChange ()
 
QScriptValue scriptValue (QObject *secondaryScope, bool *isUndefined)
 
void setEvaluateFlags (EvaluateFlags flags)
 
void setNotifyObject (QObject *, int)
 
void setNotifyOnValueChange (bool)
 
virtual ~QDeclarativeQtScriptExpression ()
 
- Public Functions inherited from QDeclarativeAbstractExpression
QDeclarativeContextDatacontext () const
 
bool isValid () const
 
 QDeclarativeAbstractExpression ()
 
virtual void refresh ()
 
void setContext (QDeclarativeContextData *)
 
virtual ~QDeclarativeAbstractExpression ()
 
- Public Functions inherited from QDeclarativeDelayedError
bool addError (QDeclarativeEnginePrivate *)
 
 QDeclarativeDelayedError ()
 
void removeError ()
 
 ~QDeclarativeDelayedError ()
 

Public Variables

QDeclarativeRefCountdataRef
 
QString expression
 
QScriptValue expressionContext
 
QScriptValue expressionFunction
 
Mode expressionFunctionMode
 
QObjectscopeObject
 
- Public Variables inherited from QDeclarativeDelayedError
QDeclarativeError error
 

Private Functions

void clearGuards ()
 
QScriptValue eval (QObject *secondaryScope, bool *isUndefined)
 
void updateGuards (const QPODVector< QDeclarativeEnginePrivate::CapturedProperty, 16 > &properties)
 

Properties

bool * deleted
 
EvaluateFlags evalFlags
 
QDeclarativeNotifierEndpointguardList
 
int guardListLength
 
QObjectguardObject
 
int guardObjectNotifyIndex
 
bool trackChange
 

Detailed Description

Definition at line 110 of file qdeclarativeexpression_p.h.

Enumerations

◆ EvaluateFlag

Enumerator
RequiresThisObject 

Definition at line 116 of file qdeclarativeexpression_p.h.

◆ Mode

Constructors and Destructors

◆ QDeclarativeQtScriptExpression()

QDeclarativeQtScriptExpression::QDeclarativeQtScriptExpression ( )

◆ ~QDeclarativeQtScriptExpression()

QDeclarativeQtScriptExpression::~QDeclarativeQtScriptExpression ( )
virtual

Definition at line 80 of file qdeclarativeexpression.cpp.

81 {
82  if (guardList) { delete [] guardList; guardList = 0; }
83  if (dataRef) dataRef->release();
84  if (deleted) *deleted = true;
85 }
QDeclarativeNotifierEndpoint * guardList

Functions

◆ clearGuards()

void QDeclarativeQtScriptExpression::clearGuards ( )
private

Definition at line 806 of file qdeclarativeexpression.cpp.

807 {
808  delete [] guardList;
809  guardList = 0;
810  guardListLength = 0;
811 }
QDeclarativeNotifierEndpoint * guardList

◆ eval()

QScriptValue QDeclarativeQtScriptExpression::eval ( QObject secondaryScope,
bool *  isUndefined 
)
private

Definition at line 493 of file qdeclarativeexpression.cpp.

494 {
495  Q_ASSERT(context() && context()->engine);
496 
497  DeleteWatcher watcher(this);
498 
499  QDeclarativeEngine *engine = context()->engine;
501 
503 
504  QDeclarativeContextData *oldSharedContext = 0;
505  QObject *oldSharedScope = 0;
506  QObject *oldOverride = 0;
507  bool isShared = (expressionFunctionMode == SharedContext);
508 
509  if (isShared) {
510  oldSharedContext = ep->sharedContext;
511  oldSharedScope = ep->sharedScope;
512  ep->sharedContext = context();
513  ep->sharedScope = scopeObject;
514  } else {
515  oldOverride = ep->contextClass->setOverrideObject(expressionContext, secondaryScope);
516  }
517 
518  QScriptValue thisObject;
520  thisObject = ep->objectClass->newQObject(scopeObject);
521  QScriptValue svalue = expressionFunction.call(thisObject); // This could cause this c++ object to be deleted
522 
523  if (isShared) {
524  ep->sharedContext = oldSharedContext;
525  ep->sharedScope = oldSharedScope;
526  } else if (!watcher.wasDeleted()) {
528  }
529 
530  if (isUndefined)
531  *isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException();
532 
533  // Handle exception
534  if (scriptEngine->hasUncaughtException()) {
535  if (!watcher.wasDeleted())
537 
538  scriptEngine->clearExceptions();
539  return QScriptValue();
540  } else {
541  if (!watcher.wasDeleted())
543 
544  return svalue;
545  }
546 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
QObject * setOverrideObject(QScriptValue &, QObject *)
QDeclarativeEngine * engine
#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.
The QDeclarativeError class encapsulates a QML error.
QDeclarativeContextData * sharedContext
QDeclarativeObjectScriptClass * objectClass
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeContextData * context() const
void clearExceptions()
Clears any uncaught exceptions in this engine.
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
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
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...
QDeclarativeContextScriptClass * contextClass

◆ evaluateFlags()

QDeclarativeQtScriptExpression::EvaluateFlags QDeclarativeQtScriptExpression::evaluateFlags ( ) const

Definition at line 449 of file qdeclarativeexpression.cpp.

450 {
451  return evalFlags;
452 }

◆ notifyOnValueChange()

bool QDeclarativeQtScriptExpression::notifyOnValueChange ( ) const

Definition at line 413 of file qdeclarativeexpression.cpp.

414 {
415  return trackChange;
416 }

◆ resetNotifyOnChange()

void QDeclarativeQtScriptExpression::resetNotifyOnChange ( )

Definition at line 425 of file qdeclarativeexpression.cpp.

◆ scriptValue()

QScriptValue QDeclarativeQtScriptExpression::scriptValue ( QObject secondaryScope,
bool *  isUndefined 
)

Definition at line 454 of file qdeclarativeexpression.cpp.

Referenced by QDeclarativeExpressionPrivate::scriptValue().

455 {
456  Q_ASSERT(context() && context()->engine);
458 
459  if (!expressionFunction.isValid()) {
460  if (isUndefined) *isUndefined = true;
461  return QScriptValue();
462  }
463 
464  DeleteWatcher watcher(this);
465 
467 
468  bool lastCaptureProperties = ep->captureProperties;
471  ep->capturedProperties.copyAndClear(lastCapturedProperties);
472 
473  QScriptValue value = eval(secondaryScope, isUndefined);
474 
475  if (!watcher.wasDeleted() && trackChange) {
476  if (ep->capturedProperties.count() == 0) {
477 
478  if (guardList) clearGuards();
479 
480  } else {
481 
483 
484  }
485  }
486 
487  lastCapturedProperties.copyAndClear(ep->capturedProperties);
488  ep->captureProperties = lastCaptureProperties;
489 
490  return value;
491 }
void copyAndClear(QPODVector< T, Increment > &other)
Definition: qpodvector_p.h:152
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeNotifierEndpoint * guardList
QDeclarativeContextData * context() const
void updateGuards(const QPODVector< QDeclarativeEnginePrivate::CapturedProperty, 16 > &properties)
QScriptValue eval(QObject *secondaryScope, bool *isUndefined)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
QPODVector< CapturedProperty, 16 > capturedProperties

◆ setEvaluateFlags()

void QDeclarativeQtScriptExpression::setEvaluateFlags ( EvaluateFlags  flags)

Definition at line 444 of file qdeclarativeexpression.cpp.

445 {
446  evalFlags = flags;
447 }

◆ setNotifyObject()

void QDeclarativeQtScriptExpression::setNotifyObject ( QObject object,
int  notifyIndex 
)

Definition at line 430 of file qdeclarativeexpression.cpp.

431 {
432  if (guardList) clearGuards();
433 
434  if (!object || notifyIndex == -1) {
435  guardObject = 0;
436  notifyIndex = -1;
437  } else {
438  guardObject = object;
439  guardObjectNotifyIndex = notifyIndex;
440 
441  }
442 }
QDeclarativeNotifierEndpoint * guardList

◆ setNotifyOnValueChange()

void QDeclarativeQtScriptExpression::setNotifyOnValueChange ( bool  notify)

Definition at line 418 of file qdeclarativeexpression.cpp.

419 {
420  trackChange = notify;
421  if (!notify && guardList)
422  clearGuards();
423 }
QDeclarativeNotifierEndpoint * guardList

◆ updateGuards()

void QDeclarativeQtScriptExpression::updateGuards ( const QPODVector< QDeclarativeEnginePrivate::CapturedProperty, 16 > &  properties)
private

Definition at line 548 of file qdeclarativeexpression.cpp.

549 {
552 
553  if (properties.count() != guardListLength) {
554  QDeclarativeNotifierEndpoint *newGuardList = new QDeclarativeNotifierEndpoint[properties.count()];
555 
556  for (int ii = 0; ii < qMin(guardListLength, properties.count()); ++ii)
557  guardList[ii].copyAndClear(newGuardList[ii]);
558 
559  delete [] guardList;
560  guardList = newGuardList;
561  guardListLength = properties.count();
562  }
563 
564  bool outputWarningHeader = false;
565  bool noChanges = true;
566  for (int ii = 0; ii < properties.count(); ++ii) {
568  const QDeclarativeEnginePrivate::CapturedProperty &property = properties.at(ii);
569 
570  guard.target = guardObject;
572 
573  if (property.notifier != 0) {
574 
575  if (!noChanges && guard.isConnected(property.notifier)) {
576  // Nothing to do
577 
578  } else {
579  noChanges = false;
580 
581  bool existing = false;
582  for (int jj = 0; !existing && jj < ii; ++jj)
583  if (guardList[jj].isConnected(property.notifier))
584  existing = true;
585 
586  if (existing) {
587  // duplicate
588  guard.disconnect();
589  } else {
590  guard.connect(property.notifier);
591  }
592  }
593 
594 
595  } else if (property.notifyIndex != -1) {
596 
597  if (!noChanges && guard.isConnected(property.object, property.notifyIndex)) {
598  // Nothing to do
599 
600  } else {
601  noChanges = false;
602 
603  bool existing = false;
604  for (int jj = 0; !existing && jj < ii; ++jj)
605  if (guardList[jj].isConnected(property.object, property.notifyIndex))
606  existing = true;
607 
608  if (existing) {
609  // duplicate
610  guard.disconnect();
611  } else {
612  guard.connect(property.object, property.notifyIndex);
613  }
614  }
615 
616  } else {
617  if (!outputWarningHeader) {
618  outputWarningHeader = true;
619  qWarning() << "QDeclarativeExpression: Expression" << expression
620  << "depends on non-NOTIFYable properties:";
621  }
622 
623  const QMetaObject *metaObj = property.object->metaObject();
624  QMetaProperty metaProp = metaObj->property(property.coreIndex);
625 
626  qWarning().nospace() << " " << metaObj->className() << "::" << metaProp.name();
627  }
628  }
629 }
const T & at(int idx) const
Definition: qpodvector_p.h:69
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void connect(QObject *source, int sourceSignal)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qWarning(const char *,...)
QDeclarativeNotifierEndpoint * guardList
const char * name() const
Returns this property&#39;s name.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
const char * property
Definition: qwizard.cpp:138
int count() const
Definition: qpodvector_p.h:148
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

Properties

◆ dataRef

QDeclarativeRefCount* QDeclarativeQtScriptExpression::dataRef

◆ deleted

bool* QDeclarativeQtScriptExpression::deleted
private

◆ evalFlags

EvaluateFlags QDeclarativeQtScriptExpression::evalFlags
private

Definition at line 167 of file qdeclarativeexpression_p.h.

◆ expression

QString QDeclarativeQtScriptExpression::expression

Definition at line 124 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeExpressionPrivate::init().

◆ expressionContext

QScriptValue QDeclarativeQtScriptExpression::expressionContext

Definition at line 129 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeExpressionPrivate::init().

◆ expressionFunction

QScriptValue QDeclarativeQtScriptExpression::expressionFunction

Definition at line 127 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeExpressionPrivate::init().

◆ expressionFunctionMode

Mode QDeclarativeQtScriptExpression::expressionFunctionMode

Definition at line 126 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeExpressionPrivate::init().

◆ guardList

QDeclarativeNotifierEndpoint* QDeclarativeQtScriptExpression::guardList
private

Definition at line 160 of file qdeclarativeexpression_p.h.

Referenced by ~QDeclarativeQtScriptExpression().

◆ guardListLength

int QDeclarativeQtScriptExpression::guardListLength
private

Definition at line 161 of file qdeclarativeexpression_p.h.

◆ guardObject

QObject* QDeclarativeQtScriptExpression::guardObject
private

Definition at line 163 of file qdeclarativeexpression_p.h.

◆ guardObjectNotifyIndex

int QDeclarativeQtScriptExpression::guardObjectNotifyIndex
private

Definition at line 164 of file qdeclarativeexpression_p.h.

◆ scopeObject

QObject* QDeclarativeQtScriptExpression::scopeObject

Definition at line 130 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeExpressionPrivate::init().

◆ trackChange

bool QDeclarativeQtScriptExpression::trackChange
private

Definition at line 158 of file qdeclarativeexpression_p.h.


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