From dd901eae47dee9305cff3330d28f79f0fbc3e9f8 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 14:10:54 +0100 Subject: Introduced the internal virtual method QmlView::setRootObject(object). Done-with: mae --- src/declarative/util/qmlview.cpp | 96 ++++++++++++++++++++++------------------ src/declarative/util/qmlview.h | 3 +- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 4a6d697..a906554 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -429,52 +429,60 @@ void QmlView::continueExecute() return; } - if (obj) { - if (QmlGraphicsItem *item = qobject_cast(obj)) { - - d->scene.addItem(item); - - QPerformanceLog::displayData(); - QPerformanceLog::clear(); - d->root = item; - d->qmlRoot = item; - connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); - connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); - if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) - d->initialSize.setWidth(d->qmlRoot->width()); - if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) - d->initialSize.setHeight(d->qmlRoot->height()); - resize(d->initialSize); - - if (d->resizeMode == SizeRootObjectToView) { - d->qmlRoot->setWidth(width()); - d->qmlRoot->setHeight(height()); - } else { - QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); - emit sceneResized(sz); - resize(sz); - } - updateGeometry(); - } else if (QGraphicsObject *item = qobject_cast(obj)) { - d->scene.addItem(item); - qWarning() << "QmlView::resizeMode is not honored for components of type QGraphicsObject"; - } else if (QWidget *wid = qobject_cast(obj)) { - window()->setAttribute(Qt::WA_OpaquePaintEvent, false); - window()->setAttribute(Qt::WA_NoSystemBackground, false); - if (!layout()) { - setLayout(new QVBoxLayout); - layout()->setContentsMargins(0, 0, 0, 0); - } else if (layout()->count()) { - // Hide the QGraphicsView in GV mode. - QLayoutItem *item = layout()->itemAt(0); - if (item->widget()) - item->widget()->hide(); - } - layout()->addWidget(wid); - emit sceneResized(wid->size()); + setRootObject(obj); + emit statusChanged(status()); +} + + +/*! + \internal +*/ +void QmlView::setRootObject(QObject *obj) +{ + Q_D(QmlView); + + if (QmlGraphicsItem *item = qobject_cast(obj)) { + d->scene.addItem(item); + + QPerformanceLog::displayData(); + QPerformanceLog::clear(); + d->root = item; + d->qmlRoot = item; + connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); + connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); + if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) + d->initialSize.setWidth(d->qmlRoot->width()); + if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) + d->initialSize.setHeight(d->qmlRoot->height()); + resize(d->initialSize); + + if (d->resizeMode == SizeRootObjectToView) { + d->qmlRoot->setWidth(width()); + d->qmlRoot->setHeight(height()); + } else { + QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); + emit sceneResized(sz); + resize(sz); } + updateGeometry(); + } else if (QGraphicsObject *item = qobject_cast(obj)) { + d->scene.addItem(item); + qWarning() << "QmlView::resizeMode is not honored for components of type QGraphicsObject"; + } else if (QWidget *wid = qobject_cast(obj)) { + window()->setAttribute(Qt::WA_OpaquePaintEvent, false); + window()->setAttribute(Qt::WA_NoSystemBackground, false); + if (!layout()) { + setLayout(new QVBoxLayout); + layout()->setContentsMargins(0, 0, 0, 0); + } else if (layout()->count()) { + // Hide the QGraphicsView in GV mode. + QLayoutItem *item = layout()->itemAt(0); + if (item->widget()) + item->widget()->hide(); + } + layout()->addWidget(wid); + emit sceneResized(wid->size()); } - emit statusChanged(status()); } /*! diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index 1c6d865..7c9a97b 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -102,7 +102,8 @@ private Q_SLOTS: protected: virtual void resizeEvent(QResizeEvent *); virtual void paintEvent(QPaintEvent *event); - void timerEvent(QTimerEvent*); + virtual void timerEvent(QTimerEvent*); + virtual void setRootObject(QObject *obj); }; QT_END_NAMESPACE -- cgit v0.12 From 94164f66a6f3272e63b2fe12f63fba91d16ab0f0 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 15:21:35 +0100 Subject: Introduced a new parser for qmldir files. --- src/declarative/qml/qml.pri | 6 +- src/declarative/qml/qmldirparser.cpp | 209 +++++++++++++++++++++++++++++++++++ src/declarative/qml/qmldirparser_p.h | 123 +++++++++++++++++++++ src/declarative/qml/qmlengine.cpp | 34 +++--- 4 files changed, 352 insertions(+), 20 deletions(-) create mode 100644 src/declarative/qml/qmldirparser.cpp create mode 100644 src/declarative/qml/qmldirparser_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index a8df61e..5e0c3e0 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -51,7 +51,8 @@ SOURCES += \ $$PWD/qmllistscriptclass.cpp \ $$PWD/qmlworkerscript.cpp \ $$PWD/qmlimageprovider.cpp \ - $$PWD/qmlnetworkaccessmanagerfactory.cpp + $$PWD/qmlnetworkaccessmanagerfactory.cpp \ + $$PWD/qmldirparser.cpp HEADERS += \ $$PWD/qmlparser_p.h \ $$PWD/qmlglobal_p.h \ @@ -119,7 +120,8 @@ HEADERS += \ $$PWD/qmlscriptclass_p.h \ $$PWD/qmlguard_p.h \ $$PWD/qmlimageprovider.h \ - $$PWD/qmlnetworkaccessmanagerfactory.h + $$PWD/qmlnetworkaccessmanagerfactory.h \ + $$PWD/qmldirparser_p.h QT += sql include(parser/parser.pri) include(rewriter/rewriter.pri) diff --git a/src/declarative/qml/qmldirparser.cpp b/src/declarative/qml/qmldirparser.cpp new file mode 100644 index 0000000..c7de233 --- /dev/null +++ b/src/declarative/qml/qmldirparser.cpp @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qmldirparser_p.h" +#include "qmlerror.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QmlDirParser::QmlDirParser() +{ +} + +QmlDirParser::~QmlDirParser() +{ +} + +QUrl QmlDirParser::url() const +{ + return _url; +} + +void QmlDirParser::setUrl(const QUrl &url) +{ + _url = url; +} + +QString QmlDirParser::source() const +{ + return _source; +} + +void QmlDirParser::setSource(const QString &source) +{ + _source = source; +} + +bool QmlDirParser::parse() +{ + _errors.clear(); + _plugins.clear(); + _components.clear(); + + QTextStream stream(&_source); + int lineNumber = 0; + + forever { + ++lineNumber; + + const QString line = stream.readLine(); + if (line.isNull()) + break; + + QString sections[3]; + int sectionCount = 0; + + int index = 0; + const int length = line.length(); + + while (index != length) { + const QChar ch = line.at(index); + + if (ch.isSpace()) { + do { ++index; } + while (index != length && line.at(index).isSpace()); + + } else if (ch == QLatin1Char('#')) { + // recognized a comment + break; + + } else { + const int start = index; + + do { ++index; } + while (index != length && !line.at(index).isSpace()); + + const QString lexeme = line.mid(start, index - start); + + if (sectionCount >= 3) { + reportError(lineNumber, start, QLatin1String("unexpected token")); + + } else { + sections[sectionCount++] = lexeme; + } + } + } + + if (sectionCount == 0) { + continue; // no sections, no party. + + } else if (sections[0] == QLatin1String("plugin")) { + if (sectionCount < 2) { + reportError(lineNumber, -1, + QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1)); + + continue; + } + + const Plugin entry(sections[1], sections[2]); + + _plugins.append(entry); + + } else if (sectionCount == 3) { + const QString &version = sections[1]; + const int dotIndex = version.indexOf(QLatin1Char('.')); + + if (dotIndex == -1) { + qWarning() << "expected '.'"; // ### use reportError + + } else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) { + qWarning() << "unexpected '.'"; // ### use reportError + + } else { + bool validVersionNumber = false; + const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber); + + if (validVersionNumber) { + const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber); + + if (validVersionNumber) { + const Component entry(sections[0], sections[2], majorVersion, minorVersion); + + _components.append(entry); + } + } + } + } else { + // ### use reportError + qWarning() << "a component declaration requires 3 arguments, but" << (sectionCount + 1) << "were provided"; + } + } + + return hasError(); +} + +void QmlDirParser::reportError(int line, int column, const QString &description) +{ + QmlError error; + error.setUrl(_url); + error.setLine(line); + error.setColumn(column); + error.setDescription(description); + _errors.append(error); +} + +bool QmlDirParser::hasError() const +{ + if (! _errors.isEmpty()) + return true; + + return false; +} + +QList QmlDirParser::errors() const +{ + return _errors; +} + +QList QmlDirParser::plugins() const +{ + return _plugins; +} + +QList QmlDirParser::components() const +{ + return _components; +} + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmldirparser_p.h b/src/declarative/qml/qmldirparser_p.h new file mode 100644 index 0000000..ff8b0f8 --- /dev/null +++ b/src/declarative/qml/qmldirparser_p.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 QMLDIRPARSER_P_H +#define QMLDIRPARSER_P_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 +#include + +QT_BEGIN_NAMESPACE + +class QmlError; + +class QmlDirParser +{ + Q_DISABLE_COPY(QmlDirParser) + +public: + QmlDirParser(); + ~QmlDirParser(); + + QUrl url() const; + void setUrl(const QUrl &url); + + QString source() const; + void setSource(const QString &source); + + bool parse(); + + bool hasError() const; + QList errors() const; + + struct Plugin + { + Plugin() {} + + Plugin(const QString &name, const QString &path) + : name(name), path(path) {} + + QString name; + QString path; + }; + + struct Component + { + Component() + : majorVersion(0), minorVersion(0) {} + + Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion) + : typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) {} + + QString typeName; + QString fileName; + int majorVersion; + int minorVersion; + }; + + QList components() const; + QList plugins() const; + +private: + void reportError(int line, int column, const QString &message); + +private: + QList _errors; + QUrl _url; + QString _source; + QList _components; + QList _plugins; +}; + +QT_END_NAMESPACE + +#endif // QMLDIRPARSER_P_H diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index cf26f58..6f26a07 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -66,6 +66,7 @@ #include "qmlscriptclass_p.h" #include "qmlnetworkaccessmanagerfactory.h" #include "qmlimageprovider.h" +#include "qmldirparser_p.h" #include @@ -1262,24 +1263,21 @@ struct QmlEnginePrivate::ImportedNamespace { qmldircontent = QString::fromUtf8(qmldir.readAll()); } } - QString typespace = QString::fromUtf8(type)+QLatin1Char(' '); - QStringList lines = qmldircontent.split(QLatin1Char('\n')); - foreach (QString line, lines) { - if (line.isEmpty() || line.at(0) == QLatin1Char('#')) - continue; - if (line.startsWith(typespace)) { - int space1 = line.indexOf(QLatin1Char(' ')); - int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; - QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-1:space2-space1-1); - int dot = mapversions.indexOf(QLatin1Char('.')); - int mapvmaj = mapversions.left(dot).toInt(); - if (mapvmaj<=vmaj) { - if (mapvmaj= mapversions.mid(dot+1).toInt()) { - QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-1); - if (url_return) - *url_return = url.resolved(QUrl(mapfile.toString())); - return true; - } + + const QString typespace = QString::fromUtf8(type); + + QmlDirParser qmldirParser; + qmldirParser.setUrl(url); + qmldirParser.setSource(qmldircontent); + qmldirParser.parse(); + + foreach (const QmlDirParser::Component &c, qmldirParser.components()) { // ### TODO: cache the components + if (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion)) { + if (c.typeName == typespace) { + if (url_return) + *url_return = url.resolved(QUrl(c.fileName)); + + return true; } } } -- cgit v0.12 From af9bee69a9d902cffb4b590012cba79328fd2a1b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 15:29:33 +0100 Subject: Added QmlExtensionPlugin and QmlExtensionInterface. --- src/declarative/qml/qml.pri | 9 +++++++-- src/declarative/qml/qmlextensioninterface.h | 25 +++++++++++++++++++++++ src/declarative/qml/qmlextensionplugin.cpp | 12 +++++++++++ src/declarative/qml/qmlextensionplugin.h | 31 +++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/declarative/qml/qmlextensioninterface.h create mode 100644 src/declarative/qml/qmlextensionplugin.cpp create mode 100644 src/declarative/qml/qmlextensionplugin.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 5e0c3e0..6c74863 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -52,7 +52,9 @@ SOURCES += \ $$PWD/qmlworkerscript.cpp \ $$PWD/qmlimageprovider.cpp \ $$PWD/qmlnetworkaccessmanagerfactory.cpp \ - $$PWD/qmldirparser.cpp + $$PWD/qmldirparser.cpp \ + $$PWD/qmlextensionplugin.cpp + HEADERS += \ $$PWD/qmlparser_p.h \ $$PWD/qmlglobal_p.h \ @@ -121,7 +123,10 @@ HEADERS += \ $$PWD/qmlguard_p.h \ $$PWD/qmlimageprovider.h \ $$PWD/qmlnetworkaccessmanagerfactory.h \ - $$PWD/qmldirparser_p.h + $$PWD/qmldirparser_p.h \ + $$PWD/qmlextensioninterface.h \ + $$PWD/qmlextensionplugin.h + QT += sql include(parser/parser.pri) include(rewriter/rewriter.pri) diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h new file mode 100644 index 0000000..d336e6e --- /dev/null +++ b/src/declarative/qml/qmlextensioninterface.h @@ -0,0 +1,25 @@ +#ifndef QMLEXTENSIONINTERFACE_H +#define QMLEXTENSIONINTERFACE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlEngine; + +struct Q_DECLARATIVE_EXPORT QmlExtensionInterface +{ + virtual void initialize(QmlEngine *engine) = 0; +}; + +Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLEXTENSIONINTERFACE_H diff --git a/src/declarative/qml/qmlextensionplugin.cpp b/src/declarative/qml/qmlextensionplugin.cpp new file mode 100644 index 0000000..15ad44e --- /dev/null +++ b/src/declarative/qml/qmlextensionplugin.cpp @@ -0,0 +1,12 @@ + +#include "qmlextensionplugin.h" + +QmlExtensionPlugin::QmlExtensionPlugin(QObject *parent) + : QObject(parent) +{ +} + +QmlExtensionPlugin::~QmlExtensionPlugin() +{ +} + diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h new file mode 100644 index 0000000..8f3194f --- /dev/null +++ b/src/declarative/qml/qmlextensionplugin.h @@ -0,0 +1,31 @@ +#ifndef QMLEXTENSIONPLUGIN_H +#define QMLEXTENSIONPLUGIN_H + +#include + +#include "qmlextensioninterface.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlEngine; + +class Q_DECLARATIVE_EXPORT QmlExtensionPlugin : public QObject, public QmlExtensionInterface +{ + Q_OBJECT + Q_INTERFACES(QmlExtensionInterface) +public: + explicit QmlExtensionPlugin(QObject *parent = 0); + ~QmlExtensionPlugin(); + + virtual void initialize(QmlEngine *engine) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLEXTENSIONPLUGIN_H -- cgit v0.12 From 3731e214baeb44434f12f773b1c68e772f25323e Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 18:16:36 +0100 Subject: Get rid of the unfriendly ImportedNamespace::isBuiltin flag. The `isBuiltin' flag doesn't play nice with hybrid apps where the types in a namespace are provided by both C++ and QML code. Done-with: mae --- src/declarative/qml/qmlengine.cpp | 43 +++++++++++++++------------------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6f26a07..7a60f9c 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1227,7 +1227,6 @@ struct QmlEnginePrivate::ImportedNamespace { QList majversions; QList minversions; QList isLibrary; - QList isBuiltin; // Types provided by C++ code (including plugins) QList qmlDirContent; bool find(const QByteArray& type, int *vmajor, int *vminor, QmlType** type_return, QUrl* url_return) const @@ -1236,23 +1235,22 @@ struct QmlEnginePrivate::ImportedNamespace { int vmaj = majversions.at(i); int vmin = minversions.at(i); - if (isBuiltin.at(i)) { - QByteArray qt = uris.at(i).toUtf8(); - qt += '/'; - qt += type; + QByteArray qt = uris.at(i).toUtf8(); + qt += '/'; + qt += type; + if (qmlImportTrace()) + qDebug() << "Look in" << qt; + QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); + if (vmajor) *vmajor = vmaj; + if (vminor) *vminor = vmin; + if (t) { if (qmlImportTrace()) - qDebug() << "Look in" << qt; - QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); - if (vmajor) *vmajor = vmaj; - if (vminor) *vminor = vmin; - if (t) { - if (qmlImportTrace()) - qDebug() << "Found" << qt; - if (type_return) - *type_return = t; - return true; - } + qDebug() << "Found" << qt; + if (type_return) + *type_return = t; + return true; } + QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml")); QString qmldircontent = qmlDirContent.at(i); if (vmaj>=0 || !qmldircontent.isEmpty()) { @@ -1321,7 +1319,6 @@ public: set.insert(prefix,(s=new QmlEnginePrivate::ImportedNamespace)); } QString url = uri; - bool isbuiltin = false; if (importType == QmlScriptParser::Import::Library) { url.replace(QLatin1Char('.'),QLatin1Char('/')); bool found = false; @@ -1334,16 +1331,11 @@ public: break; } } - if (!found) { - // XXX assume it is a built-in type qualifier - isbuiltin = true; - } QFactoryLoader *l = loader(); QmlModuleFactoryInterface *factory = qobject_cast(l->instance(uri)); if (factory) { factory->defineModuleOnce(uri); - isbuiltin = true; } } else { url = base.resolved(QUrl(url)).toString(); @@ -1353,7 +1345,6 @@ public: s->majversions.prepend(vmaj); s->minversions.prepend(vmin); s->isLibrary.prepend(importType == QmlScriptParser::Import::Library); - s->isBuiltin.prepend(isbuiltin); s->qmlDirContent.prepend(qmldircontent); return true; } @@ -1376,10 +1367,11 @@ public: if (s) { if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return)) return true; - if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) { + if (s->urls.count() == 1 && !s->isLibrary[0] && url_return) { *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); return true; } + } if (url_return) { *url_return = base.resolved(QUrl(QString::fromUtf8(type + ".qml"))); @@ -1440,9 +1432,6 @@ static QmlTypeNameCache *cacheForNamespace(QmlEngine *engine, const QmlEnginePri QList types = QmlMetaType::qmlTypes(); for (int ii = 0; ii < set.uris.count(); ++ii) { - if (!set.isBuiltin.at(ii)) - continue; - QByteArray base = set.uris.at(ii).toUtf8() + '/'; int major = set.majversions.at(ii); int minor = set.minversions.at(ii); -- cgit v0.12 From 80fc5bf17e5f049a395d6a5612843c69c5b0fde1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 12:21:06 +0100 Subject: Introduced QmlEngine::importExtension. importExtension can be used to import QmlExtensionInterface(s) into a QmlEngine. --- src/declarative/qml/qmlengine.cpp | 21 ++++++++++++++++++++- src/declarative/qml/qmlengine.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 7a60f9c..1f5caa5 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -67,7 +67,7 @@ #include "qmlnetworkaccessmanagerfactory.h" #include "qmlimageprovider.h" #include "qmldirparser_p.h" - +#include "qmlextensioninterface.h" #include #include @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -1530,6 +1531,24 @@ void QmlEngine::addImportPath(const QString& path) } /*! + Imports the given \a extension into this QmlEngine. Returns + true if the extension was successfully imported. + + \sa QmlExtensionInterface +*/ +bool QmlEngine::importExtension(const QString &fileName) +{ + QPluginLoader loader(fileName); + + if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { + iface->initialize(this); + return true; + } + + return false; +} + +/*! \property QmlEngine::offlineStoragePath \brief the directory for storing offline user data diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 64d0b9d..13a67b0 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -78,6 +78,7 @@ public: void clearComponentCache(); void addImportPath(const QString& dir); + bool importExtension(const QString &fileName); void setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *); QmlNetworkAccessManagerFactory *networkAccessManagerFactory() const; -- cgit v0.12 From e271f9c64f1be3a3608d2010a3561d512650f547 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 13:52:46 +0100 Subject: Compile. --- src/declarative/util/qmlview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index e990e83..8844430 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -427,8 +427,6 @@ void QmlView::continueExecute() */ void QmlView::setRootObject(QObject *obj) { - Q_D(QmlView); - if (QmlGraphicsItem *item = qobject_cast(obj)) { d->scene.addItem(item); -- cgit v0.12 From cdeb85498e4cbd37022ba2bf4dc594db2326d0a4 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 14:02:08 +0100 Subject: Document the QmlExtensionPlugin interface. --- src/declarative/qml/qmlextensioninterface.h | 41 ++++++++++++++++ src/declarative/qml/qmlextensionplugin.cpp | 75 +++++++++++++++++++++++++++++ src/declarative/qml/qmlextensionplugin.h | 41 ++++++++++++++++ 3 files changed, 157 insertions(+) diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index d336e6e..d37a5bc 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 QMLEXTENSIONINTERFACE_H #define QMLEXTENSIONINTERFACE_H diff --git a/src/declarative/qml/qmlextensionplugin.cpp b/src/declarative/qml/qmlextensionplugin.cpp index 15ad44e..c1195d2 100644 --- a/src/declarative/qml/qmlextensionplugin.cpp +++ b/src/declarative/qml/qmlextensionplugin.cpp @@ -1,6 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qmlextensionplugin.h" +QT_BEGIN_NAMESPACE + +/*! + \since 4.7 + \class QmlExtensionPlugin + \brief The QmlExtensionPlugin class provides an abstract base for custom QML extension plugins. + + \ingroup plugins + + QmlExtensionPlugin is a plugin interface that makes it + possible to offer extensions that can be loaded dynamically into + applications using the QmlEngine class. + + Writing a QML extension plugin is achieved by subclassing this + base class, reimplementing the pure virtual initialize() + function, and exporting the class using the Q_EXPORT_PLUGIN2() + macro. See \l {How to Create Qt Plugins} for details. + + \sa QmlEngine::importExtension() +*/ + +/*! + \fn void QmlExtensionPlugin::initialize(QmlEngine *engine) + + Initializes the extension specified in the given \a engine. +*/ + +/*! + Constructs a QML extension plugin with the given \a parent. + + Note that this constructor is invoked automatically by the + Q_EXPORT_PLUGIN2() macro, so there is no need for calling it + explicitly. +*/ QmlExtensionPlugin::QmlExtensionPlugin(QObject *parent) : QObject(parent) { @@ -10,3 +84,4 @@ QmlExtensionPlugin::~QmlExtensionPlugin() { } +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index 8f3194f..eda7d0c 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 QMLEXTENSIONPLUGIN_H #define QMLEXTENSIONPLUGIN_H -- cgit v0.12 From 20fc9f2e264f34dd8580949ddbe5511b78ab0ac4 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 15:54:36 +0100 Subject: Load QML extensions. This allows projects which use the QtDeclarative module to register QML types and functions through C++ extensions. Reviewed-by: mae --- src/declarative/qml/qmldirparser.cpp | 11 +++++ src/declarative/qml/qmldirparser_p.h | 2 + src/declarative/qml/qmlengine.cpp | 67 +++++++++++++++++++---------- src/declarative/qml/qmlengine.h | 2 +- src/declarative/qml/qmlengine_p.h | 1 + src/declarative/qml/qmlextensioninterface.h | 2 +- src/declarative/qml/qmlextensionplugin.h | 2 +- 7 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/declarative/qml/qmldirparser.cpp b/src/declarative/qml/qmldirparser.cpp index c7de233..60beb72 100644 --- a/src/declarative/qml/qmldirparser.cpp +++ b/src/declarative/qml/qmldirparser.cpp @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE QmlDirParser::QmlDirParser() + : _isParsed(false) { } @@ -72,11 +73,21 @@ QString QmlDirParser::source() const void QmlDirParser::setSource(const QString &source) { + _isParsed = false; _source = source; } +bool QmlDirParser::isParsed() const +{ + return _isParsed; +} + bool QmlDirParser::parse() { + if (_isParsed) + return true; + + _isParsed = true; _errors.clear(); _plugins.clear(); _components.clear(); diff --git a/src/declarative/qml/qmldirparser_p.h b/src/declarative/qml/qmldirparser_p.h index ff8b0f8..c58c03f 100644 --- a/src/declarative/qml/qmldirparser_p.h +++ b/src/declarative/qml/qmldirparser_p.h @@ -74,6 +74,7 @@ public: QString source() const; void setSource(const QString &source); + bool isParsed() const; bool parse(); bool hasError() const; @@ -116,6 +117,7 @@ private: QString _source; QList _components; QList _plugins; + unsigned _isParsed: 1; }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index ce2a693..d47db9b 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -97,7 +97,6 @@ #include #include -#include #include #include @@ -1249,12 +1248,13 @@ struct QmlEnginePrivate::ImportedNamespace { QByteArray qt = uris.at(i).toUtf8(); qt += '/'; qt += type; + if (qmlImportTrace()) qDebug() << "Look in" << qt; QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); - if (vmajor) *vmajor = vmaj; - if (vminor) *vminor = vmin; if (t) { + if (vmajor) *vmajor = vmaj; + if (vminor) *vminor = vmin; if (qmlImportTrace()) qDebug() << "Found" << qt; if (type_return) @@ -1273,7 +1273,7 @@ struct QmlEnginePrivate::ImportedNamespace { } } - const QString typespace = QString::fromUtf8(type); + const QString typeName = QString::fromUtf8(type); QmlDirParser qmldirParser; qmldirParser.setUrl(url); @@ -1282,7 +1282,7 @@ struct QmlEnginePrivate::ImportedNamespace { foreach (const QmlDirParser::Component &c, qmldirParser.components()) { // ### TODO: cache the components if (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion)) { - if (c.typeName == typespace) { + if (c.typeName == typeName) { if (url_return) *url_return = url.resolved(QUrl(c.fileName)); @@ -1290,6 +1290,7 @@ struct QmlEnginePrivate::ImportedNamespace { } } } + } else { // XXX search non-files too! (eg. zip files, see QT-524) QFileInfo f(toLocalFileOrQrc(url)); @@ -1304,9 +1305,6 @@ struct QmlEnginePrivate::ImportedNamespace { } }; -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QmlModuleFactoryInterface_iid, QLatin1String("/qmlmodules"))) - class QmlImportsPrivate { public: QmlImportsPrivate() : ref(1) @@ -1319,7 +1317,9 @@ public: delete s; } - bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) + QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; + + bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath, QmlEngine *engine) { QmlEnginePrivate::ImportedNamespace *s; if (prefix.isEmpty()) { @@ -1331,26 +1331,48 @@ public: } QString url = uri; if (importType == QmlScriptParser::Import::Library) { - url.replace(QLatin1Char('.'),QLatin1Char('/')); + url.replace(QLatin1Char('.'), QLatin1Char('/')); bool found = false; - foreach (QString p, importPath) { - QString dir = p+QLatin1Char('/')+url; + QString content; + QString dir; + QStringList paths = importPath; + paths.prepend(QFileInfo(base.toLocalFile()).path()); + foreach (const QString &p, paths) { + dir = p+QLatin1Char('/')+url; QFileInfo fi(dir+QLatin1String("/qmldir")); + const QString absoluteFilePath = fi.absoluteFilePath(); + if (fi.isFile()) { - url = QUrl::fromLocalFile(fi.absolutePath()).toString(); found = true; + + url = QUrl::fromLocalFile(fi.absolutePath()).toString(); + + QFile file(absoluteFilePath); + if (file.open(QFile::ReadOnly)) + content = QString::fromUtf8(file.readAll()); + + if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { + qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); + + QmlDirParser qmldirParser; + qmldirParser.setSource(content); + qmldirParser.parse(); + + foreach (const QmlDirParser::Plugin &plugin, qmldirParser.plugins()) { + const QFileInfo pluginFileInfo(dir + QDir::separator() + plugin.path, plugin.name); + const QString pluginFilePath = pluginFileInfo.absoluteFilePath(); + engine->importExtension(pluginFilePath, uri); + } + } + break; } } - QFactoryLoader *l = loader(); - QmlModuleFactoryInterface *factory = - qobject_cast(l->instance(uri)); - if (factory) { - factory->defineModuleOnce(uri); - } + } else { url = base.resolved(QUrl(url)).toString(); } + s->uris.prepend(uri); s->urls.prepend(url); s->majversions.prepend(vmaj); @@ -1546,12 +1568,12 @@ void QmlEngine::addImportPath(const QString& path) \sa QmlExtensionInterface */ -bool QmlEngine::importExtension(const QString &fileName) +bool QmlEngine::importExtension(const QString &fileName, const QString &uri) { QPluginLoader loader(fileName); if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { - iface->initialize(this); + iface->initialize(this, uri); return true; } @@ -1604,7 +1626,8 @@ QString QmlEngine::offlineStoragePath() const */ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath); + QmlEngine *engine = QmlEnginePrivate::get(const_cast(this)); + bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath, engine); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << '.' << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 13a67b0..dd2012a 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -78,7 +78,7 @@ public: void clearComponentCache(); void addImportPath(const QString& dir); - bool importExtension(const QString &fileName); + bool importExtension(const QString &fileName, const QString &uri); void setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *); QmlNetworkAccessManagerFactory *networkAccessManagerFactory() const; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 3fe7991..d916286 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -263,6 +263,7 @@ public: QmlImportsPrivate *d; }; + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index d37a5bc..cbdd34c 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -54,7 +54,7 @@ class QmlEngine; struct Q_DECLARATIVE_EXPORT QmlExtensionInterface { - virtual void initialize(QmlEngine *engine) = 0; + virtual void initialize(QmlEngine *engine, const QString &uri) = 0; }; Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index eda7d0c..82553e7 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -62,7 +62,7 @@ public: explicit QmlExtensionPlugin(QObject *parent = 0); ~QmlExtensionPlugin(); - virtual void initialize(QmlEngine *engine) = 0; + virtual void initialize(QmlEngine *engine, const QString &uri) = 0; }; QT_END_NAMESPACE -- cgit v0.12 From db817f85def9dcfd335bca46029b7eed168edb32 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 19:00:12 +1000 Subject: Fix compile error in QEasingCurve Reviewed-by: akennedy --- src/corelib/tools/qeasingcurve.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 6b26907..89edb2d 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -861,7 +861,7 @@ QDebug operator<<(QDebug debug, const QEasingCurve &item) QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) { stream << easing.d_ptr->type; - stream << intptr_t(easing.d_ptr->func); + stream << quint64(intptr_t(easing.d_ptr->func)); bool hasConfig = easing.d_ptr->config; stream << hasConfig; @@ -891,9 +891,9 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) type = static_cast(int_type); easing.setType(type); - intptr_t ptr_func; + quint64 ptr_func; stream >> ptr_func; - easing.d_ptr->func = QEasingCurve::EasingFunction(ptr_func); + easing.d_ptr->func = QEasingCurve::EasingFunction(intptr_t(ptr_func)); bool hasConfig; stream >> hasConfig; -- cgit v0.12 From d9a390c6d5f18f335fa0a4766180ffa62f28c363 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 12:09:52 +0100 Subject: Added QmlEnginePrivate::resolvePlugin. resolvePlugin returns the merge of the plugin's base name with the platform suffix (e.g. .dylib) and prefix (e.g. lib). --- src/declarative/qml/qmlengine.cpp | 89 +++++++++++++++++++++++++++++++++++++-- src/declarative/qml/qmlengine_p.h | 6 +++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 67d8c7d..98e16aa 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1359,9 +1359,11 @@ public: qmldirParser.parse(); foreach (const QmlDirParser::Plugin &plugin, qmldirParser.plugins()) { - const QFileInfo pluginFileInfo(dir + QDir::separator() + plugin.path, plugin.name); - const QString pluginFilePath = pluginFileInfo.absoluteFilePath(); - engine->importExtension(pluginFilePath, uri); + QString resolvedFilePath = QmlEnginePrivate::get(engine)->resolvePlugin(dir + QDir::separator() + plugin.path, + plugin.name); + + if (!resolvedFilePath.isEmpty()) + engine->importExtension(resolvedFilePath, uri); } } @@ -1609,6 +1611,87 @@ QString QmlEngine::offlineStoragePath() const return d->scriptEngine.offlineStoragePath; } +/*! + \internal + + Returns the result of the merge of \a baseName with \a dir, \a suffixes, and \a prefix. + */ +QString QmlEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName, + const QStringList &suffixes, + const QString &prefix) +{ + foreach (const QString &suffix, suffixes) { + QString pluginFileName = prefix; + + pluginFileName += baseName; + pluginFileName += QLatin1Char('.'); + pluginFileName += suffix; + + QFileInfo fileInfo(dir, pluginFileName); + + if (fileInfo.exists()) + return fileInfo.absoluteFilePath(); + } + + return QString(); +} + +/*! + \internal + + Returns the result of the merge of \a baseName with \a dir and the platform suffix. + + \table + \header \i Platform \i Valid suffixes + \row \i Windows \i \c .dll + \row \i Unix/Linux \i \c .so + \row \i AIX \i \c .a + \row \i HP-UX \i \c .sl, \c .so (HP-UXi) + \row \i Mac OS X \i \c .dylib, \c .bundle, \c .so + \row \i Symbian \i \c .dll + \endtable + + Version number on unix are ignored. +*/ +QString QmlEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName) +{ +#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) + return resolvePlugin(dir, baseName, QStringList(QLatin1String("dll"))); +#elif defined(Q_OS_SYMBIAN) + return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dll") << QLatin1String("qtplugin")); +#else + +# if defined(Q_OS_DARWIN) + + return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dylib") << QLatin1String("so") << QLatin1String("bundle"), + QLatin1String("lib")); +# else // Generic Unix + QStringList validSuffixList; + +# if defined(Q_OS_HPUX) +/* + See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF": + "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), + the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." + */ + validSuffixList << QLatin1String("sl"); +# if defined __ia64 + validSuffixList << QLatin1String("so"); +# endif +# elif defined(Q_OS_AIX) + validSuffixList << QLatin1String("a") << QLatin1String("so"); +# elif defined(Q_OS_UNIX) + validSuffixList << QLatin1String("so"); +# endif + + // Examples of valid library names: + // libfoo.so + + return resolvePlugin(dir, baseName, validSuffixList, QLatin1String("lib")); +# endif + +#endif +} /*! \internal diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index d916286..53a88b1 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -104,6 +104,7 @@ class QmlCleanup; class QmlDelayedError; class QmlWorkerScriptEngine; class QmlGlobalScriptClass; +class QDir; class QmlScriptEngine : public QScriptEngine { @@ -263,6 +264,11 @@ public: QmlImportsPrivate *d; }; + QString resolvePlugin(const QDir &dir, const QString &baseName, + const QStringList &suffixes, + const QString &prefix = QString()); + QString resolvePlugin(const QDir &dir, const QString &baseName); + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, -- cgit v0.12 From 5eb3c2fc8f90509cb368ab56f14364d6e17844f1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 12:48:16 +0100 Subject: Look for QML plugins in the paths specified in QML_PLUGIN_PATH env var. --- src/declarative/qml/qmlengine.cpp | 30 +++++++++++++++++++++++++---- src/declarative/qml/qmlengine_p.h | 3 +++ src/declarative/qml/qmlextensioninterface.h | 2 +- src/declarative/qml/qmlextensionplugin.h | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 98e16aa..a7c3d08 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -158,6 +158,21 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) } globalClass = new QmlGlobalScriptClass(&scriptEngine); fileImportPath.append(QLibraryInfo::location(QLibraryInfo::DataPath)+QDir::separator()+QLatin1String("qml")); + + // env import paths + QByteArray envImportPath = qgetenv("QML_IMPORT_PATH"); + if (!envImportPath.isEmpty()) { +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QLatin1Char pathSep(';'); +#else + QLatin1Char pathSep(':'); +#endif + foreach (const QString &path, QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts)) { + QString canonicalPath = QDir(path).canonicalPath(); + if (!canonicalPath.isEmpty() && !environmentImportPath.contains(canonicalPath)) + environmentImportPath.append(canonicalPath); + } + } } QUrl QmlScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) @@ -1334,9 +1349,16 @@ public: url.replace(QLatin1Char('.'), QLatin1Char('/')); bool found = false; QString content; - QString dir; - QStringList paths = importPath; - paths.prepend(QFileInfo(base.toLocalFile()).path()); + QString dir; + + // user import paths + QStringList paths; + + // base.. + paths += QFileInfo(base.toLocalFile()).path(); + paths += importPath; + paths += QmlEnginePrivate::get(engine)->environmentImportPath; + foreach (const QString &p, paths) { dir = p+QLatin1Char('/')+url; QFileInfo fi(dir+QLatin1String("/qmldir")); @@ -1575,7 +1597,7 @@ bool QmlEngine::importExtension(const QString &fileName, const QString &uri) QPluginLoader loader(fileName); if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { - iface->initialize(this, uri); + iface->initialize(this, uri.toUtf8().constData()); return true; } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 53a88b1..85c5fbe 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -264,6 +264,9 @@ public: QmlImportsPrivate *d; }; + + QStringList environmentImportPath; + QString resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, const QString &prefix = QString()); diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index cbdd34c..b993e82 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -54,7 +54,7 @@ class QmlEngine; struct Q_DECLARATIVE_EXPORT QmlExtensionInterface { - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index 82553e7..8cc64ad 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -62,7 +62,7 @@ public: explicit QmlExtensionPlugin(QObject *parent = 0); ~QmlExtensionPlugin(); - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; QT_END_NAMESPACE -- cgit v0.12 From 3fb191bbeb0e8a2d49c5107df07c5457872357b3 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 09:46:34 +0100 Subject: Get rid of QmlModulePlugin. --- .../plugins/com/nokia/TimeExample/Clock.qml | 50 ++++++++++ .../plugins/com/nokia/TimeExample/center.png | Bin 0 -> 765 bytes .../plugins/com/nokia/TimeExample/clock.png | Bin 0 -> 20653 bytes .../plugins/com/nokia/TimeExample/hour.png | Bin 0 -> 625 bytes .../plugins/com/nokia/TimeExample/minute.png | Bin 0 -> 625 bytes examples/declarative/plugins/files/Clock.qml | 50 ---------- examples/declarative/plugins/files/center.png | Bin 765 -> 0 bytes examples/declarative/plugins/files/clock.png | Bin 20653 -> 0 bytes examples/declarative/plugins/files/hour.png | Bin 625 -> 0 bytes examples/declarative/plugins/files/minute.png | Bin 625 -> 0 bytes examples/declarative/plugins/plugin.cpp | 14 +-- examples/declarative/plugins/plugins.pro | 13 ++- src/declarative/qml/qml.pri | 2 - src/declarative/qml/qmlengine.cpp | 1 - src/declarative/qml/qmlmoduleplugin.cpp | 111 --------------------- src/declarative/qml/qmlmoduleplugin.h | 86 ---------------- src/multimedia/qml/qml.cpp | 10 +- src/multimedia/qml/qml.h | 4 +- src/plugins/qmlmodules/multimedia/multimedia.cpp | 16 +-- 19 files changed, 79 insertions(+), 278 deletions(-) create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/Clock.qml create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/center.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/clock.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/hour.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/minute.png delete mode 100644 examples/declarative/plugins/files/Clock.qml delete mode 100644 examples/declarative/plugins/files/center.png delete mode 100644 examples/declarative/plugins/files/clock.png delete mode 100644 examples/declarative/plugins/files/hour.png delete mode 100644 examples/declarative/plugins/files/minute.png delete mode 100644 src/declarative/qml/qmlmoduleplugin.cpp delete mode 100644 src/declarative/qml/qmlmoduleplugin.h diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml new file mode 100644 index 0000000..01ec686 --- /dev/null +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -0,0 +1,50 @@ +import Qt 4.6 + +Item { + id: clock + width: 200; height: 200 + + property alias city: cityLabel.text + property var hours + property var minutes + property var shift : 0 + + Image { id: background; source: "clock.png" } + + Image { + x: 92.5; y: 27 + source: "hour.png" + smooth: true + transform: Rotation { + id: hourRotation + origin.x: 7.5; origin.y: 73; angle: 0 + angle: SpringFollow { + spring: 2; damping: 0.2; modulus: 360 + source: (clock.hours * 30) + (clock.minutes * 0.5) + } + } + } + + Image { + x: 93.5; y: 17 + source: "minute.png" + smooth: true + transform: Rotation { + id: minuteRotation + origin.x: 6.5; origin.y: 83; angle: 0 + angle: SpringFollow { + spring: 2; damping: 0.2; modulus: 360 + source: clock.minutes * 6 + } + } + } + + Image { + anchors.centerIn: background; source: "center.png" + } + + Text { + id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" + anchors.horizontalCenter: parent.horizontalCenter + } +} diff --git a/examples/declarative/plugins/com/nokia/TimeExample/center.png b/examples/declarative/plugins/com/nokia/TimeExample/center.png new file mode 100644 index 0000000..7fbd802 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/center.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/clock.png b/examples/declarative/plugins/com/nokia/TimeExample/clock.png new file mode 100644 index 0000000..462edac Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/clock.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/hour.png b/examples/declarative/plugins/com/nokia/TimeExample/hour.png new file mode 100644 index 0000000..f8061a1 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/hour.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/minute.png b/examples/declarative/plugins/com/nokia/TimeExample/minute.png new file mode 100644 index 0000000..1297ec7 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/minute.png differ diff --git a/examples/declarative/plugins/files/Clock.qml b/examples/declarative/plugins/files/Clock.qml deleted file mode 100644 index 01ec686..0000000 --- a/examples/declarative/plugins/files/Clock.qml +++ /dev/null @@ -1,50 +0,0 @@ -import Qt 4.6 - -Item { - id: clock - width: 200; height: 200 - - property alias city: cityLabel.text - property var hours - property var minutes - property var shift : 0 - - Image { id: background; source: "clock.png" } - - Image { - x: 92.5; y: 27 - source: "hour.png" - smooth: true - transform: Rotation { - id: hourRotation - origin.x: 7.5; origin.y: 73; angle: 0 - angle: SpringFollow { - spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) - } - } - } - - Image { - x: 93.5; y: 17 - source: "minute.png" - smooth: true - transform: Rotation { - id: minuteRotation - origin.x: 6.5; origin.y: 83; angle: 0 - angle: SpringFollow { - spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 - } - } - } - - Image { - anchors.centerIn: background; source: "center.png" - } - - Text { - id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" - anchors.horizontalCenter: parent.horizontalCenter - } -} diff --git a/examples/declarative/plugins/files/center.png b/examples/declarative/plugins/files/center.png deleted file mode 100644 index 7fbd802..0000000 Binary files a/examples/declarative/plugins/files/center.png and /dev/null differ diff --git a/examples/declarative/plugins/files/clock.png b/examples/declarative/plugins/files/clock.png deleted file mode 100644 index 462edac..0000000 Binary files a/examples/declarative/plugins/files/clock.png and /dev/null differ diff --git a/examples/declarative/plugins/files/hour.png b/examples/declarative/plugins/files/hour.png deleted file mode 100644 index f8061a1..0000000 Binary files a/examples/declarative/plugins/files/hour.png and /dev/null differ diff --git a/examples/declarative/plugins/files/minute.png b/examples/declarative/plugins/files/minute.png deleted file mode 100644 index 1297ec7..0000000 Binary files a/examples/declarative/plugins/files/minute.png and /dev/null differ diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp index 820d4eb..8e21263 100644 --- a/examples/declarative/plugins/plugin.cpp +++ b/examples/declarative/plugins/plugin.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include +#include #include #include #include @@ -140,19 +140,15 @@ MinuteTimer *Time::timer=0; QML_DECLARE_TYPE(Time); -class QExampleQmlPlugin : public QmlModulePlugin +class QExampleQmlPlugin : public QmlExtensionPlugin { Q_OBJECT public: - QStringList keys() const - { - return QStringList() << QLatin1String("com.nokia.TimeExample"); - } - - void defineModule(const QString& uri) + void initialize(QmlEngine *engine, const char *uri) { + Q_UNUSED(engine); Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); - qmlRegisterType