Commit 43f2c77a authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: fixing states for Qt Quick 2.0

Depending on the import we have QtQuick.State.1.0 or
QtQuick.State.2.0.

We use majorQtQuickVersion to distinguish between 1.0/2.0.

QmlModelNodeFacade::qmlModelView() is made public for convenience.

Change-Id: Ice53f4985ed4fe1475e2155c16a70988d413e2e7
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 80eae788
......@@ -138,8 +138,9 @@ void StatesEditorView::addState()
try {
if ((rootStateGroup().allStates().count() < 1) && //QtQuick import might be missing
(!model()->hasImport(Import::createLibraryImport("QtQuick", "1.0"), true) &&
!model()->hasImport(Import::createLibraryImport("QtQuick", "1.1"), true)))
(!model()->hasImport(Import::createLibraryImport("QtQuick", "1.0"), true)
&& !model()->hasImport(Import::createLibraryImport("QtQuick", "1.1"), true)
&& !model()->hasImport(Import::createLibraryImport("QtQuick", "2.0"), true)))
model()->changeImports(QList<Import>() << Import::createLibraryImport("QtQuick", "1.0"), QList<Import>());
ModelNode newState = rootStateGroup().addState(newStateName);
setCurrentState(newState);
......
......@@ -48,10 +48,10 @@ public:
QmlModelNodeFacade();
bool isRootNode() const;
QmlModelView* qmlModelView() const;
protected:
QmlModelNodeFacade(const ModelNode &modelNode);
QmlModelView* qmlModelView() const;
private:
ModelNode m_modelNode;
......
......@@ -68,6 +68,8 @@ public:
int minorVersion,
const PropertyListType &propertyList = PropertyListType());
ModelNode createQmlState(const PropertyListType &propertyList = PropertyListType());
QmlItemNode createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode);
QmlItemNode createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode);
......
......@@ -329,7 +329,7 @@ QmlModelState QmlModelStateGroup::addState(const QString &name)
PropertyListType propertyList;
propertyList.append(qMakePair(QString("name"), QVariant(name)));
ModelNode newState = modelNode().view()->createModelNode("QtQuick.State", 1, 0, propertyList);
ModelNode newState = QmlObjectNode(modelNode()).qmlModelView()->createQmlState(propertyList);
modelNode().nodeListProperty("states").reparentHere(newState);
return newState;
......
......@@ -47,6 +47,8 @@
#include "plaintexteditmodifier.h"
#include "modelmerger.h"
#include <utils/qtcassert.h>
namespace QmlDesigner {
QmlModelView::QmlModelView(QObject *parent)
......@@ -465,5 +467,17 @@ void QmlModelView::otherPropertyChanged(const QmlObjectNode &/*qmlObjectNode*/,
{
}
ModelNode QmlModelView::createQmlState(const QmlDesigner::PropertyListType &propertyList)
{
QTC_ASSERT(rootModelNode().majorQtQuickVersion() < 3);
if (rootModelNode().majorQtQuickVersion() > 1) {
return createModelNode("QtQuick.State", 2, 0, propertyList);
} else {
return createModelNode("QtQuick.State", 1, 0, propertyList);
}
}
} //QmlDesigner
......@@ -178,7 +178,13 @@ void QmlModelState::addChangeSetIfNotExists(const ModelNode &node)
return; //changeSet already there
}
ModelNode newChangeSet = modelNode().view()->createModelNode("QtQuick.PropertyChanges", 1, 0);
ModelNode newChangeSet;
if (qmlModelView()->rootModelNode().majorQtQuickVersion() > 1) {
newChangeSet = modelNode().view()->createModelNode("QtQuick.PropertyChanges", 2, 0);
} else {
newChangeSet = modelNode().view()->createModelNode("QtQuick.PropertyChanges", 1, 0);
}
modelNode().nodeListProperty("changes").reparentHere(newChangeSet);
QmlPropertyChanges(newChangeSet).setTarget(node);
......@@ -245,7 +251,7 @@ bool QmlModelState::isValid() const
{
return QmlModelNodeFacade::isValid() &&
modelNode().metaInfo().isValid() &&
(modelNode().metaInfo().isSubclassOf("QtQuick.State", 1, 0) || isBaseState());
(modelNode().metaInfo().isSubclassOf("QtQuick.State", -1, -1) || isBaseState());
}
/**
......@@ -279,7 +285,7 @@ QmlModelState QmlModelState::duplicate(const QString &name) const
// QmlModelState newState(stateGroup().addState(name));
PropertyListType propertyList;
propertyList.append(qMakePair(QString("name"), QVariant(name)));
QmlModelState newState ( qmlModelView()->createModelNode("QtQuick.State", 1, 0, propertyList) );
QmlModelState newState ( qmlModelView()->createQmlState(propertyList) );
foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) {
ModelNode newModelNode(qmlModelView()->createModelNode(childNode.type(), childNode.majorVersion(), childNode.minorVersion()));
......
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