Skip to content
Snippets Groups Projects
Commit cbfda384 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Bugfix to DisplayContext overlayOrder update - should have noticed this

a long time ago. Overlay order was not being preserved when overlays
were removed from the list.
parent f830b56e
No related branches found
No related tags found
No related merge requests found
...@@ -290,21 +290,56 @@ class DisplayContext(props.SyncableHasProperties): ...@@ -290,21 +290,56 @@ class DisplayContext(props.SyncableHasProperties):
# Ensure that the overlayOrder # Ensure that the overlayOrder
# property is valid ... # property is valid ...
#
# NOTE: The following logic assumes that operations
# which modify the overlay list will only do
# one of the following:
#
# - Adding one or more overlays to the list
# - Removing one or more overlays from the list
# #
# More complex overlay list modifications
# will cause this code to break.
oldList = self.__overlayList.getLastValue('overlays')[:]
oldOrder = self.overlayOrder[:]
# If overlays have been added to # If overlays have been added to
# the overlay list, add indices # the overlay list, add indices
# for them to the overlayOrder list # for them to the overlayOrder list
if len(self.overlayOrder) < len(self.__overlayList): if len(self.overlayOrder) < len(self.__overlayList):
self.overlayOrder.extend(range(len(self.overlayOrder),
len(self.__overlayList)))
# Otherwise, if overlays have been removed newOrder = []
# from the overlay list, remove the corresponding newOverlayIdx = len(oldList)
# indices from the overlayOrder list
# The order of existing overlays is preserved,
# and all new overlays added to the end of the
# overlay order.
for overlay in self.__overlayList:
if overlay in oldList:
newOrder.append(oldOrder[oldList.index(overlay)])
else:
newOrder.append(newOverlayIdx)
newOverlayIdx += 1
self.overlayOrder[:] = newOrder
# Otherwise, if overlays have been
# removed from the overlay list ...
elif len(self.overlayOrder) > len(self.__overlayList): elif len(self.overlayOrder) > len(self.__overlayList):
for idx in range(len(self.__overlayList),
len(self.overlayOrder)): # Remove the corresponding indices
self.overlayOrder.remove(idx) # from the overlayOrder list
for overlay, orderIdx in zip(oldList, self.overlayOrder):
if overlay not in self.__overlayList:
oldOrder.remove(orderIdx)
# Re-generate new indices,
# preserving the order of
# the remaining overlays
newOrder = [sorted(oldOrder).index(idx) for idx in oldOrder]
self.overlayOrder[:] = newOrder
# Ensure that the bounds property is accurate # Ensure that the bounds property is accurate
self.__updateBounds() self.__updateBounds()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment