forked from qt-creator/qt-creator
QmlDesigner.subComponentManager: remove the need for a QDeclarativeEngine
There were cases where a QDeclarativeEngine was crashing. Reviewed-by: Kai Koehne
This commit is contained in:
@@ -287,9 +287,6 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
|
|||||||
m_d->subComponentModel = Model::create("QtQuick.Rectangle", 1, 0);
|
m_d->subComponentModel = Model::create("QtQuick.Rectangle", 1, 0);
|
||||||
m_d->subComponentModel->setFileUrl(m_d->searchPath);
|
m_d->subComponentModel->setFileUrl(m_d->searchPath);
|
||||||
|
|
||||||
m_d->subComponentManager = new SubComponentManager(m_d->masterModel->metaInfo(), this);
|
|
||||||
m_d->subComponentManager->update(m_d->searchPath, m_d->textModifier->text().toUtf8());
|
|
||||||
|
|
||||||
m_d->rewriterView = new RewriterView(RewriterView::Amend, m_d->masterModel.data());
|
m_d->rewriterView = new RewriterView(RewriterView::Amend, m_d->masterModel.data());
|
||||||
m_d->rewriterView->setTextModifier( m_d->textModifier);
|
m_d->rewriterView->setTextModifier( m_d->textModifier);
|
||||||
connect(m_d->rewriterView.data(), SIGNAL(errorsChanged(const QList<RewriterView::Error> &)),
|
connect(m_d->rewriterView.data(), SIGNAL(errorsChanged(const QList<RewriterView::Error> &)),
|
||||||
@@ -298,7 +295,8 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
|
|||||||
m_d->masterModel->attachView(m_d->rewriterView.data());
|
m_d->masterModel->attachView(m_d->rewriterView.data());
|
||||||
m_d->model = m_d->masterModel;
|
m_d->model = m_d->masterModel;
|
||||||
|
|
||||||
|
m_d->subComponentManager = new SubComponentManager(m_d->masterModel->metaInfo(), this);
|
||||||
|
m_d->subComponentManager->update(m_d->searchPath, m_d->model->imports());
|
||||||
|
|
||||||
loadCurrentModel();
|
loadCurrentModel();
|
||||||
|
|
||||||
|
|||||||
@@ -41,10 +41,11 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <private/qdeclarativedom_p.h>
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class Import;
|
||||||
|
|
||||||
class CORESHARED_EXPORT SubComponentManager : public QObject
|
class CORESHARED_EXPORT SubComponentManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -52,8 +53,7 @@ public:
|
|||||||
explicit SubComponentManager(MetaInfo metaInfo, QObject *parent = 0);
|
explicit SubComponentManager(MetaInfo metaInfo, QObject *parent = 0);
|
||||||
~SubComponentManager();
|
~SubComponentManager();
|
||||||
|
|
||||||
void update(const QUrl &fileUrl, const QByteArray &data);
|
void update(const QUrl &fileUrl, const QList<Import> &imports);
|
||||||
void update(const QUrl &fileUrl, const QList<QDeclarativeDomImport> &imports);
|
|
||||||
|
|
||||||
QStringList qmlFiles() const;
|
QStringList qmlFiles() const;
|
||||||
QStringList directories() const;
|
QStringList directories() const;
|
||||||
|
|||||||
@@ -37,10 +37,9 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QDeclarativeEngine>
|
|
||||||
#include <private/qdeclarativemetatype_p.h>
|
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <private/qdeclarativedom_p.h>
|
#include <import.h>
|
||||||
|
|
||||||
|
|
||||||
enum { debug = false };
|
enum { debug = false };
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ class SubComponentManagerPrivate : QObject {
|
|||||||
public:
|
public:
|
||||||
SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q);
|
SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q);
|
||||||
|
|
||||||
void addImport(int pos, const QDeclarativeDomImport &import);
|
void addImport(int pos, const Import &import);
|
||||||
void removeImport(int pos);
|
void removeImport(int pos);
|
||||||
void parseDirectories();
|
void parseDirectories();
|
||||||
|
|
||||||
@@ -97,12 +96,11 @@ public slots:
|
|||||||
public:
|
public:
|
||||||
QList<QFileInfo> watchedFiles(const QString &canonicalDirPath);
|
QList<QFileInfo> watchedFiles(const QString &canonicalDirPath);
|
||||||
void unregisterQmlFile(const QFileInfo &fileInfo, const QString &qualifier);
|
void unregisterQmlFile(const QFileInfo &fileInfo, const QString &qualifier);
|
||||||
void registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier, const QDeclarativeDomDocument &document, bool addToLibrary);
|
void registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier, bool addToLibrary);
|
||||||
|
|
||||||
SubComponentManager *m_q;
|
SubComponentManager *m_q;
|
||||||
|
|
||||||
MetaInfo m_metaInfo;
|
MetaInfo m_metaInfo;
|
||||||
QDeclarativeEngine m_engine;
|
|
||||||
|
|
||||||
QFileSystemWatcher m_watcher;
|
QFileSystemWatcher m_watcher;
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ public:
|
|||||||
|
|
||||||
QUrl m_filePath;
|
QUrl m_filePath;
|
||||||
|
|
||||||
QList<QDeclarativeDomImport> m_imports;
|
QList<Import> m_imports;
|
||||||
};
|
};
|
||||||
|
|
||||||
SubComponentManagerPrivate::SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q) :
|
SubComponentManagerPrivate::SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q) :
|
||||||
@@ -121,20 +119,20 @@ SubComponentManagerPrivate::SubComponentManagerPrivate(MetaInfo metaInfo, SubCom
|
|||||||
connect(&m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(parseDirectory(QString)));
|
connect(&m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(parseDirectory(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubComponentManagerPrivate::addImport(int pos, const QDeclarativeDomImport &import)
|
void SubComponentManagerPrivate::addImport(int pos, const Import &import)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << Q_FUNC_INFO << pos << import.uri();
|
qDebug() << Q_FUNC_INFO << pos << import.file().toAscii();
|
||||||
|
|
||||||
if (import.type() == QDeclarativeDomImport::File) {
|
if (import.isFileImport()) {
|
||||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.uri()).toLocalFile());
|
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||||
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
||||||
m_watcher.addPath(canonicalDirPath);
|
m_watcher.addPath(canonicalDirPath);
|
||||||
m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier());
|
//m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier()); ### todo: proper support for import as
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString url = import.uri();
|
QString url = import.url();
|
||||||
|
|
||||||
url.replace(QLatin1Char('.'), QLatin1Char('/'));
|
url.replace(QLatin1Char('.'), QLatin1Char('/'));
|
||||||
|
|
||||||
@@ -144,7 +142,7 @@ void SubComponentManagerPrivate::addImport(int pos, const QDeclarativeDomImport
|
|||||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||||
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
||||||
m_watcher.addPath(canonicalDirPath);
|
m_watcher.addPath(canonicalDirPath);
|
||||||
m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier());
|
//m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier()); ### todo: proper support for import as
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: QDeclarativeDomImport::Library
|
// TODO: QDeclarativeDomImport::Library
|
||||||
@@ -155,21 +153,21 @@ void SubComponentManagerPrivate::addImport(int pos, const QDeclarativeDomImport
|
|||||||
|
|
||||||
void SubComponentManagerPrivate::removeImport(int pos)
|
void SubComponentManagerPrivate::removeImport(int pos)
|
||||||
{
|
{
|
||||||
const QDeclarativeDomImport import = m_imports.takeAt(pos);
|
const Import import = m_imports.takeAt(pos);
|
||||||
|
|
||||||
if (import.type() == QDeclarativeDomImport::File) {
|
if (import.isFileImport()) {
|
||||||
const QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.uri()).toLocalFile());
|
const QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||||
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
||||||
|
|
||||||
m_dirToQualifier.remove(canonicalDirPath, import.qualifier());
|
//m_dirToQualifier.remove(canonicalDirPath, import.qualifier()); ### todo: proper support for import as
|
||||||
|
|
||||||
if (!m_dirToQualifier.contains(canonicalDirPath))
|
if (!m_dirToQualifier.contains(canonicalDirPath))
|
||||||
m_watcher.removePath(canonicalDirPath);
|
m_watcher.removePath(canonicalDirPath);
|
||||||
|
|
||||||
foreach (const QFileInfo &monitoredFile, watchedFiles(canonicalDirPath)) {
|
// foreach (const QFileInfo &monitoredFile, watchedFiles(canonicalDirPath)) { ### todo: proper support for import as
|
||||||
if (!m_dirToQualifier.contains(canonicalDirPath))
|
// if (!m_dirToQualifier.contains(canonicalDirPath))
|
||||||
unregisterQmlFile(monitoredFile, import.qualifier());
|
// unregisterQmlFile(monitoredFile, import.qualifier());
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
// TODO: QDeclarativeDomImport::Library
|
// TODO: QDeclarativeDomImport::Library
|
||||||
}
|
}
|
||||||
@@ -184,14 +182,14 @@ void SubComponentManagerPrivate::parseDirectories()
|
|||||||
parseDirectory(dirInfo.canonicalFilePath());
|
parseDirectory(dirInfo.canonicalFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QDeclarativeDomImport &import, m_imports) {
|
foreach (const Import &import, m_imports) {
|
||||||
if (import.type() == QDeclarativeDomImport::File) {
|
if (import.isFileImport()) {
|
||||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.uri()).toLocalFile());
|
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||||
parseDirectory(dirInfo.canonicalFilePath());
|
parseDirectory(dirInfo.canonicalFilePath());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString url = import.uri();
|
QString url = import.url();
|
||||||
foreach(const QString path, importPaths()) {
|
foreach(const QString path, importPaths()) {
|
||||||
url.replace(QLatin1Char('.'), QLatin1Char('/'));
|
url.replace(QLatin1Char('.'), QLatin1Char('/'));
|
||||||
url = path + QLatin1String("/") + url;
|
url = path + QLatin1String("/") + url;
|
||||||
@@ -281,17 +279,11 @@ void SubComponentManagerPrivate::parseFile(const QString &canonicalFilePath, boo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDeclarativeDomDocument document;
|
|
||||||
if (!document.load(&m_engine, file.readAll(), QUrl::fromLocalFile(canonicalFilePath))) {
|
|
||||||
// TODO: Put the errors somewhere?
|
|
||||||
qWarning() << "Could not load qml file " << canonicalFilePath;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString dir = QFileInfo(canonicalFilePath).path();
|
QString dir = QFileInfo(canonicalFilePath).path();
|
||||||
foreach (const QString &qualifier, m_dirToQualifier.values(dir)) {
|
foreach (const QString &qualifier, m_dirToQualifier.values(dir)) {
|
||||||
registerQmlFile(canonicalFilePath, qualifier, document, addToLibrary);
|
registerQmlFile(canonicalFilePath, qualifier, addToLibrary);
|
||||||
}
|
}
|
||||||
|
registerQmlFile(canonicalFilePath, QString(), addToLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubComponentManagerPrivate::parseFile(const QString &canonicalFilePath)
|
void SubComponentManagerPrivate::parseFile(const QString &canonicalFilePath)
|
||||||
@@ -330,7 +322,7 @@ static inline bool isDepricatedQtType(const QString &typeName)
|
|||||||
|
|
||||||
|
|
||||||
void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier,
|
void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier,
|
||||||
const QDeclarativeDomDocument &, bool addToLibrary)
|
bool addToLibrary)
|
||||||
{
|
{
|
||||||
QString componentName = fileInfo.baseName();
|
QString componentName = fileInfo.baseName();
|
||||||
|
|
||||||
@@ -386,27 +378,7 @@ QStringList SubComponentManager::qmlFiles() const
|
|||||||
return m_d->m_watcher.files();
|
return m_d->m_watcher.files();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool importEqual(const QDeclarativeDomImport &import1, const QDeclarativeDomImport &import2)
|
void SubComponentManager::update(const QUrl &filePath, const QList<Import> &imports)
|
||||||
{
|
|
||||||
return import1.type() == import2.type()
|
|
||||||
&& import1.uri() == import2.uri()
|
|
||||||
&& import1.version() == import2.version()
|
|
||||||
&& import1.qualifier() == import2.qualifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubComponentManager::update(const QUrl &filePath, const QByteArray &data)
|
|
||||||
{
|
|
||||||
QDeclarativeEngine engine;
|
|
||||||
QDeclarativeDomDocument document;
|
|
||||||
|
|
||||||
QList<QDeclarativeDomImport> imports;
|
|
||||||
if (document.load(&engine, data, filePath))
|
|
||||||
imports = document.imports();
|
|
||||||
|
|
||||||
update(filePath, imports);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubComponentManager::update(const QUrl &filePath, const QList<QDeclarativeDomImport> &imports)
|
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << Q_FUNC_INFO << filePath << imports.size();
|
qDebug() << Q_FUNC_INFO << filePath << imports.size();
|
||||||
@@ -446,7 +418,7 @@ void SubComponentManager::update(const QUrl &filePath, const QList<QDeclarativeD
|
|||||||
// skip first list items until the lists differ
|
// skip first list items until the lists differ
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < qMin(imports.size(), m_d->m_imports.size())) {
|
while (i < qMin(imports.size(), m_d->m_imports.size())) {
|
||||||
if (!importEqual(imports.at(i), m_d->m_imports.at(i)))
|
if (!(imports.at(i) == m_d->m_imports.at(i)))
|
||||||
break;
|
break;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user