Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QDeclarativeExpressionPrivate Class Reference

#include <qdeclarativeexpression_p.h>

Inheritance diagram for QDeclarativeExpressionPrivate:
QObjectPrivate QDeclarativeQtScriptExpression QObjectData QDeclarativeAbstractExpression QDeclarativeDelayedError QDeclarativeBindingPrivate

Public Functions

void _q_notify ()
 
virtual void emitValueChanged ()
 
void init (QDeclarativeContextData *, const QString &, QObject *)
 
void init (QDeclarativeContextData *, const QScriptValue &, QObject *)
 
void init (QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int)
 
 QDeclarativeExpressionPrivate ()
 
QScriptValue scriptValue (QObject *secondaryScope=0, bool *isUndefined=0)
 
QVariant value (QObject *secondaryScope=0, bool *isUndefined=0)
 
 ~QDeclarativeExpressionPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 
- Public Functions inherited from QDeclarativeQtScriptExpression
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 ()
 

Static Public Functions

static QScriptValue evalInObjectScope (QDeclarativeContextData *, QObject *, const QString &, const QString &, int, QScriptValue *)
 
static QScriptValue evalInObjectScope (QDeclarativeContextData *, QObject *, const QScriptProgram &, QScriptValue *)
 
static void exceptionToError (QScriptEngine *, QDeclarativeError &)
 
static QDeclarativeExpressionPrivateget (QDeclarativeExpression *expr)
 
static QDeclarativeExpressionget (QDeclarativeExpressionPrivate *expr)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

bool expressionFunctionValid:1
 
int line
 
QByteArray name
 
QString url
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 
- Public Variables inherited from QDeclarativeQtScriptExpression
QDeclarativeRefCountdataRef
 
QString expression
 
QScriptValue expressionContext
 
QScriptValue expressionFunction
 
Mode expressionFunctionMode
 
QObjectscopeObject
 
- Public Variables inherited from QDeclarativeDelayedError
QDeclarativeError error
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Public Types inherited from QDeclarativeQtScriptExpression
enum  EvaluateFlag { RequiresThisObject = 0x01 }
 
enum  Mode { SharedContext, ExplicitContext }
 

Detailed Description

Definition at line 175 of file qdeclarativeexpression_p.h.

Constructors and Destructors

◆ QDeclarativeExpressionPrivate()

QDeclarativeExpressionPrivate::QDeclarativeExpressionPrivate ( )

◆ ~QDeclarativeExpressionPrivate()

QDeclarativeExpressionPrivate::~QDeclarativeExpressionPrivate ( )

Definition at line 92 of file qdeclarativeexpression.cpp.

93 {
94 }

Functions

◆ _q_notify()

void QDeclarativeExpressionPrivate::_q_notify ( )
Warning
This function is not part of the public interface.

Definition at line 801 of file qdeclarativeexpression.cpp.

802 {
804 }

◆ emitValueChanged()

void QDeclarativeExpressionPrivate::emitValueChanged ( )
virtual

Reimplemented in QDeclarativeBindingPrivate.

Definition at line 824 of file qdeclarativeexpression.cpp.

