Qt 4.8
Classes | Public Functions | Static Public Functions | Public Variables | Private Functions | List of all members
QDeclarativeContextData Class Reference

#include <qdeclarativecontext_p.h>

Classes

struct  ContextGuard
 

Public Functions

void addImportedScript (const QDeclarativeParser::Object::ScriptBlock &script)
 
void addObject (QObject *)
 
QDeclarativeContextasQDeclarativeContext ()
 
QDeclarativeContextPrivateasQDeclarativeContextPrivate ()
 
void clearContext ()
 
void destroy ()
 
QString findObjectId (const QObject *obj) const
 
void invalidate ()
 
bool isValid () const
 
 QDeclarativeContextData ()
 
 QDeclarativeContextData (QDeclarativeContext *)
 
void refreshExpressions ()
 
QUrl resolvedUrl (const QUrl &)
 
void setIdProperty (int, QObject *)
 
void setIdPropertyData (QDeclarativeIntegerCache *)
 
void setParent (QDeclarativeContextData *)
 

Static Public Functions

static QDeclarativeContextDataget (QDeclarativeContext *context)
 

Public Variables

QDeclarativeContextDatachildContexts
 
QDeclarativeComponentAttachedcomponentAttached
 
QDeclarativeGuardedContextDatacontextGuards
 
QObjectcontextObject
 
QDeclarativeDatacontextObjects
 
QDeclarativeEngineengine
 
QDeclarativeAbstractExpressionexpressions
 
int idValueCount
 
ContextGuardidValues
 
QList< QScriptValueimportedScripts
 
QDeclarativeTypeNameCacheimports
 
bool isInternal
 
QDeclarativeContextDatalinkedContext
 
QDeclarativeContextDatanextChild
 
QDeclarativeCompiledBindingsoptimizedBindings
 
QDeclarativeContextDataparent
 
QDeclarativeContextData ** prevChild
 
QDeclarativeIntegerCachepropertyNames
 
QDeclarativeContextpublicContext
 
QUrl url
 

Private Functions

 ~QDeclarativeContextData ()
 

Detailed Description

Definition at line 110 of file qdeclarativecontext_p.h.

Constructors and Destructors

◆ QDeclarativeContextData() [1/2]

QDeclarativeContextData::QDeclarativeContextData ( )

Definition at line 503 of file qdeclarativecontext.cpp.

504 : parent(0), engine(0), isInternal(false), publicContext(0), propertyNames(0), contextObject(0),
508 {
509 }
QDeclarativeEngine * engine
QDeclarativeContext * publicContext
QDeclarativeComponentAttached * componentAttached
QDeclarativeAbstractExpression * expressions
QDeclarativeContextData * linkedContext
QDeclarativeContextData * parent
QDeclarativeTypeNameCache * imports
QDeclarativeContextData * nextChild
QDeclarativeData * contextObjects
QDeclarativeIntegerCache * propertyNames
QDeclarativeContextData ** prevChild
QDeclarativeCompiledBindings * optimizedBindings
QDeclarativeGuardedContextData * contextGuards
QDeclarativeContextData * childContexts

◆ QDeclarativeContextData() [2/2]

QDeclarativeContextData::QDeclarativeContextData ( QDeclarativeContext ctxt)

Definition at line 511 of file qdeclarativecontext.cpp.

512 : parent(0), engine(0), isInternal(false), publicContext(ctxt), propertyNames(0), contextObject(0),
516 {
517 }
QDeclarativeEngine * engine
QDeclarativeContext * publicContext
QDeclarativeComponentAttached * componentAttached
QDeclarativeAbstractExpression * expressions
QDeclarativeContextData * linkedContext
QDeclarativeContextData * parent
QDeclarativeTypeNameCache * imports
QDeclarativeContextData * nextChild
QDeclarativeData * contextObjects
QDeclarativeIntegerCache * propertyNames
QDeclarativeContextData ** prevChild
QDeclarativeCompiledBindings * optimizedBindings
QDeclarativeGuardedContextData * contextGuards
QDeclarativeContextData * childContexts

◆ ~QDeclarativeContextData()

QDeclarativeContextData::~QDeclarativeContextData ( )
inlineprivate

Definition at line 208 of file qdeclarativecontext_p.h.

208 {}

Functions

◆ addImportedScript()

void QDeclarativeContextData::addImportedScript ( const QDeclarativeParser::Object::ScriptBlock script)

