diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientlineqmladaptor.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientlineqmladaptor.cpp index 5ffa7c5994a0927a4425a430df9be80cc80bba2d..cfd9812baf4b80f3a2bf4a06f1712443ca49fe65 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientlineqmladaptor.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientlineqmladaptor.cpp @@ -128,7 +128,7 @@ void GradientLineQmlAdaptor::writeGradient() modelNode.removeProperty(gradientName().toUtf8()); } - ModelNode gradientNode= modelNode.view()->createModelNode("QtQuick.Gradient", modelNode.majorQtQuickVersion(), 0); + ModelNode gradientNode= modelNode.view()->createModelNode("QtQuick.Gradient", modelNode.view()->majorQtQuickVersion(), 0); modelNode.nodeProperty(gradientName().toUtf8()).reparentHere(gradientNode); RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction(); @@ -137,7 +137,7 @@ void GradientLineQmlAdaptor::writeGradient() gradientNode.setId(oldId); for (int i = 0;i < stops.size(); i++) { - ModelNode gradientStopNode = modelNode.view()->createModelNode("QtQuick.GradientStop", modelNode.majorQtQuickVersion(), 0); + ModelNode gradientStopNode = modelNode.view()->createModelNode("QtQuick.GradientStop", modelNode.view()->majorQtQuickVersion(), 0); gradientStopNode.variantProperty("position").setValue(roundReal(stops.at(i).first)); gradientStopNode.variantProperty("color").setValue(normalizeColor(stops.at(i).second)); gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode); diff --git a/src/plugins/qmldesigner/designercore/include/abstractview.h b/src/plugins/qmldesigner/designercore/include/abstractview.h index 69a9da8ef55978d6f9273a04b77516d9e3bdbde8..d29f3e4b6e828a9badd9bbc1d24dffe43547a0b7 100644 --- a/src/plugins/qmldesigner/designercore/include/abstractview.h +++ b/src/plugins/qmldesigner/designercore/include/abstractview.h @@ -237,6 +237,8 @@ public: void setAcutalStateNode(const ModelNode &node); ModelNode actualStateNode() const; + int majorQtQuickVersion() const; + void resetView(); virtual bool hasWidget() const; diff --git a/src/plugins/qmldesigner/designercore/include/modelnode.h b/src/plugins/qmldesigner/designercore/include/modelnode.h index 309521b62853f3ccbfe4da5248916714b624501d..63b63c4ad5f269daa0efab52e8cd06512cff23fd 100644 --- a/src/plugins/qmldesigner/designercore/include/modelnode.h +++ b/src/plugins/qmldesigner/designercore/include/modelnode.h @@ -100,7 +100,6 @@ public: TypeName simplifiedTypeName() const; int minorVersion() const; int majorVersion() const; - int majorQtQuickVersion() const; bool isValid() const; bool isInHierarchy() const; diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index e37635eb992d5dfebd01ef20fc27d13d30b67dd8..4e8eac4e9a1f420fa6d5a29e72e2d0989b6af814 100644 --- a/src/plugins/qmldesigner/designercore/model/abstractview.cpp +++ b/src/plugins/qmldesigner/designercore/model/abstractview.cpp @@ -528,4 +528,43 @@ ModelNode AbstractView::actualStateNode() const return ModelNode(); } +static int getMajorVersionFromImport(const Model *model) +{ + foreach (const Import &import, model->imports()) { + if (import.isLibraryImport() && import.url() == QLatin1String("QtQuick")) { + const QString versionString = import.version(); + if (versionString.contains(QLatin1String("."))) { + const QString majorVersionString = versionString.split(QLatin1String(".")).first(); + return majorVersionString.toInt(); + } + } + } + + return -1; +} + +static int getMajorVersionFromNode(const ModelNode &modelNode) +{ + if (modelNode.metaInfo().isValid()) { + if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") + return modelNode.majorVersion(); + + foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) { + if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") + return superClass.majorVersion(); + } + } + + return 1; //default +} + +int AbstractView::majorQtQuickVersion() const +{ + int majorVersionFromImport = getMajorVersionFromImport(model()); + if (majorVersionFromImport >= 0) + return majorVersionFromImport; + + return getMajorVersionFromNode(rootModelNode()); +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/model/modelnode.cpp b/src/plugins/qmldesigner/designercore/model/modelnode.cpp index c25ff30b17486c977e4c07a4d200a6e03518dd9b..06a016f4fed8c7462f99cb65cac56daff2772610 100644 --- a/src/plugins/qmldesigner/designercore/model/modelnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/modelnode.cpp @@ -232,54 +232,6 @@ int ModelNode::majorVersion() const return m_internalNode->majorVersion(); } -int getMajorVersionFromImport(Model *model) -{ - foreach (const Import &import, model->imports()) { - if (import.isLibraryImport() && import.url() == QLatin1String("QtQuick")) { - const QString versionString = import.version(); - if (versionString.contains(QLatin1String("."))) { - const QString majorVersionString = versionString.split(QLatin1String(".")).first(); - return majorVersionString.toInt(); - } - } - } - - return -1; -} - -int getMajorVersionFromNode(const ModelNode &modelNode) -{ - if (modelNode.metaInfo().isValid()) { - if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") - return modelNode.majorVersion(); - - foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) { - if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") - return superClass.majorVersion(); - } - } - - return 1; //default -} - -/*! \brief major number of the QtQuick version used -\return major number of QtQuickVersion -*/ -int ModelNode::majorQtQuickVersion() const -{ - if (!isValid()) { - Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid"); - throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); - } - - int majorVersionFromImport = getMajorVersionFromImport(model()); - if (majorVersionFromImport >= 0) - return majorVersionFromImport; - - return getMajorVersionFromNode(*this); -} - - /*! \return the short-hand type name of the node. */ TypeName ModelNode::simplifiedTypeName() const { diff --git a/src/plugins/qmldesigner/designercore/model/qmlmodelview.cpp b/src/plugins/qmldesigner/designercore/model/qmlmodelview.cpp index c027ced50063fac4e57e31698fcfa2d1985e48a6..ac74264058b2d470972ec5189a1ffd0cabc57cf4 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlmodelview.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlmodelview.cpp @@ -288,9 +288,9 @@ bool QmlModelView::hasInstanceForModelNode(const ModelNode &modelNode) ModelNode QmlModelView::createQmlState(const QmlDesigner::PropertyListType &propertyList) { - QTC_CHECK(rootModelNode().majorQtQuickVersion() < 3); + QTC_CHECK(majorQtQuickVersion() < 3); - if (rootModelNode().majorQtQuickVersion() > 1) + if (majorQtQuickVersion() > 1) return createModelNode("QtQuick.State", 2, 0, propertyList); else return createModelNode("QtQuick.State", 1, 0, propertyList); diff --git a/src/plugins/qmldesigner/designercore/model/qmlstate.cpp b/src/plugins/qmldesigner/designercore/model/qmlstate.cpp index 57907c92355f90de8624682ffd61a1a6fd1d9089..406c84f795bfc7012e80fa988dcc3079afc0ce25 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlstate.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlstate.cpp @@ -179,7 +179,7 @@ void QmlModelState::addChangeSetIfNotExists(const ModelNode &node) return; //changeSet already there ModelNode newChangeSet; - if (qmlModelView()->rootModelNode().majorQtQuickVersion() > 1) + if (qmlModelView()->majorQtQuickVersion() > 1) newChangeSet = modelNode().view()->createModelNode("QtQuick.PropertyChanges", 2, 0); else newChangeSet = modelNode().view()->createModelNode("QtQuick.PropertyChanges", 1, 0);