825 {
827  emit q->valueChanged();
828 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QDeclarativeExpression class evaluates JavaScript in a QML context.

◆ evalInObjectScope() [1/2]

QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope ( QDeclarativeContextData context,
QObject object,
const QString program,
const QString fileName,
int  lineNumber,
QScriptValue contextObject 
)
static

Definition at line 174 of file qdeclarativeexpression.cpp.

Referenced by init(), QDeclarativeVMEMetaObject::method(), and QDeclarativeEngineDebugService::setMethodBody().

177 {
180  if (contextObject) {
181  *contextObject = ep->contextClass->newContext(context, object);
182  scriptContext->pushScope(*contextObject);
183  } else {
184  scriptContext->pushScope(ep->contextClass->newContext(context, object));
185  }
186  scriptContext->pushScope(ep->globalClass->staticGlobalObject());
187  QScriptValue rv = ep->scriptEngine.evaluate(program, fileName, lineNumber);
188  ep->scriptEngine.popContext();
189  return rv;
190 }
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...
QDeclarativeEngine * engine
QDeclarativeGlobalScriptClass * globalClass
void popContext()
Pops the current execution context and restores the previous one.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
const QScriptValue & staticGlobalObject() const
QDeclarativeScriptEngine scriptEngine
QScriptValue newContext(QDeclarativeContextData *, QObject *=0)
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QDeclarativeContextScriptClass * contextClass

◆ evalInObjectScope() [2/2]

QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope ( QDeclarativeContextData context,
QObject object,
const QScriptProgram program,
QScriptValue contextObject 
)
static

Definition at line 192 of file qdeclarativeexpression.cpp.

195 {
198  if (contextObject) {
199  *contextObject = ep->contextClass->newContext(context, object);
200  scriptContext->pushScope(*contextObject);
201  } else {
202  scriptContext->pushScope(ep->contextClass->newContext(context, object));
203  }
204  scriptContext->pushScope(ep->globalClass->staticGlobalObject());
205  QScriptValue rv = ep->scriptEngine.evaluate(program);
206  ep->scriptEngine.popContext();
207  return rv;
208 }
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...
QDeclarativeEngine * engine
QDeclarativeGlobalScriptClass * globalClass
void popContext()
Pops the current execution context and restores the previous one.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
const QScriptValue & staticGlobalObject() const
QDeclarativeScriptEngine scriptEngine
QScriptValue newContext(QDeclarativeContextData *, QObject *=0)
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QDeclarativeContextScriptClass * contextClass

◆ exceptionToError()

void QDeclarativeExpressionPrivate::exceptionToError ( QScriptEngine scriptEngine,
QDeclarativeError error 
)
static

Definition at line 386 of file qdeclarativeexpression.cpp.

Referenced by QDeclarativeContextData::addImportedScript(), QDeclarativeQtScriptExpression::eval(), QDeclarativeXMLHttpRequest::printError(), and QDeclarativeWorkerScriptEnginePrivate::reportScriptException().

388 {
389  if (scriptEngine->hasUncaughtException() &&
390  scriptEngine->uncaughtException().isError()) {
391 
393  int lineNumber = scriptEngine->uncaughtExceptionLineNumber();
394 
395  QScriptValue exception = scriptEngine->uncaughtException();
396  QLatin1String fileNameProp("fileName");
397 
398  if (!exception.property(fileNameProp).toString().isEmpty()){
399  fileName = exception.property(fileNameProp).toString();
400  } else {
401  fileName = QLatin1String("<Unknown File>");
402  }
403 
404  error.setUrl(QUrl(fileName));
405  error.setLine(lineNumber);
406  error.setColumn(-1);
407  error.setDescription(exception.toString());
408  } else {
409  error = QDeclarativeError();
410  }
411 }
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...
void setDescription(const QString &)
Sets the error description.
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
void setColumn(int)
Sets the error column number.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QDeclarativeError class encapsulates a QML error.
int uncaughtExceptionLineNumber() const
Returns the line number where the last uncaught exception occurred.
void setLine(int)
Sets the error line number.
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
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)
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...

◆ get() [1/2]

static QDeclarativeExpressionPrivate* QDeclarativeExpressionPrivate::get ( QDeclarativeExpression expr)
inlinestatic

Definition at line 189 of file qdeclarativeexpression_p.h.

Referenced by QDeclarativeBoundSignal::qt_metacall().

189  {
190  return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
191  }
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177

◆ get() [2/2]

static QDeclarativeExpression* QDeclarativeExpressionPrivate::get ( QDeclarativeExpressionPrivate expr)
inlinestatic

Definition at line 192 of file qdeclarativeexpression_p.h.

192  {
193  return expr->q_func();
194  }

◆ init() [1/3]

void QDeclarativeExpressionPrivate::init ( QDeclarativeContextData ctxt,
const QString expr,
QObject me 
)

◆ init() [2/3]

void QDeclarativeExpressionPrivate::init ( QDeclarativeContextData ctxt,
const QScriptValue func,
QObject me 
)

Definition at line 106 of file qdeclarativeexpression.cpp.

108 {
109  expression = func.toString();
110 
112  scopeObject = me;
113 
114  expressionFunction = func;
117 }
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
void setContext(QDeclarativeContextData *)

◆ init() [3/3]

void QDeclarativeExpressionPrivate::init ( QDeclarativeContextData ctxt,
void *  expr,
QDeclarativeRefCount rc,
QObject me,
const QString srcUrl,
int  lineNumber 
)

Definition at line 119 of file qdeclarativeexpression.cpp.

