mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-21 13:06:28 +02:00
[graph] ListAttribute: replace '__getitem__ by 'at'
__getitem__ is spuriously called when the object is used inside a Qt model and exposed to QML, leading to unexpected behaviors
This commit is contained in:
parent
a5cda66670
commit
2cd724f957
4 changed files with 25 additions and 22 deletions
|
@ -285,12 +285,15 @@ class ListAttribute(Attribute):
|
||||||
super(ListAttribute, self).__init__(node, attributeDesc, isOutput, root, parent)
|
super(ListAttribute, self).__init__(node, attributeDesc, isOutput, root, parent)
|
||||||
self._value = ListModel(parent=self)
|
self._value = ListModel(parent=self)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
|
||||||
return self._value.at(item)
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._value)
|
return len(self._value)
|
||||||
|
|
||||||
|
def at(self, idx):
|
||||||
|
""" Returns child attribute at index 'idx' """
|
||||||
|
# implement 'at' rather than '__getitem__'
|
||||||
|
# since the later is called spuriously when object is used in QML
|
||||||
|
return self._value.at(idx)
|
||||||
|
|
||||||
def _set_value(self, value):
|
def _set_value(self, value):
|
||||||
self.desc.validateValue(value)
|
self.desc.validateValue(value)
|
||||||
self._value.clear()
|
self._value.clear()
|
||||||
|
@ -317,7 +320,7 @@ class ListAttribute(Attribute):
|
||||||
def remove(self, index, count=1):
|
def remove(self, index, count=1):
|
||||||
if self.node.graph:
|
if self.node.graph:
|
||||||
for i in range(index, index + count):
|
for i in range(index, index + count):
|
||||||
attr = self[i]
|
attr = self._value.at(i)
|
||||||
if attr.isLink:
|
if attr.isLink:
|
||||||
self.node.graph.removeEdge(attr) # delete edge if the attribute is linked
|
self.node.graph.removeEdge(attr) # delete edge if the attribute is linked
|
||||||
self._value.removeAt(index, count)
|
self._value.removeAt(index, count)
|
||||||
|
|
|
@ -259,7 +259,7 @@ class UIGraph(QObject):
|
||||||
if isinstance(dst, graph.ListAttribute):
|
if isinstance(dst, graph.ListAttribute):
|
||||||
with self.groupedGraphModification("Insert and Add Edge on {}".format(dst.fullName())):
|
with self.groupedGraphModification("Insert and Add Edge on {}".format(dst.fullName())):
|
||||||
self.appendAttribute(dst)
|
self.appendAttribute(dst)
|
||||||
self.push(commands.AddEdgeCommand(self._graph, src, dst[-1]))
|
self.push(commands.AddEdgeCommand(self._graph, src, dst.at(-1)))
|
||||||
else:
|
else:
|
||||||
self.push(commands.AddEdgeCommand(self._graph, src, dst))
|
self.push(commands.AddEdgeCommand(self._graph, src, dst))
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ class LiveSfmManager(QObject):
|
||||||
def imagePathsInCameraInit(self, node):
|
def imagePathsInCameraInit(self, node):
|
||||||
""" Get images in the given CameraInit node. """
|
""" Get images in the given CameraInit node. """
|
||||||
assert node.nodeType == 'CameraInit'
|
assert node.nodeType == 'CameraInit'
|
||||||
return [vp.path.value for vp in node.viewpoints]
|
return [vp.path.value for vp in node.viewpoints.value]
|
||||||
|
|
||||||
def imagesInStep(self):
|
def imagesInStep(self):
|
||||||
""" Get images in the current augmentation step. """
|
""" Get images in the current augmentation step. """
|
||||||
|
@ -304,11 +304,11 @@ class Reconstruction(UIGraph):
|
||||||
|
|
||||||
def allImagePaths(self):
|
def allImagePaths(self):
|
||||||
""" Get all image paths in the reconstruction. """
|
""" Get all image paths in the reconstruction. """
|
||||||
return [vp.path.value for node in self._cameraInits for vp in node.viewpoints]
|
return [vp.path.value for node in self._cameraInits for vp in node.viewpoints.value]
|
||||||
|
|
||||||
def allViewIds(self):
|
def allViewIds(self):
|
||||||
""" Get all view Ids involved in the reconstruction. """
|
""" Get all view Ids involved in the reconstruction. """
|
||||||
return [vp.viewId.value for node in self._cameraInits for vp in node.viewpoints]
|
return [vp.viewId.value for node in self._cameraInits for vp in node.viewpoints.value]
|
||||||
|
|
||||||
@Slot(QObject, graph.Node)
|
@Slot(QObject, graph.Node)
|
||||||
def handleFilesDrop(self, drop, cameraInit):
|
def handleFilesDrop(self, drop, cameraInit):
|
||||||
|
|
|
@ -17,10 +17,10 @@ def test_multiviewPipeline():
|
||||||
{'path': '/non/existing/file2', 'intrinsicId': 55}
|
{'path': '/non/existing/file2', 'intrinsicId': 55}
|
||||||
])
|
])
|
||||||
|
|
||||||
assert graph1.findNode('CameraInit').viewpoints[0].path.value == '/non/existing/fileA'
|
assert graph1.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/fileA'
|
||||||
assert len(graph2.findNode('CameraInit').viewpoints) == 0
|
assert len(graph2.findNode('CameraInit').viewpoints) == 0
|
||||||
assert graph3.findNode('CameraInit').viewpoints[0].path.value == '/non/existing/file1'
|
assert graph3.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/file1'
|
||||||
assert graph4.findNode('CameraInit').viewpoints[0].path.value == '/non/existing/file1'
|
assert graph4.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/file1'
|
||||||
|
|
||||||
assert len(graph1.findNode('CameraInit').viewpoints) == 1
|
assert len(graph1.findNode('CameraInit').viewpoints) == 1
|
||||||
assert len(graph2.findNode('CameraInit').viewpoints) == 0
|
assert len(graph2.findNode('CameraInit').viewpoints) == 0
|
||||||
|
@ -28,15 +28,15 @@ def test_multiviewPipeline():
|
||||||
assert len(graph4.findNode('CameraInit').viewpoints) == 2
|
assert len(graph4.findNode('CameraInit').viewpoints) == 2
|
||||||
|
|
||||||
viewpoints = graph3.findNode('CameraInit').viewpoints
|
viewpoints = graph3.findNode('CameraInit').viewpoints
|
||||||
assert viewpoints[0].path.value == '/non/existing/file1'
|
assert viewpoints.at(0).path.value == '/non/existing/file1'
|
||||||
|
|
||||||
assert viewpoints[0].path.value == '/non/existing/file1'
|
assert viewpoints.at(0).path.value == '/non/existing/file1'
|
||||||
assert viewpoints[0].intrinsicId.value == -1
|
assert viewpoints.at(0).intrinsicId.value == -1
|
||||||
assert viewpoints[1].path.value == '/non/existing/file2'
|
assert viewpoints.at(1).path.value == '/non/existing/file2'
|
||||||
assert viewpoints[1].intrinsicId.value == -1
|
assert viewpoints.at(1).intrinsicId.value == -1
|
||||||
|
|
||||||
assert viewpoints[0].path.isDefault == False
|
assert not viewpoints.at(0).path.isDefault
|
||||||
assert viewpoints[0].intrinsicId.isDefault == True
|
assert viewpoints.at(0).intrinsicId.isDefault
|
||||||
assert viewpoints.getPrimitiveValue(exportDefault=False) == [
|
assert viewpoints.getPrimitiveValue(exportDefault=False) == [
|
||||||
{"path": '/non/existing/file1'},
|
{"path": '/non/existing/file1'},
|
||||||
{"path": '/non/existing/file2'},
|
{"path": '/non/existing/file2'},
|
||||||
|
@ -44,10 +44,10 @@ def test_multiviewPipeline():
|
||||||
|
|
||||||
for graph in (graph4, graph4b):
|
for graph in (graph4, graph4b):
|
||||||
viewpoints = graph.findNode('CameraInit').viewpoints
|
viewpoints = graph.findNode('CameraInit').viewpoints
|
||||||
assert viewpoints[0].path.value == '/non/existing/file1'
|
assert viewpoints.at(0).path.value == '/non/existing/file1'
|
||||||
assert viewpoints[0].intrinsicId.value == 50
|
assert viewpoints.at(0).intrinsicId.value == 50
|
||||||
assert viewpoints[1].path.value == '/non/existing/file2'
|
assert viewpoints.at(1).path.value == '/non/existing/file2'
|
||||||
assert viewpoints[1].intrinsicId.value == 55
|
assert viewpoints.at(1).intrinsicId.value == 55
|
||||||
|
|
||||||
# Ensure that all output UIDs are different as the input is different:
|
# Ensure that all output UIDs are different as the input is different:
|
||||||
# graph1 != graph2 != graph3 != graph4
|
# graph1 != graph2 != graph3 != graph4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue