Skip to content

Commit 71e08e3

Browse files
committed
Update object titles to correctly reflect order numbers in operations
1 parent 12a6309 commit 71e08e3

File tree

3 files changed

+518
-488
lines changed

3 files changed

+518
-488
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ This release requires PlotPy v2.4.0 or later, which brings the following bug fix
4444

4545
* Difference, division, ...: dialog box for the second operand selection was allowing to select a group (only a signal or an image should be selected)
4646

47+
* When doing an operation which involves an object (signal or image) with higher order number than the current object (e.g. when subtracting an image with an image from a group below the current image), the resulting object's title now correctly refers to the order numbers of the objects involved in the operation (e.g., to continue with the subtraction example mentioned above, the resulting object's title was previously referring to the order number before the insertion of the resulting image)
48+
4749
## DataLab Version 0.16.1 ##
4850

4951
Since version 0.16.0, many validation functions have been added to the test suite.

cdl/core/gui/objectmodel.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def remove_group(self, group: ObjectGroup) -> None:
310310

311311
def add_object(self, obj: SignalObj | ImageObj, group_id: str) -> None:
312312
"""Add object to model"""
313+
self.__replace_short_ids_by_uuids_in_titles([obj])
313314
self._objects[obj.uuid] = obj
314315
onb = 0
315316
for group in self._groups:
@@ -321,6 +322,7 @@ def add_object(self, obj: SignalObj | ImageObj, group_id: str) -> None:
321322
else:
322323
raise KeyError(f"Group with uuid '{group_id}' not found")
323324
self.reset_short_ids()
325+
self.__replace_uuids_by_short_ids_in_titles()
324326

325327
def remove_object(self, obj: SignalObj | ImageObj) -> None:
326328
"""Remove object from model"""
@@ -402,19 +404,29 @@ def __get_group_object_mapping_to_shortid(self) -> dict[str, str]:
402404
mapping[obj.uuid] = obj.short_id
403405
return mapping
404406

405-
def __replace_short_ids_by_uuids_in_titles(self) -> None:
407+
def __replace_short_ids_by_uuids_in_titles(
408+
self, other_objects: tuple[SignalObj | ImageObj] | None = None
409+
) -> None:
406410
"""Replace short IDs by uuids in titles
407411
408-
This method is called before reorganizing groups or objects. It replaces
409-
the short IDs in titles by the uuids. This is needed because the short IDs
410-
are used to reflect in the title the operation performed on the object/group,
411-
e.g. "fft(s001)" or "g001 + g002". But when reorganizing groups or objects,
412-
the short IDs may change, so we need to replace them by the uuids, which
413-
are stable. Once the reorganization is done, we will replace the uuids by the
414-
new short IDs thanks to the `__replace_uuids_by_short_ids_in_titles` method.
412+
Args:
413+
other_objects: tuple of other objects to consider for short ID replacement
414+
415+
.. note::
416+
417+
This method is called before reorganizing groups or objects. It replaces the
418+
short IDs in titles by the uuids. This is needed because the short IDs are
419+
used to reflect in the title the operation performed on the object/group,
420+
e.g. "fft(s001)" or "g001 + g002". But when reorganizing groups or objects,
421+
the short IDs may change, so we need to replace them by the uuids, which are
422+
stable. Once the reorganization is done, we will replace the uuids by the
423+
new short IDs thanks to the `__replace_uuids_by_short_ids_in_titles` method.
415424
"""
416425
mapping = self.__get_group_object_mapping_to_shortid()
417-
for obj in self._objects.values():
426+
objs = self._objects.values()
427+
if other_objects is not None:
428+
objs = list(objs) + list(other_objects)
429+
for obj in objs:
418430
for obj_uuid, short_id in mapping.items():
419431
obj.title = obj.title.replace(short_id, obj_uuid)
420432
for group in self._groups:
@@ -424,8 +436,10 @@ def __replace_short_ids_by_uuids_in_titles(self) -> None:
424436
def __replace_uuids_by_short_ids_in_titles(self) -> None:
425437
"""Replace uuids by short IDs in titles
426438
427-
This method is called after reorganizing groups or objects. It replaces
428-
the uuids in titles by the short IDs.
439+
.. note::
440+
441+
This method is called after reorganizing groups or objects. It replaces
442+
the uuids in titles by the short IDs.
429443
"""
430444
mapping = self.__get_group_object_mapping_to_shortid()
431445
for obj in self._objects.values():

0 commit comments

Comments
 (0)