From f9d79627b5083c2c1bd21b4af32d6849a0e6df5d Mon Sep 17 00:00:00 2001 From: Slawomir Gonet Date: Mon, 12 May 2025 10:23:42 +0200 Subject: [PATCH] CAM: Fix Existing Stock from resetting Due to a Qt signal setup, the clone object for Existing Stock stock type was recreated every time the Job properties dialog was opened (during the stock candidates list population). This fix blocks the Qt signal from being emitted during the dropdown population. --- src/Mod/CAM/Path/Main/Gui/Job.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Mod/CAM/Path/Main/Gui/Job.py b/src/Mod/CAM/Path/Main/Gui/Job.py index 2c19d35973..6d480cd4ad 100644 --- a/src/Mod/CAM/Path/Main/Gui/Job.py +++ b/src/Mod/CAM/Path/Main/Gui/Job.py @@ -643,16 +643,22 @@ class StockFromExistingEdit(StockEdit): return sorted(solids, key=lambda c: c.Label) def setFields(self, obj): - self.form.stockExisting.clear() - stockName = obj.Stock.Label if obj.Stock else None - index = -1 - for i, solid in enumerate(self.candidates(obj)): - self.form.stockExisting.addItem(solid.Label, solid) - label = "{}-{}".format(self.StockLabelPrefix, solid.Label) + # Block signal propagation during stock dropdown population. This prevents + # the `currentIndexChanged` signal from being emitted while populating the + # dropdown list. This is important because the `currentIndexChanged` signal + # will in the end result in the stock object being recreated in `getFields` + # method, discarding any changes made (like position in respect to origin). + with QtCore.QSignalBlocker(self.form.stockExisting): + self.form.stockExisting.clear() + stockName = obj.Stock.Label if obj.Stock else None + index = -1 + for i, solid in enumerate(self.candidates(obj)): + self.form.stockExisting.addItem(solid.Label, solid) + label = "{}-{}".format(self.StockLabelPrefix, solid.Label) - if label == stockName: - index = i - self.form.stockExisting.setCurrentIndex(index if index != -1 else 0) + if label == stockName: + index = i + self.form.stockExisting.setCurrentIndex(index if index != -1 else 0) if not self.IsStock(obj): self.getFields(obj)