From 6251730f8f6def8afa019bc4beb01586d13fe74b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 4 Sep 2023 17:08:37 +0300 Subject: [PATCH] QmlDesigner: Refactor 3D view background and grid color implementation The new implementation doesn't require these colors to be stored in external dependencies anymore, as auxiliary properties are used for them instead. Fixes: QDS-10496 Change-Id: Ie71408617259d1af73a45f327d4bdfa4f2fa3a2b Reviewed-by: Mahmoud Badri --- .../commands/createscenecommand.h | 12 +- .../interfaces/nodeinstanceglobal.h | 3 - .../edit3d/backgroundcolorselection.cpp | 14 +-- .../edit3d/backgroundcolorselection.h | 11 +- .../components/edit3d/edit3dactions.cpp | 4 +- .../components/edit3d/edit3dview.cpp | 31 +++-- .../components/edit3d/edit3dviewconfig.h | 17 ++- .../include/externaldependenciesinterface.h | 2 - .../instances/nodeinstanceview.cpp | 7 +- .../qmldesignerexternaldependencies.cpp | 14 --- .../qmldesignerexternaldependencies.h | 2 - .../qml2puppet/mockfiles/qt6/EditView3D.qml | 36 +++--- .../qml2puppet/editor3d/generalhelper.cpp | 13 ++ .../qml2puppet/editor3d/generalhelper.h | 9 +- .../qt5informationnodeinstanceserver.cpp | 114 ++++++++++-------- .../qt5informationnodeinstanceserver.h | 2 + .../qmldesigner/coretests/tst_testcore.cpp | 2 - .../tests/mocks/externaldependenciesmock.h | 2 - 18 files changed, 153 insertions(+), 142 deletions(-) diff --git a/src/libs/qmlpuppetcommunication/commands/createscenecommand.h b/src/libs/qmlpuppetcommunication/commands/createscenecommand.h index ada540829c3..f052da1eaaa 100644 --- a/src/libs/qmlpuppetcommunication/commands/createscenecommand.h +++ b/src/libs/qmlpuppetcommunication/commands/createscenecommand.h @@ -38,9 +38,7 @@ public: const QString &language, QSize captureImageMinimumSize, QSize captureImageMaximumSize, - qint32 stateInstanceId, - const QList &edit3dBackgroundColor, - const QColor &edit3dGridColor) + qint32 stateInstanceId) : instances(instanceContainer) , reparentInstances(reparentContainer) , ids(idVector) @@ -56,8 +54,6 @@ public: , captureImageMinimumSize(captureImageMinimumSize) , captureImageMaximumSize(captureImageMaximumSize) , stateInstanceId{stateInstanceId} - , edit3dBackgroundColor{edit3dBackgroundColor} - , edit3dGridColor{edit3dGridColor} {} friend QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command) @@ -77,8 +73,6 @@ public: out << command.stateInstanceId; out << command.captureImageMinimumSize; out << command.captureImageMaximumSize; - out << command.edit3dBackgroundColor; - out << command.edit3dGridColor; return out; } @@ -100,8 +94,6 @@ public: in >> command.stateInstanceId; in >> command.captureImageMinimumSize; in >> command.captureImageMaximumSize; - in >> command.edit3dBackgroundColor; - in >> command.edit3dGridColor; return in; } @@ -122,8 +114,6 @@ public: QSize captureImageMinimumSize; QSize captureImageMaximumSize; qint32 stateInstanceId = 0; - QList edit3dBackgroundColor; - QColor edit3dGridColor; }; QDebug operator<<(QDebug debug, const CreateSceneCommand &command); diff --git a/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h b/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h index 67f0fa4c5c2..6e25b3b419c 100644 --- a/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h +++ b/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h @@ -44,9 +44,6 @@ enum class View3DActionType { ParticlesPlay, ParticlesRestart, ParticlesSeek, - SelectBackgroundColor, - SelectGridColor, - ResetBackgroundColor, SyncBackgroundColor, GetNodeAtPos, SetBakeLightsView3D diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp index a50966292fa..74f2417bd16 100644 --- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp +++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.cpp @@ -13,13 +13,13 @@ using namespace QmlDesigner; void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType, + const AuxiliaryDataKeyView &auxProp, const std::function &colorSelected) { if (m_dialog) return; - m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, actionType, colorSelected); + m_dialog = BackgroundColorSelection::createColorDialog(parent, key, view, auxProp, colorSelected); QTC_ASSERT(m_dialog, return); QObject::connect(m_dialog, &QWidget::destroyed, m_dialog, [&]() { @@ -30,7 +30,7 @@ void BackgroundColorSelection::showBackgroundColorSelectionWidget(QWidget *paren QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType, + const AuxiliaryDataKeyView &auxProp, const std::function &colorSelected) { auto dialog = new QColorDialog(parent); @@ -43,8 +43,8 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, dialog->show(); QObject::connect(dialog, &QColorDialog::currentColorChanged, dialog, - [actionType, view](const QColor &color) { - Edit3DViewConfig::setColors(view, actionType, {color}); + [auxProp, view](const QColor &color) { + Edit3DViewConfig::setColors(view, auxProp, {color}); }); QObject::connect(dialog, &QColorDialog::colorSelected, dialog, @@ -57,8 +57,8 @@ QColorDialog *BackgroundColorSelection::createColorDialog(QWidget *parent, if (Edit3DViewConfig::colorsValid(oldColorConfig)) { QObject::connect(dialog, &QColorDialog::rejected, dialog, - [actionType, oldColorConfig, view]() { - Edit3DViewConfig::setColors(view, actionType, oldColorConfig); + [auxProp, oldColorConfig, view]() { + Edit3DViewConfig::setColors(view, auxProp, oldColorConfig); }); } diff --git a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h index efed2e661ef..8bdc816220a 100644 --- a/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h +++ b/src/plugins/qmldesigner/components/edit3d/backgroundcolorselection.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -13,6 +13,11 @@ QT_FORWARD_DECLARE_CLASS(QColorDialog) namespace QmlDesigner { class AbstractView; +inline constexpr AuxiliaryDataKeyView edit3dGridColorProperty{AuxiliaryDataType::NodeInstanceAuxiliary, + "edit3dGridColor"}; +inline constexpr AuxiliaryDataKeyView edit3dBgColorProperty{AuxiliaryDataType::NodeInstanceAuxiliary, + "edit3dBgColor"}; + class BackgroundColorSelection : public QObject { Q_OBJECT @@ -25,14 +30,14 @@ public: static void showBackgroundColorSelectionWidget(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType, + const AuxiliaryDataKeyView &auxProp, const std::function &colorSelected = {}); private: static QColorDialog *createColorDialog(QWidget *parent, const QByteArray &key, AbstractView *view, - View3DActionType actionType, + const AuxiliaryDataKeyView &auxProp, const std::function &colorSelected); inline static QColorDialog *m_dialog = nullptr; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp index 4ffdf0e801c..add61d195de 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dactions.cpp @@ -25,10 +25,8 @@ Edit3DActionTemplate::Edit3DActionTemplate(const QString &description, void Edit3DActionTemplate::actionTriggered(bool b) { - if (m_type != View3DActionType::Empty && m_type != View3DActionType::SelectBackgroundColor - && m_type != View3DActionType::SelectGridColor) { + if (m_type != View3DActionType::Empty) m_view->emitView3DAction(m_type, b); - } if (m_action) m_action(m_selectionContext); diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index 588aad00c1d..3b1c282148b 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -119,6 +119,7 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState) const QString cameraFrustumKey = QStringLiteral("showCameraFrustum"); const QString particleEmitterKey = QStringLiteral("showParticleEmitter"); const QString particlesPlayKey = QStringLiteral("particlePlay"); + const QString syncBgColorKey = QStringLiteral("syncBackgroundColor"); if (sceneState.contains(sceneKey)) { qint32 newActiveScene = sceneState[sceneKey].value(); @@ -189,6 +190,11 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState) else m_particlesPlayAction->action()->setChecked(true); + if (sceneState.contains(syncBgColorKey)) + m_syncBackgroundColorAction->action()->setChecked(sceneState[syncBgColorKey].toBool()); + else + m_syncBackgroundColorAction->action()->setChecked(true); + // Selection context change updates visible and enabled states SelectionContext selectionContext(this); selectionContext.setUpdateMode(SelectionContext::UpdateMode::Fast); @@ -202,6 +208,13 @@ void Edit3DView::modelAttached(Model *model) syncSnapAuxPropsToSettings(); + rootModelNode().setAuxiliaryData(edit3dGridColorProperty, + QVariant::fromValue(Edit3DViewConfig::loadColor( + DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR))); + rootModelNode().setAuxiliaryData(edit3dBgColorProperty, + QVariant::fromValue(Edit3DViewConfig::loadColor( + DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR))); + checkImports(); auto cachedImage = m_canvasCache.take(model); if (cachedImage) { @@ -423,10 +436,10 @@ void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorA edit3DWidget(), DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, this, - View3DActionType::SelectBackgroundColor, + edit3dBgColorProperty, [this, syncBackgroundColorAction]() { if (syncBackgroundColorAction->isChecked()) { - Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); + emitView3DAction(View3DActionType::SyncBackgroundColor, false); syncBackgroundColorAction->setChecked(false); } }); @@ -434,7 +447,7 @@ void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorA m_selectBackgroundColorAction = std::make_unique( Constants::EDIT3D_EDIT_SELECT_BACKGROUND_COLOR, - View3DActionType::SelectBackgroundColor, + View3DActionType::Empty, description, QKeySequence(), false, @@ -456,12 +469,12 @@ void Edit3DView::createGridColorSelectionAction() edit3DWidget(), DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, this, - View3DActionType::SelectGridColor); + edit3dGridColorProperty); }; m_selectGridColorAction = std::make_unique( Constants::EDIT3D_EDIT_SELECT_GRID_COLOR, - View3DActionType::SelectGridColor, + View3DActionType::Empty, description, QKeySequence(), false, @@ -481,22 +494,22 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { QList bgColors = {QRgb(0x222222), QRgb(0x999999)}; - Edit3DViewConfig::setColors(this, View3DActionType::SelectBackgroundColor, bgColors); + Edit3DViewConfig::setColors(this, edit3dBgColorProperty, bgColors); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); QColor gridColor{0xaaaaaa}; - Edit3DViewConfig::setColors(this, View3DActionType::SelectGridColor, {gridColor}); + Edit3DViewConfig::setColors(this, edit3dGridColorProperty, {gridColor}); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor}); if (syncBackgroundColorAction->isChecked()) { - Edit3DViewConfig::set(this, View3DActionType::SyncBackgroundColor, false); + emitView3DAction(View3DActionType::SyncBackgroundColor, false); syncBackgroundColorAction->setChecked(false); } }; m_resetColorAction = std::make_unique( QmlDesigner::Constants::EDIT3D_EDIT_RESET_BACKGROUND_COLOR, - View3DActionType::ResetBackgroundColor, + View3DActionType::Empty, description, QKeySequence(), false, diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h index 5c461cc7327..2783cba08bc 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dviewconfig.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -38,20 +38,20 @@ public: QmlDesignerPlugin::settings().insert(key, value); } - static void setColors(AbstractView *view, View3DActionType type, const QList &colorConfig) + static void setColors(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const QList &colorConfig) { QVariant param; - if (type == View3DActionType::SelectGridColor) + if (auxProp.name == "edit3dGridColor") param = colorConfig.isEmpty() ? QColor() : colorConfig[0]; else param = QVariant::fromValue(colorConfig); - setVariant(view, type, param); + setVariant(view, auxProp, param); } template - static void set(AbstractView *view, View3DActionType type, const T &value) + static void set(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const T &value) { - setVariant(view, type, QVariant::fromValue(value)); + setVariant(view, auxProp, QVariant::fromValue(value)); } static void saveColors(const QByteArray &key, const QList &colorConfig) @@ -66,11 +66,10 @@ public: static bool colorsValid(const QList &colorConfig) { return !colorConfig.isEmpty(); } private: - static void setVariant(AbstractView *view, View3DActionType type, const QVariant &value) + static void setVariant(AbstractView *view, const AuxiliaryDataKeyView &auxProp, const QVariant &value) { - view->emitView3DAction(type, value); + view->rootModelNode().setAuxiliaryData(auxProp, value); } - }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/include/externaldependenciesinterface.h b/src/plugins/qmldesigner/designercore/include/externaldependenciesinterface.h index d4a087f4c7b..eecbdd96b8f 100644 --- a/src/plugins/qmldesigner/designercore/include/externaldependenciesinterface.h +++ b/src/plugins/qmldesigner/designercore/include/externaldependenciesinterface.h @@ -29,8 +29,6 @@ public: virtual QString defaultPuppetToplevelBuildDirectory() const = 0; virtual QUrl projectUrl() const = 0; virtual QString currentProjectDirPath() const = 0; - virtual QList designerSettingsEdit3DViewBackgroundColor() const = 0; - virtual QColor designerSettingsEdit3DViewGridColor() const = 0; virtual QUrl currentResourcePath() const = 0; virtual void parseItemLibraryDescriptions() = 0; virtual const DesignerSettings &designerSettings() const = 0; diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index d49ed5b7d46..42c0a4263a2 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -1182,9 +1182,6 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand() if (stateNode.isValid() && stateNode.metaInfo().isQtQuickState()) stateInstanceId = stateNode.internalId(); - QColor gridColor = m_externalDependencies.designerSettingsEdit3DViewGridColor(); - QList backgroundColor = m_externalDependencies.designerSettingsEdit3DViewBackgroundColor(); - return CreateSceneCommand(instanceContainerList, reparentContainerList, idContainerList, @@ -1199,9 +1196,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand() lastUsedLanguage, m_captureImageMinimumSize, m_captureImageMaximumSize, - stateInstanceId, - backgroundColor, - gridColor); + stateInstanceId); } ClearSceneCommand NodeInstanceView::createClearSceneCommand() const diff --git a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp index a703f838663..4b2cd9212b3 100644 --- a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp +++ b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp @@ -62,20 +62,6 @@ QString ExternalDependencies::currentProjectDirPath() const return QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString(); } -QList ExternalDependencies::designerSettingsEdit3DViewBackgroundColor() const -{ - return Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR); -} - -QColor ExternalDependencies::designerSettingsEdit3DViewGridColor() const -{ - QList gridColorList = Edit3DViewConfig::loadColor(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR); - if (!gridColorList.isEmpty()) - return gridColorList.front(); - - return {}; -} - QUrl ExternalDependencies::currentResourcePath() const { return QUrl::fromLocalFile( diff --git a/src/plugins/qmldesigner/qmldesignerexternaldependencies.h b/src/plugins/qmldesigner/qmldesignerexternaldependencies.h index 0f6acf2c106..13317075027 100644 --- a/src/plugins/qmldesigner/qmldesignerexternaldependencies.h +++ b/src/plugins/qmldesigner/qmldesignerexternaldependencies.h @@ -22,8 +22,6 @@ public: QString defaultPuppetToplevelBuildDirectory() const override; QUrl projectUrl() const override; QString currentProjectDirPath() const override; - QList designerSettingsEdit3DViewBackgroundColor() const override; - QColor designerSettingsEdit3DViewGridColor() const override; QUrl currentResourcePath() const override; void parseItemLibraryDescriptions() override; const DesignerSettings &designerSettings() const override; diff --git a/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml b/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml index 14f1bb2037a..9de033e5349 100644 --- a/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml +++ b/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml @@ -136,6 +136,11 @@ Item { } } + if (syncBackgroundColor) + updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]); + else + updateBackgroundColors(_generalHelper.bgColor); + notifyActiveSceneChange(); } } @@ -191,21 +196,14 @@ Item { cameraControl.alignView(cameraNodes); } - function updateViewStates(viewStates) - { - if ("selectBackgroundColor" in viewStates) { - var colors = viewStates.selectBackgroundColor - if (colors.length === 1) { - backgroundGradientColorStart = colors[0]; - backgroundGradientColorEnd = colors[0]; - } else { - backgroundGradientColorStart = colors[0]; - backgroundGradientColorEnd = colors[1]; - } + function updateBackgroundColors(colors) { + if (colors.length === 1) { + backgroundGradientColorStart = colors[0]; + backgroundGradientColorEnd = colors[0]; + } else { + backgroundGradientColorStart = colors[0]; + backgroundGradientColorEnd = colors[1]; } - - if ("selectGridColor" in viewStates) - viewRoot.gridColor = viewStates.selectGridColor } // If resetToDefault is true, tool states not specifically set to anything will be reset to @@ -224,13 +222,13 @@ Item { if ("syncBackgroundColor" in toolStates) { syncBackgroundColor = toolStates.syncBackgroundColor; - if (syncBackgroundColor) { - var color = []; - color[0] = _generalHelper.sceneEnvironmentColor(sceneId); - updateViewStates({"selectBackgroundColor": color}); - } + if (syncBackgroundColor) + updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]); + else + updateBackgroundColors(_generalHelper.bgColor); } else if (resetToDefault) { syncBackgroundColor = false; + updateBackgroundColors(_generalHelper.bgColor); } if ("showSelectionBox" in toolStates) diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp index 7e53a766c3e..099855384d5 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp @@ -568,6 +568,11 @@ QColor GeneralHelper::sceneEnvironmentColor(const QString &sceneId) const return m_sceneEnvironmentColor[sceneId]; } +void GeneralHelper::clearSceneEnvironmentColors() +{ + m_sceneEnvironmentColor.clear(); +} + void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates) { m_toolStates[sceneId] = toolStates; @@ -977,6 +982,14 @@ QVector3D GeneralHelper::adjustScaleForSnap(const QVector3D &newScale) return adjScale; } +void GeneralHelper::setBgColor(const QVariant &colors) +{ + if (m_bgColor != colors) { + m_bgColor = colors; + emit bgColorChanged(); + } +} + void GeneralHelper::handlePendingToolStateUpdate() { m_toolStateUpdateTimer.stop(); diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h index 70605345c0c..a2416c82799 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h @@ -32,6 +32,7 @@ class GeneralHelper : public QObject { Q_OBJECT Q_PROPERTY(bool isMacOS READ isMacOS CONSTANT) + Q_PROPERTY(QVariant bgColor READ bgColor NOTIFY bgColorChanged FINAL) public: GeneralHelper(); @@ -94,6 +95,7 @@ public: void setSceneEnvironmentColor(const QString &sceneId, const QColor &color); Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const; + void clearSceneEnvironmentColors(); bool isMacOS() const; @@ -118,13 +120,16 @@ public: void setSnapRotationInterval(double interval) { m_snapRotationInterval = interval; } void setSnapScaleInterval(double interval) { m_snapScaleInterval = interval / 100.; } + void setBgColor(const QVariant &colors); + QVariant bgColor() const { return m_bgColor; } + signals: void overlayUpdateNeeded(); void toolStateChanged(const QString &sceneId, const QString &tool, const QVariant &toolState); void hiddenStateChanged(QQuick3DNode *node); void lockedStateChanged(QQuick3DNode *node); void rotationBlocksChanged(); - + void bgColorChanged(); private: void handlePendingToolStateUpdate(); QVector3D pivotScenePosition(QQuick3DNode *node) const; @@ -159,6 +164,8 @@ private: double m_snapPositionInterval = 50.; double m_snapRotationInterval = 5.; double m_snapScaleInterval = .1; + + QVariant m_bgColor; }; } diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 203a2971ea5..5d198a2ca70 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -393,6 +393,25 @@ void Qt5InformationNodeInstanceServer::updateSnapSettings(const QVector &valueChanges) +{ +#ifdef QUICK3D_MODULE + if (m_editView3DData.rootItem) { + for (const auto &container : valueChanges) { + if (container.name() == "edit3dGridColor") { + QQmlProperty gridProp(m_editView3DData.rootItem, "gridColor", context()); + gridProp.write(container.value()); + } else if (container.name() == "edit3dBgColor") { + QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors", + Q_ARG(QVariant, container.value())); + if (auto helper = qobject_cast(m_3dHelper)) + helper->setBgColor(container.value()); + } + } + } +#endif +} + void Qt5InformationNodeInstanceServer::removeRotationBlocks( [[maybe_unused]] const QVector &instanceIds) { @@ -943,20 +962,8 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D([[maybe_unu updateView3DRect(m_active3DView); - auto helper = qobject_cast(m_3dHelper); - if (helper) { + if (auto helper = qobject_cast(m_3dHelper)) helper->storeToolState(helper->globalStateId(), helper->lastSceneIdKey(), QVariant(sceneId), 0); - QVariantMap toolStates = helper->getToolStates(sceneId); - if (toolStates.contains("syncBackgroundColor")) { - bool sync = toolStates["syncBackgroundColor"].toBool(); - if (sync) { - QList colors{helper->sceneEnvironmentColor(sceneId)}; - View3DActionCommand cmd(View3DActionType::SelectBackgroundColor, - QVariant::fromValue(colors)); - view3DAction(cmd); - } - } - } #endif } @@ -1036,6 +1043,9 @@ void Qt5InformationNodeInstanceServer::resolveSceneRoots() } ++it; } + + updateSceneEnvColorsToHelper(); + if (updateActiveScene) { m_active3DView = findView3DForSceneRoot(m_active3DScene); updateActiveSceneToEditView3D(); @@ -1975,18 +1985,7 @@ void Qt5InformationNodeInstanceServer::setup3DEditView( m_editView3DSetupDone = true; - auto activeView = qobject_cast(m_active3DView); - if (activeView) { - QQuick3DSceneEnvironment *activeEnv = activeView->environment(); - QColor clearColor = activeEnv->clearColor(); - - if (clearColor.isValid() && helper) { - ServerNodeInstance activeSceneInstance = active3DSceneInstance(); - const QString sceneId = activeSceneInstance.id(); - - helper->setSceneEnvironmentColor(sceneId, clearColor); - } - } + updateSceneEnvColorsToHelper(); if (toolStates.contains({})) { // Update tool state to an existing no-scene state before updating the active scene to @@ -2000,19 +1999,6 @@ void Qt5InformationNodeInstanceServer::setup3DEditView( createCameraAndLightGizmos(instanceList); - if (!command.edit3dBackgroundColor.isEmpty()) { - View3DActionCommand backgroundColorCommand(View3DActionType::SelectBackgroundColor, - QVariant::fromValue( - command.edit3dBackgroundColor)); - view3DAction(backgroundColorCommand); - } - - if (command.edit3dGridColor.isValid()) { - View3DActionCommand backgroundColorCommand(View3DActionType::SelectGridColor, - QVariant::fromValue(command.edit3dGridColor)); - view3DAction(backgroundColorCommand); - } - // Queue two renders to make sure icon gizmos update properly render3DEditView(2); #endif @@ -2140,6 +2126,7 @@ void Qt5InformationNodeInstanceServer::createScene(const CreateSceneCommand &com updateRotationBlocks(command.auxiliaryChanges); updateMaterialPreviewData(command.auxiliaryChanges); updateSnapSettings(command.auxiliaryChanges); + updateColorSettings(command.auxiliaryChanges); } QObject::connect(&m_renderModelNodeImageViewTimer, &QTimer::timeout, @@ -2346,11 +2333,10 @@ void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor(const PropertyVa if (toolStates.contains("syncBackgroundColor")) { bool sync = toolStates["syncBackgroundColor"].toBool(); - QList colors{color}; if (sync) { - View3DActionCommand cmd(View3DActionType::SelectBackgroundColor, - QVariant::fromValue(colors)); - view3DAction(cmd); + QList colors{color}; + QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors", + Q_ARG(QVariant, QVariant::fromValue(colors))); } } #else @@ -2396,6 +2382,42 @@ QVariantList Qt5InformationNodeInstanceServer::alignCameraList() const return cameras; } +void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper() +{ +#ifdef QUICK3D_MODULE + // Update stored scene environment colors for all scenes + auto helper = qobject_cast(m_3dHelper); + if (!helper) + return; + + helper->clearSceneEnvironmentColors(); + + const auto sceneRoots = m_3DSceneMap.uniqueKeys(); + for (QObject *sceneRoot : sceneRoots) { + auto view3D = qobject_cast(findView3DForSceneRoot(sceneRoot)); + if (!view3D) + continue; + + QQuick3DSceneEnvironment *env = view3D->environment(); + if (!env) + continue; + + QColor clearColor = env->clearColor(); + if (clearColor.isValid() && helper) { + ServerNodeInstance sceneInstance; + if (hasInstanceForObject(sceneRoot)) + sceneInstance = instanceForObject(sceneRoot); + else if (hasInstanceForObject(view3D)) + sceneInstance = instanceForObject(view3D); + + const QString sceneId = sceneInstance.id(); + + helper->setSceneEnvironmentColor(sceneId, clearColor); + } + } +#endif +} + void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) { bool hasDynamicProperties = false; @@ -2510,13 +2532,6 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c case View3DActionType::SyncBackgroundColor: updatedToolState.insert("syncBackgroundColor", command.isEnabled()); break; - case View3DActionType::SelectBackgroundColor: - updatedViewState.insert("selectBackgroundColor", command.value()); - break; - case View3DActionType::SelectGridColor: { - updatedViewState.insert("selectGridColor", command.value()); - break; - } #ifdef QUICK3D_PARTICLES_MODULE case View3DActionType::ShowParticleEmitter: updatedToolState.insert("showParticleEmitter", command.isEnabled()); @@ -2581,6 +2596,7 @@ void Qt5InformationNodeInstanceServer::changeAuxiliaryValues(const ChangeAuxilia updateRotationBlocks(command.auxiliaryChanges); updateMaterialPreviewData(command.auxiliaryChanges); updateSnapSettings(command.auxiliaryChanges); + updateColorSettings(command.auxiliaryChanges); Qt5NodeInstanceServer::changeAuxiliaryValues(command); render3DEditView(); } diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index 3f0e68f854d..c774bc8f33f 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -126,6 +126,7 @@ private: void updateMaterialPreviewData(const QVector &valueChanges); void updateRotationBlocks(const QVector &valueChanges); void updateSnapSettings(const QVector &valueChanges); + void updateColorSettings(const QVector &valueChanges); void removeRotationBlocks(const QVector &instanceIds); void getNodeAtPos(const QPointF &pos); @@ -137,6 +138,7 @@ private: #endif void setSceneEnvironmentColor(const PropertyValueContainer &container); QVariantList alignCameraList() const; + void updateSceneEnvColorsToHelper(); RenderViewData m_editView3DData; RenderViewData m_modelNode3DImageViewData; diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index f8fb4860243..ed2b110e967 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -146,8 +146,6 @@ public: QString defaultPuppetToplevelBuildDirectory() const override { return {}; } QString qmlPuppetFallbackDirectory() const override { return {}; } QUrl projectUrl() const override { return {}; } - QList designerSettingsEdit3DViewBackgroundColor() const override { return {}; } - QColor designerSettingsEdit3DViewGridColor() const override { return {}; } void parseItemLibraryDescriptions() override {} const QmlDesigner::DesignerSettings &designerSettings() const override { return settings; } void undoOnCurrentDesignDocument() override {} diff --git a/tests/unit/tests/mocks/externaldependenciesmock.h b/tests/unit/tests/mocks/externaldependenciesmock.h index 37c2da1850c..673363a2148 100644 --- a/tests/unit/tests/mocks/externaldependenciesmock.h +++ b/tests/unit/tests/mocks/externaldependenciesmock.h @@ -16,8 +16,6 @@ public: MOCK_METHOD(QString, defaultPuppetToplevelBuildDirectory, (), (const, override)); MOCK_METHOD(QUrl, projectUrl, (), (const, override)); MOCK_METHOD(QString, currentProjectDirPath, (), (const, override)); - MOCK_METHOD(QList, designerSettingsEdit3DViewBackgroundColor, (), (const, override)); - MOCK_METHOD(QColor, designerSettingsEdit3DViewGridColor, (), (const, override)); MOCK_METHOD(QUrl, currentResourcePath, (), (const, override)); MOCK_METHOD(void, parseItemLibraryDescriptions, (), (override)); MOCK_METHOD(const QmlDesigner::DesignerSettings &, designerSettings, (), (const, override));