Commit ff96f520 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Refactor creation of nodes in the qmlmodelview



Change-Id: Iad331275421a9ff4a693d6f04bb2da793304a48d
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent d5ce90af
...@@ -56,16 +56,6 @@ public: ...@@ -56,16 +56,6 @@ public:
QmlModelState baseState() const; QmlModelState baseState() const;
QmlModelStateGroup rootStateGroup() const; QmlModelStateGroup rootStateGroup() const;
QmlObjectNode createQmlObjectNode(const TypeName &typeString,
int majorVersion,
int minorVersion,
const PropertyListType &propertyList = PropertyListType());
QmlItemNode createQmlItemNode(const TypeName &typeString,
int majorVersion,
int minorVersion,
const PropertyListType &propertyList = PropertyListType());
ModelNode createQmlState(const PropertyListType &propertyList = PropertyListType()); ModelNode createQmlState(const PropertyListType &propertyList = PropertyListType());
QmlItemNode createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode); QmlItemNode createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode);
......
...@@ -80,30 +80,14 @@ QmlModelStateGroup QmlModelView::rootStateGroup() const ...@@ -80,30 +80,14 @@ QmlModelStateGroup QmlModelView::rootStateGroup() const
return QmlModelStateGroup(rootModelNode()); return QmlModelStateGroup(rootModelNode());
} }
QmlObjectNode QmlModelView::createQmlObjectNode(const TypeName &typeString, QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentQmlItemNode)
int majorVersion,
int minorVersion,
const PropertyListType &propertyList)
{ {
return QmlObjectNode(createModelNode(typeString, majorVersion, minorVersion, propertyList)); if (!parentQmlItemNode.isValid() && rootQmlItemNode().isValid())
} parentQmlItemNode = rootQmlItemNode();
QmlItemNode QmlModelView::createQmlItemNode(const TypeName &typeString,
int majorVersion,
int minorVersion,
const PropertyListType &propertyList)
{
return createQmlObjectNode(typeString, majorVersion, minorVersion, propertyList).toQmlItemNode();
}
QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid() && rootQmlItemNode().isValid())
parentNode = rootQmlItemNode();
else else
return QmlItemNode(); return QmlItemNode();
QmlItemNode newNode; QmlItemNode newQmlItemNode;
RewriterTransaction transaction = beginRewriterTransaction(); RewriterTransaction transaction = beginRewriterTransaction();
{ {
const QString newImportUrl = QLatin1String("QtQuick"); const QString newImportUrl = QLatin1String("QtQuick");
...@@ -139,11 +123,11 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c ...@@ -139,11 +123,11 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c
if (metaInfo.isValid()) { if (metaInfo.isValid()) {
int minorVersion = metaInfo.minorVersion(); int minorVersion = metaInfo.minorVersion();
int majorVersion = metaInfo.majorVersion(); int majorVersion = metaInfo.majorVersion();
newNode = createQmlItemNode("QtQuick.Image", majorVersion, minorVersion, propertyPairList); newQmlItemNode = QmlItemNode(createModelNode("QtQuick.Image", majorVersion, minorVersion, propertyPairList));
parentNode.nodeAbstractProperty("data").reparentHere(newNode); parentQmlItemNode.nodeAbstractProperty("data").reparentHere(newQmlItemNode);
} }
Q_ASSERT(newNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
QString id; QString id;
int i = 1; int i = 1;
...@@ -154,28 +138,28 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c ...@@ -154,28 +138,28 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c
i++; i++;
} while (hasId(id)); //If the name already exists count upwards } while (hasId(id)); //If the name already exists count upwards
newNode.setId(id); newQmlItemNode.setId(id);
if (!currentState().isBaseState()) { if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0; newQmlItemNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1); newQmlItemNode.setVariantProperty("opacity", 1);
} }
Q_ASSERT(newNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
} }
Q_ASSERT(newNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
return newNode; return newQmlItemNode;
} }
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode) QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentQmlItemNode)
{ {
if (!parentNode.isValid()) if (!parentQmlItemNode.isValid())
parentNode = rootQmlItemNode(); parentQmlItemNode = rootQmlItemNode();
Q_ASSERT(parentNode.isValid()); Q_ASSERT(parentQmlItemNode.isValid());
QmlItemNode newNode; QmlItemNode newQmlItemNode;
try { try {
RewriterTransaction transaction = beginRewriterTransaction(); RewriterTransaction transaction = beginRewriterTransaction();
...@@ -221,7 +205,7 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE ...@@ -221,7 +205,7 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
foreach (const PropertyContainer &property, itemLibraryEntry.properties()) foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value())); propertyPairList.append(qMakePair(property.name(), property.value()));
newNode = createQmlItemNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList); newQmlItemNode = QmlItemNode(createModelNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList));
} else { } else {
QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model())); QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
inputModel->setFileUrl(model()->fileUrl()); inputModel->setFileUrl(model()->fileUrl());
...@@ -244,15 +228,15 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE ...@@ -244,15 +228,15 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
rootModelNode.variantProperty("y") = propertyPairList.at(1).second; rootModelNode.variantProperty("y") = propertyPairList.at(1).second;
ModelMerger merger(this); ModelMerger merger(this);
newNode = merger.insertModel(rootModelNode); newQmlItemNode = merger.insertModel(rootModelNode);
} }
} }
if (parentNode.hasDefaultProperty()) if (parentQmlItemNode.hasDefaultProperty())
parentNode.nodeAbstractProperty(parentNode.defaultProperty()).reparentHere(newNode); parentQmlItemNode.nodeAbstractProperty(parentQmlItemNode.defaultProperty()).reparentHere(newQmlItemNode);
if (!newNode.isValid()) if (!newQmlItemNode.isValid())
return newNode; return newQmlItemNode;
QString id; QString id;
int i = 1; int i = 1;
...@@ -264,14 +248,14 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE ...@@ -264,14 +248,14 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
i++; i++;
} while (hasId(id)); //If the name already exists count upwards } while (hasId(id)); //If the name already exists count upwards
newNode.setId(id); newQmlItemNode.setId(id);
if (!currentState().isBaseState()) { if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("opacity") = 0; newQmlItemNode.modelNode().variantProperty("opacity") = 0;
newNode.setVariantProperty("opacity", 1); newQmlItemNode.setVariantProperty("opacity", 1);
} }
Q_ASSERT(newNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
} }
catch (RewritingException &e) { catch (RewritingException &e) {
QMessageBox::warning(0, "Error", e.description()); QMessageBox::warning(0, "Error", e.description());
...@@ -281,9 +265,9 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE ...@@ -281,9 +265,9 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
QMessageBox::warning(0, tr("Invalid Id"), e.description()); QMessageBox::warning(0, tr("Invalid Id"), e.description());
} }
Q_ASSERT(newNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
return newNode; return newQmlItemNode;
} }
QmlObjectNode QmlModelView::rootQmlObjectNode() const QmlObjectNode QmlModelView::rootQmlObjectNode() const
......
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