src/declarative/qml/qdeclarativeexpression_p.h
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
   105 private:
   105 private:
   106     QDeclarativeDelayedError  *nextError;
   106     QDeclarativeDelayedError  *nextError;
   107     QDeclarativeDelayedError **prevError;
   107     QDeclarativeDelayedError **prevError;
   108 };
   108 };
   109 
   109 
   110 class QDeclarativeExpressionData : public QDeclarativeAbstractExpression, public QDeclarativeDelayedError, public QDeclarativeRefCount
   110 class QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression, 
   111 {
   111                                        public QDeclarativeDelayedError
   112 public:
   112 {
   113     QDeclarativeExpressionData();
   113 public:
   114     virtual ~QDeclarativeExpressionData();
   114     enum Mode { SharedContext, ExplicitContext };
   115 
   115 
   116     QDeclarativeExpressionPrivate *q;
   116     QDeclarativeQtScriptExpression();
       
   117     virtual ~QDeclarativeQtScriptExpression();
   117 
   118 
   118     QDeclarativeRefCount *dataRef;
   119     QDeclarativeRefCount *dataRef;
       
   120 
   119     QString expression;
   121     QString expression;
   120     bool expressionFunctionValid:1;
   122 
   121     bool expressionRewritten:1;
   123     Mode expressionFunctionMode;
   122     QScriptValue expressionFunction;
   124     QScriptValue expressionFunction;
   123     QScriptValue expressionContext;
   125 
   124 
   126     QScriptValue expressionContext; // Only used in ExplicitContext
   125     QObject *me;
   127     QObject *scopeObject;           // Only used in SharedContext
       
   128 
       
   129     bool notifyOnValueChange() const;
       
   130     void setNotifyOnValueChange(bool);
       
   131     void resetNotifyOnChange();
       
   132     void setNotifyObject(QObject *, int );
       
   133 
       
   134     QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined);
       
   135 
       
   136     class DeleteWatcher {
       
   137     public:
       
   138         inline DeleteWatcher(QDeclarativeQtScriptExpression *data);
       
   139         inline ~DeleteWatcher();
       
   140         inline bool wasDeleted() const;
       
   141     private:
       
   142         bool *m_wasDeleted;
       
   143         bool m_wasDeletedStorage;
       
   144         QDeclarativeQtScriptExpression *m_d;
       
   145     };
       
   146 
       
   147 private:
       
   148     void clearGuards();
       
   149     QScriptValue eval(QObject *secondaryScope, bool *isUndefined);
       
   150     void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties);
       
   151 
   126     bool trackChange;
   152     bool trackChange;
   127 
       
   128     bool isShared;
       
   129 
       
   130     QString url; // This is a QString for a reason.  QUrls are slooooooow...
       
   131     int line;
       
   132 
   153 
   133     QDeclarativeNotifierEndpoint *guardList;
   154     QDeclarativeNotifierEndpoint *guardList;
   134     int guardListLength;
   155     int guardListLength;
       
   156 
       
   157     QObject *guardObject;
       
   158     int guardObjectNotifyIndex;
       
   159     bool *deleted;
   135 };
   160 };
   136 
   161 
   137 class QDeclarativeExpression;
   162 class QDeclarativeExpression;
   138 class QString;
   163 class QString;
   139 class QDeclarativeExpressionPrivate : public QObjectPrivate
   164 class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression
   140 {
   165 {
   141     Q_DECLARE_PUBLIC(QDeclarativeExpression)
   166     Q_DECLARE_PUBLIC(QDeclarativeExpression)
   142 public:
   167 public:
   143     QDeclarativeExpressionPrivate();
   168     QDeclarativeExpressionPrivate();
   144     QDeclarativeExpressionPrivate(QDeclarativeExpressionData *);
       
   145     ~QDeclarativeExpressionPrivate();
   169     ~QDeclarativeExpressionPrivate();
   146 
   170 
   147     void init(QDeclarativeContextData *, const QString &, QObject *);
   171     void init(QDeclarativeContextData *, const QString &, QObject *);
   148     void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int);
   172     void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int);
   149 
   173 
   150     QDeclarativeExpressionData *data;
       
   151 
       
   152     QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0);
   174     QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0);
   153     QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0);
   175     QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0);
   154 
       
   155     QScriptValue eval(QObject *secondaryScope, bool *isUndefined = 0);
       
   156 
       
   157     void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties);
       
   158     void clearGuards();
       
   159 
   176 
   160     static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) {
   177     static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) {
   161         return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
   178         return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
   162     }
   179     }
   163     static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) {
   180     static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) {
   170     static void exceptionToError(QScriptEngine *, QDeclarativeError &);
   187     static void exceptionToError(QScriptEngine *, QDeclarativeError &);
   171     static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &,
   188     static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &,
   172                                           int, QScriptValue *);
   189                                           int, QScriptValue *);
   173     static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, 
   190     static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, 
   174                                           QScriptValue *);
   191                                           QScriptValue *);
   175 };
   192 
       
   193     bool expressionFunctionValid:1;
       
   194 
       
   195     QString url; // This is a QString for a reason.  QUrls are slooooooow...
       
   196     int line;
       
   197 };
       
   198 
       
   199 QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data)
       
   200 : m_wasDeletedStorage(false), m_d(data) 
       
   201 {
       
   202     if (!m_d->deleted) 
       
   203         m_d->deleted = &m_wasDeletedStorage; 
       
   204     m_wasDeleted = m_d->deleted;
       
   205 }
       
   206 
       
   207 QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher() 
       
   208 {
       
   209     if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted)
       
   210         m_d->deleted = 0;
       
   211 }
       
   212 
       
   213 bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const 
       
   214 { 
       
   215     return *m_wasDeleted; 
       
   216 }
   176 
   217 
   177 QT_END_NAMESPACE
   218 QT_END_NAMESPACE
   178 
   219 
   179 #endif // QDECLARATIVEEXPRESSION_P_H
   220 #endif // QDECLARATIVEEXPRESSION_P_H