Commit 4844ead3 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.copyNPase: fix for components

Since the buffer for copy and paste has no proper
representation in the project managment QmlJs::Check cannot
handle components. For now we just turn of Check for this case, since
we check the final document anyway.

Reviewed-by: Kai Koehne
parent 13df303b
......@@ -507,7 +507,7 @@ void DesignDocumentController::deleteSelected()
void DesignDocumentController::copySelected()
{
QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
QScopedPointer<Model> model(Model::create("QtQuick.Rectangle", 1, 0));
model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl());
model->changeImports(m_d->model->imports(), QList<Import>());
......@@ -552,7 +552,7 @@ void DesignDocumentController::copySelected()
foreach (ModelNode node, view.rootModelNode().allDirectSubModelNodes()) {
node.destroy();
}
view.changeRootNodeType("Qt/Rectangle", 4, 7);
view.changeRootNodeType("QtQuick.Rectangle", 1, 0);
view.rootModelNode().setId("designer__Selection");
foreach (const ModelNode &selectedNode, selectedNodes) {
......
......@@ -158,10 +158,20 @@ QString DesignDocumentControllerView::toText() const
QScopedPointer<Model> outputModel(Model::create("QtQuick.Rectangle", 1, 0));
outputModel->setMetaInfo(model()->metaInfo());
QPlainTextEdit textEdit;
textEdit.setPlainText("import Qt 4.7; Item {}");
QString imports;
foreach (const Import &import, model()->imports()) {
if (import.isFileImport())
imports += QLatin1String("import ") + QLatin1String("\"") + import.file() + QLatin1String("\"")+ QLatin1String(";\n");
else
imports += QLatin1String("import ") + import.url() + QLatin1String(" ") + import.version() + QLatin1String(";\n");
}
textEdit.setPlainText(imports + QLatin1String("Item {\n}\n"));
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setCheckSemanticErrors(false);
rewriterView->setTextModifier(&modifier);
outputModel->attachView(rewriterView.data());
......@@ -189,6 +199,7 @@ void DesignDocumentControllerView::fromText(QString text)
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setCheckSemanticErrors(false);
rewriterView->setTextModifier(&modifier);
inputModel->attachView(rewriterView.data());
......
......@@ -187,6 +187,12 @@ public:
QmlJS::LookupContext *lookupContext() const;
QmlJS::Document *document() const;
bool checkSemanticErrors() const
{ return m_checkErrors; }
void setCheckSemanticErrors(bool b)
{ m_checkErrors = b; }
signals:
void errorsChanged(const QList<RewriterView::Error> &errors);
......@@ -213,6 +219,7 @@ private: //variables
RewriterTransaction m_removeDefaultPropertyTransaction;
QString m_rewritingErrorMessage;
QString lastCorrectQmlSource;
bool m_checkErrors;
};
} //QmlDesigner
......
......@@ -172,12 +172,12 @@ ModelNode ModelMerger::insertModel(const ModelNode &modelNode)
void ModelMerger::replaceModel(const ModelNode &modelNode)
{
try {
RewriterTransaction transaction(view()->beginRewriterTransaction());
view()->model()->changeImports(modelNode.model()->imports(), QList<Import>());
view()->model()->setFileUrl(modelNode.model()->fileUrl());
try {
RewriterTransaction transaction(view()->beginRewriterTransaction());
ModelNode rootNode(view()->rootModelNode());
foreach (const QString &propertyName, rootNode.propertyNames())
......
......@@ -133,7 +133,8 @@ RewriterView::RewriterView(DifferenceHandling differenceHandling, QObject *paren
m_modelToTextMerger(new Internal::ModelToTextMerger(this)),
m_textToModelMerger(new Internal::TextToModelMerger(this)),
m_textModifier(0),
transactionLevel(0)
transactionLevel(0),
m_checkErrors(true)
{
}
......
......@@ -662,16 +662,18 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
errors.append(RewriterView::Error(diagnosticMessage, QUrl::fromLocalFile(doc->fileName())));
}
Check check(doc, snapshot, m_lookupContext->context());
check.setOptions(check.options() & ~Check::ErrCheckTypeErrors);
foreach (const QmlJS::DiagnosticMessage &diagnosticMessage, check())
if (diagnosticMessage.isError())
errors.append(RewriterView::Error(diagnosticMessage, QUrl::fromLocalFile(doc->fileName())));
if (!errors.isEmpty()) {
m_rewriterView->setErrors(errors);
setActive(false);
return false;
if (view()->checkSemanticErrors()) {
Check check(doc, snapshot, m_lookupContext->context());
check.setOptions(check.options() & ~Check::ErrCheckTypeErrors);
foreach (const QmlJS::DiagnosticMessage &diagnosticMessage, check())
if (diagnosticMessage.isError())
errors.append(RewriterView::Error(diagnosticMessage, QUrl::fromLocalFile(doc->fileName())));
if (!errors.isEmpty()) {
m_rewriterView->setErrors(errors);
setActive(false);
return false;
}
}
setupImports(doc, differenceHandler);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment