blob: e8d3aa15569d83ffe69b0ba0bdafd9393482409f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qml3dnode.h"
#include "auxiliarydataproperties.h"
#include "bindingproperty.h"
#include "invalidmodelnodeexception.h"
#include "itemlibraryinfo.h"
#include "nodehints.h"
#include "nodelistproperty.h"
#include "qmlanchors.h"
#include "qmlchangeset.h"
#include "variantproperty.h"
#include <metainfo.h>
#include "plaintexteditmodifier.h"
#include "rewriterview.h"
#include "modelmerger.h"
#include "rewritingexception.h"
#include <QUrl>
#include <QPlainTextEdit>
#include <QFileInfo>
#include <QDir>
namespace QmlDesigner {
bool Qml3DNode::isValid() const
{
return isValidQml3DNode(modelNode());
}
bool Qml3DNode::isValidQml3DNode(const ModelNode &modelNode)
{
return isValidQmlObjectNode(modelNode) && (modelNode.metaInfo().isQtQuick3DNode());
}
bool Qml3DNode::isValidVisualRoot(const ModelNode &modelNode)
{
return isValidQmlObjectNode(modelNode)
&& (modelNode.metaInfo().isQtQuick3DNode() || modelNode.metaInfo().isQtQuick3DMaterial());
}
void Qml3DNode::setVariantProperty(const PropertyName &name, const QVariant &value)
{
if (isBlocked(name))
return;
if (name.startsWith("eulerRotation"))
handleEulerRotationSet();
QmlObjectNode::setVariantProperty(name, value);
}
void Qml3DNode::setBindingProperty(const PropertyName &name, const QString &expression)
{
if (isBlocked(name))
return;
if (name.startsWith("eulerRotation"))
handleEulerRotationSet();
QmlObjectNode::setBindingProperty(name, expression);
}
bool Qml3DNode::isBlocked(const PropertyName &propName) const
{
if (modelNode().isValid() && propName.startsWith("eulerRotation"))
return modelNode().auxiliaryDataWithDefault(rotBlockProperty).toBool();
return false;
}
void Qml3DNode::handleEulerRotationSet()
{
ModelNode node = modelNode();
// The rotation property is quaternion, which is difficult to deal with for users, so QDS
// only supports eulerRotation. Since having both on the same object isn't supported,
// remove the rotation property if eulerRotation is set.
if (node.isValid() && node.metaInfo().isQtQuick3DNode()) {
if (!isInBaseState()) {
QmlPropertyChanges changeSet(currentState().propertyChanges(node));
Q_ASSERT(changeSet.isValid());
node = changeSet.modelNode();
}
if (node.hasProperty("rotation")) {
// We need to reset the eulerRotation values as removing rotation will zero them,
// which is not desirable if the change only targets one of the xyz subproperties.
// Get the eulerRotation value from instance, as they are not available in model.
QVector3D eulerVec = instanceValue("eulerRotation").value<QVector3D>();
node.removeProperty("rotation");
if (qIsNaN(eulerVec.x()))
eulerVec.setX(0.);
if (qIsNaN(eulerVec.y()))
eulerVec.setY(0.);
if (qIsNaN(eulerVec.z()))
eulerVec.setZ(0.);
node.variantProperty("eulerRotation.x").setValue(eulerVec.x());
node.variantProperty("eulerRotation.y").setValue(eulerVec.y());
node.variantProperty("eulerRotation.z").setValue(eulerVec.z());
}
}
}
QList<ModelNode> toModelNodeList(const QList<Qml3DNode> &qmlVisualNodeList)
{
QList<ModelNode> modelNodeList;
for (const Qml3DNode &qml3DNode : qmlVisualNodeList)
modelNodeList.append(qml3DNode.modelNode());
return modelNodeList;
}
QList<Qml3DNode> toQml3DNodeList(const QList<ModelNode> &modelNodeList)
{
QList<Qml3DNode> qml3DNodeList;
for (const ModelNode &modelNode : modelNodeList) {
if (Qml3DNode::isValidQml3DNode(modelNode))
qml3DNodeList.append(modelNode);
}
return qml3DNodeList;
}
} //QmlDesigner
|