aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp122
1 files changed, 86 insertions, 36 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
index 798baa61ac..2a2c7fce8f 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
@@ -170,31 +170,37 @@ void Qt5InformationNodeInstanceServer::handleSelectionChanged(const QVariant &ob
}
QVector<Qt5InformationNodeInstanceServer::InstancePropertyValueTriple>
-Qt5InformationNodeInstanceServer::vectorToPropertyValue(
+Qt5InformationNodeInstanceServer::propertyToPropertyValueTriples(
const ServerNodeInstance &instance,
const PropertyName &propertyName,
const QVariant &variant)
{
QVector<InstancePropertyValueTriple> result;
-
- auto vector3d = variant.value<QVector3D>();
-
- if (vector3d.isNull())
- return result;
-
- const PropertyName dot = propertyName.isEmpty() ? "" : ".";
-
InstancePropertyValueTriple propTriple;
- propTriple.instance = instance;
- propTriple.propertyName = propertyName + dot + PropertyName("x");
- propTriple.propertyValue = vector3d.x();
- result.append(propTriple);
- propTriple.propertyName = propertyName + dot + PropertyName("y");
- propTriple.propertyValue = vector3d.y();
- result.append(propTriple);
- propTriple.propertyName = propertyName + dot + PropertyName("z");
- propTriple.propertyValue = vector3d.z();
- result.append(propTriple);
+
+ if (variant.type() == QVariant::Vector3D) {
+ auto vector3d = variant.value<QVector3D>();
+
+ if (vector3d.isNull())
+ return result;
+
+ const PropertyName dot = propertyName.isEmpty() ? "" : ".";
+ propTriple.instance = instance;
+ propTriple.propertyName = propertyName + dot + PropertyName("x");
+ propTriple.propertyValue = vector3d.x();
+ result.append(propTriple);
+ propTriple.propertyName = propertyName + dot + PropertyName("y");
+ propTriple.propertyValue = vector3d.y();
+ result.append(propTriple);
+ propTriple.propertyName = propertyName + dot + PropertyName("z");
+ propTriple.propertyValue = vector3d.z();
+ result.append(propTriple);
+ } else {
+ propTriple.instance = instance;
+ propTriple.propertyName = propertyName;
+ propTriple.propertyValue = variant;
+ result.append(propTriple);
+ }
return result;
}
@@ -222,7 +228,7 @@ void Qt5InformationNodeInstanceServer::modifyVariantValue(
instance.setModifiedFlag(false);
// We do have to split position into position.x, position.y, position.z
- ValuesModifiedCommand command = createValuesModifiedCommand(vectorToPropertyValue(
+ ValuesModifiedCommand command = createValuesModifiedCommand(propertyToPropertyValueTriples(
instance,
targetPropertyName,
obj->property(propertyName)));
@@ -361,6 +367,10 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D()
Q_ARG(QVariant, QVariant::fromValue(sceneId)));
updateView3DRect(m_active3DView);
+
+ auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
+ if (helper)
+ helper->storeToolState(helper->globalStateId(), helper->lastSceneIdKey(), QVariant(sceneId), 0);
#endif
}
@@ -457,11 +467,17 @@ void Qt5InformationNodeInstanceServer::doRender3DEditView()
};
updateNodesRecursive(m_editView3DContentItem);
+ // Fake render loop signaling to update things like QML items as 3D textures
+ m_editView3D->beforeSynchronizing();
+ m_editView3D->beforeRendering();
+
QSizeF size = qobject_cast<QQuickItem *>(m_editView3DContentItem)->size();
QRectF renderRect(QPointF(0., 0.), size);
QImage renderImage = designerSupport()->renderImageForItem(m_editView3DContentItem,
renderRect, size.toSize());
+ m_editView3D->afterRendering();
+
// There's no instance related to image, so instance id is -1.
// Key number is selected so that it is unlikely to conflict other ImageContainer use.
const qint32 edit3DKey = 2100000000;
@@ -481,6 +497,7 @@ Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceC
Qt5NodeInstanceServer(nodeInstanceClient)
{
m_propertyChangeTimer.setInterval(100);
+ m_propertyChangeTimer.setSingleShot(true);
m_selectionChangeTimer.setSingleShot(true);
m_renderTimer.setSingleShot(true);
}
@@ -797,19 +814,9 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeIns
add3DViewPorts(instanceList);
add3DScenes(instanceList);
- // Find any scene to show
- if (!m_3DSceneMap.isEmpty()) {
- m_active3DScene = m_3DSceneMap.begin().key();
- m_active3DView = findView3DForSceneRoot(m_active3DScene);
- }
-
createEditView3D();
- if (!m_editView3DRootItem) {
- m_active3DScene = nullptr;
- m_active3DView = nullptr;
- return;
- }
+ QString lastSceneId;
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
if (helper) {
auto it = toolStates.constBegin();
@@ -817,9 +824,31 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeIns
helper->initToolStates(it.key(), it.value());
++it;
}
- if (toolStates.contains(helper->globalStateId())
- && toolStates[helper->globalStateId()].contains("rootSize")) {
- m_editView3DRootItem->setSize(toolStates[helper->globalStateId()]["rootSize"].value<QSize>());
+ if (toolStates.contains(helper->globalStateId())) {
+ if (toolStates[helper->globalStateId()].contains(helper->rootSizeKey()))
+ m_editView3DRootItem->setSize(toolStates[helper->globalStateId()][helper->rootSizeKey()].value<QSize>());
+ if (toolStates[helper->globalStateId()].contains(helper->lastSceneIdKey()))
+ lastSceneId = toolStates[helper->globalStateId()][helper->lastSceneIdKey()].toString();
+ }
+ }
+
+ // Find a scene to show
+ m_active3DScene = nullptr;
+ m_active3DView = nullptr;
+ if (m_editView3DRootItem && !m_3DSceneMap.isEmpty()) {
+ // Restore the previous scene if possible
+ if (!lastSceneId.isEmpty()) {
+ const auto keys = m_3DSceneMap.uniqueKeys();
+ for (const auto key : keys) {
+ m_active3DScene = key;
+ m_active3DView = findView3DForSceneRoot(m_active3DScene);
+ ServerNodeInstance sceneInstance = active3DSceneInstance();
+ if (lastSceneId == sceneInstance.id())
+ break;
+ }
+ } else {
+ m_active3DScene = m_3DSceneMap.begin().key();
+ m_active3DView = findView3DForSceneRoot(m_active3DScene);
}
}
@@ -1224,12 +1253,33 @@ void Qt5InformationNodeInstanceServer::changeIds(const ChangeIdsCommand &command
{
Qt5NodeInstanceServer::changeIds(command);
+#ifdef QUICK3D_MODULE
+ ServerNodeInstance sceneInstance = active3DSceneInstance();
if (m_active3DSceneUpdatePending) {
- ServerNodeInstance sceneInstance = active3DSceneInstance();
const QString sceneId = sceneInstance.id();
if (!sceneId.isEmpty())
updateActiveSceneToEditView3D();
+ } else {
+ qint32 sceneInstanceId = sceneInstance.instanceId();
+ const QVector<IdContainer> ids = command.ids();
+ for (const auto &id : ids) {
+ if (sceneInstanceId == id.instanceId()) {
+ QMetaObject::invokeMethod(m_editView3DRootItem, "handleActiveSceneIdChange",
+ Qt::QueuedConnection,
+ Q_ARG(QVariant, QVariant(sceneInstance.id())));
+ render3DEditView();
+ break;
+ }
+ }
}
+#endif
+}
+
+void Qt5InformationNodeInstanceServer::changeState(const ChangeStateCommand &command)
+{
+ Qt5NodeInstanceServer::changeState(command);
+
+ render3DEditView();
}
// update 3D view size when it changes in creator side
@@ -1241,7 +1291,7 @@ void Qt5InformationNodeInstanceServer::update3DViewState(const Update3dViewState
m_editView3DRootItem->setSize(command.size());
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
if (helper)
- helper->storeToolState(helper->globalStateId(), "rootSize", QVariant(command.size()), 0);
+ helper->storeToolState(helper->globalStateId(), helper->rootSizeKey(), QVariant(command.size()), 0);
// Queue two renders to make sure icon gizmos update properly
render3DEditView(2);
}