Skip to content

Commit 6be1d6e

Browse files
blevinpixar-oss
authored andcommitted
Hdui tree views now sort and uniquify children.
(Internal change: 2384269)
1 parent f296424 commit 6be1d6e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

extras/imaging/examples/hdui/dataSourceTreeWidget.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ PXR_NAMESPACE_OPEN_SCOPE
2626
namespace
2727
{
2828

29+
// Helper function to sort and uniquie-ify container data source names.
30+
static std::set<TfToken, TfDictionaryLessThan>
31+
Hdui_GetSortedNames(HdContainerDataSourceHandle const& container)
32+
{
33+
const auto names = container->GetNames();
34+
return std::set<TfToken, TfDictionaryLessThan>(names.begin(), names.end());
35+
}
36+
2937
class Hdui_DataSourceTreeWidgetItem : public QTreeWidgetItem
3038
{
3139
public:
@@ -128,7 +136,7 @@ class Hdui_DataSourceTreeWidgetItem : public QTreeWidgetItem
128136

129137
// add any new items
130138
for (const TfToken &childName :
131-
containerDataSource->GetNames()) {
139+
Hdui_GetSortedNames(containerDataSource)) {
132140
if (usedNames.find(childName) == usedNames.end()) {
133141

134142
if (HdDataSourceBaseHandle childDs =
@@ -228,7 +236,7 @@ class Hdui_DataSourceTreeWidgetItem : public QTreeWidgetItem
228236
HdContainerDataSource::Cast(_dataSource)) {
229237
TfDenseHashSet<TfToken, TfHash> usedNames;
230238

231-
for (const TfToken &childName : container->GetNames()) {
239+
for (const TfToken &childName : Hdui_GetSortedNames(container)) {
232240
if (usedNames.find(childName) != usedNames.end()) {
233241
continue;
234242
}
@@ -332,7 +340,7 @@ HduiDataSourceTreeWidget::SetPrimDataSource(const SdfPath &primPath,
332340
HdContainerDataSource::Cast(dataSource)) {
333341
// add all container children as roots
334342
TfDenseHashSet<TfToken, TfHash> usedNames;
335-
for (TfToken const& childName: container->GetNames()) {
343+
for (TfToken const& childName: Hdui_GetSortedNames(container)) {
336344
if (usedNames.find(childName) != usedNames.end()) {
337345
continue;
338346
}

extras/imaging/examples/hdui/sceneIndexTreeWidget.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ class Hdui_SceneIndexPrimTreeWidgetItem : public QTreeWidgetItem
8181
return;
8282
}
8383

84-
for (const SdfPath &childPath :
85-
treeWidget->_inputSceneIndex->GetChildPrimPaths(_primPath)) {
84+
// Put child prim paths into a set to put them in order and ensure uniqueness.
85+
const auto childPathVec =
86+
treeWidget->_inputSceneIndex->GetChildPrimPaths(_primPath);
87+
const SdfPathSet sortedChildPaths(childPathVec.begin(), childPathVec.end());
88+
89+
for (const SdfPath &childPath : sortedChildPaths) {
8690

8791
HdSceneIndexPrim prim =
8892
treeWidget->_inputSceneIndex->GetPrim(childPath);

0 commit comments

Comments
 (0)