diff options
Diffstat (limited to 'src/declarative/qml')
40 files changed, 784 insertions, 263 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejs.g b/src/declarative/qml/parser/qdeclarativejs.g index 1b66ba0..c84f0b3 100644 --- a/src/declarative/qml/parser/qdeclarativejs.g +++ b/src/declarative/qml/parser/qdeclarativejs.g @@ -1254,7 +1254,7 @@ case $rule_number: { else node = makeAstNode<AST::ObjectLiteral> (driver->nodePool()); node->lbraceToken = loc(1); - node->lbraceToken = loc(3); + node->rbraceToken = loc(3); sym(1).Node = node; } break; ./ @@ -1265,7 +1265,7 @@ case $rule_number: { AST::ObjectLiteral *node = makeAstNode<AST::ObjectLiteral> (driver->nodePool(), sym(2).PropertyNameAndValueList->finish ()); node->lbraceToken = loc(1); - node->lbraceToken = loc(4); + node->rbraceToken = loc(4); sym(1).Node = node; } break; ./ diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index 1eb42e4..52f6210 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -510,15 +510,18 @@ int Lexer::lex() setDone(Eof); } } else if (isLineTerminator()) { - shiftWindowsLineBreak(); - yylineno++; - yycolumn = 0; - bol = true; - terminator = true; - syncProhibitAutomaticSemicolon(); if (restrKeyword) { + // automatic semicolon insertion + recordStartPos(); token = QDeclarativeJSGrammar::T_SEMICOLON; setDone(Other); + } else { + shiftWindowsLineBreak(); + yylineno++; + yycolumn = 0; + bol = true; + terminator = true; + syncProhibitAutomaticSemicolon(); } } else if (current == '"' || current == '\'') { recordStartPos(); diff --git a/src/declarative/qml/parser/qdeclarativejsparser.cpp b/src/declarative/qml/parser/qdeclarativejsparser.cpp index 8afb93d..28ef17d 100644 --- a/src/declarative/qml/parser/qdeclarativejsparser.cpp +++ b/src/declarative/qml/parser/qdeclarativejsparser.cpp @@ -679,7 +679,7 @@ case 85: { else node = makeAstNode<AST::ObjectLiteral> (driver->nodePool()); node->lbraceToken = loc(1); - node->lbraceToken = loc(3); + node->rbraceToken = loc(3); sym(1).Node = node; } break; @@ -687,7 +687,7 @@ case 86: { AST::ObjectLiteral *node = makeAstNode<AST::ObjectLiteral> (driver->nodePool(), sym(2).PropertyNameAndValueList->finish ()); node->lbraceToken = loc(1); - node->lbraceToken = loc(4); + node->rbraceToken = loc(4); sym(1).Node = node; } break; diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index 941a1b3..0b9bde6 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE -class Q_DECLARATIVE_EXPORT QDeclarativeAbstractBinding +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeAbstractBinding { public: typedef QWeakPointer<QDeclarativeAbstractBinding> Pointer; @@ -138,7 +138,7 @@ private: class QDeclarativeContext; class QDeclarativeBindingPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding { Q_OBJECT public: diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 5f0fd56..fbe5829 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -601,7 +601,7 @@ struct QDeclarativeBindingCompilerPrivate QDeclarativeImports imports; QDeclarativeEnginePrivate *engine; - QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((intptr_t)context, 16); } + QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((quintptr)context, 16); } bool compile(QDeclarativeJS::AST::Node *); diff --git a/src/declarative/qml/qdeclarativecompileddata.cpp b/src/declarative/qml/qdeclarativecompileddata.cpp index 5d73d89..a4ecc77 100644 --- a/src/declarative/qml/qdeclarativecompileddata.cpp +++ b/src/declarative/qml/qdeclarativecompileddata.cpp @@ -205,7 +205,7 @@ const QMetaObject *QDeclarativeCompiledData::TypeReference::metaObject() const return type->metaObject(); } else { Q_ASSERT(component); - return static_cast<QDeclarativeComponentPrivate *>(QObjectPrivate::get(component))->cc->root; + return component->root; } } diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index dc28e22..b2740b8 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -590,7 +590,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, COMPILE_EXCEPTION(parserRef->refObjects.first(), err); } } else if (tref.typeData) { - ref.component = tref.typeData->component(); + ref.component = tref.typeData->compiledData(); ref.ref = tref.typeData; ref.ref->addref(); } @@ -722,7 +722,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) obj->metatype = tr.metaObject(); if (tr.component) - obj->url = tr.component->url(); + obj->url = tr.component->url; if (tr.type) obj->typeName = tr.type->qmlTypeName(); obj->className = tr.className; @@ -940,7 +940,7 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) // ### Surely the creation of this property cache could be more efficient QDeclarativePropertyCache *propertyCache = 0; if (tr.component) - propertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache->copy(); + propertyCache = tr.component->rootPropertyCache->copy(); else propertyCache = enginePrivate->cache(obj->metaObject()->superClass())->copy(); @@ -957,7 +957,7 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) output->bytecode << meta; } else if (obj == unitRoot) { if (tr.component) - output->rootPropertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache; + output->rootPropertyCache = tr.component->rootPropertyCache; else output->rootPropertyCache = enginePrivate->cache(obj->metaObject()); @@ -1932,6 +1932,9 @@ bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property { obj->addValueProperty(prop); + if (prop->values.count() > 1) + COMPILE_EXCEPTION(prop->values.at(0), tr( "Cannot assign multiple values to a singular property") ); + for (int ii = 0; ii < prop->values.count(); ++ii) { Value *v = prop->values.at(ii); if (v->object) { @@ -2562,8 +2565,8 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder, QStringList alias = astNodeToStringList(node); - if (alias.count() != 1 && alias.count() != 2) - COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. An alias reference must be specified as <id> or <id>.<property>")); + if (alias.count() < 1 || alias.count() > 3) + COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>")); if (!compileState.ids.contains(alias.at(0))) COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0))); @@ -2575,11 +2578,14 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder, int propIdx = -1; int flags = 0; bool writable = false; - if (alias.count() == 2) { + if (alias.count() == 2 || alias.count() == 3) { propIdx = idObject->metaObject()->indexOfProperty(alias.at(1).toUtf8().constData()); - if (-1 == propIdx) + if (-1 == propIdx) { COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + } else if (propIdx > 0xFFFF) { + COMPILE_EXCEPTION(prop.defaultValue, tr("Alias property exceeds alias bounds")); + } QMetaProperty aliasProperty = idObject->metaObject()->property(propIdx); if (!aliasProperty.isScriptable()) @@ -2587,6 +2593,22 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder, writable = aliasProperty.isWritable(); + if (alias.count() == 3) { + QDeclarativeValueType *valueType = enginePrivate->valueTypes[aliasProperty.type()]; + if (!valueType) + COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + + propIdx |= ((unsigned int)aliasProperty.type()) << 24; + + int valueTypeIndex = valueType->metaObject()->indexOfProperty(alias.at(2).toUtf8().constData()); + if (valueTypeIndex == -1) + COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + Q_ASSERT(valueTypeIndex <= 0xFF); + + aliasProperty = valueType->metaObject()->property(valueTypeIndex); + propIdx |= (valueTypeIndex << 16); + } + if (aliasProperty.isEnumType()) typeName = "int"; // Avoid introducing a dependency on the aliased metaobject else diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 89eef09..43a0901 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -93,10 +93,11 @@ public: QByteArray className; QDeclarativeType *type; - QDeclarativeComponent *component; +// QDeclarativeComponent *component; + QDeclarativeCompiledData *component; QDeclarativeRefCount *ref; - QObject *createInstance(QDeclarativeContextData *, const QBitField &) const; + QObject *createInstance(QDeclarativeContextData *, const QBitField &, QList<QDeclarativeError> *) const; const QMetaObject *metaObject() const; }; QList<TypeReference> types; diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b532b0c..2686ce3 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -57,7 +57,6 @@ #include <QStack> #include <QStringList> -#include <QFileInfo> #include <QtCore/qdebug.h> #include <QApplication> @@ -99,6 +98,43 @@ class QByteArray; int width = item->width(); // width = 200 \endcode + + \section2 Network Components + + If the URL passed to QDeclarativeComponent is a network resource, or if the QML document references a + network resource, the QDeclarativeComponent has to fetch the network data before it is able to create + objects. In this case, the QDeclarativeComponent will have a \l {QDeclarativeComponent::Loading}{Loading} + \l {QDeclarativeComponent::status()}{status}. An application will have to wait until the component + is \l {QDeclarativeComponent::Ready}{Ready} before calling \l {QDeclarativeComponent::create()}. + + The following example shows how to load a QML file from a network resource. After creating + the QDeclarativeComponent, it tests whether the component is loading. If it is, it connects to the + QDeclarativeComponent::statusChanged() signal and otherwise calls the \c {continueLoading()} method + directly. Note that QDeclarativeComponent::isLoading() may be false for a network component if the + component has been cached and is ready immediately. + + \code + MyApplication::MyApplication() + { + // ... + component = new QDeclarativeComponent(engine, QUrl("http://www.example.com/main.qml")); + if (component->isLoading()) + QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), + this, SLOT(continueLoading())); + else + continueLoading(); + } + + void MyApplication::continueLoading() + { + if (component->isError()) { + qWarning() << component->errors(); + } else { + QObject *myObject = component->create(); + } + } + \endcode + \sa {Using QML in C++ Applications}, {Integrating QML with existing Qt UI code} */ @@ -734,48 +770,45 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons return 0; } - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + return begin(context, creationContext, cc, start, count, &state, 0, bindings); +} + +QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *parentContext, + QDeclarativeContextData *componentCreationContext, + QDeclarativeCompiledData *component, int start, int count, + ConstructionState *state, QList<QDeclarativeError> *errors, + const QBitField &bindings) +{ + QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(parentContext->engine); + bool isRoot = !enginePriv->inBeginCreate; + + Q_ASSERT(!isRoot || state); // Either this isn't a root component, or a state data must be provided + Q_ASSERT((state != 0) ^ (errors != 0)); // One of state or errors (but not both) must be provided - bool isRoot = !ep->inBeginCreate; if (isRoot) QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::Creating); - QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::Creating, cc->url); QDeclarativeContextData *ctxt = new QDeclarativeContextData; ctxt->isInternal = true; - ctxt->url = cc->url; - ctxt->imports = cc->importCache; + ctxt->url = component->url; + ctxt->imports = component->importCache; // Nested global imports - if (creationContext && start != -1) - ctxt->importedScripts = creationContext->importedScripts; - - cc->importCache->addref(); - ctxt->setParent(context); - - QObject *rv = begin(ctxt, ep, cc, start, count, &state, bindings); + if (componentCreationContext && start != -1) + ctxt->importedScripts = componentCreationContext->importedScripts; - if (ep->isDebugging && rv) { - if (!context->isInternal) - context->asQDeclarativeContextPrivate()->instances.append(rv); - QDeclarativeEngineDebugServer::instance()->objectCreated(engine, rv); - } - - return rv; -} + component->importCache->addref(); + ctxt->setParent(parentContext); -QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv, - QDeclarativeCompiledData *component, int start, int count, - ConstructionState *state, const QBitField &bindings) -{ - bool isRoot = !enginePriv->inBeginCreate; enginePriv->inBeginCreate = true; QDeclarativeVME vme; QObject *rv = vme.run(ctxt, component, start, count, bindings); - if (vme.isError()) - state->errors = vme.errors(); + if (vme.isError()) { + if(errors) *errors = vme.errors(); + else state->errors = vme.errors(); + } if (isRoot) { enginePriv->inBeginCreate = false; @@ -795,6 +828,12 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe enginePriv->inProgressCreations++; } + if (enginePriv->isDebugging && rv) { + if (!parentContext->isInternal) + parentContext->asQDeclarativeContextPrivate()->instances.append(rv); + QDeclarativeEngineDebugServer::instance()->objectCreated(parentContext->engine, rv); + } + return rv; } diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h index a551cc8..7b30bad 100644 --- a/src/declarative/qml/qdeclarativecomponent_p.h +++ b/src/declarative/qml/qdeclarativecomponent_p.h @@ -109,9 +109,10 @@ public: }; ConstructionState state; - static QObject *begin(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv, - QDeclarativeCompiledData *component, int start, int count, - ConstructionState *state, const QBitField &bindings = QBitField()); + static QObject *begin(QDeclarativeContextData *parentContext, QDeclarativeContextData *componentCreationContext, + QDeclarativeCompiledData *component, int start, int count, + ConstructionState *state, QList<QDeclarativeError> *errors, + const QBitField &bindings = QBitField()); static void beginDeferred(QDeclarativeEnginePrivate *enginePriv, QObject *object, ConstructionState *state); static void complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 59d5cfa..3ee0e6f 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -86,9 +86,14 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate() QDeclarativeComponent component(&engine); component.setData("import QtQuick 1.0\nListView { model: myModel }", QUrl()); - component.create(context); + QObject *window = component.create(context); \endcode + Note it is the responsibility of the creator to delete any QDeclarativeContext it + constructs. If the \c context object in the example is no longer needed when the + \c window component instance is destroyed, the \c context must be destroyed explicitly. + The simplest way to ensure this is to set \c window as the parent of \c context. + To simplify binding and maintaining larger data sets, a context object can be set on a QDeclarativeContext. All the properties of the context object are available by name in the context, as though they were all individually added through calls @@ -119,11 +124,13 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate() All properties added explicitly by QDeclarativeContext::setContextProperty() take precedence over the context object's properties. - Contexts form a hierarchy. The root of this hierarchy is the QDeclarativeEngine's - \l {QDeclarativeEngine::rootContext()}{root context}. A component instance can - access the data in its own context, as well as all its ancestor contexts. Data - can be made available to all instances by modifying the - \l {QDeclarativeEngine::rootContext()}{root context}. + \section2 The Context Hierarchy + + Contexts form a hierarchy. The root of this hierarchy is the QML engine's + \l {QDeclarativeEngine::rootContext()}{root context}. Child contexts inherit + the context properties of their parents; if a child context sets a context property + that already exists in its parent, the new context property overrides that of the + parent. The following example defines two contexts - \c context1 and \c context2. The second context overrides the "b" context property inherited from the first with a @@ -144,7 +151,7 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate() context, their bindings are. If a context is destroyed, the property bindings of outstanding QML objects will stop evaluating. - \note Setting the context object or adding new context properties after an object + \warning Setting the context object or adding new context properties after an object has been created in that context is an expensive operation (essentially forcing all bindings to reevaluate). Thus whenever possible you should complete "setup" of the context before using it to create any objects. @@ -467,7 +474,7 @@ int QDeclarativeContextPrivate::context_count(QDeclarativeListProperty<QObject> { QDeclarativeContext *context = static_cast<QDeclarativeContext*>(prop->object); QDeclarativeContextPrivate *d = QDeclarativeContextPrivate::get(context); - int contextProperty = (int)(intptr_t)prop->data; + int contextProperty = (int)(quintptr)prop->data; if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId<QList<QObject*> >()) { return 0; @@ -480,7 +487,7 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject { QDeclarativeContext *context = static_cast<QDeclarativeContext*>(prop->object); QDeclarativeContextPrivate *d = QDeclarativeContextPrivate::get(context); - int contextProperty = (int)(intptr_t)prop->data; + int contextProperty = (int)(quintptr)prop->data; if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId<QList<QObject*> >()) { return 0; diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index e916273..def4188 100644 --- a/src/declarative/qml/qdeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -64,6 +64,7 @@ class QDeclarativeAbstractBinding; class QDeclarativeContext; class QDeclarativePropertyCache; class QDeclarativeContextData; +class QDeclarativeNotifier; // This class is structured in such a way, that simply zero'ing it is the // default state for elemental object allocations. This is crucial in the // workings of the QDeclarativeInstruction::CreateSimpleObject instruction. @@ -75,20 +76,23 @@ public: : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), - attachedProperties(0), scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0) { + scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0), extendedData(0) { init(); } static inline void init() { QAbstractDeclarativeData::destroyed = destroyed; QAbstractDeclarativeData::parentChanged = parentChanged; + QAbstractDeclarativeData::objectNameChanged = objectNameChanged; } static void destroyed(QAbstractDeclarativeData *, QObject *); static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *); + static void objectNameChanged(QAbstractDeclarativeData *, QObject *); void destroyed(QObject *); void parentChanged(QObject *, QObject *); + void objectNameChanged(QObject *); void setImplicitDestructible() { if (!explicitIndestructibleSet) indestructible = false; @@ -123,8 +127,6 @@ public: QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context? unsigned int deferredIdx; - QHash<int, QObject *> *attachedProperties; - // ### Can we make this QScriptValuePrivate so we incur no additional allocation // cost? QScriptValue *scriptValue; @@ -147,6 +149,18 @@ public: return 0; } } + + QDeclarativeNotifier *objectNameNotifier() const; + QHash<int, QObject *> *attachedProperties() const; + + struct ExtendedData { + ExtendedData(); + ~ExtendedData(); + + QHash<int, QObject *> attachedProperties; + void *objectNameNotifier; + }; + mutable ExtendedData *extendedData; }; template<class T> diff --git a/src/declarative/qml/qdeclarativedom_p.h b/src/declarative/qml/qdeclarativedom_p.h index 6043ead..ee3625c 100644 --- a/src/declarative/qml/qdeclarativedom_p.h +++ b/src/declarative/qml/qdeclarativedom_p.h @@ -58,6 +58,8 @@ #include <QtCore/qlist.h> #include <QtCore/qshareddata.h> +#include <private/qdeclarativeglobal_p.h> + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -76,7 +78,7 @@ class QIODevice; class QDeclarativeDomDocumentPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomDocument +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomDocument { public: QDeclarativeDomDocument(); @@ -96,7 +98,7 @@ private: }; class QDeclarativeDomPropertyPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomProperty +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomProperty { public: QDeclarativeDomProperty(); @@ -123,7 +125,7 @@ private: }; class QDeclarativeDomDynamicPropertyPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomDynamicProperty +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomDynamicProperty { public: QDeclarativeDomDynamicProperty(); @@ -151,7 +153,7 @@ private: }; class QDeclarativeDomObjectPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomObject +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomObject { public: QDeclarativeDomObject(); @@ -196,7 +198,7 @@ private: class QDeclarativeDomValuePrivate; class QDeclarativeDomBasicValuePrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomValueLiteral +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomValueLiteral { public: QDeclarativeDomValueLiteral(); @@ -211,7 +213,7 @@ private: QSharedDataPointer<QDeclarativeDomBasicValuePrivate> d; }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomValueBinding +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomValueBinding { public: QDeclarativeDomValueBinding(); @@ -226,7 +228,7 @@ private: QSharedDataPointer<QDeclarativeDomBasicValuePrivate> d; }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomValueValueSource +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomValueValueSource { public: QDeclarativeDomValueValueSource(); @@ -241,7 +243,7 @@ private: QSharedDataPointer<QDeclarativeDomBasicValuePrivate> d; }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomValueValueInterceptor +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomValueValueInterceptor { public: QDeclarativeDomValueValueInterceptor(); @@ -257,7 +259,7 @@ private: }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomComponent : public QDeclarativeDomObject +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomComponent : public QDeclarativeDomObject { public: QDeclarativeDomComponent(); @@ -268,7 +270,7 @@ public: QDeclarativeDomObject componentRoot() const; }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomValue +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomValue { public: enum Type { @@ -312,7 +314,7 @@ private: QSharedDataPointer<QDeclarativeDomValuePrivate> d; }; -class Q_DECLARATIVE_EXPORT QDeclarativeDomList +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomList { public: QDeclarativeDomList(); @@ -333,7 +335,7 @@ private: }; class QDeclarativeDomImportPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDomImport +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDomImport { public: enum Type { Library, File }; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 9ca7858..cd11336 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -68,6 +68,7 @@ #include "private/qdeclarativelist_p.h" #include "private/qdeclarativetypenamecache_p.h" #include "private/qdeclarativeinclude_p.h" +#include "private/qdeclarativenotifier_p.h" #include <QtCore/qmetaobject.h> #include <QScriptClass> @@ -104,6 +105,7 @@ #ifdef Q_OS_WIN // for %APPDATA% #include <qt_windows.h> #include <qlibrary.h> +#include <windows.h> #define CSIDL_APPDATA 0x001a // <username>\Application Data #endif @@ -174,6 +176,7 @@ struct StaticQtMetaObject : public QObject }; static bool qt_QmlQtModule_registered = false; +bool QDeclarativeEnginePrivate::qml_debugging_enabled = false; void QDeclarativeEnginePrivate::defineModule() { @@ -468,6 +471,11 @@ void QDeclarativeData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QO static_cast<QDeclarativeData *>(d)->parentChanged(o, p); } +void QDeclarativeData::objectNameChanged(QAbstractDeclarativeData *d, QObject *o) +{ + static_cast<QDeclarativeData *>(d)->objectNameChanged(o); +} + void QDeclarativeEnginePrivate::init() { Q_Q(QDeclarativeEngine); @@ -601,7 +609,7 @@ QDeclarativeContext *QDeclarativeEngine::rootContext() const QNetworkAccessManager with specialized caching, proxy and cookie support. - The factory must be set before exceuting the engine. + The factory must be set before executing the engine. */ void QDeclarativeEngine::setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *factory) { @@ -871,7 +879,7 @@ void QDeclarativeEngine::setContextForObject(QObject *object, QDeclarativeContex created by calling QDeclarativeCompnent::create() or QDeclarativeComponent::beginCreate() which have CppOwnership by default. The ownership of these root-level objects is considered to - have been transfered to the C++ caller. + have been transferred to the C++ caller. Objects not-created by QML have CppOwnership by default. The exception to this is objects returned from a C++ method call. The @@ -949,7 +957,7 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre if (!data) return 0; // Attached properties are only on objects created by QML - QObject *rv = data->attachedProperties?data->attachedProperties->value(id):0; + QObject *rv = data->extendedData?data->attachedProperties()->value(id):0; if (rv || !create) return rv; @@ -959,11 +967,8 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre rv = pf(const_cast<QObject *>(object)); - if (rv) { - if (!data->attachedProperties) - data->attachedProperties = new QHash<int, QObject *>(); - data->attachedProperties->insert(id, rv); - } + if (rv) + data->attachedProperties()->insert(id, rv); return rv; } @@ -984,8 +989,6 @@ void QDeclarativeData::destroyed(QObject *object) { if (deferredComponent) deferredComponent->release(); - if (attachedProperties) - delete attachedProperties; if (nextContextObject) nextContextObject->prevContextObject = prevContextObject; @@ -1019,6 +1022,9 @@ void QDeclarativeData::destroyed(QObject *object) if (scriptValue) delete scriptValue; + if (extendedData) + delete extendedData; + if (ownMemory) delete this; } @@ -1028,6 +1034,11 @@ void QDeclarativeData::parentChanged(QObject *, QObject *parent) if (!parent && scriptValue) { delete scriptValue; scriptValue = 0; } } +void QDeclarativeData::objectNameChanged(QObject *) +{ + if (extendedData) objectNameNotifier()->notify(); +} + bool QDeclarativeData::hasBindingBit(int bit) const { if (bindingBitsSize > bit) @@ -1064,6 +1075,28 @@ void QDeclarativeData::setBindingBit(QObject *obj, int bit) bindingBits[bit / 32] |= (1 << (bit % 32)); } +QDeclarativeData::ExtendedData::ExtendedData() +: objectNameNotifier(0) +{ +} + +QDeclarativeData::ExtendedData::~ExtendedData() +{ + ((QDeclarativeNotifier *)&objectNameNotifier)->~QDeclarativeNotifier(); +} + +QDeclarativeNotifier *QDeclarativeData::objectNameNotifier() const +{ + if (!extendedData) extendedData = new ExtendedData; + return (QDeclarativeNotifier *)&extendedData->objectNameNotifier; +} + +QHash<int, QObject *> *QDeclarativeData::attachedProperties() const +{ + if (!extendedData) extendedData = new ExtendedData; + return &extendedData->attachedProperties; +} + /*! Creates a QScriptValue allowing you to use \a object in QML script. \a engine is the QDeclarativeEngine it is to be created in. @@ -2159,4 +2192,42 @@ const QMetaObject *QDeclarativeEnginePrivate::metaObjectForType(int t) const } } +bool QDeclarative_isFileCaseCorrect(const QString &fileName) +{ +#if defined(Q_OS_MAC) || defined(Q_OS_WIN32) + QFileInfo info(fileName); + + QString absolute = info.absoluteFilePath(); + +#if defined(Q_OS_MAC) + QString canonical = info.canonicalFilePath(); +#elif defined(Q_OS_WIN32) + wchar_t buffer[1024]; + + DWORD rv = ::GetShortPathName((wchar_t*)absolute.utf16(), buffer, 1024); + if (rv == 0 || rv >= 1024) return true; + rv = ::GetLongPathName(buffer, buffer, 1024); + if (rv == 0 || rv >= 1024) return true; + + QString canonical((QChar *)buffer); +#endif + + int absoluteLength = absolute.length(); + int canonicalLength = canonical.length(); + + int length = qMin(absoluteLength, canonicalLength); + for (int ii = 0; ii < length; ++ii) { + const QChar &a = absolute.at(absoluteLength - 1 - ii); + const QChar &c = canonical.at(canonicalLength - 1 - ii); + + if (a.toLower() != c.toLower()) + return true; + if (a != c) + return false; + } +#endif + + return true; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 8539fbf..deb4a77 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -321,6 +321,8 @@ public: static QString urlToLocalFileOrQrc(const QUrl& url); static void defineModule(); + + static bool qml_debugging_enabled; }; /*! diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index ed28185..bffe681 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -502,7 +502,8 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, property.write(expression); } else if (hasValidSignal(object, propertyName)) { QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); - QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + QDeclarativeExpression *oldExpression = QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + declarativeExpression->setSourceLocation(oldExpression->sourceFile(), oldExpression->lineNumber()); } else if (property.isProperty()) { QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); binding->setTarget(property); diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index 613f1fe..97b8121 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -117,10 +117,10 @@ private: QList<QDeclarativeEngine *> m_engines; QDeclarativeWatcher *m_watch; }; -Q_DECLARATIVE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &); -Q_DECLARATIVE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectData &); -Q_DECLARATIVE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); -Q_DECLARATIVE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectData &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativefastproperties.cpp b/src/declarative/qml/qdeclarativefastproperties.cpp index eb69b6a..78e3afd 100644 --- a/src/declarative/qml/qdeclarativefastproperties.cpp +++ b/src/declarative/qml/qdeclarativefastproperties.cpp @@ -51,10 +51,19 @@ QT_BEGIN_NAMESPACE // primarily read from bindings is a candidate for inclusion as a fast // property. +static void QObject_objectName(QObject *object, void *output, QDeclarativeNotifierEndpoint *endpoint) +{ + if (endpoint) + endpoint->connect(QDeclarativeData::get(object, true)->objectNameNotifier()); + *((QString *)output) = object->objectName(); +} + QDeclarativeFastProperties::QDeclarativeFastProperties() { add(&QDeclarativeItem::staticMetaObject, QDeclarativeItem::staticMetaObject.indexOfProperty("parent"), QDeclarativeItemPrivate::parentProperty); + add(&QObject::staticMetaObject, QObject::staticMetaObject.indexOfProperty("objectName"), + QObject_objectName); } int QDeclarativeFastProperties::accessorIndexForProperty(const QMetaObject *metaObject, int propertyIndex) diff --git a/src/declarative/qml/qdeclarativeglobal_p.h b/src/declarative/qml/qdeclarativeglobal_p.h index 1041992..31fbb1e 100644 --- a/src/declarative/qml/qdeclarativeglobal_p.h +++ b/src/declarative/qml/qdeclarativeglobal_p.h @@ -64,6 +64,12 @@ QT_MODULE(Declarative) return status == Yes; \ } +#ifdef Q_OS_SYMBIAN +#define Q_DECLARATIVE_PRIVATE_EXPORT +#else +#define Q_DECLARATIVE_PRIVATE_EXPORT Q_DECLARATIVE_EXPORT +#endif + struct QDeclarativeGraphics_DerivedObject : public QObject { void setParent_noEvent(QObject *parent) { @@ -75,6 +81,19 @@ struct QDeclarativeGraphics_DerivedObject : public QObject }; /*! + Returns true if the case of \a fileName is equivalent to the file case of + \a fileName on disk, and false otherwise. + + This is used to ensure that the behavior of QML on a case-insensitive file + system is the same as on a case-sensitive file system. This function + performs a "best effort" attempt to determine the real case of the file. + It may have false positives (say the case is correct when it isn't), but it + should never have a false negative (say the case is incorrect when it is + correct). +*/ +bool QDeclarative_isFileCaseCorrect(const QString &fileName); + +/*! Makes the \a object a child of \a parent. Note that when using this method, neither \a parent nor the object's previous parent (if it had one) will receive ChildRemoved or ChildAdded events. diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp index fe4ed48..6f5216a 100644 --- a/src/declarative/qml/qdeclarativeimport.cpp +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -351,7 +351,11 @@ bool QDeclarativeImportsPrivate::importExtension(const QString &absoluteFilePath { QFile file(absoluteFilePath); QString filecontent; - if (file.open(QFile::ReadOnly)) { + if (!QDeclarative_isFileCaseCorrect(absoluteFilePath)) { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("cannot load module \"%1\": File name case mismatch for \"%2\"").arg(uri).arg(absoluteFilePath); + return false; + } else if (file.open(QFile::ReadOnly)) { filecontent = QString::fromUtf8(file.readAll()); if (qmlImportTrace()) qDebug().nospace() << "QDeclarativeImports(" << qPrintable(base.toString()) << "::importExtension: " @@ -913,6 +917,11 @@ bool QDeclarativeImportDatabase::importPlugin(const QString &filePath, const QSt } if (!engineInitialized || !typesRegistered) { + if (!QDeclarative_isFileCaseCorrect(absoluteFilePath)) { + if (errorString) + *errorString = tr("File name case mismatch for \"%2\"").arg(absoluteFilePath); + return false; + } QPluginLoader loader(absoluteFilePath); if (!loader.load()) { diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index c6560dd..56c0599 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -55,7 +55,8 @@ QT_BEGIN_NAMESPACE \fn QDeclarativeInfo qmlInfo(const QObject *object) \relates QDeclarativeEngine - \brief Prints warnings messages that include the file and line number for QML types. + Prints warning messages that include the file and line number for the + specified QML \a object. When QML types display warning messages, it improves traceability if they include the QML file and line number on which the diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index 382abd2..9c486d3 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -58,6 +58,7 @@ #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> #include <QtCore/qbitarray.h> +#include <private/qdeclarativeglobal_p.h> QT_BEGIN_NAMESPACE @@ -65,7 +66,7 @@ class QDeclarativeType; class QDeclarativeCustomParser; class QDeclarativeTypePrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeMetaType +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType { public: static bool copy(int type, void *data, const void *copy = 0); @@ -105,7 +106,7 @@ public: static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions(); }; -class Q_DECLARATIVE_EXPORT QDeclarativeType +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType { public: QByteArray typeName() const; diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index ab6ff74..eff59df 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -239,8 +239,13 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) } } else { if (enginePriv->captureProperties && !(lastData->flags & QDeclarativePropertyCache::Data::IsConstant)) { - enginePriv->capturedProperties << - QDeclarativeEnginePrivate::CapturedProperty(obj, lastData->coreIndex, lastData->notifyIndex); + if (lastData->coreIndex == 0) { + enginePriv->capturedProperties << + QDeclarativeEnginePrivate::CapturedProperty(QDeclarativeData::get(obj, true)->objectNameNotifier()); + } else { + enginePriv->capturedProperties << + QDeclarativeEnginePrivate::CapturedProperty(obj, lastData->coreIndex, lastData->notifyIndex); + } } if (QDeclarativeValueTypeFactory::isValueType((uint)lastData->propType)) { @@ -416,7 +421,7 @@ QScriptValue QDeclarativeObjectScriptClass::tostring(QScriptContext *context, QS ret += QString::fromUtf8(obj->metaObject()->className()); ret += QLatin1String("(0x"); - ret += QString::number((intptr_t)obj,16); + ret += QString::number((quintptr)obj,16); if (!objectName.isEmpty()) { ret += QLatin1String(", \""); @@ -833,9 +838,19 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: { MethodData *method = static_cast<MethodData *>(o); - if (method->data.flags & QDeclarativePropertyCache::Data::HasArguments) { + if (method->data.relatedIndex == -1) + return callPrecise(method->object, method->data, ctxt); + else + return callOverloaded(method, ctxt); +} + +QDeclarativeObjectMethodScriptClass::Value +QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclarativePropertyCache::Data &data, + QScriptContext *ctxt) +{ + if (data.flags & QDeclarativePropertyCache::Data::HasArguments) { - QMetaMethod m = method->object->metaObject()->method(method->data.coreIndex); + QMetaMethod m = object->metaObject()->method(data.coreIndex); QList<QByteArray> argTypeNames = m.parameterTypes(); QVarLengthArray<int, 9> argTypes(argTypeNames.count()); @@ -843,7 +858,7 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: for (int ii = 0; ii < argTypeNames.count(); ++ii) { argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); if (argTypes[ii] == QVariant::Invalid) - argTypes[ii] = enumType(method->object->metaObject(), QString::fromLatin1(argTypeNames.at(ii))); + argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii))); if (argTypes[ii] == QVariant::Invalid) return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); } @@ -851,39 +866,301 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: if (argTypes.count() > ctxt->argumentCount()) return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments"))); - QVarLengthArray<MetaCallArgument, 9> args(argTypes.count() + 1); - args[0].initAsType(method->data.propType, engine); + return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt); - for (int ii = 0; ii < argTypes.count(); ++ii) + } else { + + return callMethod(object, data.coreIndex, data.propType, 0, 0, ctxt); + + } +} + +QDeclarativeObjectMethodScriptClass::Value +QDeclarativeObjectMethodScriptClass::callMethod(QObject *object, int index, + int returnType, int argCount, int *argTypes, + QScriptContext *ctxt) +{ + if (argCount > 0) { + + QVarLengthArray<MetaCallArgument, 9> args(argCount + 1); + args[0].initAsType(returnType, engine); + + for (int ii = 0; ii < argCount; ++ii) args[ii + 1].fromScriptValue(argTypes[ii], engine, ctxt->argument(ii)); QVarLengthArray<void *, 9> argData(args.count()); for (int ii = 0; ii < args.count(); ++ii) argData[ii] = args[ii].dataPtr(); - QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, argData.data()); + QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, argData.data()); return args[0].toValue(engine); - } else if (method->data.propType != 0) { - + } else if (returnType != 0) { + MetaCallArgument arg; - arg.initAsType(method->data.propType, engine); + arg.initAsType(returnType, engine); void *args[] = { arg.dataPtr() }; - QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, args); + QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args); return arg.toValue(engine); } else { void *args[] = { 0 }; - QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, args); + QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args); return Value(); } - return Value(); +} + +/*! +Resolve the overloaded method to call. The algorithm works conceptually like this: + 1. Resolve the set of overloads it is *possible* to call. + Impossible overloads include those that have too many parameters or have parameters + of unknown type. + 2. Filter the set of overloads to only contain those with the closest number of + parameters. + For example, if we are called with 3 parameters and there are 2 overloads that + take 2 parameters and one that takes 3, eliminate the 2 parameter overloads. + 3. Find the best remaining overload based on its match score. + If two or more overloads have the same match score, call the last one. The match + score is constructed by adding the matchScore() result for each of the parameters. +*/ +QDeclarativeObjectMethodScriptClass::Value +QDeclarativeObjectMethodScriptClass::callOverloaded(MethodData *method, QScriptContext *ctxt) +{ + int argumentCount = ctxt->argumentCount(); + + QDeclarativePropertyCache::Data *best = 0; + int bestParameterScore = INT_MAX; + int bestMatchScore = INT_MAX; + + QDeclarativePropertyCache::Data dummy; + QDeclarativePropertyCache::Data *attempt = &method->data; + + do { + QList<QByteArray> methodArgTypeNames; + + if (attempt->flags & QDeclarativePropertyCache::Data::HasArguments) + methodArgTypeNames = method->object->metaObject()->method(attempt->coreIndex).parameterTypes(); + + int methodArgumentCount = methodArgTypeNames.count(); + + if (methodArgumentCount > argumentCount) + continue; // We don't have sufficient arguments to call this method + + int methodParameterScore = argumentCount - methodArgumentCount; + if (methodParameterScore > bestParameterScore) + continue; // We already have a better option + + int methodMatchScore = 0; + QVarLengthArray<int, 9> methodArgTypes(methodArgumentCount); + + bool unknownArgument = false; + for (int ii = 0; ii < methodArgumentCount; ++ii) { + methodArgTypes[ii] = QMetaType::type(methodArgTypeNames.at(ii)); + if (methodArgTypes[ii] == QVariant::Invalid) + methodArgTypes[ii] = enumType(method->object->metaObject(), + QString::fromLatin1(methodArgTypeNames.at(ii))); + if (methodArgTypes[ii] == QVariant::Invalid) { + unknownArgument = true; + break; + } + methodMatchScore += matchScore(ctxt->argument(ii), methodArgTypes[ii], methodArgTypeNames.at(ii)); + } + if (unknownArgument) + continue; // We don't understand all the parameters + + if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) { + best = attempt; + bestParameterScore = methodParameterScore; + bestMatchScore = methodMatchScore; + } + + if (bestParameterScore == 0 && bestMatchScore == 0) + break; // We can't get better than that + + } while((attempt = relatedMethod(method->object, attempt, dummy)) != 0); + + if (best) { + return callPrecise(method->object, *best, ctxt); + } else { + QString error = QLatin1String("Unable to determine callable overload. Candidates are:"); + QDeclarativePropertyCache::Data *candidate = &method->data; + while (candidate) { + error += QLatin1String("\n ") + QString::fromUtf8(method->object->metaObject()->method(candidate->coreIndex).signature()); + candidate = relatedMethod(method->object, candidate, dummy); + } + return Value(ctxt, ctxt->throwError(error)); + } +} + +/*! + Returns the match score for converting \a actual to be of type \a conversionType. A + zero score means "perfect match" whereas a higher score is worse. + + The conversion table is copied out of the QtScript callQtMethod() function. +*/ +int QDeclarativeObjectMethodScriptClass::matchScore(const QScriptValue &actual, int conversionType, + const QByteArray &conversionTypeName) +{ + if (actual.isNumber()) { + switch (conversionType) { + case QMetaType::Double: + return 0; + case QMetaType::Float: + return 1; + case QMetaType::LongLong: + case QMetaType::ULongLong: + return 2; + case QMetaType::Long: + case QMetaType::ULong: + return 3; + case QMetaType::Int: + case QMetaType::UInt: + return 4; + case QMetaType::Short: + case QMetaType::UShort: + return 5; + break; + case QMetaType::Char: + case QMetaType::UChar: + return 6; + default: + return 10; + } + } else if (actual.isString()) { + switch (conversionType) { + case QMetaType::QString: + return 0; + default: + return 10; + } + } else if (actual.isBoolean()) { + switch (conversionType) { + case QMetaType::Bool: + return 0; + default: + return 10; + } + } else if (actual.isDate()) { + switch (conversionType) { + case QMetaType::QDateTime: + return 0; + case QMetaType::QDate: + return 1; + case QMetaType::QTime: + return 2; + default: + return 10; + } + } else if (actual.isRegExp()) { + switch (conversionType) { + case QMetaType::QRegExp: + return 0; + default: + return 10; + } + } else if (actual.isVariant()) { + if (conversionType == qMetaTypeId<QVariant>()) + return 0; + else if (actual.toVariant().userType() == conversionType) + return 0; + else + return 10; + } else if (actual.isArray()) { + switch (conversionType) { + case QMetaType::QStringList: + case QMetaType::QVariantList: + return 5; + default: + return 10; + } + } else if (actual.isQObject()) { + switch (conversionType) { + case QMetaType::QObjectStar: + return 0; + default: + return 10; + } + } else if (actual.isNull()) { + switch (conversionType) { + case QMetaType::VoidStar: + case QMetaType::QObjectStar: + return 0; + default: + if (!conversionTypeName.endsWith('*')) + return 10; + else + return 0; + } + } else { + return 10; + } +} + +static inline int QMetaObject_methods(const QMetaObject *metaObject) +{ + struct Private + { + int revision; + int className; + int classInfoCount, classInfoData; + int methodCount, methodData; + }; + + return reinterpret_cast<const Private *>(metaObject->d.data)->methodCount; +} + +static QByteArray QMetaMethod_name(const QMetaMethod &m) +{ + QByteArray sig = m.signature(); + int paren = sig.indexOf('('); + if (paren == -1) + return sig; + else + return sig.left(paren); +} + +/*! +Returns the next related method, if one, or 0. +*/ +QDeclarativePropertyCache::Data * +QDeclarativeObjectMethodScriptClass::relatedMethod(QObject *object, QDeclarativePropertyCache::Data *current, + QDeclarativePropertyCache::Data &dummy) +{ + QDeclarativePropertyCache *cache = QDeclarativeData::get(object)->propertyCache; + if (current->relatedIndex == -1) + return 0; + + if (cache) { + return cache->method(current->relatedIndex); + } else { + const QMetaObject *mo = object->metaObject(); + int methodOffset = mo->methodCount() - QMetaObject_methods(mo); + + while (methodOffset > current->relatedIndex) { + mo = mo->superClass(); + methodOffset -= QMetaObject_methods(mo); + } + + QMetaMethod method = mo->method(current->relatedIndex); + dummy.load(method); + + // Look for overloaded methods + QByteArray methodName = QMetaMethod_name(method); + for (int ii = current->relatedIndex - 1; ii >= methodOffset; --ii) { + if (methodName == QMetaMethod_name(mo->method(ii))) { + dummy.relatedIndex = ii; + return &dummy; + } + } + + return &dummy; + } } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 75e384c..7956c40 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -65,6 +65,7 @@ class QDeclarativeEngine; class QScriptContext; class QScriptEngine; class QDeclarativeContextData; +class MethodData; class Q_AUTOTEST_EXPORT QDeclarativeObjectMethodScriptClass : public QScriptDeclarativeClass { @@ -82,6 +83,14 @@ protected: private: int enumType(const QMetaObject *, const QString &); + Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *); + Value callOverloaded(MethodData *, QScriptContext *); + Value callMethod(QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt); + + int matchScore(const QScriptValue &, int, const QByteArray &); + QDeclarativePropertyCache::Data *relatedMethod(QObject *, QDeclarativePropertyCache::Data *current, + QDeclarativePropertyCache::Data &dummy); + PersistentIdentifier m_connectId; PersistentIdentifier m_disconnectId; QScriptValue m_connect; diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index c58aebc..77184c2 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -54,7 +54,6 @@ // #include "qdeclarative.h" -#include "private/qdeclarativerefcount_p.h" #include <QtCore/qbytearray.h> #include <QtCore/qlist.h> @@ -63,6 +62,8 @@ #include <QtCore/qstringlist.h> #include <private/qobject_p.h> +#include <private/qdeclarativerefcount_p.h> +#include <private/qdeclarativeglobal_p.h> QT_BEGIN_HEADER @@ -355,7 +356,7 @@ namespace QDeclarativeParser // True if the setting of this property will be deferred. Set by the // QDeclarativeCompiler bool isDeferred; - // True if this property is a value-type psuedo-property + // True if this property is a value-type pseudo-property bool isValueTypeSubProperty; LocationSpan location; diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h index d45ddbc..388c92e 100644 --- a/src/declarative/qml/qdeclarativeprivate.h +++ b/src/declarative/qml/qdeclarativeprivate.h @@ -55,9 +55,6 @@ #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> -#ifndef Q_OS_WIN -#include <stdint.h> -#endif QT_BEGIN_HEADER @@ -105,7 +102,7 @@ namespace QDeclarativePrivate template<class From, class To> struct StaticCastSelectorClass<From, To, sizeof(int)> { - static inline int cast() { return int(reinterpret_cast<intptr_t>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; } + static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; } }; template<class From, class To> diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index b5fb619..1395e97 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -1408,8 +1408,8 @@ static inline void flush_vme_signal(const QObject *object, int index) int methodOffset = metaObject->methodOffset(); while (methodOffset > index) { - methodOffset -= QMetaObject_methods(metaObject); metaObject = metaObject->d.superdata; + methodOffset -= QMetaObject_methods(metaObject); } QDeclarativeVMEMetaObject *vme = diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h index a8438c8..a9d6979 100644 --- a/src/declarative/qml/qdeclarativeproperty_p.h +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -55,17 +55,17 @@ #include "qdeclarativeproperty.h" -#include "private/qdeclarativepropertycache_p.h" -#include "private/qdeclarativeguard_p.h" - #include <private/qobject_p.h> +#include <private/qdeclarativeglobal_p.h> +#include <private/qdeclarativepropertycache_p.h> +#include <private/qdeclarativeguard_p.h> QT_BEGIN_NAMESPACE class QDeclarativeContext; class QDeclarativeEnginePrivate; class QDeclarativeExpression; -class Q_DECLARATIVE_EXPORT QDeclarativePropertyPrivate +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePropertyPrivate { public: enum WriteFlag { BypassInterceptor = 0x01, DontRemoveBinding = 0x02 }; diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 9e1ceb8..0adcdbd 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -93,6 +93,7 @@ void QDeclarativePropertyCache::Data::load(const QMetaProperty &p, QDeclarativeE void QDeclarativePropertyCache::Data::load(const QMetaMethod &m) { coreIndex = m.methodIndex(); + relatedIndex = -1; flags |= Data::IsFunction; if (m.methodType() == QMetaMethod::Signal) flags |= Data::IsSignal; @@ -140,15 +141,25 @@ void QDeclarativePropertyCache::clear() if (indexCache.at(ii)) indexCache.at(ii)->release(); } + for (int ii = 0; ii < methodIndexCache.count(); ++ii) { + RData *data = methodIndexCache.at(ii); + if (data) data->release(); + } + for (StringCache::ConstIterator iter = stringCache.begin(); - iter != stringCache.end(); ++iter) - (*iter)->release(); + iter != stringCache.end(); ++iter) { + RData *data = (*iter); + data->release(); + } for (IdentifierCache::ConstIterator iter = identifierCache.begin(); - iter != identifierCache.end(); ++iter) - (*iter)->release(); + iter != identifierCache.end(); ++iter) { + RData *data = (*iter); + data->release(); + } indexCache.clear(); + methodIndexCache.clear(); stringCache.clear(); identifierCache.clear(); } @@ -202,12 +213,16 @@ QDeclarativePropertyCache *QDeclarativePropertyCache::copy() const { QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine); cache->indexCache = indexCache; + cache->methodIndexCache = methodIndexCache; cache->stringCache = stringCache; cache->identifierCache = identifierCache; for (int ii = 0; ii < indexCache.count(); ++ii) { if (indexCache.at(ii)) indexCache.at(ii)->addref(); } + for (int ii = 0; ii < methodIndexCache.count(); ++ii) { + if (methodIndexCache.at(ii)) methodIndexCache.at(ii)->addref(); + } for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter) (*iter)->addref(); for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter) @@ -221,43 +236,14 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb { QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - int propCount = metaObject->propertyCount(); - int propOffset = metaObject->propertyOffset(); - - indexCache.resize(propCount); - for (int ii = propOffset; ii < propCount; ++ii) { - QMetaProperty p = metaObject->property(ii); - if (!p.isScriptable()) - continue; - - QString propName = QString::fromUtf8(p.name()); - - RData *data = new RData; - data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); - - data->load(p, engine); - data->flags |= propertyFlags; - - indexCache[ii] = data; - - if (stringCache.contains(propName)) { - stringCache[propName]->release(); - identifierCache[data->identifier.identifier]->release(); - } - - stringCache.insert(propName, data); - identifierCache.insert(data->identifier.identifier, data); - data->addref(); - data->addref(); - } - int methodCount = metaObject->methodCount(); - int methodOffset = qMax(2, metaObject->methodOffset()); // 2 to block the destroyed signal + // 3 to block the destroyed signal and the deleteLater() slot + int methodOffset = qMax(3, metaObject->methodOffset()); methodIndexCache.resize(methodCount); for (int ii = methodOffset; ii < methodCount; ++ii) { QMetaMethod m = metaObject->method(ii); - if (m.access() == QMetaMethod::Private) + if (m.access() == QMetaMethod::Private) continue; QString methodName = QString::fromUtf8(m.signature()); @@ -267,11 +253,7 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName); - - if (stringCache.contains(methodName)) { - stringCache[methodName]->release(); - identifierCache[data->identifier.identifier]->release(); - } + methodIndexCache[ii] = data; data->load(m); if (m.methodType() == QMetaMethod::Slot || m.methodType() == QMetaMethod::Method) @@ -279,73 +261,74 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb else if (m.methodType() == QMetaMethod::Signal) data->flags |= signalFlags; - methodIndexCache[ii] = data; + if (stringCache.contains(methodName)) { + RData *old = stringCache[methodName]; + // We only overload methods in the same class, exactly like C++ + if (old->flags & Data::IsFunction && old->coreIndex >= methodOffset) + data->relatedIndex = old->coreIndex; + stringCache[methodName]->release(); + identifierCache[data->identifier.identifier]->release(); + } stringCache.insert(methodName, data); identifierCache.insert(data->identifier.identifier, data); data->addref(); + data->addref(); } -} -void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject) -{ - Q_ASSERT(engine); - Q_ASSERT(metaObject); - QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - - clear(); - - // ### The properties/methods should probably be spliced on a per-metaobject basis int propCount = metaObject->propertyCount(); + int propOffset = metaObject->propertyOffset(); indexCache.resize(propCount); - for (int ii = propCount - 1; ii >= 0; --ii) { + for (int ii = propOffset; ii < propCount; ++ii) { QMetaProperty p = metaObject->property(ii); - if (!p.isScriptable()) { - indexCache[ii] = 0; + if (!p.isScriptable()) continue; - } + QString propName = QString::fromUtf8(p.name()); RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); + indexCache[ii] = data; data->load(p, engine); + data->flags |= propertyFlags; - indexCache[ii] = data; - - if (stringCache.contains(propName)) - continue; + if (stringCache.contains(propName)) { + stringCache[propName]->release(); + identifierCache[data->identifier.identifier]->release(); + } stringCache.insert(propName, data); identifierCache.insert(data->identifier.identifier, data); data->addref(); data->addref(); } +} - int methodCount = metaObject->methodCount(); - for (int ii = methodCount - 1; ii >= 3; --ii) { // >=3 to block the destroyed signal and deleteLater() slot - QMetaMethod m = metaObject->method(ii); - if (m.access() == QMetaMethod::Private) - continue; - QString methodName = QString::fromUtf8(m.signature()); +void QDeclarativePropertyCache::updateRecur(QDeclarativeEngine *engine, const QMetaObject *metaObject) +{ + if (!metaObject) + return; - int parenIdx = methodName.indexOf(QLatin1Char('(')); - Q_ASSERT(parenIdx != -1); - methodName = methodName.left(parenIdx); + updateRecur(engine, metaObject->superClass()); - if (stringCache.contains(methodName)) - continue; + append(engine, metaObject); +} - RData *data = new RData; - data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName); +void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject) +{ + Q_ASSERT(engine); + Q_ASSERT(metaObject); + QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - data->load(m); + clear(); - stringCache.insert(methodName, data); - identifierCache.insert(data->identifier.identifier, data); - data->addref(); - } + // Optimization to prevent unnecessary reallocation of lists + indexCache.reserve(metaObject->propertyCount()); + methodIndexCache.reserve(metaObject->methodCount()); + + updateRecur(engine,metaObject); } QDeclarativePropertyCache::Data * diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h index 79b126d..922010d 100644 --- a/src/declarative/qml/qdeclarativepropertycache_p.h +++ b/src/declarative/qml/qdeclarativepropertycache_p.h @@ -96,7 +96,7 @@ public: IsVMEFunction = 0x00000400, HasArguments = 0x00000800, IsSignal = 0x00001000, - IsVMESignal = 0x00002000, + IsVMESignal = 0x00002000 }; Q_DECLARE_FLAGS(Flags, Flag) @@ -105,7 +105,10 @@ public: Flags flags; int propType; int coreIndex; - int notifyIndex; + union { + int notifyIndex; // When !IsFunction + int relatedIndex; // When IsFunction + }; static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0); void load(const QMetaProperty &, QDeclarativeEngine *engine = 0); @@ -152,6 +155,8 @@ private: typedef QHash<QString, RData *> StringCache; typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache; + void updateRecur(QDeclarativeEngine *, const QMetaObject *); + QDeclarativeEngine *engine; IndexCache indexCache; IndexCache methodIndexCache; diff --git a/src/declarative/qml/qdeclarativestringconverters_p.h b/src/declarative/qml/qdeclarativestringconverters_p.h index e6b0abe..b632222 100644 --- a/src/declarative/qml/qdeclarativestringconverters_p.h +++ b/src/declarative/qml/qdeclarativestringconverters_p.h @@ -56,6 +56,8 @@ #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> +#include <private/qdeclarativeglobal_p.h> + QT_BEGIN_NAMESPACE class QColor; @@ -69,19 +71,19 @@ class QVector3D; // XXX - Bauhaus currently uses these methods which is why they're exported namespace QDeclarativeStringConverters { - QVariant Q_DECLARATIVE_EXPORT variantFromString(const QString &); - QVariant Q_DECLARATIVE_EXPORT variantFromString(const QString &, int preferredType, bool *ok = 0); + QVariant Q_DECLARATIVE_PRIVATE_EXPORT variantFromString(const QString &); + QVariant Q_DECLARATIVE_PRIVATE_EXPORT variantFromString(const QString &, int preferredType, bool *ok = 0); - QColor Q_DECLARATIVE_EXPORT colorFromString(const QString &, bool *ok = 0); + QColor Q_DECLARATIVE_PRIVATE_EXPORT colorFromString(const QString &, bool *ok = 0); #ifndef QT_NO_DATESTRING - QDate Q_DECLARATIVE_EXPORT dateFromString(const QString &, bool *ok = 0); - QTime Q_DECLARATIVE_EXPORT timeFromString(const QString &, bool *ok = 0); - QDateTime Q_DECLARATIVE_EXPORT dateTimeFromString(const QString &, bool *ok = 0); + QDate Q_DECLARATIVE_PRIVATE_EXPORT dateFromString(const QString &, bool *ok = 0); + QTime Q_DECLARATIVE_PRIVATE_EXPORT timeFromString(const QString &, bool *ok = 0); + QDateTime Q_DECLARATIVE_PRIVATE_EXPORT dateTimeFromString(const QString &, bool *ok = 0); #endif - QPointF Q_DECLARATIVE_EXPORT pointFFromString(const QString &, bool *ok = 0); - QSizeF Q_DECLARATIVE_EXPORT sizeFFromString(const QString &, bool *ok = 0); - QRectF Q_DECLARATIVE_EXPORT rectFFromString(const QString &, bool *ok = 0); - QVector3D Q_DECLARATIVE_EXPORT vector3DFromString(const QString &, bool *ok = 0); + QPointF Q_DECLARATIVE_PRIVATE_EXPORT pointFFromString(const QString &, bool *ok = 0); + QSizeF Q_DECLARATIVE_PRIVATE_EXPORT sizeFFromString(const QString &, bool *ok = 0); + QRectF Q_DECLARATIVE_PRIVATE_EXPORT rectFFromString(const QString &, bool *ok = 0); + QVector3D Q_DECLARATIVE_PRIVATE_EXPORT vector3DFromString(const QString &, bool *ok = 0); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativetypeloader.cpp b/src/declarative/qml/qdeclarativetypeloader.cpp index 061f309..c015519 100644 --- a/src/declarative/qml/qdeclarativetypeloader.cpp +++ b/src/declarative/qml/qdeclarativetypeloader.cpp @@ -44,6 +44,7 @@ #include <private/qdeclarativeengine_p.h> #include <private/qdeclarativecompiler_p.h> #include <private/qdeclarativecomponent_p.h> +#include <private/qdeclarativeglobal_p.h> #include <QtDeclarative/qdeclarativecomponent.h> #include <QtCore/qdebug.h> @@ -493,6 +494,13 @@ void QDeclarativeDataLoader::load(QDeclarativeDataBlob *blob) QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(blob->m_url); if (!lf.isEmpty()) { + if (!QDeclarative_isFileCaseCorrect(lf)) { + QDeclarativeError error; + error.setUrl(blob->m_url); + error.setDescription(QLatin1String("File name case mismatch")); + blob->setError(error); + return; + } QFile file(lf); if (file.open(QFile::ReadOnly)) { QByteArray data = file.readAll(); @@ -711,7 +719,7 @@ void QDeclarativeTypeLoader::clearCache() QDeclarativeTypeData::QDeclarativeTypeData(const QUrl &url, QDeclarativeTypeLoader::Options options, QDeclarativeTypeLoader *manager) : QDeclarativeDataBlob(url, QmlFile), m_options(options), m_typesResolved(false), - m_compiledData(0), m_component(0), m_typeLoader(manager) + m_compiledData(0), m_typeLoader(manager) { } @@ -760,23 +768,6 @@ QDeclarativeCompiledData *QDeclarativeTypeData::compiledData() const return m_compiledData; } -QDeclarativeComponent *QDeclarativeTypeData::component() const -{ - if (!m_component) { - - if (m_compiledData) { - m_component = new QDeclarativeComponent(typeLoader()->engine(), m_compiledData, -1, -1, 0); - } else { - m_component = new QDeclarativeComponent(typeLoader()->engine()); - QDeclarativeComponentPrivate::get(m_component)->url = finalUrl(); - QDeclarativeComponentPrivate::get(m_component)->state.errors = errors(); - } - - } - - return m_component; -} - void QDeclarativeTypeData::registerCallback(TypeDataCallback *callback) { Q_ASSERT(!m_callbacks.contains(callback)); diff --git a/src/declarative/qml/qdeclarativetypeloader_p.h b/src/declarative/qml/qdeclarativetypeloader_p.h index 7381f28..718537a 100644 --- a/src/declarative/qml/qdeclarativetypeloader_p.h +++ b/src/declarative/qml/qdeclarativetypeloader_p.h @@ -243,7 +243,6 @@ public: const QList<ScriptReference> &resolvedScripts() const; QDeclarativeCompiledData *compiledData() const; - QDeclarativeComponent *component() const; // Used by QDeclarativeComponent to get notifications struct TypeDataCallback { @@ -278,7 +277,6 @@ private: bool m_typesResolved:1; QDeclarativeCompiledData *m_compiledData; - mutable QDeclarativeComponent *m_component; QList<TypeDataCallback *> m_callbacks; diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index 4b1bbd6..06c8669 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE -class Q_DECLARATIVE_EXPORT QDeclarativeValueType : public QObject +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueType : public QObject { Q_OBJECT public: @@ -81,7 +81,7 @@ public: virtual void setValue(QVariant) = 0; }; -class Q_DECLARATIVE_EXPORT QDeclarativeValueTypeFactory +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeValueTypeFactory { public: QDeclarativeValueTypeFactory(); diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 360186c..db90aff 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -185,12 +185,9 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, bindings = bindings.united(bindingSkipList); QObject *o = - types.at(instr.create.type).createInstance(ctxt, bindings); + types.at(instr.create.type).createInstance(ctxt, bindings, &vmeErrors); if (!o) { - if(types.at(instr.create.type).component) - vmeErrors << types.at(instr.create.type).component->errors(); - VME_EXCEPTION(QCoreApplication::translate("QDeclarativeVME","Unable to create object of type %1").arg(QString::fromLatin1(types.at(instr.create.type).className))); } @@ -933,8 +930,9 @@ QList<QDeclarativeError> QDeclarativeVME::errors() const } QObject * -QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData *ctxt, - const QBitField &bindings) const +QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData *ctxt, + const QBitField &bindings, + QList<QDeclarativeError> *errors) const { if (type) { QObject *rv = 0; @@ -948,7 +946,7 @@ QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData return rv; } else { Q_ASSERT(component); - return QDeclarativeComponentPrivate::get(component)->create(ctxt, bindings); + return QDeclarativeComponentPrivate::begin(ctxt, 0, component, -1, -1, 0, errors, bindings); } } diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 37f08fc..e28062b 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -459,7 +459,7 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) id -= propOffset; if (id < metaData->propertyCount) { - int t = (metaData->propertyData() + id)->propertyType; + int t = (metaData->propertyData() + id)->propertyType; bool needActivate = false; if (t == -1) { @@ -586,11 +586,26 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) connectAlias(id); - if (d->propertyIdx == -1) { + if (d->isObjectAlias()) { *reinterpret_cast<QObject **>(a[0]) = target; return -1; + } else if (d->isValueTypeAlias()) { + // Value type property + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(ctxt->engine); + + QDeclarativeValueType *valueType = ep->valueTypes[d->valueType()]; + Q_ASSERT(valueType); + + valueType->read(target, d->propertyIndex()); + int rv = QMetaObject::metacall(valueType, c, d->valueTypeIndex(), a); + + if (c == QMetaObject::WriteProperty) + valueType->write(target, d->propertyIndex(), 0x00); + + return rv; + } else { - return QMetaObject::metacall(target, c, d->propertyIdx, a); + return QMetaObject::metacall(target, c, d->propertyIndex(), a); } } @@ -823,8 +838,8 @@ void QDeclarativeVMEMetaObject::connectAlias(int aliasId) int sigIdx = methodOffset + aliasId + metaData->propertyCount; QMetaObject::connect(context, d->contextIdx + ctxtPriv->notifyIndex, object, sigIdx); - if (d->propertyIdx != -1) { - QMetaProperty prop = target->metaObject()->property(d->propertyIdx); + if (!d->isObjectAlias()) { + QMetaProperty prop = target->metaObject()->property(d->propertyIndex()); if (prop.hasNotifySignal()) QDeclarativePropertyPrivate::connect(target, prop.notifySignalIndex(), object, sigIdx); } diff --git a/src/declarative/qml/qdeclarativevmemetaobject_p.h b/src/declarative/qml/qdeclarativevmemetaobject_p.h index 4ccaa73..5134763 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject_p.h +++ b/src/declarative/qml/qdeclarativevmemetaobject_p.h @@ -84,6 +84,25 @@ struct QDeclarativeVMEMetaData int contextIdx; int propertyIdx; int flags; + + bool isObjectAlias() const { + return propertyIdx == -1; + } + bool isPropertyAlias() const { + return !isObjectAlias() && !(propertyIdx & 0xFF000000); + } + bool isValueTypeAlias() const { + return !isObjectAlias() && (propertyIdx & 0xFF000000); + } + int propertyIndex() const { + return propertyIdx & 0x0000FFFF; + } + int valueTypeIndex() const { + return (propertyIdx & 0x00FF0000) >> 16; + } + int valueType() const { + return ((unsigned int)propertyIdx) >> 24; + } }; struct PropertyData { diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 509ca6b..ae7a80d 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -514,7 +514,7 @@ void QDeclarativeWorkerScriptEngine::run() /*! \qmlclass WorkerScript QDeclarativeWorkerScript - \ingroup qml-utility-elements + \ingroup qml-utility-elements \brief The WorkerScript element enables the use of threads in QML. Use WorkerScript to run operations in a new thread. @@ -528,7 +528,7 @@ void QDeclarativeWorkerScriptEngine::run() \snippet doc/src/snippets/declarative/workerscript.qml 0 - The above worker script specifies a javascript file, "script.js", that handles + The above worker script specifies a JavaScript file, "script.js", that handles the operations to be performed in the new thread. Here is \c script.js: \qml @@ -543,6 +543,19 @@ void QDeclarativeWorkerScriptEngine::run() \tt script.js. This in turn sends a reply message that is then received by the \tt onMessage() handler of \tt myWorker. + + \section3 Restrictions + + Since the \c WorkerScript.onMessage() function is run in a separate thread, the + JavaScript file is evaluated in a context separate from the main QML engine. This means + that unlike an ordinary JavaScript file that is imported into QML, the \c script.js + in the above example cannot access the properties, methods or other attributes + of the QML item, nor can it access any context properties set on the QML object + through QDeclarativeContext. + + Additionally, there are restrictions on the types of values that can be passed to and + from the worker script. See the sendMessage() documentation for details. + \sa {declarative/threading/workerscript}{WorkerScript example}, {declarative/threading/threadedlistmodel}{Threaded ListModel example} */ @@ -586,6 +599,19 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source) Sends the given \a message to a worker script handler in another thread. The other worker script handler can receive this message through the onMessage() handler. + + The \c message object may only contain values of the following + types: + + \list + \o boolean, number, string + \o JavaScript objects and arrays + \o ListModel objects (any other type of QObject* is not allowed) + \endlist + + All objects and arrays are copied to the \c message. With the exception + of ListModel objects, any modifications by the other thread to an object + passed in \c message will not be reflected in the original object. */ void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message) { diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp index 58f8811..dfe89f8 100644 --- a/src/declarative/qml/qmetaobjectbuilder.cpp +++ b/src/declarative/qml/qmetaobjectbuilder.cpp @@ -41,10 +41,6 @@ #include "private/qmetaobjectbuilder_p.h" -#ifndef Q_OS_WIN -#include <stdint.h> -#endif - QT_BEGIN_NAMESPACE /*! @@ -1264,8 +1260,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, char *str = reinterpret_cast<char *>(buf + size); if (buf) { if (relocatable) { - meta->d.stringdata = reinterpret_cast<const char *>((intptr_t)size); - meta->d.data = reinterpret_cast<uint *>((intptr_t)pmetaSize); + meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size); + meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize); } else { meta->d.stringdata = str; meta->d.data = reinterpret_cast<uint *>(data); @@ -1502,8 +1498,8 @@ void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, const char *buf = data.constData(); const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf); - intptr_t stringdataOffset = (intptr_t)dataMo->d.stringdata; - intptr_t dataOffset = (intptr_t)dataMo->d.data; + quintptr stringdataOffset = (quintptr)dataMo->d.stringdata; + quintptr dataOffset = (quintptr)dataMo->d.data; output->d.superdata = superclass; output->d.stringdata = buf + stringdataOffset; diff --git a/src/declarative/qml/qmetaobjectbuilder_p.h b/src/declarative/qml/qmetaobjectbuilder_p.h index dbaf9e6..a90ba63 100644 --- a/src/declarative/qml/qmetaobjectbuilder_p.h +++ b/src/declarative/qml/qmetaobjectbuilder_p.h @@ -58,6 +58,8 @@ #include <QtCore/qdatastream.h> #include <QtCore/qmap.h> +#include <private/qdeclarativeglobal_p.h> + QT_BEGIN_NAMESPACE class QMetaObjectBuilderPrivate; @@ -68,7 +70,7 @@ class QMetaPropertyBuilderPrivate; class QMetaEnumBuilder; class QMetaEnumBuilderPrivate; -class Q_DECLARATIVE_EXPORT QMetaObjectBuilder +class Q_DECLARATIVE_PRIVATE_EXPORT QMetaObjectBuilder { public: enum AddMember @@ -193,7 +195,7 @@ private: friend class QMetaEnumBuilder; }; -class Q_DECLARATIVE_EXPORT QMetaMethodBuilder +class Q_DECLARATIVE_PRIVATE_EXPORT QMetaMethodBuilder { public: QMetaMethodBuilder() : _mobj(0), _index(0) {} @@ -231,7 +233,7 @@ private: QMetaMethodBuilderPrivate *d_func() const; }; -class Q_DECLARATIVE_EXPORT QMetaPropertyBuilder +class Q_DECLARATIVE_PRIVATE_EXPORT QMetaPropertyBuilder { public: QMetaPropertyBuilder() : _mobj(0), _index(0) {} @@ -282,7 +284,7 @@ private: QMetaPropertyBuilderPrivate *d_func() const; }; -class Q_DECLARATIVE_EXPORT QMetaEnumBuilder +class Q_DECLARATIVE_PRIVATE_EXPORT QMetaEnumBuilder { public: QMetaEnumBuilder() : _mobj(0), _index(0) {} |