Definition at line 668 of file qdeclarativecontext.cpp.

669 {
670  if (!engine)
671  return;
672 
675 
676  const QString &code = script.code;
677  const QString &url = script.file;
678  const QDeclarativeParser::Object::ScriptBlock::Pragmas &pragmas = script.pragmas;
679 
680  Q_ASSERT(!url.isEmpty());
681 
683 
685  if (iter == enginePriv->m_sharedScriptImports.end()) {
686  QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
687 
688  scriptContext->pushScope(enginePriv->contextClass->newUrlContext(url));
689  scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
690 
692  scriptContext->pushScope(scope);
693 
694  scriptEngine->evaluate(code, url, 1);
695 
696  if (scriptEngine->hasUncaughtException()) {
699  enginePriv->warning(error);
700  }
701 
702  scriptEngine->popContext();
703 
704  iter = enginePriv->m_sharedScriptImports.insert(url, scope);
705  }
706 
707  importedScripts.append(*iter);
708 
709  } else {
710 
711  QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
712 
713  scriptContext->pushScope(enginePriv->contextClass->newUrlContext(this, 0, url));
714  scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
715 
717  scriptContext->pushScope(scope);
718 
719  scriptEngine->evaluate(code, url, 1);
720 
721  if (scriptEngine->hasUncaughtException()) {
724  enginePriv->warning(error);
725  }
726 
727  scriptEngine->popContext();
728 
729  importedScripts.append(scope);
730 
731  }
732 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptContext class represents a Qt Script function invocation.
QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &)
QHash< QString, QScriptValue > m_sharedScriptImports
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
#define error(msg)
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
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const QScriptValue & staticGlobalObject() const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QScriptEngine class provides an environment for evaluating Qt Script code.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QDeclarativeError class encapsulates a QML error.
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.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
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...
void warning(const QDeclarativeError &)
QList< QScriptValue > importedScripts
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

◆ addObject()

void QDeclarativeContextData::addObject ( QObject o)

Definition at line 652 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeVME::run(), and QDeclarativeEngine::setContextForObject().

653 {
655 
656  Q_ASSERT(data->context == 0);
657 
658  data->context = this;
659  data->outerContext = this;
660 
662  if (data->nextContextObject)
666 }
QDeclarativeContextData * outerContext
QDeclarativeContextData * context
static QDeclarativeData * get(const QObject *object, bool create=false)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char * data(const QByteArray &arr)
QDeclarativeData * contextObjects
QDeclarativeData ** prevContextObject
QDeclarativeData * nextContextObject

◆ asQDeclarativeContext()

QDeclarativeContext * QDeclarativeContextData::asQDeclarativeContext ( )

◆ asQDeclarativeContextPrivate()

QDeclarativeContextPrivate * QDeclarativeContextData::asQDeclarativeContextPrivate ( )

Definition at line 772 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeComponentPrivate::begin(), QDeclarativeCompiledBindingsPrivate::findgeneric(), and QDeclarativeContextScriptClass::property().

773 {
775 }
static QDeclarativeContextPrivate * get(QDeclarativeContext *context)
QDeclarativeContext * asQDeclarativeContext()

◆ clearContext()

void QDeclarativeContextData::clearContext ( )

Definition at line 546 of file qdeclarativecontext.cpp.

Referenced by destroy(), and QDeclarativeVisualDataModel::release().

547 {
548  if (engine) {
549  while (componentAttached) {
551  componentAttached = a->next;
553 
554  a->next = 0;
555  a->prev = 0;
556 
557  emit a->destruction();
558  }
559  }
560 
562  while (expression) {
563  QDeclarativeAbstractExpression *nextExpression = expression->m_nextExpression;
564 
565  expression->m_context = 0;
566  expression->m_prevExpression = 0;
567  expression->m_nextExpression = 0;
568 
569  expression = nextExpression;
570  }
571  expressions = 0;
572 }
QDeclarativeComponentAttached * next
QDeclarativeEngine * engine
QDeclarativeAbstractExpression ** m_prevExpression
QDeclarativeComponentAttached * componentAttached
QDeclarativeComponentAttached ** prev
long ASN1_INTEGER_get ASN1_INTEGER * a
QDeclarativeAbstractExpression * expressions
QDeclarativeAbstractExpression * m_nextExpression
#define emit
Definition: qobjectdefs.h:76
QDeclarativeContextData * m_context

