forked from qt-creator/qt-creator
QmlJS: Switch to new format for QML meta data.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user