Mainwindow: Fix save as for multiple scenarios.

scenarios
Pierre-Antoine 2025-09-02 14:25:08 +02:00
parent e5b4c998cb
commit 37963b7b21
1 changed files with 38 additions and 10 deletions

View File

@ -686,13 +686,13 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
options=options,
)
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
logger.debug(f"Save study as : {repr(file_name)}")
if file_name == "":
return
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
if file_name.rsplit(".", 1)[-1] == "pamhyr":
logger.debug(
"Pamhyr extention is present : " +
@ -706,9 +706,42 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
self._study.filename = file_name + ".pamhyr"
sql_request_count = self._study.sql_save_request_count()
if len(self._study.scenarios) != 1:
self.save_as_study_multi_scenario()
else:
self.save_as_study_single_scenario()
self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def save_as_study_multi_scenario(self):
scenarios = self._study.scenarios.lst
progress = QProgressDialog(
"Saving...", None,
"Saving scenarios...", None,
0, len(scenarios),
parent=self
)
progress.setWindowModality(Qt.WindowModal)
progress.setValue(0)
for scenario in scenarios:
self._study.reload_from_scenario(scenario)
self.save_as_study_single_scenario(scenario.id)
progress.setValue(progress.value() + 1)
def save_as_study_single_scenario(self, sid=-1):
sql_request_count = self._study.sql_save_request_count()
msg = "Saving..."
if sid != -1:
msg = f"Saving scenario {sid}..."
progress = QProgressDialog(
msg, None,
0, sql_request_count,
parent=self
)
@ -727,11 +760,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
logger.info(status)
self.statusbar.showMessage(status, 3000)
self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def _backup(self):
logger.debug("Backup signal...")
if not self.conf.backup_enable: