Commit b91a46ed authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Move majorQtQuickVersion from ModelNode to AbstractView

It has nothing to do with a ModelNode

Change-Id: I5fd6afd42be8db9e6ac17de9df8777c8f286a9c2
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 96ba1dd4
......@@ -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);
......
......@@ -237,6 +237,8 @@ public:
void setAcutalStateNode(const ModelNode &node);
ModelNode actualStateNode() const;
int majorQtQuickVersion() const;
void resetView();
virtual bool hasWidget() const;
......
......@@ -100,7 +100,6 @@ public:
TypeName simplifiedTypeName() const;
int minorVersion() const;
int majorVersion() const;
int majorQtQuickVersion() const;
bool isValid() const;
bool isInHierarchy() const;
......
......@@ -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
......@@ -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
{
......
......@@ -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);
......
......@@ -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);
......
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