Skip to content

Commit

Permalink
Merge pull request #3544 from Autodesk/bailp/EMSUSD-840/expand-collap…
Browse files Browse the repository at this point in the history
…se-all

EMSUSD-840 expand and collapse all layer items
  • Loading branch information
seando-adsk authored Jan 11, 2024
2 parents 654ea69 + c4c88ca commit c71ac3a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/usd/ui/layerEditor/layerTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "layerTreeModel.h"
#include "stringResources.h"

#include <maya/MGlobal.h>

#include <QtGui/QColor>
#include <QtWidgets/QMenu>

Expand Down Expand Up @@ -101,6 +103,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 +140,55 @@ void LayerTreeView::onItemDoubleClicked(const QModelIndex& index)
}
}

bool LayerTreeView::shouldExpandOrCollapseAll() const
{
// Internal private function to check if the expand and collapse of
// items should be recursive. Currently, this is controlled by the
// fact the user is pressing the SHIFT key on the keyboard.
int modifiers = 0;
MGlobal::executeCommand("getModifiers", modifiers);

// Magic constant 2 is how the getModifiers reports the SHIFT key.
// This is a public command and the shift value is only declared in
// its documentation. Being a public command, it is practically
// guaranteed to never change, so hard-coding the value is not a problem.
const bool shiftHeld = ((modifiers % 2) != 0);
return shiftHeld;
}

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) { expandRecursively(index); }

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 c71ac3a

Please sign in to comment.