◆ destroy()

void QDeclarativeContextData::destroy ( )

Definition at line 574 of file qdeclarativecontext.cpp.

Referenced by destroy(), and QDeclarativePrivate::qdeclarativeelement_destructor().

575 {
576  if (linkedContext)
578 
579  if (engine) invalidate();
580 
581  clearContext();
582 
583  while (contextObjects) {
586 
587  co->context = 0;
588  co->outerContext = 0;
589  co->nextContextObject = 0;
590  co->prevContextObject = 0;
591  }
592 
594  while (contextGuard) {
595  QDeclarativeGuardedContextData *next = contextGuard->m_next;
596  contextGuard->m_next = 0;
597  contextGuard->m_prev = 0;
598  contextGuard->m_contextData = 0;
599  contextGuard = next;
600  }
601  contextGuards = 0;
602 
603  if (propertyNames)
605 
606  if (imports)
607  imports->release();
608 
609  if (optimizedBindings)
611 
612  delete [] idValues;
613 
614  if (isInternal)
615  delete publicContext;
616 
617  delete this;
618 }
QDeclarativeContextData * outerContext
QDeclarativeContextData * context
QDeclarativeEngine * engine
QDeclarativeContext * publicContext
QDeclarativeContextData * linkedContext
QDeclarativeTypeNameCache * imports
QDeclarativeData * contextObjects
QDeclarativeIntegerCache * propertyNames
QDeclarativeData ** prevContextObject
QDeclarativeData * nextContextObject
QDeclarativeCompiledBindings * optimizedBindings
QDeclarativeGuardedContextData * contextGuards

◆ findObjectId()

QString QDeclarativeContextData::findObjectId ( const QObject obj) const

Definition at line 750 of file qdeclarativecontext.cpp.

Referenced by findObjectId(), and QDeclarativeEngineDebugService::objectData().

751 {
752  if (!idValues || !propertyNames)
753  return QString();
754 
755  for (int i=0; i<idValueCount; i++) {
756  if (idValues[i] == obj)
757  return propertyNames->findId(i);
758  }
759 
760  if (linkedContext)
761  return linkedContext->findObjectId(obj);
762  return QString();
763 }
QString findId(int value) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeContextData * linkedContext
QDeclarativeIntegerCache * propertyNames
QString findObjectId(const QObject *obj) const

◆ get()

static QDeclarativeContextData* QDeclarativeContextData::get ( QDeclarativeContext context)
inlinestatic

◆ invalidate()

void QDeclarativeContextData::invalidate ( )

Definition at line 519 of file qdeclarativecontext.cpp.

Referenced by destroy(), and invalidate().

520 {
521  while (childContexts)
523 
524  while (componentAttached) {
526  componentAttached = a->next;
528 
529  a->next = 0;
530  a->prev = 0;
531 
532  emit a->destruction();
533  }
534 
535  if (prevChild) {
536  *prevChild = nextChild;
538  nextChild = 0;
539  prevChild = 0;
540  }
541 
542  engine = 0;
543  parent = 0;
544 }
QDeclarativeComponentAttached * next
QDeclarativeEngine * engine
QDeclarativeComponentAttached * componentAttached
QDeclarativeComponentAttached ** prev
long ASN1_INTEGER_get ASN1_INTEGER * a
QDeclarativeContextData * parent
#define emit
Definition: qobjectdefs.h:76
QDeclarativeContextData * nextChild
QDeclarativeContextData ** prevChild
QDeclarativeContextData * childContexts

◆ isValid()

bool QDeclarativeContextData::isValid ( ) const
inline

◆ refreshExpressions()

void QDeclarativeContextData::refreshExpressions ( )

Definition at line 637 of file qdeclarativecontext.cpp.

Referenced by refreshExpressions(), and QDeclarativeContext::setContextProperty().

638 {
640  while (child) {
641  child->refreshExpressions();
642  child = child->nextChild;
643  }
644 
646  while (expression) {
647  expression->refresh();
648  expression = expression->m_nextExpression;
649  }
650 }
QDeclarativeAbstractExpression * expressions
QDeclarativeAbstractExpression * m_nextExpression
QDeclarativeContextData * nextChild
QDeclarativeContextData * childContexts

◆ resolvedUrl()

QUrl QDeclarativeContextData::resolvedUrl ( const QUrl src)

