Commit dc1ce254 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.copyNPaste: fix for Components and default properties

To handle defaultProperties correctly in the text buffer for
copy n paste we have to forward the meta system.
Since the text buffer is not a qml document in Qt Creator
with all the infrastructure attached the meta system is
incomplete.
So we forward in these cases the meta system of the actual document.

Model::create() now gets an additional paramater where we can specify another
model for proxying the meta system.

Reviewed-by: Kai Koehne
parent ca1f5707
......@@ -507,8 +507,7 @@ void DesignDocumentController::deleteSelected()
void DesignDocumentController::copySelected()
{
QScopedPointer<Model> model(Model::create("QtQuick.Rectangle", 1, 0));
model->setMetaInfo(m_d->model->metaInfo());
QScopedPointer<Model> model(Model::create("QtQuick.Rectangle", 1, 0, model()));
model->setFileUrl(m_d->model->fileUrl());
model->changeImports(m_d->model->imports(), QList<Import>());
......@@ -603,8 +602,7 @@ static void scatterItem(ModelNode pastedNode, const ModelNode targetNode, int of
void DesignDocumentController::paste()
{
QScopedPointer<Model> model(Model::create("empty"));
model->setMetaInfo(m_d->model->metaInfo());
QScopedPointer<Model> model(Model::create("empty", 1, 0, model()));
model->setFileUrl(m_d->model->fileUrl());
model->changeImports(m_d->model->imports(), QList<Import>());
......
......@@ -155,8 +155,7 @@ void DesignDocumentControllerView::fromClipboard()
QString DesignDocumentControllerView::toText() const
{
QScopedPointer<Model> outputModel(Model::create("QtQuick.Rectangle", 1, 0));
outputModel->setMetaInfo(model()->metaInfo());
QScopedPointer<Model> outputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
QPlainTextEdit textEdit;
QString imports;
......@@ -187,8 +186,7 @@ QString DesignDocumentControllerView::toText() const
void DesignDocumentControllerView::fromText(QString text)
{
QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0));
inputModel->setMetaInfo(model()->metaInfo());
QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
inputModel->setFileUrl(model()->fileUrl());
QPlainTextEdit textEdit;
QString imports;
......
......@@ -84,7 +84,7 @@ public:
virtual ~Model();
static Model *create(QString type, int major = 4, int minor = 7);
static Model *create(QString type, int major = 4, int minor = 7, Model *metaInfoPropxyModel = 0);
Model *masterModel() const;
void setMasterModel(Model *model);
......@@ -96,7 +96,6 @@ public:
MetaInfo metaInfo();
NodeMetaInfo metaInfo(const QString &typeName, int majorVersion = -1, int minorVersion = -1);
bool hasNodeMetaInfo(const QString &typeName, int majorVersion = -1, int minorVersion = -1);
void setMetaInfo(const MetaInfo &metaInfo);
void attachView(AbstractView *view);
void detachView(AbstractView *view, ViewNotification emitDetachNotify = NotifyView);
......@@ -109,6 +108,8 @@ public:
RewriterView *rewriterView() const;
Model *metaInfoProxyModel();
protected:
Model();
......
......@@ -121,10 +121,11 @@ void ModelPrivate::detachAllViews()
}
}
Model *ModelPrivate::create(QString type, int major, int minor)
Model *ModelPrivate::create(QString type, int major, int minor, Model *metaInfoPropxyModel)
{
Model *model = new Model;
model->m_d->m_metaInfoProxyModel = metaInfoPropxyModel;
model->m_d->rootNode()->setType(type);
model->m_d->rootNode()->setMajorVersion(major);
model->m_d->rootNode()->setMinorVersion(minor);
......@@ -1628,9 +1629,9 @@ Model::~Model()
}
Model *Model::create(QString type, int major, int minor)
Model *Model::create(QString type, int major, int minor, Model *metaInfoPropxyModel)
{
return Internal::ModelPrivate::create(type, major, minor);
return Internal::ModelPrivate::create(type, major, minor, metaInfoPropxyModel);
}
......@@ -1686,6 +1687,18 @@ RewriterView *Model::rewriterView() const
return m_d->rewriterView();
}
/*!
\brief Returns the model that is used for metainfo
\return Return itself if not other metaInfoProxyModel does exist
*/
Model *Model::metaInfoProxyModel()
{
if (m_d->m_metaInfoProxyModel)
return m_d->m_metaInfoProxyModel->metaInfoProxyModel();
else
return this;
}
#if 0
/*!
\brief Creates a new empty model
......@@ -1746,15 +1759,6 @@ NodeMetaInfo Model::metaInfo(const QString &typeName, int majorVersion, int mino
return NodeMetaInfo(this, typeName, majorVersion, minorVersion);
}
/*!
\brief Sets a specific Metainfo on this Model
*/
void Model::setMetaInfo(const MetaInfo &metaInfo)
{
Internal::WriteLocker locker(m_d);
m_d->setMetaInfo(metaInfo);
}
/*!
\brief Returns list of QML types available within the model.
*/
......
......@@ -97,7 +97,7 @@ public:
ModelPrivate(Model *model);
~ModelPrivate();
static Model *create(QString type, int major, int minor);
static Model *create(QString type, int major, int minor, Model *metaInfoPropxyModel);
QUrl fileUrl() const;
void setFileUrl(const QUrl &url);
......@@ -240,6 +240,8 @@ private:
QWeakPointer<Model> m_masterModel;
QWeakPointer<RewriterView> m_rewriterView;
QWeakPointer<NodeInstanceView> m_nodeInstanceView;
QWeakPointer<Model> m_metaInfoProxyModel;
bool m_writeLock;
qint32 m_internalIdCounter;
};
......
......@@ -740,7 +740,7 @@ const NodeMetaInfo ModelNode::metaInfo() const
throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
}
return NodeMetaInfo(model(), type(), majorVersion(), minorVersion());
return NodeMetaInfo(model()->metaInfoProxyModel(), type(), majorVersion(), minorVersion());
}
/*! \brief has a node the selection of the model
......
......@@ -43,6 +43,7 @@
#include "texttomodelmerger.h"
#include "rewriterview.h"
#include "variantproperty.h"
#include "nodemetainfo.h"
#include <languageutils/componentversion.h>
#include <qmljs/qmljsevaluate.h>
......@@ -727,6 +728,8 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
int majorVersion;
int minorVersion;
context->lookup(astObjectType, typeName, majorVersion, minorVersion, defaultPropertyName);
if (defaultPropertyName.isEmpty()) //fallback and use the meta system of the model
defaultPropertyName = modelNode.metaInfo().defaultPropertyName();
if (typeName.isEmpty()) {
qWarning() << "Skipping node with unknown type" << flatten(astObjectType);
......
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