Skip to content

Commit

Permalink
Added a "DrawMode" column to the prim tree-view widget to control the…
Browse files Browse the repository at this point in the history
… draw mode

of models. The column is hidden by default, so it doesn't take up precious real estate
in the browser when it's not necessary.

This change promotes "PrimView" to a custom widget that derives from QTreeWidget,
in preparation for moving most of the prim browser functionality into this (separate)
module. It also includes several smaller improvements including:
* Set elide mode of the propertyView QTreeWidget to ElideMiddle.
* Renamed property inspector related methods and widgets to have "property" in the
name instead of "attribute".

(Internal change: 1905606)
  • Loading branch information
shriramiyer authored and pixar-oss committed Oct 29, 2018
1 parent 17a48ef commit 3dc4c5c
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _testSelectionChangeScrollPosition(appController):
# tab view does not affect the current scroll position in
# the property view
propView = appController._ui.propertyView
inspectorView = appController._ui.attributeInspector
inspectorView = appController._ui.propertyInspector

initialScroll = propView.verticalScrollBar().value()

Expand All @@ -52,7 +52,7 @@ def _testSelectionChangeScrollPosition(appController):
assert propView.verticalScrollBar().value() == initialScroll

def _testBasic(appController):
inspectorView = appController._ui.attributeInspector
inspectorView = appController._ui.propertyInspector

inspectorView.setCurrentIndex(0)
appController._mainWindow.repaint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def _setupWidgets(appController):

def _getVariantSelector(appController, whichVariant):
# Select the metadata tab in the lower right corner
attributeInspector = appController._ui.attributeInspector
attributeInspector.setCurrentIndex(1)
propertyInspector = appController._ui.propertyInspector
propertyInspector.setCurrentIndex(1)

# Grab the rows of our metadata tab and select the set containing
# our variant selection
metadataTable = attributeInspector.currentWidget().findChildren(QtWidgets.QTableWidget)[0]
metadataTable = propertyInspector.currentWidget().findChildren(QtWidgets.QTableWidget)[0]

for i in range(0, metadataTable.rowCount()):
currentName = metadataTable.item(i,0).text()
Expand Down
1 change: 1 addition & 0 deletions pxr/usdImaging/lib/usdviewq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pxr_library(usdviewq
common.py
legendUtil.py
primLegend.py
primTreeWidget.py
propertyLegend.py
attributeValueEditor.py
overridableLineEdit.py
Expand Down
75 changes: 55 additions & 20 deletions pxr/usdImaging/lib/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from customAttributes import (_GetCustomAttributes, CustomAttribute,
BoundingBoxAttribute, LocalToWorldXformAttribute,
ResolvedBoundMaterial)
from primTreeWidget import PrimTreeWidget, PrimViewColumnIndex
from primViewItem import PrimViewItem
from variantComboBox import VariantComboBox
from legendUtil import ToggleLegendWithBrowser
Expand Down Expand Up @@ -139,7 +140,8 @@ def __init__(self, mainWindow, parent, name):

self._mainWindow = mainWindow
primViewColumnVisibility = self.stateProperty("primViewColumnVisibility",
default=[True, True, True], validator=lambda value: len(value) == 3)
default=[True, True, True, False], validator=lambda value:
len(value) == 4)
propertyViewColumnVisibility = self.stateProperty("propertyViewColumnVisibility",
default=[True, True, True], validator=lambda value: len(value) == 3)
attributeInspectorCurrentTab = self.stateProperty("attributeInspectorCurrentTab", default=PropertyIndex.VALUE)
Expand Down Expand Up @@ -182,7 +184,7 @@ def __init__(self, mainWindow, parent, name):
propertyIndex = attributeInspectorCurrentTab
if propertyIndex not in PropertyIndex:
propertyIndex = PropertyIndex.VALUE
self._mainWindow._ui.attributeInspector.setCurrentIndex(propertyIndex)
self._mainWindow._ui.propertyInspector.setCurrentIndex(propertyIndex)

def onSaveState(self, state):
# UI is different when --norender is used so don't load the splitter sizes.
Expand Down Expand Up @@ -220,7 +222,7 @@ def onSaveState(self, state):
not self._mainWindow._ui.propertyView.isColumnHidden(c)
for c in range(self._mainWindow._ui.propertyView.columnCount())]

state["attributeInspectorCurrentTab"] = self._mainWindow._ui.attributeInspector.currentIndex()
state["attributeInspectorCurrentTab"] = self._mainWindow._ui.propertyInspector.currentIndex()


