diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-17 06:58:40 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-17 06:58:40 (GMT) |
commit | f5668a63a9396b8f21a62a3a780f1e0023715806 (patch) | |
tree | 88cad63bd0dfea70bcf54e3eed57b8a11189fd29 /src/declarative/qml | |
parent | fd3f9dd0f31efeea3aa0ec28b54c70d85712c7ba (diff) | |
parent | 060d833d3e0fd5a99876e0717fb26ef93fae30e1 (diff) | |
download | Qt-f5668a63a9396b8f21a62a3a780f1e0023715806.zip Qt-f5668a63a9396b8f21a62a3a780f1e0023715806.tar.gz Qt-f5668a63a9396b8f21a62a3a780f1e0023715806.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-qml: (47 commits)
Add missing NOTIFY signals to various QML item class properties
Fix currentIndex after itemsMoved()
qmlviewer: build on symbian
Revert "Replace QList<>* support with QmlListProperty"
Declare QmlXmlListModelRole meta type before any code uses it.
Make compile on Symbian (call Q_DECLARE_METATYPE earlier)
Conditionally link webkit on wince
Revert "Run dos2unix on these files."
Expose LayoutItem documentation
Fix palette on the N900
Fix QTBUG-8090, improve original patch effectiveness.
Replace QList<>* support with QmlListProperty
Run dos2unix on these files.
Remove standalone QmlDebugger. It is now only available through the
Mobility 404
Fix crash in QmlMetaProperty that could occur when using value-type
QML binding optimizer crash
QML binding optimizer crash
Fix crash in QML binding optimizer
Don't delete binding directly
...
Diffstat (limited to 'src/declarative/qml')
24 files changed, 456 insertions, 171 deletions
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index cd2fbff..021ef9e 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -50,6 +50,7 @@ SOURCES += \ $$PWD/qmltypenamescriptclass.cpp \ $$PWD/qmllistscriptclass.cpp \ $$PWD/qmlworkerscript.cpp \ + $$PWD/qmlimageprovider.cpp \ $$PWD/qmlnetworkaccessmanagerfactory.cpp HEADERS += \ $$PWD/qmlparser_p.h \ @@ -117,6 +118,7 @@ HEADERS += \ $$PWD/qmlworkerscript_p.h \ $$PWD/qmlscriptclass_p.h \ $$PWD/qmlguard_p.h \ + $$PWD/qmlimageprovider.h \ $$PWD/qmlnetworkaccessmanagerfactory.h QT += sql include(parser/parser.pri) diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 3e29a3c..a986818 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -291,6 +291,12 @@ void QmlAbstractBinding::removeFromObject() } } +void QmlAbstractBinding::clear() +{ + if (m_mePtr) + *m_mePtr = 0; +} + QString QmlAbstractBinding::expression() const { return QLatin1String("<Unknown>"); diff --git a/src/declarative/qml/qmlbinding.h b/src/declarative/qml/qmlbinding.h index cefb4fe..bae971d 100644 --- a/src/declarative/qml/qmlbinding.h +++ b/src/declarative/qml/qmlbinding.h @@ -75,6 +75,9 @@ public: void addToObject(QObject *); void removeFromObject(); +protected: + void clear(); + private: friend class QmlDeclarativeData; friend class QmlMetaProperty; diff --git a/src/declarative/qml/qmlcleanup.cpp b/src/declarative/qml/qmlcleanup.cpp index 599e4e7..e7767d2 100644 --- a/src/declarative/qml/qmlcleanup.cpp +++ b/src/declarative/qml/qmlcleanup.cpp @@ -43,6 +43,8 @@ #include "qmlengine_p.h" +QT_BEGIN_NAMESPACE + /*! \internal \class QmlCleanup @@ -82,4 +84,4 @@ QmlCleanup::~QmlCleanup() prev = 0; next = 0; } - +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcompiledbindings.cpp b/src/declarative/qml/qmlcompiledbindings.cpp index b5fbab9..bc62d9a 100644 --- a/src/declarative/qml/qmlcompiledbindings.cpp +++ b/src/declarative/qml/qmlcompiledbindings.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ +// #define COMPILEDBINDINGS_DEBUG + #include "qmlcompiledbindings_p.h" #include <QtDeclarative/qmlinfo.h> @@ -275,6 +277,7 @@ void QmlCompiledBindingsPrivate::Binding::destroy() enabled = false; removeFromObject(); parent->q_func()->release(); + clear(); } int QmlCompiledBindings::qt_metacall(QMetaObject::Call c, int id, void **) @@ -975,6 +978,147 @@ static void throwException(int id, QmlDelayedError *error, qWarning() << error->error; } +static void dumpInstruction(const Instr *instr) +{ + switch (instr->common.type) { + case Instr::Noop: + qWarning().nospace() << "Noop"; + break; + case Instr::Subscribe: + qWarning().nospace() << "Subscribe" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; + break; + case Instr::SubscribeId: + qWarning().nospace() << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; + break; + case Instr::LoadId: + qWarning().nospace() << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg; + break; + case Instr::LoadScope: + qWarning().nospace() << "LoadScope" << "\t\t" << instr->load.index << "\t" << instr->load.reg; + break; + case Instr::LoadRoot: + qWarning().nospace() << "LoadRoot" << "\t\t" << instr->load.index << "\t" << instr->load.reg; + break; + case Instr::LoadAttached: + qWarning().nospace() << "LoadAttached" << "\t\t" << instr->attached.output << "\t" << instr->attached.reg << "\t" << instr->attached.index; + break; + case Instr::ConvertIntToReal: + qWarning().nospace() << "ConvertIntToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + case Instr::ConvertRealToInt: + qWarning().nospace() << "ConvertRealToInt" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + case Instr::Real: + qWarning().nospace() << "Real" << "\t\t\t" << instr->real_value.reg << "\t" << instr->real_value.value; + break; + case Instr::Int: + qWarning().nospace() << "Int" << "\t\t\t" << instr->int_value.reg << "\t" << instr->int_value.value; + break; + case Instr::Bool: + qWarning().nospace() << "Bool" << "\t\t\t" << instr->bool_value.reg << "\t" << instr->bool_value.value; + break; + case Instr::String: + qWarning().nospace() << "String" << "\t\t\t" << instr->string_value.reg << "\t" << instr->string_value.offset << "\t" << instr->string_value.length; + break; + case Instr::AddReal: + qWarning().nospace() << "AddReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::AddInt: + qWarning().nospace() << "AddInt" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::AddString: + qWarning().nospace() << "AddString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::MinusReal: + qWarning().nospace() << "MinusReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::MinusInt: + qWarning().nospace() << "MinusInt" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::CompareReal: + qWarning().nospace() << "CompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::CompareString: + qWarning().nospace() << "CompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::NotCompareReal: + qWarning().nospace() << "NotCompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::NotCompareString: + qWarning().nospace() << "NotCompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::GreaterThanReal: + qWarning().nospace() << "GreaterThanReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::MaxReal: + qWarning().nospace() << "MaxReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::MinReal: + qWarning().nospace() << "MinReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; + break; + case Instr::NewString: + qWarning().nospace() << "NewString" << "\t\t" << instr->construct.reg; + break; + case Instr::NewUrl: + qWarning().nospace() << "NewUrl" << "\t\t\t" << instr->construct.reg; + break; + case Instr::CleanupString: + qWarning().nospace() << "CleanupString" << "\t\t" << instr->cleanup.reg; + break; + case Instr::CleanupUrl: + qWarning().nospace() << "CleanupUrl" << "\t\t" << instr->cleanup.reg; + break; + case Instr::Fetch: + qWarning().nospace() << "Fetch" << "\t\t\t" << instr->fetch.output << "\t" << instr->fetch.index << "\t" << instr->fetch.objectReg; + break; + case Instr::Store: + qWarning().nospace() << "Store" << "\t\t\t" << instr->store.output << "\t" << instr->store.index << "\t" << instr->store.reg; + break; + case Instr::Copy: + qWarning().nospace() << "Copy" << "\t\t\t" << instr->copy.reg << "\t" << instr->copy.src; + break; + case Instr::Skip: + qWarning().nospace() << "Skip" << "\t\t\t" << instr->skip.reg << "\t" << instr->skip.count; + break; + case Instr::Done: + qWarning().nospace() << "Done"; + break; + case Instr::InitString: + qWarning().nospace() << "InitString" << "\t\t" << instr->initstring.offset << "\t" << instr->initstring.dataIdx; + break; + case Instr::FindGeneric: + qWarning().nospace() << "FindGeneric" << "\t\t" << instr->find.reg << "\t" << instr->find.name; + break; + case Instr::FindGenericTerminal: + qWarning().nospace() << "FindGenericTerminal" << "\t" << instr->find.reg << "\t" << instr->find.name; + break; + case Instr::FindProperty: + qWarning().nospace() << "FindProperty" << "\t\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name; + break; + case Instr::FindPropertyTerminal: + qWarning().nospace() << "FindPropertyTerminal" << "\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name; + break; + case Instr::CleanupGeneric: + qWarning().nospace() << "CleanupGeneric" << "\t\t" << instr->cleanup.reg; + break; + case Instr::ConvertGenericToReal: + qWarning().nospace() << "ConvertGenericToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + case Instr::ConvertGenericToBool: + qWarning().nospace() << "ConvertGenericToBool" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + case Instr::ConvertGenericToString: + qWarning().nospace() << "ConvertGenericToString" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + case Instr::ConvertGenericToUrl: + qWarning().nospace() << "ConvertGenericToUrl" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; + break; + default: + qWarning().nospace() << "Unknown"; + break; + } +} + void QmlCompiledBindingsPrivate::run(int instrIndex, QmlContextPrivate *context, QmlDelayedError *error, QObject *scope, QObject *output) @@ -990,7 +1134,14 @@ void QmlCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); +#ifdef COMPILEDBINDINGS_DEBUG + qWarning().nospace() << "Begin binding run"; +#endif + while (instr) { +#ifdef COMPILEDBINDINGS_DEBUG + dumpInstruction(instr); +#endif switch (instr->common.type) { case Instr::Noop: @@ -1403,144 +1554,7 @@ void QmlBindingCompiler::dump(const QByteArray &programData) while (count--) { - switch (instr->common.type) { - case Instr::Noop: - qWarning().nospace() << "Noop"; - break; - case Instr::Subscribe: - qWarning().nospace() << "Subscribe" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; - break; - case Instr::SubscribeId: - qWarning().nospace() << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; - break; - case Instr::LoadId: - qWarning().nospace() << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg; - break; - case Instr::LoadScope: - qWarning().nospace() << "LoadScope" << "\t\t" << instr->load.index << "\t" << instr->load.reg; - break; - case Instr::LoadRoot: - qWarning().nospace() << "LoadRoot" << "\t\t" << instr->load.index << "\t" << instr->load.reg; - break; - case Instr::LoadAttached: - qWarning().nospace() << "LoadAttached" << "\t\t" << instr->attached.output << "\t" << instr->attached.reg << "\t" << instr->attached.index; - break; - case Instr::ConvertIntToReal: - qWarning().nospace() << "ConvertIntToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - case Instr::ConvertRealToInt: - qWarning().nospace() << "ConvertRealToInt" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - case Instr::Real: - qWarning().nospace() << "Real" << "\t\t\t" << instr->real_value.reg << "\t" << instr->real_value.value; - break; - case Instr::Int: - qWarning().nospace() << "Int" << "\t\t\t" << instr->int_value.reg << "\t" << instr->int_value.value; - break; - case Instr::Bool: - qWarning().nospace() << "Bool" << "\t\t\t" << instr->bool_value.reg << "\t" << instr->bool_value.value; - break; - case Instr::String: - qWarning().nospace() << "String" << "\t\t\t" << instr->string_value.reg << "\t" << instr->string_value.offset << "\t" << instr->string_value.length; - break; - case Instr::AddReal: - qWarning().nospace() << "AddReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::AddInt: - qWarning().nospace() << "AddInt" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::AddString: - qWarning().nospace() << "AddString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::MinusReal: - qWarning().nospace() << "MinusReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::MinusInt: - qWarning().nospace() << "MinusInt" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::CompareReal: - qWarning().nospace() << "CompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::CompareString: - qWarning().nospace() << "CompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::NotCompareReal: - qWarning().nospace() << "NotCompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::NotCompareString: - qWarning().nospace() << "NotCompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::GreaterThanReal: - qWarning().nospace() << "GreaterThanReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::MaxReal: - qWarning().nospace() << "MaxReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::MinReal: - qWarning().nospace() << "MinReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2; - break; - case Instr::NewString: - qWarning().nospace() << "NewString" << "\t\t" << instr->construct.reg; - break; - case Instr::NewUrl: - qWarning().nospace() << "NewUrl" << "\t\t\t" << instr->construct.reg; - break; - case Instr::CleanupString: - qWarning().nospace() << "CleanupString" << "\t\t" << instr->cleanup.reg; - break; - case Instr::CleanupUrl: - qWarning().nospace() << "CleanupUrl" << "\t\t" << instr->cleanup.reg; - break; - case Instr::Fetch: - qWarning().nospace() << "Fetch" << "\t\t\t" << instr->fetch.output << "\t" << instr->fetch.index << "\t" << instr->fetch.objectReg; - break; - case Instr::Store: - qWarning().nospace() << "Store" << "\t\t\t" << instr->store.output << "\t" << instr->store.index << "\t" << instr->store.reg; - break; - case Instr::Copy: - qWarning().nospace() << "Copy" << "\t\t\t" << instr->copy.reg << "\t" << instr->copy.src; - break; - case Instr::Skip: - qWarning().nospace() << "Skip" << "\t\t\t" << instr->skip.reg << "\t" << instr->skip.count; - break; - case Instr::Done: - qWarning().nospace() << "Done"; - break; - case Instr::InitString: - qWarning().nospace() << "InitString" << "\t\t" << instr->initstring.offset << "\t" << instr->initstring.dataIdx; - break; - case Instr::FindGeneric: - qWarning().nospace() << "FindGeneric" << "\t\t" << instr->find.reg << "\t" << instr->find.name; - break; - case Instr::FindGenericTerminal: - qWarning().nospace() << "FindGenericTerminal" << "\t" << instr->find.reg << "\t" << instr->find.name; - break; - case Instr::FindProperty: - qWarning().nospace() << "FindProperty" << "\t\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name; - break; - case Instr::FindPropertyTerminal: - qWarning().nospace() << "FindPropertyTerminal" << "\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name; - break; - case Instr::CleanupGeneric: - qWarning().nospace() << "CleanupGeneric" << "\t\t" << instr->cleanup.reg; - break; - case Instr::ConvertGenericToReal: - qWarning().nospace() << "ConvertGenericToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - case Instr::ConvertGenericToBool: - qWarning().nospace() << "ConvertGenericToBool" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - case Instr::ConvertGenericToString: - qWarning().nospace() << "ConvertGenericToString" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - case Instr::ConvertGenericToUrl: - qWarning().nospace() << "ConvertGenericToUrl" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src; - break; - default: - qWarning().nospace() << "Unknown"; - break; - } - + dumpInstruction(instr); ++instr; } } @@ -1585,6 +1599,9 @@ bool QmlBindingCompilerPrivate::compile(QmlJS::AST::Node *node) { resetInstanceState(); + if (destination->type == -1) + return false; + Result type; if (!parseExpression(node, type)) @@ -1864,7 +1881,8 @@ bool QmlBindingCompilerPrivate::parseName(AST::Node *node, Result &type) subscribeName << contextName(); subscribeName << name; - fetch(type, context->metaObject(), reg, d0Idx, subscribeName, nameNodes.at(ii)); + if (!fetch(type, context->metaObject(), reg, d0Idx, subscribeName, nameNodes.at(ii))) + return false; } else if(d1Idx != -1) { Instr instr; instr.common.type = Instr::LoadRoot; @@ -1875,7 +1893,8 @@ bool QmlBindingCompilerPrivate::parseName(AST::Node *node, Result &type) subscribeName << QLatin1String("$$$ROOT"); subscribeName << name; - fetch(type, component->metaObject(), reg, d1Idx, subscribeName, nameNodes.at(ii)); + if (!fetch(type, component->metaObject(), reg, d1Idx, subscribeName, nameNodes.at(ii))) + return false; } else { Instr find; if (nameParts.count() == 1) @@ -1935,8 +1954,7 @@ bool QmlBindingCompilerPrivate::parseName(AST::Node *node, Result &type) if (absType || (wasAttachedObject && idx != -1) || (mo && mo->property(idx).isFinal())) { absType = 0; - fetch(type, mo, reg, idx, subscribeName, nameNodes.at(ii)); - if (type.type == -1) + if (!fetch(type, mo, reg, idx, subscribeName, nameNodes.at(ii))) return false; } else { diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 9e06016..343bd4b 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -539,7 +539,6 @@ QObject *QmlComponent::create(QmlContext *context) QObject *QmlComponentPrivate::create(QmlContext *context, const QBitField &bindings) { - QObject *create(QmlContext *context, const QBitField &); if (!context) context = engine->rootContext(); diff --git a/src/declarative/qml/qmlcompositetypedata_p.h b/src/declarative/qml/qmlcompositetypedata_p.h index c8b9f25..5358963 100644 --- a/src/declarative/qml/qmlcompositetypedata_p.h +++ b/src/declarative/qml/qmlcompositetypedata_p.h @@ -146,5 +146,7 @@ public: QByteArray data; }; +QT_END_NAMESPACE + #endif // QMLCOMPOSITETYPEDATA_P_H diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index d9fc76b..3c419b6 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -300,8 +300,6 @@ QmlContext::~QmlContext() co->prevContextObject = 0; } - delete [] d->idValues; - if (d->propertyNames) d->propertyNames->release(); @@ -310,6 +308,8 @@ QmlContext::~QmlContext() if (d->optimizedBindings) d->optimizedBindings->release(); + + delete [] d->idValues; } void QmlContextPrivate::invalidateEngines() diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index cdbe5f3..7da24f4 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -65,6 +65,7 @@ #include "qmlcomponent_p.h" #include "qmlscriptclass_p.h" #include "qmlnetworkaccessmanagerfactory.h" +#include "qmlimageprovider.h" #include <qfxperf_p_p.h> @@ -85,6 +86,7 @@ #include <QtCore/qthread.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> +#include <QtCore/qmutex.h> #include <QtGui/qcolor.h> #include <QtGui/qvector3d.h> #include <QtGui/qsound.h> @@ -95,6 +97,8 @@ #include <private/qobject_p.h> #include <private/qscriptdeclarativeclass_p.h> +#include <private/qmlgraphicsitemsmodule_p.h> + #ifdef Q_OS_WIN // for %APPDATA% #include <qt_windows.h> #include <qlibrary.h> @@ -136,6 +140,8 @@ struct StaticQtMetaObject : public QObject { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; } }; +static bool qt_QmlQtModule_registered = false; + QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0), @@ -144,6 +150,10 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) networkAccessManager(0), networkAccessManagerFactory(0), typeManager(e), uniqueId(1) { + if (!qt_QmlQtModule_registered) { + qt_QmlQtModule_registered = true; + QmlGraphicsItemModule::defineModule(); + } globalClass = new QmlGlobalScriptClass(&scriptEngine); fileImportPath.append(QLibraryInfo::location(QLibraryInfo::DataPath)+QDir::separator()+QLatin1String("qml")); } @@ -424,6 +434,7 @@ QmlContext *QmlEngine::rootContext() void QmlEngine::setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *factory) { Q_D(QmlEngine); + QMutexLocker locker(&d->mutex); d->networkAccessManagerFactory = factory; } @@ -438,17 +449,24 @@ QmlNetworkAccessManagerFactory *QmlEngine::networkAccessManagerFactory() const return d->networkAccessManagerFactory; } +QNetworkAccessManager *QmlEnginePrivate::createNetworkAccessManager(QObject *parent) const +{ + QMutexLocker locker(&mutex); + QNetworkAccessManager *nam; + if (networkAccessManagerFactory) { + nam = networkAccessManagerFactory->create(parent); + } else { + nam = new QNetworkAccessManager(parent); + } + + return nam; +} + QNetworkAccessManager *QmlEnginePrivate::getNetworkAccessManager() const { Q_Q(const QmlEngine); - - if (!networkAccessManager) { - if (networkAccessManagerFactory) { - networkAccessManager = networkAccessManagerFactory->create(const_cast<QmlEngine*>(q)); - } else { - networkAccessManager = new QNetworkAccessManager(const_cast<QmlEngine*>(q)); - } - } + if (!networkAccessManager) + networkAccessManager = createNetworkAccessManager(const_cast<QmlEngine*>(q)); return networkAccessManager; } @@ -470,6 +488,69 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const } /*! + Sets the \a provider to use for images requested via the \e image: url + scheme, with host \a providerId. + + QmlImageProvider allows images to be provided to QML asynchronously. + The image request will be run in a low priority thread. This allows + potentially costly image loading to be done in the background, without + affecting the performance of the UI. + + Note that images loaded from a QmlImageProvider are cached by + QPixmapCache, similar to any image loaded by QML. + + The QmlEngine assumes ownership of the provider. + + This example creates a provider with id \e colors: + + \snippet examples/declarative/imageprovider/main.cpp 0 + + \snippet examples/declarative/imageprovider/view.qml 0 + + \sa removeImageProvider() +*/ +void QmlEngine::addImageProvider(const QString &providerId, QmlImageProvider *provider) +{ + Q_D(QmlEngine); + QMutexLocker locker(&d->mutex); + d->imageProviders.insert(providerId, provider); +} + +/*! + Returns the QmlImageProvider set for \a providerId. +*/ +QmlImageProvider *QmlEngine::imageProvider(const QString &providerId) const +{ + Q_D(const QmlEngine); + QMutexLocker locker(&d->mutex); + return d->imageProviders.value(providerId); +} + +/*! + Removes the QmlImageProvider for \a providerId. + + Returns the provider if it was found; otherwise returns 0. + + \sa addImageProvider() +*/ +void QmlEngine::removeImageProvider(const QString &providerId) +{ + Q_D(QmlEngine); + QMutexLocker locker(&d->mutex); + delete d->imageProviders.take(providerId); +} + +QImage QmlEnginePrivate::getImageFromProvider(const QUrl &url) +{ + QMutexLocker locker(&mutex); + QImage image; + QmlImageProvider *provider = imageProviders.value(url.host()); + if (provider) + image = provider->request(url.path().mid(1)); + return image; +} + +/*! Return the base URL for this engine. The base URL is only used to resolve components when a relative URL is passed to the QmlComponent constructor. diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 7ee014a..a59a1ba 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -62,6 +62,7 @@ class QmlType; class QUrl; class QScriptEngine; class QScriptContext; +class QmlImageProvider; class QNetworkAccessManager; class QmlNetworkAccessManagerFactory; class Q_DECLARATIVE_EXPORT QmlEngine : public QObject @@ -83,6 +84,10 @@ public: QNetworkAccessManager *networkAccessManager() const; + void addImageProvider(const QString &id, QmlImageProvider *); + QmlImageProvider *imageProvider(const QString &id) const; + void removeImageProvider(const QString &id); + void setOfflineStoragePath(const QString& dir); QString offlineStoragePath() const; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 13ed5ef..5586311 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -75,6 +75,7 @@ #include <QtCore/qlist.h> #include <QtCore/qpair.h> #include <QtCore/qstack.h> +#include <QtCore/qmutex.h> #include <QtScript/qscriptengine.h> #include <private/qobject_p.h> @@ -211,10 +212,16 @@ public: bool inBeginCreate; + QNetworkAccessManager *createNetworkAccessManager(QObject *parent) const; QNetworkAccessManager *getNetworkAccessManager() const; mutable QNetworkAccessManager *networkAccessManager; mutable QmlNetworkAccessManagerFactory *networkAccessManagerFactory; + QHash<QString,QmlImageProvider*> imageProviders; + QImage getImageFromProvider(const QUrl &url); + + mutable QMutex mutex; + QmlCompositeTypeManager typeManager; QStringList fileImportPath; QString offlineStoragePath; @@ -309,6 +316,7 @@ public: static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); } static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } + static QmlEnginePrivate *get(QmlContext *c) { return (c && c->engine()) ? QmlEnginePrivate::get(c->engine()) : 0; } static QmlEnginePrivate *get(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p; } static QmlEngine *get(QmlEnginePrivate *p) { return p->q_func(); } QmlContext *getContext(QScriptContext *); diff --git a/src/declarative/qml/qmlguard_p.h b/src/declarative/qml/qmlguard_p.h index 1e55bcb..ad8dd84 100644 --- a/src/declarative/qml/qmlguard_p.h +++ b/src/declarative/qml/qmlguard_p.h @@ -94,10 +94,10 @@ private: inline void remGuard(); }; -Q_DECLARE_METATYPE(QmlGuard<QObject>); - QT_END_NAMESPACE +Q_DECLARE_METATYPE(QmlGuard<QObject>); + #include "qmldeclarativedata_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qmlimageprovider.cpp b/src/declarative/qml/qmlimageprovider.cpp new file mode 100644 index 0000000..ebb8656 --- /dev/null +++ b/src/declarative/qml/qmlimageprovider.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlimageprovider.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QmlImageProvider + \brief The QmlImageProvider class provides an interface for threaded image requests. + + Note: the request() method may be called by multiple threads, so ensure the + implementation of this method is reentrant. + + \sa QmlEngine::addImageProvider() +*/ +QmlImageProvider::~QmlImageProvider() +{ +} + +/*! + \fn QImage QmlImageProvider::request(const QString &id) + + Implement this method to return the image with \a id. + + Note: this method may be called by multiple threads, so ensure the + implementation of this method is reentrant. +*/ + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlimageprovider.h b/src/declarative/qml/qmlimageprovider.h new file mode 100644 index 0000000..9804815 --- /dev/null +++ b/src/declarative/qml/qmlimageprovider.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLIMAGEPROVIDER_H +#define QMLIMAGEPROVIDER_H + +#include <QtGui/qimage.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlImageProvider +{ +public: + virtual ~QmlImageProvider(); + virtual QImage request(const QString &id) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLIMAGEPROVIDER diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index f23a50a..70f9ad3 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -276,7 +276,7 @@ const char *QmlMetaProperty::propertyTypeName() const { if (type() & ValueTypeProperty) { - QmlEnginePrivate *ep = d->context?QmlEnginePrivate::get(d->context->engine()):0; + QmlEnginePrivate *ep = QmlEnginePrivate::get(d->context); QmlValueType *valueType = 0; if (ep) valueType = ep->valueTypes[d->core.propType]; else valueType = QmlValueTypeFactory::valueType(d->core.propType); @@ -689,7 +689,7 @@ QVariant QmlMetaPropertyPrivate::readValueProperty() } else if(type & QmlMetaProperty::ValueTypeProperty) { - QmlEnginePrivate *ep = context?QmlEnginePrivate::get(context->engine()):0; + QmlEnginePrivate *ep = QmlEnginePrivate::get(context); QmlValueType *valueType = 0; if (ep) valueType = ep->valueTypes[core.propType]; else valueType = QmlValueTypeFactory::valueType(core.propType); @@ -754,14 +754,15 @@ bool QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value, QmlMetaProperty::WriteFlags flags) { // Remove any existing bindings on this property - if (!(flags & QmlMetaProperty::DontRemoveBinding)) - delete q->setBinding(0); + if (!(flags & QmlMetaProperty::DontRemoveBinding)) { + QmlAbstractBinding *binding = q->setBinding(0); + if (binding) binding->destroy(); + } bool rv = false; uint type = q->type(); if (type & QmlMetaProperty::ValueTypeProperty) { - QmlEnginePrivate *ep = - context?static_cast<QmlEnginePrivate *>(QObjectPrivate::get(context->engine())):0; + QmlEnginePrivate *ep = QmlEnginePrivate::get(context); QmlValueType *writeBack = 0; if (ep) { diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index e66f600..7dfc48d 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -840,6 +840,8 @@ QList<QmlType*> QmlMetaType::qmlTypes() return data->nameToType.values(); } +QT_END_NAMESPACE + #include <QtGui/qfont.h> #include <QtGui/qpixmap.h> #include <QtGui/qbrush.h> @@ -867,6 +869,7 @@ QList<QmlType*> QmlMetaType::qmlTypes() Q_DECLARE_METATYPE(QScriptValue); +QT_BEGIN_NAMESPACE /*! Copies \a copy into \a data, assuming they both are of type \a type. If \a copy is zero, a default type is copied. Returns true if the copy was diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 04cffe1..a0a7cea 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -45,10 +45,10 @@ #include "qmlbinding.h" #include "qdebug.h" -QT_BEGIN_NAMESPACE - Q_DECLARE_METATYPE(QScriptValue); +QT_BEGIN_NAMESPACE + void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) { propType = p.userType(); diff --git a/src/declarative/qml/qmlscriptstring.h b/src/declarative/qml/qmlscriptstring.h index 73a473f..d07137e 100644 --- a/src/declarative/qml/qmlscriptstring.h +++ b/src/declarative/qml/qmlscriptstring.h @@ -77,10 +77,10 @@ private: QSharedDataPointer<QmlScriptStringPrivate> d; }; -Q_DECLARE_METATYPE(QmlScriptString); - QT_END_NAMESPACE +Q_DECLARE_METATYPE(QmlScriptString); + QT_END_HEADER #endif // QMLSCRIPTSTRING_H diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index 684caa2..9c951fc 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -65,6 +65,8 @@ Q_DECLARE_METATYPE(QSqlDatabase) Q_DECLARE_METATYPE(QSqlQuery) +QT_BEGIN_NAMESPACE + class QmlSqlQueryScriptClass: public QScriptClass { public: QmlSqlQueryScriptClass(QScriptEngine *engine) : QScriptClass(engine) @@ -423,3 +425,4 @@ We add a "forwardOnly" property that stops Qt caching results (code promises to through the data. */ +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlsqldatabase_p.h b/src/declarative/qml/qmlsqldatabase_p.h index 5a38bf0..9965a2b 100644 --- a/src/declarative/qml/qmlsqldatabase_p.h +++ b/src/declarative/qml/qmlsqldatabase_p.h @@ -42,6 +42,7 @@ #ifndef QMLSQLDATABASE_P_H #define QMLSQLDATABASE_P_H +#include <QtScript/qscriptengine.h> // // W A R N I N G // ------------- @@ -52,9 +53,12 @@ // // We mean it. // +QT_BEGIN_NAMESPACE class QScriptEngine; void qt_add_qmlsqldatabase(QScriptEngine *engine); +QT_END_NAMESPACE + #endif // QMLSQLDATABASE_P_H diff --git a/src/declarative/qml/qmlstringconverters_p.h b/src/declarative/qml/qmlstringconverters_p.h index dfc59ce..46b2de6 100644 --- a/src/declarative/qml/qmlstringconverters_p.h +++ b/src/declarative/qml/qmlstringconverters_p.h @@ -56,6 +56,8 @@ #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> +QT_BEGIN_NAMESPACE + class QColor; class QPointF; class QSizeF; @@ -64,8 +66,6 @@ class QString; class QByteArray; class QVector3D; -QT_BEGIN_NAMESPACE - // XXX - Bauhaus currently uses these methods which is why they're exported namespace QmlStringConverters { diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp index 5e39eaf..ec790ca 100644 --- a/src/declarative/qml/qmlworkerscript.cpp +++ b/src/declarative/qml/qmlworkerscript.cpp @@ -55,6 +55,7 @@ #include <QtDeclarative/qmlinfo.h> #include "qmlnetworkaccessmanagerfactory.h" + QT_BEGIN_NAMESPACE class WorkerDataEvent : public QEvent @@ -238,8 +239,13 @@ private: QAtomicInt m_ref; QmlWorkerListModel *m_model; }; + +QT_END_NAMESPACE + Q_DECLARE_METATYPE(QmlWorkerListModelAgent::VariantRef); +QT_BEGIN_NAMESPACE + QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate(QmlEngine *engine) : workerEngine(0), qmlengine(engine), m_nextId(0) { @@ -1030,8 +1036,10 @@ QVariant QmlWorkerListModel::data(int index, int role) const return m_values.at(index).value(role); } +QT_END_NAMESPACE + QML_DEFINE_TYPE(Qt,4,6,WorkerListModel,QmlWorkerListModel) #include "qmlworkerscript.moc" -QT_END_NAMESPACE + diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 1883d1b..54e26df 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -91,7 +91,7 @@ #define D(arg) (arg)->release() #define A(arg) (arg)->addref() -namespace { +QT_BEGIN_NAMESPACE class DocumentImpl; class NodeImpl @@ -315,12 +315,14 @@ public: static QScriptValue load(QScriptEngine *engine, const QString &data); }; -}; // namespace +QT_END_NAMESPACE Q_DECLARE_METATYPE(Node); Q_DECLARE_METATYPE(NodeList); Q_DECLARE_METATYPE(NamedNodeMap); +QT_BEGIN_NAMESPACE + void NodeImpl::addref() { A(document); @@ -1624,4 +1626,6 @@ void qt_add_qmlxmlhttprequest(QScriptEngine *engine) engine->globalObject().setProperty(QLatin1String("DOMException"), domExceptionPrototype); } +QT_END_NAMESPACE + #include <qmlxmlhttprequest.moc> diff --git a/src/declarative/qml/qmlxmlhttprequest_p.h b/src/declarative/qml/qmlxmlhttprequest_p.h index dfed5d2..3a81278 100644 --- a/src/declarative/qml/qmlxmlhttprequest_p.h +++ b/src/declarative/qml/qmlxmlhttprequest_p.h @@ -42,6 +42,7 @@ #ifndef QMLXMLHTTPREQUEST_P_H #define QMLXMLHTTPREQUEST_P_H +#include <QtScript/qscriptengine.h> // // W A R N I N G // ------------- @@ -52,9 +53,12 @@ // // We mean it. // +QT_BEGIN_NAMESPACE class QScriptEngine; void qt_add_qmlxmlhttprequest(QScriptEngine *engine); +QT_END_NAMESPACE + #endif // QMLXMLHTTPREQUEST_P_H |