aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@digia.com>2014-08-28 16:51:00 +0200
committerThomas Hartmann <Thomas.Hartmann@digia.com>2014-08-28 16:52:02 +0200
commite64b6245a91a9d2bd269452c772c7c6eea784b39 (patch)
tree7991c4cbfc7a0b702fef6b8a3e9cb362a2b9ce8b /src/qml/qml
parent26fb6a0915ec64d30eaa78e781e7f18468bc2ed7 (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/qml')
-rw-r--r--src/qml/qml/qqmldirparser.cpp13
-rw-r--r--src/qml/qml/qqmldirparser_p.h2
-rw-r--r--src/qml/qml/qqmlimport.cpp16
-rw-r--r--src/qml/qml/qqmlimport_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp4
-rw-r--r--src/qml/qml/qqmltypeloader_p.h2
6 files changed, 38 insertions, 1 deletions
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;