Skip to content

Commit

Permalink
Merge pull request #3910 from Autodesk/bailp/EMSUSD-1610/layer-manage…
Browse files Browse the repository at this point in the history
…r-flickering

EMSUSD-1610 layer manager flicker
  • Loading branch information
seando-adsk authored Sep 18, 2024
2 parents 4ddc1d9 + 03cc2cc commit 2da2a95
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/usd/ui/layerEditor/layerTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,13 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/)
_lastAskedAnonLayerNameSinceRebuild = 0;

beginResetModel();
clear();

// Note: do *not* call clear() here! Unfortunately, clear() itself calls,
// beginResetModel() and endResetModel(). Qt does not detect the nested
// begin/end/ So calling clear() would make the layer manager flicker
// to be empty for a brief time.
if (rowCount() > 0)
removeRows(0, rowCount());

if (_sessionState->isValid()) {
auto rootLayer = _sessionState->stage()->GetRootLayer();
Expand Down
33 changes: 29 additions & 4 deletions lib/usd/ui/layerEditor/layerTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ LayerViewMemento::LayerViewMemento(const LayerTreeView& view, const LayerTreeMod

void LayerViewMemento::preserve(const LayerTreeView& view, const LayerTreeModel& model)
{
if (QScrollBar* hsb = view.horizontalScrollBar()) {
_horizontalScrollbarPosition = hsb->value();
}
if (QScrollBar* vsb = view.verticalScrollBar()) {
_verticalScrollbarPosition = vsb->value();
}

const LayerItemVector items = model.getAllItems();
if (items.size() == 0)
return;
Expand Down Expand Up @@ -296,17 +303,33 @@ void LayerViewMemento::restore(LayerTreeView& view, LayerTreeModel& model)

view.setExpanded(item->index(), expanded);
}

if (QScrollBar* hsb = view.horizontalScrollBar()) {
if (hsb->value() != _horizontalScrollbarPosition) {
hsb->setValue(_horizontalScrollbarPosition);
hsb->valueChanged(_horizontalScrollbarPosition);
}
}
if (QScrollBar* vsb = view.verticalScrollBar()) {
if (vsb->value() != _verticalScrollbarPosition) {
vsb->setValue(_verticalScrollbarPosition);
vsb->valueChanged(_verticalScrollbarPosition);
}
}
}

void LayerTreeView::onModelAboutToBeReset()
{
if (!_model)
return;

LayerViewMemento memento(*this, *_model);
if (memento.empty())
// Don't allow recursive saving of the tree view state.
// Could happen if notifications are sent in response
// to other notifications or Qt events.
if (_cachedModelState)
return;

LayerViewMemento memento(*this, *_model);
_cachedModelState = std::make_unique<LayerViewMemento>(std::move(memento));
}

Expand All @@ -315,10 +338,12 @@ void LayerTreeView::onModelReset()
if (!_model)
return;

if (_cachedModelState)
if (_cachedModelState) {
_cachedModelState->restore(*this, *_model);
else
_cachedModelState.reset();
} else {
expandAll();
}
}

LayerItemVector LayerTreeView::getSelectedLayerItems() const
Expand Down
2 changes: 2 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class LayerViewMemento
};

std::map<ItemId, ItemState> _itemsState;
int _horizontalScrollbarPosition { 0 };
int _verticalScrollbarPosition { 0 };
};

/**
Expand Down

0 comments on commit 2da2a95

Please sign in to comment.