diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-02-08 13:22:34 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-02-09 10:42:49 +0100 |
commit | 2ec429e8ce7df1a017c63405442a36dd261142ac (patch) | |
tree | 03006490d7a1b6da3ea00e09d41ba9ba85be6996 /src | |
parent | dd1de1b82f9f8681aec14bc4266bb1d68d11c4fd (diff) | |
download | qt-creator-2ec429e8ce7df1a017c63405442a36dd261142ac.tar.gz |
QmlJS: Switch to new format for QML meta data.
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/qmljs/qmljsinterpreter.cpp | 50 | ||||
-rw-r--r-- | src/libs/qmljs/qmljsinterpreter.h | 13 | ||||
-rw-r--r-- | src/libs/qmljs/qmljstypedescriptionreader.cpp | 2 | ||||
-rw-r--r-- | src/libs/qmljs/qmljstypedescriptionreader.h | 9 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsmodelmanager.cpp | 12 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsplugindumper.cpp | 39 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsplugindumper.h | 4 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/qmldumptool.cpp | 1 |
8 files changed, 75 insertions, 55 deletions
diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp index 2e540f37b7..ae7d8bad8e 100644 --- a/src/libs/qmljs/qmljsinterpreter.cpp +++ b/src/libs/qmljs/qmljsinterpreter.cpp @@ -36,6 +36,7 @@ #include "qmljslink.h" #include "qmljsbind.h" #include "qmljsscopebuilder.h" +#include "qmljstypedescriptionreader.h" #include "parser/qmljsast_p.h" #include <languageutils/fakemetaobject.h> @@ -1943,45 +1944,48 @@ const Value *Function::invoke(const Activation *activation) const // typing environment //////////////////////////////////////////////////////////////////////////////// -QList<FakeMetaObject::ConstPtr> CppQmlTypesLoader::builtinObjects; +QHash<QString, FakeMetaObject::ConstPtr> CppQmlTypesLoader::builtinObjects; -QStringList CppQmlTypesLoader::loadXml(const QFileInfoList &xmlFiles) +QStringList CppQmlTypesLoader::loadQmlTypes(const QFileInfoList &qmlTypeFiles) { - QMap<QString, FakeMetaObject::Ptr> newObjects; + QHash<QString, FakeMetaObject::Ptr> newObjects; QStringList errorMsgs; - foreach (const QFileInfo &xmlFile, xmlFiles) { - QFile file(xmlFile.absoluteFilePath()); + foreach (const QFileInfo &qmlTypeFile, qmlTypeFiles) { + QFile file(qmlTypeFile.absoluteFilePath()); if (file.open(QIODevice::ReadOnly)) { - QmlXmlReader read(&file); - if (!read(&newObjects)) { - errorMsgs.append(read.errorMessage()); - } + QString contents = QString::fromUtf8(file.readAll()); file.close(); + + QmlJS::TypeDescriptionReader reader(contents); + if (!reader(&newObjects)) { + errorMsgs.append(reader.errorMessage()); + } } else { - errorMsgs.append(QmlXmlReader::tr("%1: %2").arg(xmlFile.absoluteFilePath(), - file.errorString())); + errorMsgs.append(QmlJS::TypeDescriptionReader::tr("%1: %2") + .arg(qmlTypeFile.absoluteFilePath(), + file.errorString())); } } if (errorMsgs.isEmpty()) { setSuperClasses(&newObjects); - // we need to go from QList<T *> of newObjects.values() to QList<const T *> + // we need to go from QHash<K, T::Ptr> to QHash<K, T::ConstPtr> // and there seems to be no better way - QMapIterator<QString, FakeMetaObject::Ptr> it(newObjects); + QHashIterator<QString, FakeMetaObject::Ptr> it(newObjects); while (it.hasNext()) { it.next(); - builtinObjects.append(it.value()); + builtinObjects.insert(it.key(), it.value()); } } return errorMsgs; } -QString CppQmlTypesLoader::parseQmlTypeXml(const QByteArray &xml, QMap<QString, FakeMetaObject::Ptr> *newObjects) +QString CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &xml, QHash<QString, FakeMetaObject::Ptr> *newObjects) { - QmlXmlReader reader(xml); + QmlJS::TypeDescriptionReader reader(QString::fromUtf8(xml)); if (!reader(newObjects)) { if (reader.errorMessage().isEmpty()) return QLatin1String("unknown error"); @@ -1991,16 +1995,18 @@ QString CppQmlTypesLoader::parseQmlTypeXml(const QByteArray &xml, QMap<QString, return QString(); } -void CppQmlTypesLoader::setSuperClasses(QMap<QString, FakeMetaObject::Ptr> *newObjects) +void CppQmlTypesLoader::setSuperClasses(QHash<QString, FakeMetaObject::Ptr> *newObjects) { - QMapIterator<QString, FakeMetaObject::Ptr> it(*newObjects); + QHashIterator<QString, FakeMetaObject::Ptr> it(*newObjects); while (it.hasNext()) { it.next(); FakeMetaObject::Ptr obj = it.value(); const QString superName = obj->superclassName(); if (! superName.isEmpty()) { - FakeMetaObject::Ptr superClass = newObjects->value(superName); + FakeMetaObject::ConstPtr superClass = newObjects->value(superName); + if (!superClass) + superClass = builtinObjects.value(superName); if (superClass) obj->setSuperclass(superClass); else @@ -2009,7 +2015,8 @@ void CppQmlTypesLoader::setSuperClasses(QMap<QString, FakeMetaObject::Ptr> *newO } } -void CppQmlTypes::load(Engine *engine, const QList<FakeMetaObject::ConstPtr> &objects) +template <typename T> +void CppQmlTypes::load(Engine *engine, const T &objects) { // load QList<FakeMetaObject::ConstPtr> newObjects; @@ -2052,6 +2059,9 @@ void CppQmlTypes::load(Engine *engine, const QList<FakeMetaObject::ConstPtr> &ob } } } +// explicitly instantiate load for list and hash +template void CppQmlTypes::load< QList<FakeMetaObject::ConstPtr> >(Engine *, const QList<FakeMetaObject::ConstPtr> &); +template void CppQmlTypes::load< QHash<QString, FakeMetaObject::ConstPtr> >(Engine *, const QHash<QString, FakeMetaObject::ConstPtr> &); QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName, ComponentVersion version) const { diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h index 2090dc71db..a97a19d5b0 100644 --- a/src/libs/qmljs/qmljsinterpreter.h +++ b/src/libs/qmljs/qmljsinterpreter.h @@ -585,20 +585,21 @@ class QMLJS_EXPORT CppQmlTypesLoader { public: /** \return an empty list when successful, error messages otherwise. */ - static QStringList loadXml(const QFileInfoList &xmlFiles); - static QList<LanguageUtils::FakeMetaObject::ConstPtr> builtinObjects; + static QStringList loadQmlTypes(const QFileInfoList &xmlFiles); + static QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr> builtinObjects; // parses the xml string and fills the newObjects map - static QString parseQmlTypeXml(const QByteArray &xml, - QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects); + static QString parseQmlTypeDescriptions(const QByteArray &xml, + QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects); private: - static void setSuperClasses(QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects); + static void setSuperClasses(QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects); }; class QMLJS_EXPORT CppQmlTypes { public: - void load(Interpreter::Engine *interpreter, const QList<LanguageUtils::FakeMetaObject::ConstPtr> &objects); + template <typename T> + void load(Interpreter::Engine *interpreter, const T &objects); QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, LanguageUtils::ComponentVersion version) const; Interpreter::QmlObjectValue *typeForImport(const QString &qualifiedName, diff --git a/src/libs/qmljs/qmljstypedescriptionreader.cpp b/src/libs/qmljs/qmljstypedescriptionreader.cpp index 0c2b5f318a..35bce0a826 100644 --- a/src/libs/qmljs/qmljstypedescriptionreader.cpp +++ b/src/libs/qmljs/qmljstypedescriptionreader.cpp @@ -26,7 +26,7 @@ TypeDescriptionReader::~TypeDescriptionReader() { } -bool TypeDescriptionReader::operator()(QMap<QString, FakeMetaObject::Ptr> *objects) +bool TypeDescriptionReader::operator()(QHash<QString, FakeMetaObject::Ptr> *objects) { QString fileName("typeDescription"); Engine engine; diff --git a/src/libs/qmljs/qmljstypedescriptionreader.h b/src/libs/qmljs/qmljstypedescriptionreader.h index 1b7d38c9a5..21e9c3c4d5 100644 --- a/src/libs/qmljs/qmljstypedescriptionreader.h +++ b/src/libs/qmljs/qmljstypedescriptionreader.h @@ -5,6 +5,9 @@ #include <QtCore/QScopedPointer> +// for Q_DECLARE_TR_FUNCTIONS +#include <QtCore/QCoreApplication> + QT_BEGIN_NAMESPACE class QIODevice; class QBuffer; @@ -21,11 +24,13 @@ class SourceLocation; class TypeDescriptionReader { + Q_DECLARE_TR_FUNCTIONS(QmlJS::TypeDescriptionReader) + public: explicit TypeDescriptionReader(const QString &data); ~TypeDescriptionReader(); - bool operator()(QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *objects); + bool operator()(QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *objects); QString errorMessage() const; private: @@ -45,7 +50,7 @@ private: QString _source; QString _errorMessage; - QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *_objects; + QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *_objects; }; } // namespace QmlJS diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 187007f043..41a462c0c5 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -104,6 +104,7 @@ void ModelManager::delayedInitialization() void ModelManager::loadQmlTypeDescriptions() { if (Core::ICore::instance()) { + // ### this does not necessarily work, should only call loadQmlTypes once! loadQmlTypeDescriptions(Core::ICore::instance()->resourcePath()); loadQmlTypeDescriptions(Core::ICore::instance()->userResourcePath()); } @@ -112,12 +113,13 @@ void ModelManager::loadQmlTypeDescriptions() void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath) { const QDir typeFileDir(resourcePath + QLatin1String("/qml-type-descriptions")); - const QStringList xmlExtensions = QStringList() << QLatin1String("*.xml"); - const QFileInfoList xmlFiles = typeFileDir.entryInfoList(xmlExtensions, - QDir::Files, - QDir::Name); + const QStringList qmlTypesExtensions = QStringList() << QLatin1String("*.qmltypes"); + const QFileInfoList qmlTypesFiles = typeFileDir.entryInfoList( + qmlTypesExtensions, + QDir::Files, + QDir::Name); - const QStringList errors = Interpreter::CppQmlTypesLoader::loadXml(xmlFiles); + const QStringList errors = Interpreter::CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles); foreach (const QString &error, errors) qWarning() << qPrintable(error); diff --git a/src/plugins/qmljstools/qmljsplugindumper.cpp b/src/plugins/qmljstools/qmljsplugindumper.cpp index aca066f1cf..28db6304f3 100644 --- a/src/plugins/qmljstools/qmljsplugindumper.cpp +++ b/src/plugins/qmljstools/qmljsplugindumper.cpp @@ -96,8 +96,8 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString & } // watch library xml file - if (plugin.hasPredumpedXmlFile()) { - const QString &path = plugin.predumpedXmlFilePath(); + if (plugin.hasPredumpedQmlTypesFile()) { + const QString &path = plugin.predumpedQmlTypesFilePath(); m_pluginWatcher->addFile(path); m_libraryToPluginIndex.insert(path, index); } @@ -134,15 +134,15 @@ static QString qmldumpFailedMessage(const QString &error) ).arg(firstLines); } -static QList<FakeMetaObject::ConstPtr> parseHelper(const QByteArray &xml, QString *error) +static QList<FakeMetaObject::ConstPtr> parseHelper(const QByteArray &qmlTypeDescriptions, QString *error) { QList<FakeMetaObject::ConstPtr> ret; - QMap<QString, FakeMetaObject::Ptr> newObjects; - *error = Interpreter::CppQmlTypesLoader::parseQmlTypeXml(xml, &newObjects); + QHash<QString, FakeMetaObject::Ptr> newObjects; + *error = Interpreter::CppQmlTypesLoader::parseQmlTypeDescriptions(qmlTypeDescriptions, &newObjects); if (error->isEmpty()) { // convert from QList<T *> to QList<const T *> - QMapIterator<QString, FakeMetaObject::Ptr> it(newObjects); + QHashIterator<QString, FakeMetaObject::Ptr> it(newObjects); while (it.hasNext()) { it.next(); ret.append(it.value()); @@ -178,8 +178,9 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode) if (exitCode == 0 && error.isEmpty()) { libraryInfo.setMetaObjects(objectsList); - if (libraryPath.isEmpty()) - Interpreter::CppQmlTypesLoader::builtinObjects.append(objectsList); +// ### disabled code path for running qmldump to get Qt's builtins +// if (libraryPath.isEmpty()) +// Interpreter::CppQmlTypesLoader::builtinObjects.append(objectsList); libraryInfo.setDumpStatus(LibraryInfo::DumpDone); } @@ -220,26 +221,26 @@ void PluginDumper::pluginChanged(const QString &pluginLibrary) void PluginDumper::dump(const Plugin &plugin) { - if (plugin.hasPredumpedXmlFile()) { + if (plugin.hasPredumpedQmlTypesFile()) { const Snapshot snapshot = m_modelManager->snapshot(); LibraryInfo libraryInfo = snapshot.libraryInfo(plugin.qmldirPath); if (!libraryInfo.isValid()) return; - const QString &path = plugin.predumpedXmlFilePath(); - QFile libraryXmlFile(path); - if (!libraryXmlFile.open(QFile::ReadOnly | QFile::Text)) { + const QString &path = plugin.predumpedQmlTypesFilePath(); + QFile libraryQmlTypesFile(path); + if (!libraryQmlTypesFile.open(QFile::ReadOnly | QFile::Text)) { libraryInfo.setDumpStatus(LibraryInfo::DumpError, tr("Could not open file '%1' for reading.").arg(path)); m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo); return; } - const QByteArray xml = libraryXmlFile.readAll(); - libraryXmlFile.close(); + const QByteArray qmlTypeDescriptions = libraryQmlTypesFile.readAll(); + libraryQmlTypesFile.close(); QString error; - const QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(xml, &error); + const QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(qmlTypeDescriptions, &error); if (error.isEmpty()) { libraryInfo.setMetaObjects(objectsList); @@ -390,12 +391,12 @@ QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldi #endif } -bool PluginDumper::Plugin::hasPredumpedXmlFile() const +bool PluginDumper::Plugin::hasPredumpedQmlTypesFile() const { - return QFileInfo(predumpedXmlFilePath()).isFile(); + return QFileInfo(predumpedQmlTypesFilePath()).isFile(); } -QString PluginDumper::Plugin::predumpedXmlFilePath() const +QString PluginDumper::Plugin::predumpedQmlTypesFilePath() const { - return QString("%1%2library.xml").arg(qmldirPath, QDir::separator()); + return QString("%1%2plugins.qmltypes").arg(qmldirPath, QDir::separator()); } diff --git a/src/plugins/qmljstools/qmljsplugindumper.h b/src/plugins/qmljstools/qmljsplugindumper.h index 3d37d185c2..99e4a147fc 100644 --- a/src/plugins/qmljstools/qmljsplugindumper.h +++ b/src/plugins/qmljstools/qmljsplugindumper.h @@ -77,8 +77,8 @@ private: QString importPath; QString importUri; - bool hasPredumpedXmlFile() const; - QString predumpedXmlFilePath() const; + bool hasPredumpedQmlTypesFile() const; + QString predumpedQmlTypesFilePath() const; }; void dump(const Plugin &plugin); diff --git a/src/plugins/qt4projectmanager/qmldumptool.cpp b/src/plugins/qt4projectmanager/qmldumptool.cpp index 0b8432e77a..6350313aa6 100644 --- a/src/plugins/qt4projectmanager/qmldumptool.cpp +++ b/src/plugins/qt4projectmanager/qmldumptool.cpp @@ -269,6 +269,7 @@ QString QmlDumpTool::copy(const QString &qtInstallData, QString *errorMessage) QStringList files; files << QLatin1String("main.cpp") << QLatin1String("qmldump.pro") + << QLatin1String("qmlstreamwriter.cpp") << QLatin1String("qmlstreamwriter.h") << QLatin1String("LICENSE.LGPL") << QLatin1String("LGPL_EXCEPTION.TXT") << QLatin1String("Info.plist"); |