class Blocker:
Expand Down Expand Up @@ -667,6 +669,8 @@ def __init__(self, parserData, resolverContextFn):
nvh.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
nvh.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
nvh.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
nvh.resizeSection(3, 116)
nvh.setSectionResizeMode(3, QtWidgets.QHeaderView.Fixed)

pvh = self._ui.propertyView.header()
pvh.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
Expand All @@ -687,6 +691,7 @@ def __init__(self, parserData, resolverContextFn):
QtCore.Qt.ScrollBarAlwaysOn)

self._ui.attributeValueEditor.setAppController(self)
self._ui.primView.InitDrawModeDelegate(self)

self._ui.currentPathWidget.editingFinished.connect(
self._currentPathChanged)
Expand All @@ -699,6 +704,7 @@ def __init__(self, parserData, resolverContextFn):
primViewSelModel.selectionChanged.connect(self._selectionChanged)

self._ui.primView.itemClicked.connect(self._itemClicked)
self._ui.primView.itemPressed.connect(self._itemPressed)

self._ui.primView.header().customContextMenuRequested.connect(
self._primViewHeaderContextMenu)
Expand Down Expand Up @@ -816,8 +822,8 @@ def __init__(self, parserData, resolverContextFn):
self._ui.actionCull_Backfaces.triggered.connect(
self._toggleCullBackfaces)

self._ui.attributeInspector.currentChanged.connect(
self._updateAttributeInspector)
self._ui.propertyInspector.currentChanged.connect(
self._updatePropertyInspector)

self._ui.propertyView.itemSelectionChanged.connect(
self._propertyViewSelectionChanged)
Expand Down Expand Up @@ -1571,7 +1577,7 @@ def _resetGUI(self):
self._resetPrimView()
self._updatePropertyView()

self._populateAttributeInspector()
self._populatePropertyInspector()
self._updateMetadataView()
self._updateLayerStackView()
self._updateCompositionView()
Expand Down Expand Up @@ -2523,10 +2529,10 @@ def _propSelectionChanged(self):
Updates any UI that relies on the selection state.
"""
self._updatePropertyViewSelection()
self._populateAttributeInspector()
self._updateAttributeInspector()
self._populatePropertyInspector()
self._updatePropertyInspector()

def _populateAttributeInspector(self):
def _populatePropertyInspector(self):

focusPrimPath = None
focusPropName = None
Expand All @@ -2549,11 +2555,11 @@ def _onCompositionSelectionChanged(self, curr=None, prev=None):
self._currentSpec = getattr(curr, 'spec', None)
self._currentLayer = getattr(curr, 'layer', None)

def _updateAttributeInspector(self, index=None, obj=None):
def _updatePropertyInspector(self, index=None, obj=None):
# index must be the first parameter since this method is used as
# attributeInspector tab widget's currentChanged(int) signal callback
# propertyInspector tab widget's currentChanged(int) signal callback
if index is None:
index = self._ui.attributeInspector.currentIndex()
index = self._ui.propertyInspector.currentIndex()

if obj is None:
obj = self._getSelectedObject()
Expand Down Expand Up @@ -2720,7 +2726,8 @@ def _populateItem(self, prim, depth=0, maxDepth=0):
# Create a new item. If we want its children we obviously
# have to create those too.
children = self._getFilteredChildren(prim)
item = PrimViewItem(prim, self, len(children) != 0)
item = PrimViewItem(prim, self, len(children) != 0,
parent=self._ui.primView)
self._primToItemMap[prim] = item
self._populateChildren(item, depth, maxDepth, children)
# Push the item after the children so ancestors are processed
Expand Down Expand Up @@ -2919,7 +2926,7 @@ def _primSelectionChanged(self, added, removed):
self._updateHUDPrimStats()
self._updateHUDGeomCounts()
self._stageView.updateView()
self._updateAttributeInspector(
self._updatePropertyInspector(
obj=self._dataModel.selection.getFocusPrim())
self._updatePropertyView()
self._refreshAttributeValue()
Expand Down Expand Up @@ -3033,16 +3040,19 @@ def _selectionChanged(self, added, removed):
self._dataModel.selection.removePrim(prim)

def _itemClicked(self, item, col):
# onClick() returns True if the click caused a state change (currently
# this will only be a change to visibility).
if item.onClick(col):
# toggleVis() returns True if the click caused a visibility change.
if col == PrimViewColumnIndex.VIS and item.toggleVis():
self.editComplete('Updated prim visibility')
with Timer() as t:
PrimViewItem.propagateVis(item)
if self._printTiming:
t.PrintTime("update vis column")
self._updateAttributeInspector(
obj=self._dataModel.selection.getFocusPrim())
self._updatePropertyInspector(
obj=self._dataModel.selection.getFocusPrim())

def _itemPressed(self, item, col):
if col == PrimViewColumnIndex.DRAWMODE:
self._ui.primView.ShowDrawModeWidgetForItem(item)

def _getPathsFromItems(self, items, prune = False):
# this function returns a list of paths given a list of items if
Expand Down Expand Up @@ -3216,7 +3226,7 @@ def _updatePropertyViewInternal(self):
self._propertiesDict = self._getPropertiesDict()
with self._propertyViewSelectionBlocker:
treeWidget.clear()
self._populateAttributeInspector()
self._populatePropertyInspector()

curPrimSelection = self._dataModel.selection.getFocusPrim()

Expand Down Expand Up @@ -4587,6 +4597,31 @@ def _displayPurposeChanged(self):
self._stageView.updateBboxPurposes()
self._stageView.updateView()

def _resetPrimViewDrawMode(self, rootItem=None):
"""Updates browser's "Draw Mode" columns. """
with Timer() as t:
primView = self._ui.primView
primView.setUpdatesEnabled(False)
# Update draw-model for the entire prim tree if the given
# rootItem is None.
if rootItem is None:
rootItem = primView.invisibleRootItem().child(0)
if rootItem.childCount() == 0:
self._populateChildren(rootItem)
rootsToProcess = [rootItem.child(i) for i in
xrange(rootItem.childCount())]
for item in rootsToProcess:
PrimViewItem.propagateDrawMode(item, primView)
primView.setUpdatesEnabled(True)
if self._printTiming:
t.PrintTime("update draw mode column")

def _drawModeChanged(self, primViewItem):
self._updatePropertyView()
self._resetPrimViewDrawMode(rootItem=primViewItem)
if self._stageView:
self._stageView.updateView()

def _HUDInfoChanged(self):
"""Called when a HUD setting that requires info refresh has changed."""
if self._isHUDVisible():
Expand Down
8 changes: 3 additions & 5 deletions pxr/usdImaging/lib/usdviewq/headerContextMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, parent, column):
self._parent = parent
self._column = column

if parent.__class__ == QtWidgets.QTreeWidget:
if isinstance(parent, QtWidgets.QTreeWidget):
self._text = parent.headerItem().text(column)
else:
self._text = parent.horizontalHeaderItem(column).text()
Expand All @@ -69,16 +69,14 @@ def GetText(self):
return self._text

def IsEnabled(self):
return self._column > 0
# Enable context menu item for columns except the "Name" column.
return 'Name' not in self.GetText()

def IsChecked(self):
# true if the column is visible, false otherwise
return not self._parent.isColumnHidden(self._column)

def RunCommand(self):
if self._column <= 0 :
return

# show or hide the column depending on its previous state
self._parent.setColumnHidden(self._column, self.IsChecked())

21 changes: 17 additions & 4 deletions pxr/usdImaging/lib/usdviewq/mainWindowUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
</widget>
</item>
<item>
<widget class="QTreeWidget" name="primView">
<widget class="PrimTreeWidget" name="primView">
<property name="font">
<font>
<family>Gotham Rounded</family>
Expand Down Expand Up @@ -229,6 +229,11 @@
<set>AlignLeading|AlignVCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Draw Mode</string>
</property>
</column>
</widget>
</item>
<item>
Expand Down Expand Up @@ -426,6 +431,9 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
<property name="columnCount">
<number>3</number>
</property>
Expand Down Expand Up @@ -548,7 +556,7 @@
</item>
</layout>
</widget>
<widget class="QFrame" name="attributeInspectorFrame">
<widget class="QFrame" name="propertyInspectorFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
Expand All @@ -575,7 +583,7 @@
<number>2</number>
</property>
<item>
<widget class="QFrame" name="attributeInspectorContainer">
<widget class="QFrame" name="propertyInspectorContainer">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
Expand All @@ -596,7 +604,7 @@
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="attributeInspector">
<widget class="QTabWidget" name="propertyInspector">
<property name="currentIndex">
<number>0</number>
</property>
Expand Down Expand Up @@ -2646,6 +2654,11 @@
<header>propertyLegend</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PrimTreeWidget</class>
<extends>QTreeWidget</extends>
<header>primTreeWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
Loading

0 comments on commit 3dc4c5c

Please sign in to comment.