QmlDesigenr: Collect qrc urls and create mapping for the qmlpuppet

We collect all possible qrc path and the mappings provided by
the code model in the TextToModelMerger.
Then we set this mapping as environment variable for the puppet
in the PuppetCreator(QMLDESIGNER_RC_PATHS).

Change-Id: I4b4c7253af23d1f32a75394d04199e76f2e9efdd
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-07-09 12:57:49 +02:00
committed by Thomas Hartmann
parent 165ced5568
commit c64657da22
8 changed files with 98 additions and 1 deletions

View File

@@ -206,6 +206,8 @@ public:
QStringList importDirectories() const; QStringList importDirectories() const;
QSet<QPair<QString, QString> > qrcMapping() const;
signals: signals:
void errorsChanged(const QList<RewriterView::Error> &errors); void errorsChanged(const QList<RewriterView::Error> &errors);

View File

@@ -130,7 +130,7 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
PuppetCreator::QmlPuppetVersion puppetVersion = hasQtQuick1(nodeInstanceView) ? PuppetCreator::Qml1Puppet : PuppetCreator::Qml2Puppet; PuppetCreator::QmlPuppetVersion puppetVersion = hasQtQuick1(nodeInstanceView) ? PuppetCreator::Qml1Puppet : PuppetCreator::Qml2Puppet;
PuppetCreator puppetCreator(kit, QString(), nodeInstanceView->model(), puppetVersion); PuppetCreator puppetCreator(kit, QString(), nodeInstanceView->model(), puppetVersion);
puppetCreator.setQrcMappingString(qrcMappingString());
puppetCreator.createPuppetExecutableIfMissing(); puppetCreator.createPuppetExecutableIfMissing();
@@ -326,6 +326,30 @@ void NodeInstanceServerProxy::puppetAlive(NodeInstanceServerProxy::PuppetStreamT
} }
} }
QString NodeInstanceServerProxy::qrcMappingString() const
{
if (m_nodeInstanceView && m_nodeInstanceView.data()->model()) {
RewriterView *rewriterView = m_nodeInstanceView.data()->model()->rewriterView();
if (rewriterView) {
QString mappingString;
typedef QPair<QString, QString> StringPair;
foreach (const StringPair &pair, rewriterView->qrcMapping()) {
if (!mappingString.isEmpty())
mappingString.append(QLatin1String(","));
mappingString.append(pair.first);
mappingString.append(QLatin1String("="));
mappingString.append(pair.second);
}
return mappingString;
}
}
return QString();
}
void NodeInstanceServerProxy::processFinished() void NodeInstanceServerProxy::processFinished()
{ {
processFinished(-1, QProcess::CrashExit); processFinished(-1, QProcess::CrashExit);

View File

@@ -89,6 +89,7 @@ protected:
void dispatchCommand(const QVariant &command, PuppetStreamType puppetStreamType); void dispatchCommand(const QVariant &command, PuppetStreamType puppetStreamType);
NodeInstanceClientInterface *nodeInstanceClient() const; NodeInstanceClientInterface *nodeInstanceClient() const;
void puppetAlive(PuppetStreamType puppetStreamType); void puppetAlive(PuppetStreamType puppetStreamType);
QString qrcMappingString() const;
signals: signals:
void processCrashed(); void processCrashed();

View File

@@ -349,6 +349,10 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
environment.set("QML_USE_MOCKUPS", "true"); environment.set("QML_USE_MOCKUPS", "true");
environment.set("QML_PUPPET_MODE", "true"); environment.set("QML_PUPPET_MODE", "true");
if (!m_qrcMapping.isEmpty()) {
environment.set(QLatin1String("QMLDESIGNER_RC_PATHS"), m_qrcMapping);
}
if (m_availablePuppetType != FallbackPuppet) { if (m_availablePuppetType != FallbackPuppet) {
if (m_puppetVersion == Qml1Puppet) if (m_puppetVersion == Qml1Puppet)
environment.appendOrSet("QML_IMPORT_PATH", m_model->importPaths().join(pathSep), pathSep); environment.appendOrSet("QML_IMPORT_PATH", m_model->importPaths().join(pathSep), pathSep);
@@ -385,6 +389,11 @@ QString PuppetCreator::compileLog() const
return m_compileLog; return m_compileLog;
} }
void PuppetCreator::setQrcMappingString(const QString qrcMapping)
{
m_qrcMapping = qrcMapping;
}
bool PuppetCreator::startBuildProcess(const QString &buildDirectoryPath, bool PuppetCreator::startBuildProcess(const QString &buildDirectoryPath,
const QString &command, const QString &command,
const QStringList &processArguments, const QStringList &processArguments,

View File

@@ -70,6 +70,8 @@ public:
QString compileLog() const; QString compileLog() const;
void setQrcMappingString(const QString qrcMapping);
protected: protected:
bool build(const QString &qmlPuppetProjectFilePath) const; bool build(const QString &qmlPuppetProjectFilePath) const;
@@ -121,6 +123,7 @@ private:
static QHash<Core::Id, PuppetType> m_qml1PuppetForKitPuppetHash; static QHash<Core::Id, PuppetType> m_qml1PuppetForKitPuppetHash;
static QHash<Core::Id, PuppetType> m_qml2PuppetForKitPuppetHash; static QHash<Core::Id, PuppetType> m_qml2PuppetForKitPuppetHash;
const Model *m_model; const Model *m_model;
QString m_qrcMapping;
QmlPuppetVersion m_puppetVersion; QmlPuppetVersion m_puppetVersion;
}; };

View File

@@ -766,6 +766,11 @@ QStringList RewriterView::importDirectories() const
return m_textToModelMerger->vContext().paths; return m_textToModelMerger->vContext().paths;
} }
QSet<QPair<QString, QString> > RewriterView::qrcMapping() const
{
return m_textToModelMerger->qrcMapping();
}
void RewriterView::qmlTextChanged() void RewriterView::qmlTextChanged()
{ {
if (inErrorState()) if (inErrorState())

View File

@@ -865,6 +865,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
// maybe the project environment (kit, ...) changed, so we need to clean old caches // maybe the project environment (kit, ...) changed, so we need to clean old caches
NodeMetaInfo::clearCache(); NodeMetaInfo::clearCache();
m_qrcMapping.clear();
const QUrl url = m_rewriterView->model()->fileUrl(); const QUrl url = m_rewriterView->model()->fileUrl();
@@ -1411,11 +1412,33 @@ void TextToModelMerger::syncArrayProperty(AbstractProperty &modelProperty,
} }
} }
static QString fileForFullQrcPath(const QString &string)
{
QStringList stringList = string.split(QLatin1String("/"));
if (stringList.isEmpty())
return QString();
return stringList.last();
}
static QString removeFileFromQrcPath(const QString &string)
{
QStringList stringList = string.split(QLatin1String("/"));
if (stringList.isEmpty())
return QString();
stringList.removeLast();
return stringList.join(QLatin1String("/"));
}
void TextToModelMerger::syncVariantProperty(AbstractProperty &modelProperty, void TextToModelMerger::syncVariantProperty(AbstractProperty &modelProperty,
const QVariant &astValue, const QVariant &astValue,
const TypeName &astType, const TypeName &astType,
DifferenceHandler &differenceHandler) DifferenceHandler &differenceHandler)
{ {
if (astValue.canConvert(QMetaType::QString))
populateQrcMapping(astValue.toString());
if (modelProperty.isVariantProperty()) { if (modelProperty.isVariantProperty()) {
VariantProperty modelVariantProperty = modelProperty.toVariantProperty(); VariantProperty modelVariantProperty = modelProperty.toVariantProperty();
@@ -1909,6 +1932,25 @@ void TextToModelMerger::setupComponent(const ModelNode &node)
ModelNode(node).setNodeSource(result); ModelNode(node).setNodeSource(result);
} }
void TextToModelMerger::populateQrcMapping(const QString &filePath)
{
QString path = removeFileFromQrcPath(filePath);
QString fileName = fileForFullQrcPath(filePath);
if (path.contains(QLatin1String("qrc:"))) {
path.remove(QLatin1String("qrc:"));
QMap<QString,QStringList> map = ModelManagerInterface::instance()->filesInQrcPath(path);
if (map.contains(fileName)) {
if (!map.value(fileName).isEmpty()) {
QString fileSystemPath = map.value(fileName).first();
fileSystemPath.remove(fileName);
if (path.isEmpty())
path.prepend(QLatin1String("/"));
m_qrcMapping.insert(qMakePair(path, fileSystemPath));
}
}
}
}
void TextToModelMerger::setupComponentDelayed(const ModelNode &node, bool synchron) void TextToModelMerger::setupComponentDelayed(const ModelNode &node, bool synchron)
{ {
if (synchron) { if (synchron) {
@@ -1957,6 +1999,11 @@ void TextToModelMerger::delayedSetup()
m_setupComponentList.clear(); m_setupComponentList.clear();
} }
QSet<QPair<QString, QString> > TextToModelMerger::qrcMapping() const
{
return m_qrcMapping;
}
QString TextToModelMerger::textAt(const Document::Ptr &doc, QString TextToModelMerger::textAt(const Document::Ptr &doc,
const AST::SourceLocation &location) const AST::SourceLocation &location)
{ {

View File

@@ -131,10 +131,15 @@ public:
void setupCustomParserNodeDelayed(const ModelNode &node, bool synchron); void setupCustomParserNodeDelayed(const ModelNode &node, bool synchron);
void delayedSetup(); void delayedSetup();
QSet<QPair<QString, QString> > qrcMapping() const;
private: private:
void setupCustomParserNode(const ModelNode &node); void setupCustomParserNode(const ModelNode &node);
void setupComponent(const ModelNode &node); void setupComponent(const ModelNode &node);
void populateQrcMapping(const QString &filePath);
static QString textAt(const QmlJS::Document::Ptr &doc, static QString textAt(const QmlJS::Document::Ptr &doc,
const QmlJS::AST::SourceLocation &location); const QmlJS::AST::SourceLocation &location);
static QString textAt(const QmlJS::Document::Ptr &doc, static QString textAt(const QmlJS::Document::Ptr &doc,
@@ -150,6 +155,7 @@ private:
QSet<ModelNode> m_setupComponentList; QSet<ModelNode> m_setupComponentList;
QSet<ModelNode> m_setupCustomParserList; QSet<ModelNode> m_setupCustomParserList;
QmlJS::ViewerContext m_vContext; QmlJS::ViewerContext m_vContext;
QSet<QPair<QString, QString> > m_qrcMapping;
}; };
class DifferenceHandler class DifferenceHandler