diff --git a/lib/usdLayerEditor/ui/layerTreeModel.cpp b/lib/usdLayerEditor/ui/layerTreeModel.cpp index 8694b49538..ae9584295a 100644 --- a/lib/usdLayerEditor/ui/layerTreeModel.cpp +++ b/lib/usdLayerEditor/ui/layerTreeModel.cpp @@ -405,6 +405,8 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/) || (newSessionItem && newSessionItem->isIdenticalItem(oldSessionItem)); if (!refreshLockState && rootIdentical && sessionIdentical) { + // The layers are unchanged, but the edit target that triggered this rebuild may not be. + updateTargetLayer(InRebuildModel::Yes); return; } diff --git a/test/lib/usdLayerEditor/cpp/stubSessionState.cpp b/test/lib/usdLayerEditor/cpp/stubSessionState.cpp index fd6d9d6439..e7badd05c6 100644 --- a/test/lib/usdLayerEditor/cpp/stubSessionState.cpp +++ b/test/lib/usdLayerEditor/cpp/stubSessionState.cpp @@ -28,6 +28,9 @@ namespace UsdLayerEditor { StubSessionState::StubSessionState() : _commandHookImpl(this) { + // Tests always show the session layer unless they turn auto-hide on. + _autoHideSessionLayer = false; + // Two in-memory stages, each with one anonymous sublayer. for (int i = 0; i < 2; ++i) { auto stage = PXR_NS::UsdStage::CreateInMemory(); diff --git a/test/lib/usdLayerEditor/cpp/stubSessionState.h b/test/lib/usdLayerEditor/cpp/stubSessionState.h index a57e532285..f58cdfe2b8 100644 --- a/test/lib/usdLayerEditor/cpp/stubSessionState.h +++ b/test/lib/usdLayerEditor/cpp/stubSessionState.h @@ -52,7 +52,6 @@ class StubSessionState : public SessionState void setupCreateMenu(QMenu* menu) override; void rootLayerPathChanged(std::string const& path) override; bool autoObserveUfeSelection() const override { return false; } - bool autoHideSessionLayer() const override { return false; } bool isEditForwardMode() const override { return _isEFModeActive; } void setIsEditForwardMode(bool v); diff --git a/test/lib/usdLayerEditor/cpp/testFixture.cpp b/test/lib/usdLayerEditor/cpp/testFixture.cpp index 66d89f98b3..013742e9ab 100644 --- a/test/lib/usdLayerEditor/cpp/testFixture.cpp +++ b/test/lib/usdLayerEditor/cpp/testFixture.cpp @@ -149,7 +149,7 @@ LayerTreeModel* LayerEditorTestFixture::treeModel() { return layerTree()->layerT QModelIndex LayerEditorTestFixture::sessionLayerIndex() { - // The stub always shows the session layer (autoHideSessionLayer=false). + // The stub shows the session layer unless a test turns auto-hide on. // It is always the first top-level item in the tree. return treeModel()->index(0, 0); } diff --git a/test/lib/usdLayerEditor/cpp/testLayerTreeModel.cpp b/test/lib/usdLayerEditor/cpp/testLayerTreeModel.cpp index 8a931371dd..91fca69aed 100644 --- a/test/lib/usdLayerEditor/cpp/testLayerTreeModel.cpp +++ b/test/lib/usdLayerEditor/cpp/testLayerTreeModel.cpp @@ -92,7 +92,7 @@ TEST_F(LayerTreeModelTest, CanDrop_ReturnsFalseForNullMimeData) TEST_F(LayerTreeModelTest, Rebuild_AlwaysShowsSessionLayerWhenAutoHideFalse) { - // StubSessionState::autoHideSessionLayer() returns false. + // StubSessionState starts with auto-hide off. // Session layer must always be the first top-level item. treeModel()->forceRefresh(); QApplication::processEvents(); @@ -383,4 +383,59 @@ TEST_F(LayerTreeModelTest, SelectedLayerDataChanged_NotEmittedOnPlainRefresh) << "selectedLayerDataChangedSignal should not fire for a non-data-change rebuild"; } +// ── auto-hide session layer: target icon ─────────────────────────────────────── + +// A dirty session layer stays visible under auto-hide, so changing the edit target to or from it +// must still refresh which item is drawn as the target. +class LayerTreeModelAutoHideTest : public LayerEditorTestFixture +{ +protected: + void SetUp() override + { + LayerEditorTestFixture::SetUp(); + SdfPrimSpec::New( + _sessionState.stage()->GetSessionLayer(), "RenderSetupEdit", SdfSpecifierDef); + _sessionState.setAutoHideSessionLayer(true); + settle(); + } + + // An edit target change defers a rebuild, which defers again: one pass is not enough. + static void settle() + { + for (int pass = 0; pass < 3; ++pass) + QApplication::processEvents(); + } + + bool isTarget(const QModelIndex& index) + { + return treeModel()->layerItemFromIndex(index)->isTargetLayer(); + } +}; + +TEST_F(LayerTreeModelAutoHideTest, TargetingVisibleSessionLayerMarksItAsTarget) +{ + ASSERT_TRUE(treeModel()->layerItemFromIndex(sessionLayerIndex())->isSessionLayer()); + + const auto stage = _sessionState.stage(); + stage->SetEditTarget(stage->GetSessionLayer()); + settle(); + + EXPECT_TRUE(isTarget(sessionLayerIndex())); + EXPECT_FALSE(isTarget(rootLayerIndex())); +} + +TEST_F(LayerTreeModelAutoHideTest, TargetingRootLayerAgainMovesTheTargetOffTheSessionLayer) +{ + const auto stage = _sessionState.stage(); + stage->SetEditTarget(stage->GetSessionLayer()); + settle(); + ASSERT_TRUE(isTarget(sessionLayerIndex())); + + stage->SetEditTarget(stage->GetRootLayer()); + settle(); + + EXPECT_TRUE(isTarget(rootLayerIndex())); + EXPECT_FALSE(isTarget(sessionLayerIndex())); +} + } // namespace UsdLayerEditor