Commit 7b462f1b authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed a modification call into the model when inline components got loaded.

parent 75b42f18
......@@ -163,7 +163,6 @@ protected: // functions
bool isModificationGroupActive() const;
void setModificationGroupActive(bool active);
void applyModificationGroupChanges();
void setupComponent(const ModelNode &node);
void applyChanges();
private: //variables
......
......@@ -898,7 +898,7 @@ WriteLocker::WriteLocker(ModelPrivate *model)
if (m_model->m_writeLock)
qWarning() << "QmlDesigner: Misbehaving view calls back to model!!!";
// FIXME: Enable it again
// Q_ASSERT(!m_model->m_writeLock);
Q_ASSERT(!m_model->m_writeLock);
model->m_writeLock = true;
}
......@@ -909,7 +909,7 @@ WriteLocker::WriteLocker(Model *model)
if (m_model->m_writeLock)
qWarning() << "QmlDesigner: Misbehaving view calls back to model!!!";
// FIXME: Enable it again
// Q_ASSERT(!m_model->m_writeLock);
Q_ASSERT(!m_model->m_writeLock);
m_model->m_writeLock = true;
}
......@@ -918,7 +918,7 @@ WriteLocker::~WriteLocker()
if (!m_model->m_writeLock)
qWarning() << "QmlDesigner: Misbehaving view calls back to model!!!";
// FIXME: Enable it again
// Q_ASSERT(m_model->m_writeLock);
Q_ASSERT(m_model->m_writeLock);
m_model->m_writeLock = false;
}
......
......@@ -314,8 +314,8 @@ QStringList ModelToTextMerger::getPropertyOrder()
{
if (m_propertyOrder.isEmpty()) {
m_propertyOrder
<< QLatin1String("property")
<< QLatin1String("id")
<< QLatin1String("property")
<< QLatin1String("x")
<< QLatin1String("y")
<< QLatin1String("width")
......
......@@ -152,8 +152,6 @@ void RewriterView::modelAboutToBeDetached(Model * /*model*/)
void RewriterView::nodeCreated(const ModelNode &createdNode)
{
if (createdNode.type() == QLatin1String("Qt/Component"))
setupComponent(createdNode);
Q_ASSERT(textModifier());
m_positionStorage->setNodeOffset(createdNode, ModelNodePositionStorage::INVALID_LOCATION);
if (textToModelMerger()->isActive())
......@@ -253,9 +251,6 @@ void RewriterView::bindingPropertiesChanged(const QList<BindingProperty>& proper
void RewriterView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange)
{
if (node.type() == QLatin1String("Qt/Component"))
setupComponent(node);
Q_ASSERT(textModifier());
if (textToModelMerger()->isActive())
return;
......@@ -366,30 +361,6 @@ void RewriterView::applyModificationGroupChanges()
applyChanges();
}
void RewriterView::setupComponent(const ModelNode &node)
{
Q_ASSERT(node.type() == QLatin1String("Qt/Component"));
QString componentText = extractText(QList<ModelNode>() << node).value(node);
if (componentText.isEmpty())
return;
QString result = "";
if (componentText.contains("Component")) { //explicit component
FirstDefinitionFinder firstDefinitionFinder(componentText);
int offset = firstDefinitionFinder(0);
ObjectLengthCalculator objectLengthCalculator(componentText);
int length = objectLengthCalculator(offset);
for (int i = offset;i<offset + length;i++)
result.append(componentText.at(i));
} else {
result = componentText; //implicit component
}
node.variantProperty("__component_data") = result;
}
void RewriterView::applyChanges()
{
if (inErrorState()) {
......
......@@ -29,6 +29,8 @@
#include "abstractproperty.h"
#include "bindingproperty.h"
#include "filemanager/firstdefinitionfinder.h"
#include "filemanager/objectlengthcalculator.h"
#include "nodemetainfo.h"
#include "nodeproperty.h"
#include "propertymetainfo.h"
......@@ -311,7 +313,10 @@ void TextToModelMerger::syncNodeListProperty(NodeListProperty &modelListProperty
// more elements in the dom-list, so add them to the model
QmlDomValue value = domValues.at(j);
if (value.isObject()) {
differenceHandler.listPropertyMissingModelNode(modelListProperty, value.toObject());
const QmlDomObject qmlObject = value.toObject();
const ModelNode newNode = differenceHandler.listPropertyMissingModelNode(modelListProperty, qmlObject);
if (QString::fromUtf8(qmlObject.objectType()) == QLatin1String("Qt/Component"))
setupComponent(newNode);
} else {
qDebug() << "*** Oops, we got a non-object item in the list!";
}
......@@ -412,9 +417,10 @@ void ModelValidator::modelNodeAbsentFromQml(ModelNode &modelNode)
Q_ASSERT(0);
}
void ModelValidator::listPropertyMissingModelNode(NodeListProperty &/*modelProperty*/, const QmlDomObject &/*qmlObject*/)
ModelNode ModelValidator::listPropertyMissingModelNode(NodeListProperty &/*modelProperty*/, const QmlDomObject &/*qmlObject*/)
{
Q_ASSERT(0);
return ModelNode();
}
void ModelValidator::typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject)
......@@ -488,9 +494,11 @@ void ModelAmender::modelNodeAbsentFromQml(ModelNode &modelNode)
modelNode.destroy();
}
void ModelAmender::listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject)
ModelNode ModelAmender::listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject)
{
modelProperty.reparentHere(m_merger->createModelNode(qmlObject, *this));
const ModelNode &newNode = m_merger->createModelNode(qmlObject, *this);
modelProperty.reparentHere(newNode);
return newNode;
}
void ModelAmender::typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject)
......@@ -517,3 +525,27 @@ bool TextToModelMerger::isSignalPropertyName(const QString &signalName)
return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) &&
signalName.at(2).isLetter();
}
void TextToModelMerger::setupComponent(const ModelNode &node)
{
Q_ASSERT(node.type() == QLatin1String("Qt/Component"));
QString componentText = m_rewriterView->extractText(QList<ModelNode>() << node).value(node);
if (componentText.isEmpty())
return;
QString result = "";
if (componentText.contains("Component")) { //explicit component
FirstDefinitionFinder firstDefinitionFinder(componentText);
int offset = firstDefinitionFinder(0);
ObjectLengthCalculator objectLengthCalculator(componentText);
int length = objectLengthCalculator(offset);
for (int i = offset;i<offset + length;i++)
result.append(componentText.at(i));
} else {
result = componentText; //implicit component
}
node.variantProperty("__component_data") = result;
}
......@@ -79,7 +79,9 @@ public:
private:
static bool isSignalPropertyName(const QString &signalName);
void setupComponent(const ModelNode &node);
private:
RewriterView *m_rewriterView;
bool m_isActive;
};
......@@ -100,7 +102,7 @@ public:
virtual void shouldBeVariantProperty(AbstractProperty &modelProperty, const QVariant &qmlVariantValue, const QString &dynamicTypeName) = 0;
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject) = 0;
virtual void modelNodeAbsentFromQml(ModelNode &modelNode) = 0;
virtual void listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject) = 0;
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject) = 0;
virtual void typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject) = 0;
virtual void propertyAbsentFromQml(AbstractProperty &modelProperty) = 0;
virtual void idsDiffer(ModelNode &modelNode, const QString &qmlId) = 0;
......@@ -125,7 +127,7 @@ public:
virtual void shouldBeVariantProperty(AbstractProperty &modelProperty, const QVariant &qmlVariantValue, const QString &dynamicTypeName);
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void modelNodeAbsentFromQml(ModelNode &modelNode);
virtual void listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void typeDiffers(ModelNode &modelNode, const QmlDomObject &domObject);
virtual void propertyAbsentFromQml(AbstractProperty &modelProperty);
virtual void idsDiffer(ModelNode &modelNode, const QString &qmlId);
......@@ -147,7 +149,7 @@ public:
virtual void shouldBeVariantProperty(AbstractProperty &modelProperty, const QVariant &qmlVariantValue, const QString &dynamicTypeName);
virtual void shouldBeNodeProperty(AbstractProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void modelNodeAbsentFromQml(ModelNode &modelNode);
virtual void listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual ModelNode listPropertyMissingModelNode(NodeListProperty &modelProperty, const QmlDomObject &qmlObject);
virtual void typeDiffers(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