Commit 64288df2 authored by Valentin Valls's avatar Valentin Valls
Browse files

Insert scan at right place when it is loaded from history

parent 9ab47bf7
......@@ -394,6 +394,10 @@ class Scan(qt.QObject, _Sealable):
raise KeyError("Version do not match")
return result[1]
def startTime(self):
scanInfo = self.scanInfo()
return scanInfo.get("start_time", None)
class ScanGroup(Scan):
"""Scan group object.
......
......@@ -555,6 +555,18 @@ class CurvePlotWidget(plot_helper.PlotWidget):
self.scanListUpdated.emit(self.__scans)
self.__redrawAllScans()
def insertScan(self, scan):
if scan is None:
return
if scan is self.__scan:
_logger.warning("Removing the current scan is not available")
return
self.__scans.append(scan)
self.__scans = list(reversed(sorted(self.__scans, key=lambda s: s.startTime())))
self.__syncStyleStrategy()
self.scanListUpdated.emit(self.__scans)
self.__redrawAllScans()
def setMaxStoredScans(self, maxScans: int):
# FIXME: Must emit event
self.__maxStoredScans = maxScans
......
......@@ -890,27 +890,32 @@ class CurvePlotPropertyWidget(qt.QWidget):
scan = scan_history.create_scan(nodeName)
widget = self.__focusWidget
if widget is not None:
plots = scan_info_helper.create_plot_model(scan.scanInfo(), scan)
plots = [p for p in plots if isinstance(p, plot_item_model.CurvePlot)]
if len(plots) == 0:
_logger.warning("No curve plot to display")
qt.QMessageBox.warning(
None, "Warning", "There was no curve plot in the selected scan"
)
return
plotModel = plots[0]
previousWidgetPlot = self.__plotModel
# Reuse only available values
if isinstance(previousWidgetPlot, plot_item_model.CurvePlot):
model_helper.removeNotAvailableChannels(
previousWidgetPlot, plotModel, scan
)
widget.setScan(scan)
if previousWidgetPlot is None or previousWidgetPlot.isEmpty():
if plotModel.styleStrategy() is None:
plotModel.setStyleStrategy(DefaultStyleStrategy(self.__flintModel))
widget.setPlotModel(plotModel)
if widget.isPreviousScanStored():
widget.insertScan(scan)
else:
plots = scan_info_helper.create_plot_model(scan.scanInfo(), scan)
plots = [p for p in plots if isinstance(p, plot_item_model.CurvePlot)]
if len(plots) == 0:
_logger.warning("No curve plot to display")
qt.QMessageBox.warning(
None, "Warning", "There was no curve plot in the selected scan"
)
return
plotModel = plots[0]
previousWidgetPlot = self.__plotModel
# Reuse only available values
if isinstance(previousWidgetPlot, plot_item_model.CurvePlot):
model_helper.removeNotAvailableChannels(
previousWidgetPlot, plotModel, scan
)
widget.setScan(scan)
if previousWidgetPlot is None or previousWidgetPlot.isEmpty():
if plotModel.styleStrategy() is None:
plotModel.setStyleStrategy(
DefaultStyleStrategy(self.__flintModel)
)
widget.setPlotModel(plotModel)
def __findItemFromPlotItem(
self, requestedItem: plot_model.Item
......
......@@ -378,8 +378,7 @@ class ScanStartTimeDelegate(qt.QStyledItemDelegate):
return editor
def __toStartTimeText(self, scan: scan_model.Scan) -> str:
scanInfo = scan.scanInfo()
value = scanInfo.get("start_time", None)
value = scan.startTime()
if value is None:
return ""
return value.strftime("%H:%M")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment