From 6ae9dc89f5ce97790b5392a523d905f5941f1ce3 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Mon, 22 Jun 2026 09:40:50 -0400 Subject: [PATCH] EMSUSD-3823 fix layer content refresh The layer contents widget was only refreshed on Qt selection changed signal. The layer model optimization broke the refresh because it now avoid rebuilding the model if the layer tree has not changed. Before this optimization , any change to data in the layer, for example moving a prim, would trigger a full tree model rebuild, which indirectly emitted a selection change signal. Fix: - Add a specific signal when data change. - Now, when the model receives a layer data change signal, it tells the model-rebuild function that it is being called due to internal layer data change. - The model rebuilding emit the new signal. - This reuse the on-idle behavior to limit signal traffic, avoiding emitting the signal constantly. - Make the layer editor widget listen to this signal and update the contents. --- lib/usd/ui/layerEditor/layerEditorWidget.cpp | 7 +++++++ lib/usd/ui/layerEditor/layerTreeModel.cpp | 12 +++++++++--- lib/usd/ui/layerEditor/layerTreeModel.h | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/usd/ui/layerEditor/layerEditorWidget.cpp b/lib/usd/ui/layerEditor/layerEditorWidget.cpp index 538a80f99..9f64cc7a0 100644 --- a/lib/usd/ui/layerEditor/layerEditorWidget.cpp +++ b/lib/usd/ui/layerEditor/layerEditorWidget.cpp @@ -145,6 +145,13 @@ QLayout* LayerEditorWidget::setupLayout_toolbar() this, &LayerEditorWidget::onLazyUpdateLayerContents); + // update layer contents widget on selected layer data change + connect( + _treeView->layerTreeModel(), + &LayerTreeModel::selectedLayerDataChangedSignal, + this, + &LayerEditorWidget::onLazyUpdateLayerContents); + _buttons._loadLayer = addHIGButton( ":/UsdLayerEditor/import_layer", StringResources::getAsQString(StringResources::kLoadExistingLayer), diff --git a/lib/usd/ui/layerEditor/layerTreeModel.cpp b/lib/usd/ui/layerEditor/layerTreeModel.cpp index 39b49a1ba..4bf35c2fb 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.cpp +++ b/lib/usd/ui/layerEditor/layerTreeModel.cpp @@ -294,11 +294,12 @@ void LayerTreeModel::setSessionState(SessionState* in_sessionState) this, &LayerTreeModel::autoHideSessionLayerChanged); - rebuildModelOnIdle(); + rebuildModelOnIdle(true); } -void LayerTreeModel::rebuildModelOnIdle() +void LayerTreeModel::rebuildModelOnIdle(bool dataChanged) { + _selectedLayerDataChanged |= dataChanged; if (!_rebuildOnIdlePending) { _rebuildOnIdlePending = true; QTimer::singleShot(0, this, [this]() { @@ -313,6 +314,11 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/) _rebuildOnIdlePending = false; _lastAskedAnonLayerNameSinceRebuild = 0; + if (_selectedLayerDataChanged) { + Q_EMIT selectedLayerDataChangedSignal(); + _selectedLayerDataChanged = false; + } + if (!_sessionState->isValid()) { if (rowCount() > 0) { // Note: clear() calls beginResetModel and endResetModel for us. @@ -472,7 +478,7 @@ void LayerTreeModel::usd_layerChanged(SdfNotice::LayersDidChangeSentPerLayer con { // experienced crashes in python prototype For now, rebuild everything if (!_blockUsdNotices) - rebuildModelOnIdle(); + rebuildModelOnIdle(true); } // notification from USD diff --git a/lib/usd/ui/layerEditor/layerTreeModel.h b/lib/usd/ui/layerEditor/layerTreeModel.h index d37b85276..aa7c91ada 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.h +++ b/lib/usd/ui/layerEditor/layerTreeModel.h @@ -124,6 +124,7 @@ class LayerTreeModel Q_SIGNALS: void selectLayerSignal(const QModelIndex&); + void selectedLayerDataChangedSignal(); protected: // slots @@ -149,8 +150,9 @@ class LayerTreeModel mutable int _lastAskedAnonLayerNameSinceRebuild = 0; - void rebuildModelOnIdle(); + void rebuildModelOnIdle(bool dataChanged = false); bool _rebuildOnIdlePending = false; + bool _selectedLayerDataChanged = false; void rebuildModel(bool refreshLockState = false); void updateTargetLayer(InRebuildModel inRebuild);