diff options
author | Tim Jenssen <tim.jenssen@digia.com> | 2014-08-28 16:51:00 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2014-08-28 16:52:02 +0200 |
commit | e64b6245a91a9d2bd269452c772c7c6eea784b39 (patch) | |
tree | 7991c4cbfc7a0b702fef6b8a3e9cb362a2b9ce8b /src/qml | |
parent | 26fb6a0915ec64d30eaa78e781e7f18468bc2ed7 (diff) |
Add new property "designersupported" to qmldir
This patch adds a property called "designersupported" to qmldir.
This allows the Qt Quick Designer to only load plugins that
have the line ""designersupported"" in their qmldir file.
So the designer can load sub components without risking to load
plugins that have never been tested in the designer and that might crash.
The check for "designersupported"" is activated by using
QQmlImports::setDesignerSupportRequired().
Change-Id: I4bf07cc163faa47996eacb1365a7961c51c51060
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/doc/src/qmllanguageref/modules/qmldir.qdoc | 22 | ||||
-rw-r--r-- | src/qml/qml/qqmldirparser.cpp | 13 | ||||
-rw-r--r-- | src/qml/qml/qqmldirparser_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 16 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 2 |
7 files changed, 60 insertions, 1 deletions
diff --git a/src/qml/doc/src/qmllanguageref/modules/qmldir.qdoc b/src/qml/doc/src/qmllanguageref/modules/qmldir.qdoc index ef6c8b1b67..a3ea25c005 100644 --- a/src/qml/doc/src/qmllanguageref/modules/qmldir.qdoc +++ b/src/qml/doc/src/qmllanguageref/modules/qmldir.qdoc @@ -221,6 +221,28 @@ typeinfo mymodule.qmltypes \code # this is a comment \endcode + + \row + \li designersupported + \li + \code + designersupported + \endcode + + \li Set this property if the plugin is supported by Qt Quick Designer. + By default, the plugin will not be supported. + + A plugin that is supported by Qt Quick Designer has to be properly + tested. This means that the plugin does not crash when running inside + the qml2puppet that is used by Qt Quick Designer to execute QML. + Generally the plugin should work well in the Qt Quick Designer + and not cause any show stoppers, like taking huge amounts of memory, + slowing down the qml2puppet heavily or anything else that renders + the plugin effectively unusable in the Qt Quick Designer. + + The items of an unsupported plugin are not painted in the Qt Quick Designer, + but they are still available as empty boxes and the properties can be edited. + \endtable Each command in a \c qmldir file must be on a separate line. diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp index 5f5f7d4a38..7068818f15 100644 --- a/src/qml/qml/qqmldirparser.cpp +++ b/src/qml/qml/qqmldirparser.cpp @@ -55,7 +55,7 @@ static int parseInt(const QStringRef &str, bool *ok) return number; } -QQmlDirParser::QQmlDirParser() +QQmlDirParser::QQmlDirParser() : _designerSupported(false) { } @@ -87,6 +87,7 @@ bool QQmlDirParser::parse(const QString &source) _plugins.clear(); _components.clear(); _scripts.clear(); + _designerSupported = false; quint16 lineNumber = 0; bool firstLine = true; @@ -225,6 +226,11 @@ bool QQmlDirParser::parse(const QString &source) _typeInfos.append(typeInfo); #endif + } else if (sections[0] == QLatin1String("designersupported")) { + if (sectionCount != 1) + reportError(lineNumber, 0, QString::fromLatin1("designersupported does not expect any argument")); + else + _designerSupported = true; } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) const Component entry(sections[0], sections[1], -1, -1); @@ -354,6 +360,11 @@ QList<QQmlDirParser::TypeInfo> QQmlDirParser::typeInfos() const } #endif +bool QQmlDirParser::designerSupported() const +{ + return _designerSupported; +} + QDebug &operator<< (QDebug &debug, const QQmlDirParser::Component &component) { const QString output = QString::fromLatin1("{%1 %2.%3}"). diff --git a/src/qml/qml/qqmldirparser_p.h b/src/qml/qml/qqmldirparser_p.h index faede99afd..54843a13b0 100644 --- a/src/qml/qml/qqmldirparser_p.h +++ b/src/qml/qml/qqmldirparser_p.h @@ -121,6 +121,7 @@ public: QHash<QString,Component> components() const; QList<Script> scripts() const; QList<Plugin> plugins() const; + bool designerSupported() const; #ifdef QT_CREATOR struct TypeInfo @@ -144,6 +145,7 @@ private: QHash<QString,Component> _components; // multi hash QList<Script> _scripts; QList<Plugin> _plugins; + bool _designerSupported; #ifdef QT_CREATOR QList<TypeInfo> _typeInfos; #endif diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index da37b0a76e..141cd4acbf 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -64,6 +64,7 @@ static const QLatin1Char Colon(':'); static const QLatin1String Slash_qmldir("/qmldir"); static const QLatin1String String_qmldir("qmldir"); static const QString dotqml_string(QLatin1String(".qml")); +static bool designerSupportRequired = false; namespace { @@ -881,6 +882,16 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath, qDebug().nospace() << "QQmlImports(" << qPrintable(base) << ")::importExtension: " << "loaded " << qmldirFilePath; + if (designerSupportRequired && !qmldir->designerSupported()) { + if (errors) { + QQmlError error; + error.setDescription(QQmlImportDatabase::tr("module does not support the designer \"%1\"").arg(qmldir->typeNamespace())); + error.setUrl(QUrl::fromLocalFile(qmldirFilePath)); + errors->prepend(error); + } + return false; + } + int qmldirPluginCount = qmldir->plugins().count(); if (qmldirPluginCount == 0) return true; @@ -1539,6 +1550,11 @@ bool QQmlImports::isLocal(const QUrl &url) return QQmlFile::isBundle(url) || !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); } +void QQmlImports::setDesignerSupportRequired(bool b) +{ + designerSupportRequired = b; +} + /*! \class QQmlImportDatabase diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index de29318f60..26eab669bc 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -129,6 +129,8 @@ public: static bool isLocal(const QString &url); static bool isLocal(const QUrl &url); + static void setDesignerSupportRequired(bool b); + private: friend class QQmlImportDatabase; QQmlImportsPrivate *d; diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 6913019562..0b7cc8e911 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1571,6 +1571,10 @@ QString QQmlTypeLoader::QmldirContent::pluginLocation() const return m_location; } +bool QQmlTypeLoader::QmldirContent::designerSupported() const +{ + return m_parser.designerSupported(); +} /*! Constructs a new type loader that uses the given \a engine. diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 3d3ad28091..9f98e4fd40 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -320,6 +320,8 @@ public: QString pluginLocation() const; + bool designerSupported() const; + private: QQmlDirParser m_parser; QString m_location; |