From 1800a7a7721e2b9e9254f9d687f6ad8a759724b3 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Tue, 9 Jan 2024 11:03:47 -0500 Subject: [PATCH] EMSUSD-840 expand and collapse all lyer items When holding shift while clicking the expand or collpase button, expand or collapse all items in the layer editor. --- lib/usd/ui/layerEditor/layerTreeView.cpp | 57 ++++++++++++++++++++++++ lib/usd/ui/layerEditor/layerTreeView.h | 6 +++ 2 files changed, 63 insertions(+) diff --git a/lib/usd/ui/layerEditor/layerTreeView.cpp b/lib/usd/ui/layerEditor/layerTreeView.cpp index 561fe4ff37..f66b6ed676 100644 --- a/lib/usd/ui/layerEditor/layerTreeView.cpp +++ b/lib/usd/ui/layerEditor/layerTreeView.cpp @@ -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(); @@ -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); diff --git a/lib/usd/ui/layerEditor/layerTreeView.h b/lib/usd/ui/layerEditor/layerTreeView.h index 80a718480d..dde2012409 100644 --- a/lib/usd/ui/layerEditor/layerTreeView.h +++ b/lib/usd/ui/layerEditor/layerTreeView.h @@ -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);