122 {
123  url = srcUrl;
124  line = lineNumber;
125 
126  if (dataRef) dataRef->release();
127  dataRef = rc;
128  if (dataRef) dataRef->addref();
129 
130  quint32 *exprData = (quint32 *)expr;
132 
133  expression = QString::fromRawData((QChar *)(exprData + 2), exprData[1]);
134 
135  int progIdx = *(exprData);
136  bool isSharedProgram = progIdx & 0x80000000;
137  progIdx &= 0x7FFFFFFF;
138 
139  QDeclarativeEngine *engine = ctxt->engine;
142 
143  if (isSharedProgram) {
144 
145  if (!dd->cachedClosures.at(progIdx)) {
146  QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
147  scriptContext->pushScope(ep->contextClass->newSharedContext());
148  scriptContext->pushScope(ep->globalClass->staticGlobalObject());
149  dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(expression, url, line));
150  scriptEngine->popContext();
151  }
152 
153  expressionFunction = *dd->cachedClosures.at(progIdx);
156 
157  } else {
158 
159  if (!dd->cachedPrograms.at(progIdx)) {
160  dd->cachedPrograms[progIdx] = new QScriptProgram(expression, url, line);
161  }
162 
163  expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx),
165 
168  }
169 
171  scopeObject = me;
172 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
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...
QDeclarativeEngine * engine
QDeclarativeGlobalScriptClass * globalClass
void popContext()
Pops the current execution context and restores the previous one.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static QString fromRawData(const QChar *, int size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
Definition: qstring.cpp:7673
const QScriptValue & staticGlobalObject() const
The QScriptEngine class provides an environment for evaluating Qt Script code.
static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &, int, QScriptValue *)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QScriptProgram * > cachedPrograms
QList< QScriptValue * > cachedClosures
The QDeclarativeEngine class provides an environment for instantiating QML components.
unsigned int quint32
Definition: qglobal.h:938
void setContext(QDeclarativeContextData *)
The QScriptProgram class encapsulates a Qt Script program.
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QDeclarativeContextScriptClass * contextClass

◆ scriptValue()

QScriptValue QDeclarativeExpressionPrivate::scriptValue ( QObject secondaryScope = 0,
bool *  isUndefined = 0 
)

Definition at line 631 of file qdeclarativeexpression.cpp.

632 {
634  QDeclarativeEngine *engine = context()->engine;
636 
638 
639  QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
641  scriptContext->pushScope(expressionContext);
642  scriptContext->pushScope(ep->globalClass->staticGlobalObject());
643 
645  rewriteBinding.setName(name);
646  bool ok = true;
647  const QString code = rewriteBinding(expression, &ok);
648  if (ok)
649  expressionFunction = scriptEngine->evaluate(code, url, line);
650 
651  scriptEngine->popContext();
654  }
655 
656  return QDeclarativeQtScriptExpression::scriptValue(secondaryScope, isUndefined);
657 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
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...
void setName(const QByteArray &name)
QDeclarativeEngine * engine
QDeclarativeGlobalScriptClass * globalClass
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 QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
const QScriptValue & staticGlobalObject() const
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined)
QScriptValue newContext(QDeclarativeContextData *, QObject *=0)
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeContextData * context() const
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QDeclarativeContextScriptClass * contextClass

◆ value()

QVariant QDeclarativeExpressionPrivate::value ( QObject secondaryScope = 0,
bool *  isUndefined = 0 
)

Definition at line 659 of file qdeclarativeexpression.cpp.

Referenced by QDeclarativeBoundSignal::qt_metacall().

660 {
662 
663  if (!context() || !context()->isValid()) {
664  qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context");
665  return QVariant();
666  }
667 
669 
670  return ep->scriptValueToVariant(scriptValue(secondaryScope, isUndefined), qMetaTypeId<QList<QObject*> >());
671 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptValue scriptValue(QObject *secondaryScope=0, bool *isUndefined=0)
int qMetaTypeId()
Definition: qmetatype.h:224
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QVariant scriptValueToVariant(const QScriptValue &, int hint=QVariant::Invalid)
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qWarning(const char *,...)
QDeclarativeContextData * context() const
The QDeclarativeExpression class evaluates JavaScript in a QML context.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

Properties

◆ expressionFunctionValid

bool QDeclarativeExpressionPrivate::expressionFunctionValid

Definition at line 205 of file qdeclarativeexpression_p.h.

Referenced by init().

◆ line

int QDeclarativeExpressionPrivate::line

Definition at line 208 of file qdeclarativeexpression_p.h.

Referenced by init().

◆ name

QByteArray QDeclarativeExpressionPrivate::name

Definition at line 209 of file qdeclarativeexpression_p.h.

◆ url

QString QDeclarativeExpressionPrivate::url

Definition at line 207 of file qdeclarativeexpression_p.h.

Referenced by init().


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