diff options
Diffstat (limited to 'src/declarative/qml')
18 files changed, 254 insertions, 156 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index fcaaece..65a6af2 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -103,7 +103,7 @@ Lexer::Lexer(Engine *eng, bool tokenizeComments) prohibitAutomaticSemicolon(false), tokenizeComments(tokenizeComments) { - driver->setLexer(this); + if (driver) driver->setLexer(this); // allocate space for read buffers buffer8 = new char[size8]; buffer16 = new QChar[size16]; @@ -677,9 +677,9 @@ int Lexer::lex() setDone(Other); } else state = Start; - driver->addComment(startpos, tokenLength(), startlineno, startcolumn); + if (driver) driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (current == 0) { - driver->addComment(startpos, tokenLength(), startlineno, startcolumn); + if (driver) driver->addComment(startpos, tokenLength(), startlineno, startcolumn); setDone(Eof); } @@ -689,14 +689,14 @@ int Lexer::lex() setDone(Bad); err = UnclosedComment; errmsg = QCoreApplication::translate("QDeclarativeParser", "Unclosed comment at end of file"); - driver->addComment(startpos, tokenLength(), startlineno, startcolumn); + if (driver) driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (isLineTerminator()) { shiftWindowsLineBreak(); yylineno++; } else if (current == '*' && next1 == '/') { state = Start; shift(1); - driver->addComment(startpos, tokenLength(), startlineno, startcolumn); + if (driver) driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } break; diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index 53ff51c..c6b64ae 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -116,7 +116,7 @@ int qmlRegisterType() 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } int qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message); @@ -151,7 +151,7 @@ int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMin 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } template<typename T> @@ -184,7 +184,7 @@ int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const c 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } template<typename T, typename E> @@ -217,7 +217,7 @@ int qmlRegisterExtendedType() 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } template<typename T, typename E> @@ -258,7 +258,7 @@ int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } template<typename T> @@ -278,7 +278,7 @@ int qmlRegisterInterface(const char *typeName) qobject_interface_iid<T *>() }; - return QDeclarativePrivate::registerType(interface); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::InterfaceRegistration, &interface); } template<typename T> @@ -312,7 +312,7 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, parser }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } class QDeclarativeContext; diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 23307c9..febcdef 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -240,7 +240,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: color expected")); } break; -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING case QVariant::Date: { bool ok; @@ -262,7 +262,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: datetime expected")); } break; -#endif // QT_NO_TEXTDATE +#endif // QT_NO_DATESTRING case QVariant::Point: case QVariant::PointF: { @@ -416,7 +416,7 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, instr.storeColor.value = c.rgba(); } break; -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING case QVariant::Date: { QDate d = QDeclarativeStringConverters::dateFromString(string); @@ -450,7 +450,7 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, instr.storeDateTime.valueIndex = index; } break; -#endif // QT_NO_TEXTDATE +#endif // QT_NO_DATESTRING case QVariant::Point: case QVariant::PointF: { diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 36c4b49..7bc6184 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -119,6 +119,8 @@ class QByteArray; \qml Item { + width: 100; height: 100 + Component { id: redSquare @@ -146,7 +148,7 @@ class QByteArray; to specify how each list item is to be displayed. Component objects can also be dynamically generated using - \l{Qt::createComponent}{Qt.createComponent()}. + \l{Qt::createComponent()}{Qt.createComponent()}. */ /*! diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 97ef99c..346a2f4 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -115,22 +115,55 @@ QT_BEGIN_NAMESPACE /*! \qmlclass QtObject QObject \since 4.7 - \brief The QtObject element is the most basic element in QML + \brief The QtObject element is the most basic element in QML. The QtObject element is a non-visual element which contains only the - objectName property. It is useful for when you need an extremely - lightweight element to place your own custom properties in. + objectName property. + + It can be useful to create a QtObject if you need an extremely + lightweight element to enclose a set of custom properties: + + \snippet doc/src/snippets/declarative/qtobject.qml 0 It can also be useful for C++ integration, as it is just a plain QObject. See the QObject documentation for further details. */ /*! - \qmlproperty string QtObject::objectName - This property allows you to give a name to this specific object instance. + \qmlproperty string QML:QtObject::objectName + This property holds the QObject::objectName for this specific object instance. + + This allows a C++ application to locate an item within a QML component + using the QObject::findChild() method. For example, the following C++ + application locates the child \l Rectangle item and dynamically changes its + \c color value: + + \qml + // MyRect.qml + + import Qt 4.7 + + Item { + width: 200; height: 200 + + Rectangle { + anchors.fill: parent + color: "red" + objectName: "myRect" + } + } + \endqml + + \code + // main.cpp - See \l{scripting.html#accessing-child-qobjects}{Accessing Child QObjects} - in the scripting documentation for details how objectName can be used from - scripts. + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("MyRect.qml")); + view.show(); + + QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect"); + if (item) + item->setProperty("color", QColor(Qt::yellow)); + \endcode */ struct StaticQtMetaObject : public QObject @@ -195,7 +228,7 @@ There are also string based constructors for these types. See \l{qdeclarativebas \section1 Date/Time Formatters -The Qt object contains several functions for formatting dates and times. +The Qt object contains several functions for formatting QDateTime, QDate and QTime values. \list \o \l{QML:Qt::formatDateTime}{string Qt.formatDateTime(datetime date, variant format)} @@ -237,8 +270,8 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) } /*! -\qmlmethod url Qt::resolvedUrl(url) -Returns \c url resolved relative to the URL of the caller. + \qmlmethod url Qt::resolvedUrl(url) + Returns \c url resolved relative to the URL of the caller. */ QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) { @@ -296,7 +329,7 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2)); } -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING //date/time formatting qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2)); qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2)); @@ -545,9 +578,9 @@ void QDeclarativeEngine::clearComponentCache() component instances should be added to sub-contexts parented to the root context. */ -QDeclarativeContext *QDeclarativeEngine::rootContext() +QDeclarativeContext *QDeclarativeEngine::rootContext() const { - Q_D(QDeclarativeEngine); + Q_D(const QDeclarativeEngine); return d->rootContext; } @@ -1080,18 +1113,23 @@ Here is an example. Notice it checks whether the component \l{Component::status} \c Component.Ready before calling \l {Component::createObject()}{createObject()} in case the QML file is loaded over a network and thus is not ready immediately. -\snippet doc/src/snippets/declarative/componentCreation.js 0 +\snippet doc/src/snippets/declarative/componentCreation.js vars +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js remote +\snippet doc/src/snippets/declarative/componentCreation.js func-end \codeline -\snippet doc/src/snippets/declarative/componentCreation.js 1 +\snippet doc/src/snippets/declarative/componentCreation.js finishCreation -If you are certain the files will be local, you could simplify to: +If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation() +function and call \l {Component::createObject()}{createObject()} immediately: -\snippet doc/src/snippets/declarative/componentCreation.js 2 +\snippet doc/src/snippets/declarative/componentCreation.js func +\snippet doc/src/snippets/declarative/componentCreation.js local +\snippet doc/src/snippets/declarative/componentCreation.js func-end To create a QML object from an arbitrary string of QML (instead of a file), use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}. - -\sa {Dynamic Object Management} */ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine) @@ -1139,8 +1177,6 @@ Each object in this array has the members \c lineNumber, \c columnNumber, \c fil Note that this function returns immediately, and therefore may not work if the \a qml string loads new components (that is, external QML files that have not yet been loaded). If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead. - -\sa {Dynamic Object Management} */ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine) @@ -1265,7 +1301,7 @@ QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEn \qmlmethod string Qt::formatDate(datetime date, variant format) Returns the string representation of \c date, formatted according to \c format. */ -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) { int argCount = ctxt->argumentCount(); @@ -1406,7 +1442,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr } return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); } -#endif // QT_NO_TEXTDATE +#endif // QT_NO_DATESTRING /*! \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha) diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h index 01487f5..d971d80 100644 --- a/src/declarative/qml/qdeclarativeengine.h +++ b/src/declarative/qml/qdeclarativeengine.h @@ -74,7 +74,7 @@ public: QDeclarativeEngine(QObject *p = 0); virtual ~QDeclarativeEngine(); - QDeclarativeContext *rootContext(); + QDeclarativeContext *rootContext() const; void clearComponentCache(); diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index a5c8c38..3b5dd5a 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -304,7 +304,7 @@ public: static QScriptValue consoleLog(QScriptContext*, QScriptEngine*); static QScriptValue quit(QScriptContext*, QScriptEngine*); -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING static QScriptValue formatDate(QScriptContext*, QScriptEngine*); static QScriptValue formatTime(QScriptContext*, QScriptEngine*); static QScriptValue formatDateTime(QScriptContext*, QScriptEngine*); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 001da46..1837366 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -485,24 +485,22 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, if (object && context) { + QDeclarativeProperty property(object, propertyName, context); if (isLiteralValue) { - QDeclarativeProperty literalProperty(object, propertyName, context); - literalProperty.write(expression); + property.write(expression); + } else if (hasValidSignal(object, propertyName)) { + QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); + QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + } else if (property.isProperty()) { + QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); + binding->setTarget(property); + binding->setNotifyOnValueChanged(true); + QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); + if (oldBinding) + oldBinding->destroy(); + binding->update(); } else { - if (hasValidSignal(object, propertyName)) { - QDeclarativeProperty property(object, propertyName); - QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); - QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); - } else { - QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); - QDeclarativeProperty property(object, propertyName); - binding->setTarget(property); - binding->setNotifyOnValueChanged(true); - QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); - if (oldBinding) - oldBinding->destroy(); - binding->update(); - } + qWarning() << "QDeclarativeEngineDebugServer::setBinding: unable to set property" << propertyName << "on object" << object; } } } diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp index 0660599..448fde2 100644 --- a/src/declarative/qml/qdeclarativeextensionplugin.cpp +++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp @@ -50,23 +50,76 @@ QT_BEGIN_NAMESPACE \ingroup plugins - QDeclarativeExtensionPlugin is a plugin interface that makes it - possible to offer extensions that can be loaded dynamically into - applications using the QDeclarativeEngine class. - - Writing a QML extension plugin is achieved by subclassing this - base class, reimplementing the pure virtual registerTypes() - function, and exporting the class using the Q_EXPORT_PLUGIN2() - macro. + QDeclarativeExtensionPlugin is a plugin interface that makes it possible to + create QML extensions that can be loaded dynamically into QML applications. + These extensions allow custom QML types to be made available to the QML engine. + + To write a QML extension plugin: + + \list + \o Subclass QDeclarativeExtensionPlugin, implement registerTypes() method + to register types using qmlRegisterType(), and export the class using the Q_EXPORT_PLUGIN2() macro + \o Write an appropriate project file for the plugin + \o Create a \l{The qmldir file}{qmldir file} to describe the plugin + \endlist QML extension plugins can be used to provide either application-specific or library-like plugins. Library plugins should limit themselves to registering types, as any manipulation of the engine's root context may cause conflicts or other issues in the library user's code. - See \l {Tutorial: Writing QML extensions with C++} for details on creating - QML extensions, including how to build a plugin with with QDeclarativeExtensionPlugin. - For a simple overview, see the \l{declarative/cppextensions/plugins}{plugins} example. + + \section1 An example + + Suppose there is a new \c TimeModel C++ class that should be made available + as a new QML element. It provides the current time through \c hour and \c minute + properties, like this: + + \snippet examples/declarative/cppextensions/plugins/plugin.cpp 0 + \dots + + To make this class available as a QML type, create a plugin that registers + this type using qmlRegisterType(). For this example the plugin + module will be named \c com.nokia.TimeExample (as defined in the project + file further below). + + \snippet examples/declarative/cppextensions/plugins/plugin.cpp plugin + \codeline + \snippet examples/declarative/cppextensions/plugins/plugin.cpp export + + This registers the \c TimeModel class with the 1.0 version of this + plugin library, as a QML type called \c Time. The Q_ASSERT statement + ensures the module is imported correctly by any QML components that use this plugin. + + The project file defines the project as a plugin library and specifies + it should be built into the \c com/nokia/TimeExample directory: + + \code + TEMPLATE = lib + CONFIG += qt plugin + QT += declarative + + DESTDIR = com/nokia/TimeExample + TARGET = qmlqtimeexampleplugin + ... + \endcode + + Finally, a \l{The qmldir file}{qmldir file} is required in the \c com/nokia/TimeExample directory + that describes the plugin. This directory includes a \c Clock.qml file that + should be bundled with the plugin, so it needs to be specified in the \c qmldir + file: + + \quotefile examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir + + Once the project is built and installed, the new \c Time element can be + used by any QML component that imports the \c com.nokia.TimeExample module: + + \snippet examples/declarative/cppextensions/plugins/plugins.qml 0 + + The full source code is available in the \l {declarative/cppextensions/plugins}{plugins example}. + + The \l {Tutorial: Writing QML extensions with C++} also contains a chapter + on creating QML plugins. \sa QDeclarativeEngine::importPlugin(), {How to Create Qt Plugins} */ @@ -95,7 +148,7 @@ QDeclarativeExtensionPlugin::QDeclarativeExtensionPlugin(QObject *parent) } /*! - Destroys the plugin. + \internal */ QDeclarativeExtensionPlugin::~QDeclarativeExtensionPlugin() { diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp index a294c38..241df87 100644 --- a/src/declarative/qml/qdeclarativeimageprovider.cpp +++ b/src/declarative/qml/qdeclarativeimageprovider.cpp @@ -212,9 +212,6 @@ QImage QDeclarativeImageProvider::requestImage(const QString &id, QSize *size, c In all cases, \a size must be set to the original size of the image. This is used to set the \l {Item::}{width} and \l {Item::}{height} of image elements that should be automatically sized to the loaded image. - - \note this method may be called by multiple threads, so ensure the - implementation of this method is reentrant. */ QPixmap QDeclarativeImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) { diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp index 7c89672..9598d98 100644 --- a/src/declarative/qml/qdeclarativelist.cpp +++ b/src/declarative/qml/qdeclarativelist.cpp @@ -306,7 +306,7 @@ int QDeclarativeListReference::count() const /*! \class QDeclarativeListProperty \since 4.7 -\brief The QDeclarativeListProperty class allows applications to explose list-like +\brief The QDeclarativeListProperty class allows applications to expose list-like properties to QML. QML has many list properties, where more than one object value can be assigned. diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 153e2be..a5c878f 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include <QtDeclarative/qdeclarativeprivate.h> #include "private/qdeclarativemetatype_p.h" #include "private/qdeclarativeproxymetaobject_p.h" @@ -485,17 +486,17 @@ int QDeclarativeType::index() const return d->m_index; } -int QDeclarativePrivate::registerAutoParentFunction(AutoParentFunction function) +int registerAutoParentFunction(QDeclarativePrivate::RegisterAutoParent &autoparent) { QWriteLocker lock(metaTypeDataLock()); QDeclarativeMetaTypeData *data = metaTypeData(); - data->parentFunctions.append(function); + data->parentFunctions.append(autoparent.function); return data->parentFunctions.count() - 1; } -int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &interface) +int registerInterface(const QDeclarativePrivate::RegisterInterface &interface) { if (interface.version > 0) qFatal("qmlRegisterType(): Cannot mix incompatible QML versions."); @@ -524,7 +525,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterfa return index; } -int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &type) +int registerType(const QDeclarativePrivate::RegisterType &type) { if (type.elementName) { for (int ii = 0; type.elementName[ii]; ++ii) { @@ -576,6 +577,22 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t } /* +This method is "over generalized" to allow us to (potentially) register more types of things in +the future without adding exported symbols. +*/ +int QDeclarativePrivate::qmlregister(RegistrationType type, void *data) +{ + if (type == TypeRegistration) { + return registerType(*reinterpret_cast<RegisterType *>(data)); + } else if (type == InterfaceRegistration) { + return registerInterface(*reinterpret_cast<RegisterInterface *>(data)); + } else if (type == AutoParentRegistration) { + return registerAutoParentFunction(*reinterpret_cast<RegisterAutoParent *>(data)); + } + return -1; +} + +/* Have any types been registered for \a module with at least versionMajor.versionMinor, and types for \a module with at most versionMajor.versionMinor. diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index 4c98b6f..f410547 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -63,6 +63,8 @@ QT_BEGIN_NAMESPACE class QDeclarativeType; class QDeclarativeCustomParser; +class QDeclarativeTypePrivate; + class Q_DECLARATIVE_EXPORT QDeclarativeMetaType { public: @@ -103,7 +105,6 @@ public: static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions(); }; -class QDeclarativeTypePrivate; class Q_DECLARATIVE_EXPORT QDeclarativeType { public: @@ -144,11 +145,12 @@ public: int propertyValueInterceptorCast() const; int index() const; + private: friend class QDeclarativeTypePrivate; friend struct QDeclarativeMetaTypeData; - friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &); - friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &); + friend int registerType(const QDeclarativePrivate::RegisterType &); + friend int registerInterface(const QDeclarativePrivate::RegisterInterface &); QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &); QDeclarativeType(int, const QDeclarativePrivate::RegisterType &); ~QDeclarativeType(); diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h index cd859fe..b2d7451 100644 --- a/src/declarative/qml/qdeclarativeprivate.h +++ b/src/declarative/qml/qdeclarativeprivate.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEPRIVATE_H #define QDECLARATIVEPRIVATE_H +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> #ifndef Q_OS_WIN @@ -177,6 +188,9 @@ namespace QDeclarativePrivate return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject(); } + enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent }; + typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent); + struct RegisterType { int version; @@ -214,13 +228,19 @@ namespace QDeclarativePrivate const char *iid; }; - enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent }; - typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent); + struct RegisterAutoParent { + int version; - int Q_DECLARATIVE_EXPORT registerAutoParentFunction(AutoParentFunction); - int Q_DECLARATIVE_EXPORT registerType(const RegisterType &); - int Q_DECLARATIVE_EXPORT registerType(const RegisterInterface &); + AutoParentFunction function; + }; + + enum RegistrationType { + TypeRegistration = 0, + InterfaceRegistration = 1, + AutoParentRegistration = 2 + }; + int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index 219d759..4d98ca8 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -896,6 +896,14 @@ QList<QDeclarativeError> QDeclarativeScriptParser::errors() const return _errors; } +static void replaceWithSpace(QString &str, int idx, int n) +{ + QChar *data = str.data() + idx; + QChar space(' '); + for (int ii = 0; ii < n; ++ii) + *data++ = space; +} + /* Searches for ".pragma <value>" declarations within \a script. Currently supported pragmas are: @@ -905,83 +913,48 @@ QDeclarativeParser::Object::ScriptBlock::Pragmas QDeclarativeScriptParser::extra { QDeclarativeParser::Object::ScriptBlock::Pragmas rv = QDeclarativeParser::Object::ScriptBlock::None; - const QChar forwardSlash(QLatin1Char('/')); - const QChar star(QLatin1Char('*')); - const QChar newline(QLatin1Char('\n')); - const QChar dot(QLatin1Char('.')); - const QChar semicolon(QLatin1Char(';')); - const QChar space(QLatin1Char(' ')); - const QString pragma(QLatin1String(".pragma ")); - - const QChar *pragmaData = pragma.constData(); - - const QChar *data = script.constData(); - const int length = script.count(); - for (int ii = 0; ii < length; ++ii) { - const QChar &c = data[ii]; - - if (c.isSpace()) - continue; - - if (c == forwardSlash) { - ++ii; - if (ii >= length) - return rv; - - const QChar &c = data[ii]; - if (c == forwardSlash) { - // Find next newline - while (ii < length && data[++ii] != newline) {}; - } else if (c == star) { - // Find next star - while (true) { - while (ii < length && data[++ii] != star) {}; - if (ii + 1 >= length) - return rv; - - if (data[ii + 1] == forwardSlash) { - ++ii; - break; - } - } - } else { - return rv; - } - } else if (c == dot) { - // Could be a pragma! - if (ii + pragma.length() >= length || - 0 != ::memcmp(data + ii, pragmaData, sizeof(QChar) * pragma.length())) - return rv; + const QString pragma(QLatin1String("pragma")); + const QString library(QLatin1String("library")); - int pragmaStatementIdx = ii; + QDeclarativeJS::Lexer l(0); + l.setCode(script, 0); - ii += pragma.length(); + int token = l.lex(); - while (ii < length && data[ii].isSpace()) { ++ii; } + while (true) { + if (token != QDeclarativeJSGrammar::T_DOT) + return rv; - int startIdx = ii; + int startOffset = l.tokenOffset(); + int startLine = l.currentLineNo(); - while (ii < length && data[ii].isLetter()) { ++ii; } + token = l.lex(); - int endIdx = ii; + if (token != QDeclarativeJSGrammar::T_IDENTIFIER || + l.currentLineNo() != startLine || + script.mid(l.tokenOffset(), l.tokenLength()) != pragma) + return rv; - if (ii != length && data[ii] != forwardSlash && !data[ii].isSpace() && data[ii] != semicolon) - return rv; + token = l.lex(); - QString p(data + startIdx, endIdx - startIdx); + if (token != QDeclarativeJSGrammar::T_IDENTIFIER || + l.currentLineNo() != startLine) + return rv; - if (p == QLatin1String("library")) - rv |= QDeclarativeParser::Object::ScriptBlock::Shared; - else - return rv; + QString pragmaValue = script.mid(l.tokenOffset(), l.tokenLength()); + int endOffset = l.tokenLength() + l.tokenOffset(); - for (int jj = pragmaStatementIdx; jj < endIdx; ++jj) script[jj] = space; + token = l.lex(); + if (l.currentLineNo() == startLine) + return rv; + if (pragmaValue == QLatin1String("library")) { + rv |= QDeclarativeParser::Object::ScriptBlock::Shared; + replaceWithSpace(script, startOffset, endOffset - startOffset); } else { return rv; } } - return rv; } diff --git a/src/declarative/qml/qdeclarativestringconverters.cpp b/src/declarative/qml/qdeclarativestringconverters.cpp index 8bd2cf1..7534a2c 100644 --- a/src/declarative/qml/qdeclarativestringconverters.cpp +++ b/src/declarative/qml/qdeclarativestringconverters.cpp @@ -106,14 +106,14 @@ QVariant QDeclarativeStringConverters::variantFromString(const QString &s, int p return QVariant(uint(qRound(s.toDouble(ok)))); case QMetaType::QColor: return QVariant::fromValue(colorFromString(s, ok)); -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING case QMetaType::QDate: return QVariant::fromValue(dateFromString(s, ok)); case QMetaType::QTime: return QVariant::fromValue(timeFromString(s, ok)); case QMetaType::QDateTime: return QVariant::fromValue(dateTimeFromString(s, ok)); -#endif // QT_NO_TEXTDATE +#endif // QT_NO_DATESTRING case QMetaType::QPointF: return QVariant::fromValue(pointFFromString(s, ok)); case QMetaType::QPoint: @@ -152,7 +152,7 @@ QColor QDeclarativeStringConverters::colorFromString(const QString &s, bool *ok) } } -#ifndef QT_NO_TEXTDATE +#ifndef QT_NO_DATESTRING QDate QDeclarativeStringConverters::dateFromString(const QString &s, bool *ok) { QDate d = QDate::fromString(s, Qt::ISODate); @@ -173,7 +173,7 @@ QDateTime QDeclarativeStringConverters::dateTimeFromString(const QString &s, boo if (ok) *ok = d.isValid(); return d; } -#endif // QT_NO_TEXTDATE +#endif // QT_NO_DATESTRING //expects input of "x,y" QPointF QDeclarativeStringConverters::pointFFromString(const QString &s, bool *ok) diff --git a/src/declarative/qml/qdeclarativestringconverters_p.h b/src/declarative/qml/qdeclarativestringconverters_p.h index 842d1b3..e6b0abe 100644 --- a/src/declarative/qml/qdeclarativestringconverters_p.h +++ b/src/declarative/qml/qdeclarativestringconverters_p.h @@ -73,7 +73,7 @@ namespace QDeclarativeStringConverters QVariant Q_DECLARATIVE_EXPORT variantFromString(const QString &, int preferredType, bool *ok = 0); QColor Q_DECLARATIVE_EXPORT colorFromString(const QString &, bool *ok = 0); -#ifndef QT_NO_TEXTDATE +#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); diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index c17ec95..98e9a58 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -74,7 +74,7 @@ int qmlRegisterValueTypeEnums(const char *qmlName) 0 }; - return QDeclarativePrivate::registerType(type); + return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); } QDeclarativeValueTypeFactory::QDeclarativeValueTypeFactory() @@ -973,7 +973,7 @@ qreal QDeclarativeFontValueType::letterSpacing() const void QDeclarativeFontValueType::setLetterSpacing(qreal size) { - font.setLetterSpacing(QFont::PercentageSpacing, size); + font.setLetterSpacing(QFont::AbsoluteSpacing, size); } qreal QDeclarativeFontValueType::wordSpacing() const |