Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/usdLayerEditor/ui/layerTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions test/lib/usdLayerEditor/cpp/stubSessionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion test/lib/usdLayerEditor/cpp/stubSessionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/lib/usdLayerEditor/cpp/testFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
57 changes: 56 additions & 1 deletion test/lib/usdLayerEditor/cpp/testLayerTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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