Commit 5dce7092 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner: fixes copy and paste of components

This patch ensures that meta info is available for all models
during copy and paste
parent 97c3d530
......@@ -542,6 +542,8 @@ void DesignDocumentController::deleteSelected()
void DesignDocumentController::copySelected()
{
QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
model->setMetaInfo(m_d->model->metaInfo());
Q_ASSERT(model);
DesignDocumentControllerView view;
......@@ -603,6 +605,8 @@ void DesignDocumentController::cutSelected()
void DesignDocumentController::paste()
{
QScopedPointer<Model> model(Model::create("empty"));
model->setMetaInfo(m_d->model->metaInfo());
model->setFileUrl(m_d->model->fileUrl());
Q_ASSERT(model);
if (!m_d->model)
......
......@@ -30,6 +30,7 @@
#include "designdocumentcontrollerview.h"
#include <rewriterview.h>
#include <plaintexteditmodifier.h>
#include <metainfo.h>
#include <QApplication>
#include <QPlainTextEdit>
......@@ -97,14 +98,15 @@ void DesignDocumentControllerView::fromClipboard()
QString DesignDocumentControllerView::toText() const
{
QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
QScopedPointer<Model> outputModel(Model::create("Qt/Rectangle"));
outputModel->setMetaInfo(model()->metaInfo());
QPlainTextEdit textEdit;
textEdit.setPlainText("import Qt 4.6; Item {}");
PlainTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setTextModifier(&modifier);
model->attachView(rewriterView.data());
outputModel->attachView(rewriterView.data());
ModelMerger merger(rewriterView.data());
......@@ -118,7 +120,9 @@ QString DesignDocumentControllerView::toText() const
void DesignDocumentControllerView::fromText(QString text)
{
QScopedPointer<Model> model(Model::create("Qt/Rectangle"));
QScopedPointer<Model> inputModel(Model::create("Qt/Rectangle"));
inputModel->setMetaInfo(model()->metaInfo());
inputModel->setFileUrl(model()->fileUrl());
QPlainTextEdit textEdit;
QString imports("import Qt 4.6;\n");
textEdit.setPlainText(imports + text);
......@@ -126,7 +130,7 @@ void DesignDocumentControllerView::fromText(QString text)
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setTextModifier(&modifier);
model->attachView(rewriterView.data());
inputModel->attachView(rewriterView.data());
if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
ModelMerger merger(this);
......
......@@ -147,6 +147,7 @@ void ModelMerger::replaceModel(const ModelNode &modelNode)
foreach (const Import &import, modelNode.model()->imports())
view()->model()->addImport(import);
view()->model()->setFileUrl(modelNode.model()->fileUrl());
ModelNode rootNode(view()->rootModelNode());
......
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