Skip to content

Commit

Permalink
SG-10003 Fix for incorrect parent check state (#119)
Browse files Browse the repository at this point in the history
Forces a recalculation of parent item's check status after the children have been created
  • Loading branch information
eshokrgozar authored Apr 21, 2020
1 parent 00ffe57 commit 6a6d2e5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 19 deletions.
1 change: 1 addition & 0 deletions python/tk_multi_publish2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .api import PublishManager # noqa
from . import base_hooks # noqa
from . import util # noqa
from . import publish_tree_widget # noqa


def show_dialog(app):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ def _build_item_tree_r(self, item, checked, level, tree_parent):
if not item.checked:
ui_item.set_check_state(QtCore.Qt.Unchecked)

# If we have a bunch of active tasks followed by a bunch of inactive tasks, the addition
# of the inactive tasks does not trigger an update of the parent's checkbox (because the update
# relies on the checkbox.state_changed and the default is unchecked, so inactive tasks do not
# trigger a state change). Force a recalculation to keep the parent's check_state
# correct in all situation
ui_item.recompute_check_state()

return ui_item

def build_tree(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Shotgun site. You can use any site.

The app itself has a few plugins that pretend to operate on items found in a
scene.

Install tk-toolchain and use pytest to run the tests
5 changes: 5 additions & 0 deletions tests/python/publish_api_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def setUp(self):
self.PublishManager = self.api.PublishManager
self.PublishPluginInstance = self.api.plugins.PublishPluginInstance

publish_tree_widget = self.app.import_module(
"tk_multi_publish2"
).publish_tree_widget
self.PublishTreeWidget = publish_tree_widget.PublishTreeWidget

self.image_path = os.path.join(repo_root, "icon_256.png")
self.dark_image_path = os.path.join(repo_root, "icon_256_dark.png")

Expand Down
19 changes: 0 additions & 19 deletions tests/run_tests.sh

This file was deleted.

64 changes: 64 additions & 0 deletions tests/test_tree_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2018 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

from publish_api_test_base import PublishApiTestBase
from tank_test.tank_test_base import setUpModule # noqa


class TestPublishTreeWidget(PublishApiTestBase):
def test_parent_partially_checked(self):
"""
If we have a bunch of active tasks followed by a bunch of inactive tasks, the addition
of the inactive tasks does not trigger an update of the parent's checkbox (because the update
relies on the checkbox.state_changed and the default is unchecked, so inactive tasks do not
trigger a state change). Test that we are forcing a recalculation to keep the parent's check_state
correct in all situations
"""
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.tasks[0]._active = True
item.tasks[1]._active = False

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)
self.assertEqual(parent_item.check_state, self.QtCore.Qt.PartiallyChecked)

def test_parent_checked_children_unchecked(self):
"""
If a parent item is active and only has inactive tasks, make sure that when the
tree is built the parent item's check_state is valid and is set to unchecked
"""
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 = False

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)
self.assertEqual(parent_item.check_state, self.QtCore.Qt.Unchecked)

0 comments on commit 6a6d2e5

Please sign in to comment.