Skip to content

Commit

Permalink
EMSUSD-840 expand and collapse all lyer items
Browse files Browse the repository at this point in the history
When holding shift while clicking the expand or collpase button, expand or collapse all items in the layer editor.
  • Loading branch information
pierrebai-adsk committed Jan 9, 2024
1 parent 8f08eb0 commit 1800a7a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ LayerTreeView::LayerTreeView(SessionState* in_sessionState, QWidget* in_parent)

// signals
connect(this, &QAbstractItemView::doubleClicked, this, &LayerTreeView::onItemDoubleClicked);
connect(this, &QTreeView::expanded, this, &LayerTreeView::onExpanded);
connect(this, &QTreeView::collapsed, this, &LayerTreeView::onCollapsed);

// renderSetuplike API
auto actionButtons = LayerTreeItem::actionButtonsDefinition();
Expand Down Expand Up @@ -136,6 +138,61 @@ void LayerTreeView::onItemDoubleClicked(const QModelIndex& index)
}
}

bool LayerTreeView::shouldExpandOrCollapseAll() const
{
return ((QGuiApplication::keyboardModifiers() & Qt::ShiftModifier) != 0);
}

void LayerTreeView::onExpanded(const QModelIndex& index)
{
if (!shouldExpandOrCollapseAll())
return;

expandChildren(index);
}

void LayerTreeView::onCollapsed(const QModelIndex& index)
{
if (!shouldExpandOrCollapseAll())
return;

collapseChildren(index);
}

void LayerTreeView::expandChildren(const QModelIndex& index)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
expandRecursively(index);
#else
if (!index.isValid())
return;

// Recursively expand each child node.
const int count = index.model()->rowCount(index);
for (int i = 0; i < count; i++) {
const QModelIndex& child = index.model()->index(i, 0, index);
expandChildren(child);
}

expand(index);
#endif
}

void LayerTreeView::collapseChildren(const QModelIndex& index)
{
if (!index.isValid())
return;

// Recursively collapse each child node.
const int count = index.model()->rowCount(index);
for (int i = 0; i < count; i++) {
const QModelIndex& child = index.model()->index(i, 0, index);
collapseChildren(child);
}

collapse(index);
}

LayerViewMemento::LayerViewMemento(const LayerTreeView& view, const LayerTreeModel& model)
{
preserve(view, model);
Expand Down
6 changes: 6 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ class LayerTreeView : public QTreeView
void onModelAboutToBeReset();
void onModelReset();
void onItemDoubleClicked(const QModelIndex& index);
void onExpanded(const QModelIndex& index);
void onCollapsed(const QModelIndex& index);
void onMuteLayerButtonPushed();

bool shouldExpandOrCollapseAll() const;
void expandChildren(const QModelIndex& index);
void collapseChildren(const QModelIndex& index);

// delayed signal to select a layer on idle
void selectLayerRquest(const QModelIndex& index);

Expand Down

0 comments on commit 1800a7a

Please sign in to comment.