Commit 23b4fab5 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Changed non-root-node type change behaviour.

Instead of calling changeType, the node is removed and a new one is
inserted. This is in preparation for renaming changeType.
parent d22de18f
......@@ -56,6 +56,7 @@ TextToModelMerger::TextToModelMerger(RewriterView *reWriterView):
m_rewriterView(reWriterView),
m_isActive(false)
{
Q_ASSERT(reWriterView);
}
void TextToModelMerger::setActive(bool active)
......@@ -80,21 +81,19 @@ void TextToModelMerger::setupImports(QmlDomDocument &doc,
qmlImport.qualifier()));
if (!existingImports.remove(import))
differenceHandler.modelMissesImport(m_rewriterView->model(),
import);
differenceHandler.modelMissesImport(import);
} else if (qmlImport.type() == QmlDomImport::File) {
Import import(Import:: createFileImport(qmlImport.uri(),
qmlImport.version(),
qmlImport.qualifier()));
if (!existingImports.remove(import))
differenceHandler.modelMissesImport(m_rewriterView->model(),
import);
differenceHandler.modelMissesImport(import);
}
}
foreach (const Import &import, existingImports)
differenceHandler.importAbsentInQMl(m_rewriterView->model(), import);
differenceHandler.importAbsentInQMl(import);
}
bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differenceHandler)
......@@ -126,8 +125,10 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
return success;
} catch (Exception &e) {
RewriterView::Error error(&e);
// Somehow, the error below gets eaten in upper levels, so printing the exception info here for debugging purposes:
qDebug() << "*** An exception occurred while reading the QML file:" << error.toString();
// Somehow, the error below gets eaten in upper levels, so printing the
// exception info here for debugging purposes:
qDebug() << "*** An exception occurred while reading the QML file:"
<< error.toString();
m_rewriterView->addError(error);
setActive(false);
......@@ -136,10 +137,21 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
}
}
void TextToModelMerger::syncNode(ModelNode &modelNode, const QmlDomObject &domObject, DifferenceHandler &differenceHandler)
void TextToModelMerger::syncNode(ModelNode &modelNode,
const QmlDomObject &domObject,
DifferenceHandler &differenceHandler)
{
m_rewriterView->positionStorage()->setNodeOffset(modelNode, domObject.position());
if (modelNode.type() != domObject.objectType()
|| modelNode.majorVersion() != domObject.objectTypeMajorVersion()
|| modelNode.minorVersion() != domObject.objectTypeMinorVersion()) {
const bool isRootNode = m_rewriterView->rootModelNode() == modelNode;
differenceHandler.typeDiffers(isRootNode, modelNode, domObject);
if (!isRootNode)
return; // the difference handler will create a new node, so we're done.
}
{
QString domObjectId = domObject.objectId();
const QmlDomProperty domIdProperty = domObject.property("id");
......@@ -163,12 +175,6 @@ void TextToModelMerger::syncNode(ModelNode &modelNode, const QmlDomObject &domOb
}
}
if (modelNode.type() != domObject.objectType()
|| modelNode.majorVersion() != domObject.objectTypeMajorVersion()
|| modelNode.minorVersion() != domObject.objectTypeMinorVersion()) {
differenceHandler.typeDiffers(modelNode, domObject);
}
QSet<QString> modelPropertyNames = QSet<QString>::fromList(modelNode.propertyNames());
foreach (const QmlDomProperty &domProperty, domObject.properties()) {
......@@ -383,14 +389,14 @@ QVariant TextToModelMerger::convertToVariant(const ModelNode &node, const QmlDom
}
}
void ModelValidator::modelMissesImport(Model *model, const Import &import)
void ModelValidator::modelMissesImport(const Import &import)
{
Q_ASSERT(model->imports().contains(import));
Q_ASSERT(m_merger->view()->model()->imports().contains(import));
}
void ModelValidator::importAbsentInQMl(Model *model, const Import &import)
void ModelValidator::importAbsentInQMl(const Import &import)
{
Q_ASSERT(! model->imports().contains(import));
Q_ASSERT(! m_merger->view()->model()->imports().contains(import));
}
void ModelValidator::bindingExpressionsDiffer(BindingProperty &modelProperty, const QString &qmlBinding)
......@@ -446,7 +452,7 @@ ModelNode ModelValidator::listPropertyMissingModelNode(NodeListProperty &/*model
return ModelNode();
}
void ModelValidator::typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject)
void ModelValidator::typeDiffers(bool /*isRootNode*/, ModelNode &modelNode, const QmlDomObject &domObject)
{
Q_ASSERT(modelNode.type() == domObject.objectType());
Q_ASSERT(modelNode.majorVersion() == domObject.objectTypeMajorVersion());
......@@ -466,14 +472,14 @@ void ModelValidator::idsDiffer(ModelNode &modelNode, const QString &qmlId)
Q_ASSERT(0);
}
void ModelAmender::modelMissesImport(Model *model, const Import &import)
void ModelAmender::modelMissesImport(const Import &import)
{
model->addImport(import);
m_merger->view()->model()->addImport(import);
}
void ModelAmender::importAbsentInQMl(Model *model, const Import &import)
void ModelAmender::importAbsentInQMl(const Import &import)
{
model->removeImport(import);
m_merger->view()->model()->removeImport(import);
}
void ModelAmender::bindingExpressionsDiffer(BindingProperty &modelProperty, const QString &qmlBinding)
......@@ -534,12 +540,28 @@ ModelNode ModelAmender::listPropertyMissingModelNode(NodeListProperty &modelProp
return newNode;
}
void ModelAmender::typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject)
void ModelAmender::typeDiffers(bool isRootNode, ModelNode &modelNode, const QmlDomObject &domObject)
{
foreach (const QString &propertyName, modelNode.propertyNames())
modelNode.removeProperty(propertyName);
if (isRootNode) {
modelNode.changeType(domObject.objectType(), domObject.objectTypeMajorVersion(), domObject.objectTypeMinorVersion());
} else {
NodeAbstractProperty parentProperty = modelNode.parentProperty();
int nodeIndex = -1;
if (parentProperty.isNodeListProperty()) {
nodeIndex = parentProperty.toNodeListProperty().toModelNodeList().indexOf(modelNode);
Q_ASSERT(nodeIndex >= 0);
}
modelNode.changeType(domObject.objectType(), domObject.objectTypeMajorVersion(), domObject.objectTypeMinorVersion());
modelNode.destroy();
const ModelNode &newNode = m_merger->createModelNode(domObject, *this);
parentProperty.reparentHere(newNode);
if (nodeIndex >= 0) {
int currentIndex = parentProperty.toNodeListProperty().toModelNodeList().indexOf(newNode);
if (nodeIndex != currentIndex)
parentProperty.toNodeListProperty().slide(currentIndex, nodeIndex);
}
}
}
void ModelAmender::propertyAbsentFromQml(AbstractProperty &modelProperty)
......
......@@ -57,8 +57,10 @@ public:
void setupImports(QmlDomDocument &doc, DifferenceHandler &differenceHandler);
bool load(const QByteArray &data, DifferenceHandler &differenceHandler);
RewriterView *view() const
{ return m_rewriterView; }
protected:
RewriterView *view();
void setActive(bool active);
public:
......@@ -96,8 +98,8 @@ public:
virtual ~DifferenceHandler()
{}
virtual void modelMissesImport(Model *model, const Import &import) = 0;
virtual void importAbsentInQMl(Model *model, const Import &import) = 0;
virtual void modelMissesImport(const Import &import) = 0;
virtual void importAbsentInQMl(const Import &import) = 0;
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty, const QString &qmlBinding) = 0;
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty, const QString &qmlBinding) = 0;
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty, const QmlDomList &domList) = 0;
......@@ -106,7 +108,7 @@ public:
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject) = 0;
virtual void modelNodeAbsentFromQml(ModelNode &modelNode) = 0;
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject) = 0;
virtual void typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject) = 0;
virtual void typeDiffers(bool isRootNode, ModelNode &modelNode, const QmlDomObject &domObject) = 0;
virtual void propertyAbsentFromQml(AbstractProperty &modelProperty) = 0;
virtual void idsDiffer(ModelNode &modelNode, const QString &qmlId) = 0;
......@@ -123,8 +125,8 @@ public:
~ModelValidator()
{}
virtual void modelMissesImport(Model *model, const Import &import);
virtual void importAbsentInQMl(Model *model, const Import &import);
virtual void modelMissesImport(const Import &import);
virtual void importAbsentInQMl(const Import &import);
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty, const QString &qmlBinding);
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty, const QString &qmlBinding);
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty, const QmlDomList &domList);
......@@ -133,7 +135,7 @@ public:
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void modelNodeAbsentFromQml(ModelNode &modelNode);
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject);
virtual void typeDiffers(bool isRootNode, ModelNode &modelNode, const QmlDomObject &domObject);
virtual void propertyAbsentFromQml(AbstractProperty &modelProperty);
virtual void idsDiffer(ModelNode &modelNode, const QString &qmlId);
};
......@@ -147,8 +149,8 @@ public:
~ModelAmender()
{}
virtual void modelMissesImport(Model *model, const Import &import);
virtual void importAbsentInQMl(Model *model, const Import &import);
virtual void modelMissesImport(const Import &import);
virtual void importAbsentInQMl(const Import &import);
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty, const QString &qmlBinding);
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty, const QString &qmlBinding);
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty, const QmlDomList &domList);
......@@ -157,7 +159,7 @@ public:
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void modelNodeAbsentFromQml(ModelNode &modelNode);
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject);
virtual void typeDiffers(bool isRootNode, ModelNode &modelNode, const QmlDomObject &domObject);
virtual void propertyAbsentFromQml(AbstractProperty &modelProperty);
virtual void idsDiffer(ModelNode &modelNode, const QString &qmlId);
};
......
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