Definition at line 419 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeEnginePrivate::createQmlObject(), QDeclarativeScriptEngine::resolvedUrl(), and QDeclarativePropertyPrivate::write().

420 {
421  QDeclarativeContextData *ctxt = this;
422 
423  if (src.isRelative() && !src.isEmpty()) {
424  if (ctxt) {
425  while(ctxt) {
426  if(ctxt->url.isValid())
427  break;
428  else
429  ctxt = ctxt->parent;
430  }
431 
432  if (ctxt)
433  return ctxt->url.resolved(src);
434  else if (engine)
435  return engine->baseUrl().resolved(src);
436  }
437  return QUrl();
438  } else {
439  return src;
440  }
441 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
QDeclarativeEngine * engine
QUrl baseUrl() const
Return the base URL for this engine.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QDeclarativeContextData * parent
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819

◆ setIdProperty()

void QDeclarativeContextData::setIdProperty ( int  idx,
QObject obj 
)

Definition at line 734 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeVME::run().

735 {
736  idValues[idx] = obj;
737  idValues[idx].context = this;
738 }

◆ setIdPropertyData()

void QDeclarativeContextData::setIdPropertyData ( QDeclarativeIntegerCache data)

Definition at line 740 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeVME::run().

741 {
745 
746  idValueCount = data->count();
747  idValues = new ContextGuard[idValueCount];
748 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char * data(const QByteArray &arr)
QDeclarativeIntegerCache * propertyNames

◆ setParent()

void QDeclarativeContextData::setParent ( QDeclarativeContextData p)

Definition at line 620 of file qdeclarativecontext.cpp.

Referenced by QDeclarativeComponentPrivate::begin().

621 {
622  if (p) {
623  parent = p;
624  engine = p->engine;
627  prevChild = &p->childContexts;
628  p->childContexts = this;
629  }
630 }
QDeclarativeEngine * engine
QDeclarativeContextData * parent
QDeclarativeContextData * nextChild
QDeclarativeContextData ** prevChild
QDeclarativeContextData * childContexts

Properties

◆ childContexts

QDeclarativeContextData* QDeclarativeContextData::childContexts

◆ componentAttached

QDeclarativeComponentAttached* QDeclarativeContextData::componentAttached

◆ contextGuards

QDeclarativeGuardedContextData* QDeclarativeContextData::contextGuards

◆ contextObject

QObject* QDeclarativeContextData::contextObject

◆ contextObjects

QDeclarativeData* QDeclarativeContextData::contextObjects

Definition at line 168 of file qdeclarativecontext_p.h.

Referenced by addObject(), destroy(), and QDeclarativeVME::run().

◆ engine

QDeclarativeEngine* QDeclarativeContextData::engine

◆ expressions

QDeclarativeAbstractExpression* QDeclarativeContextData::expressions

◆ idValueCount

int QDeclarativeContextData::idValueCount

◆ idValues

ContextGuard* QDeclarativeContextData::idValues

◆ importedScripts

QList<QScriptValue> QDeclarativeContextData::importedScripts

◆ imports

QDeclarativeTypeNameCache* QDeclarativeContextData::imports

◆ isInternal

bool QDeclarativeContextData::isInternal

◆ linkedContext

QDeclarativeContextData* QDeclarativeContextData::linkedContext

Definition at line 194 of file qdeclarativecontext_p.h.

Referenced by destroy(), findObjectId(), and QDeclarativeVME::run().

◆ nextChild

QDeclarativeContextData* QDeclarativeContextData::nextChild

◆ optimizedBindings

QDeclarativeCompiledBindings* QDeclarativeContextData::optimizedBindings

Definition at line 191 of file qdeclarativecontext_p.h.

Referenced by destroy(), and QDeclarativeVME::run().

◆ parent

QDeclarativeContextData* QDeclarativeContextData::parent

◆ prevChild

QDeclarativeContextData** QDeclarativeContextData::prevChild

Definition at line 162 of file qdeclarativecontext_p.h.

Referenced by invalidate(), and setParent().

◆ propertyNames

QDeclarativeIntegerCache* QDeclarativeContextData::propertyNames

◆ publicContext

QDeclarativeContext* QDeclarativeContextData::publicContext

Definition at line 139 of file qdeclarativecontext_p.h.

Referenced by asQDeclarativeContext(), and destroy().

◆ url

QUrl QDeclarativeContextData::url

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