Skip to content

Commit

Permalink
SG-14587 Unable to uncheck parent item when it is partially checked (#…
Browse files Browse the repository at this point in the history
…120)

Fixes the tristate checkbox's next state order
  • Loading branch information
eshokrgozar authored Apr 21, 2020
1 parent 6a6d2e5 commit a2f0e40
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


import sgtk
from sgtk.platform.qt import QtCore
from .ui.item_widget import Ui_ItemWidget
from .custom_widget_base import CustomTreeWidgetBase

Expand Down Expand Up @@ -60,10 +61,14 @@ def nextCheckState(self):
"""
Callback that handles QT tri-state logic
"""
# QT tri-state logic is a little odd, see the docs for more
# details.
self.ui.checkbox.setChecked(not self.ui.checkbox.isChecked())
self._tree_node.set_check_state(self.ui.checkbox.checkState())
# Qt tri-state logic is a little odd. The default behaviour is to go from unchecked
# to partially checked. We want it to go from unchecked to checked
if self.ui.checkbox.checkState() == QtCore.Qt.CheckState.Checked:
next_state = QtCore.Qt.CheckState.Unchecked
else:
next_state = QtCore.Qt.CheckState.Checked
self.ui.checkbox.setCheckState(next_state)
self._tree_node.set_check_state(next_state)

def _on_checkbox_click(self, state):
"""
Expand Down
33 changes: 33 additions & 0 deletions tests/test_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,36 @@ def test_parent_checked_children_unchecked(self):
project_item = tree_widget.topLevelItem(1)
parent_item = project_item.child(0)
self.assertEqual(parent_item.check_state, self.QtCore.Qt.Unchecked)

def test_next_check_state(self):
"""
Make sure the tristate checkbox on an item goes from Partially checked to
Checked to Unchecked every time it is clicked
"""

tree = self.manager.tree
item = tree.root_item.create_item("item.parent", "Parent", "Parent")
publish_plugins = self.manager._load_publish_plugins(item.context)

item.add_task(publish_plugins[0])
item.add_task(publish_plugins[0])

item._active = True
item.tasks[0]._active = False
item.tasks[1]._active = True

tree_widget = self.PublishTreeWidget(None)
tree_widget.set_publish_manager(self.manager)
tree_widget.build_tree()

project_item = tree_widget.topLevelItem(1)
parent_item = project_item.child(0)

from sgtk.platform.qt import QtCore

# Make sure the states go PartiallyChecked -> Checked -> Unchecked
self.assertEqual(parent_item.check_state, QtCore.Qt.PartiallyChecked)
parent_item._embedded_widget.ui.checkbox.nextCheckState()
self.assertEqual(parent_item.check_state, QtCore.Qt.Checked)
parent_item._embedded_widget.ui.checkbox.nextCheckState()
self.assertEqual(parent_item.check_state, QtCore.Qt.Unchecked)

0 comments on commit a2f0e40

Please sign in to comment.