diff --git a/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py b/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py index 4b0e24968..f1b1343bc 100644 --- a/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py +++ b/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py @@ -20,15 +20,23 @@ from qgis.core import QgsApplication from qgis.PyQt.QtCore import Qt -from qgis.PyQt.QtWidgets import QCompleter, QWizardPage +from qgis.PyQt.QtWidgets import ( + QApplication, + QCompleter, + QMessageBox, + QPushButton, + QWizardPage, +) -import QgisModelBaker.utils.gui_utils as gui_utils from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import ( IliCache, + IliDataCache, + IliToppingFileCache, ModelCompleterDelegate, ) from QgisModelBaker.libs.modelbaker.utils.qt_utils import ( FileValidator, + OverrideCursor, QValidator, make_file_selector, ) @@ -94,6 +102,9 @@ def __init__(self, parent, title): self.workflow_wizard.append_dropped_files ) + self.clear_cache_button = QPushButton(self.tr("Clear ilicache"), self) + self.clear_cache_button.clicked.connect(self._clear_cache_button_clicked) + def nextId(self): self._disconnect_punch_slots() return self.workflow_wizard.next_id() @@ -186,3 +197,42 @@ def _remove_selected_rows(self): indices = self.source_list_view.selectionModel().selectedIndexes() self.source_list_view.model().remove_sources(indices) self.remove_button.setEnabled(self._valid_selection()) + + def _clear_cache_button_clicked(self): + with OverrideCursor(Qt.WaitCursor): + + try: + IliCache.clear_cache() + except Exception as exception: + QApplication.restoreOverrideCursor() + QMessageBox.critical( + self, + "Clear cache failed", + "Can't delete the ili cache folder '{}'\n\nDetail:\n{}".format( + IliCache.CACHE_PATH, str(exception) + ), + ) + + try: + IliDataCache.clear_cache() + except Exception as exception: + QApplication.restoreOverrideCursor() + QMessageBox.critical( + self, + "Clear cache failed", + "Can't delete the ili data cache folder '{}'\n\nDetail:\n{}".format( + IliDataCache.CACHE_PATH, str(exception) + ), + ) + + try: + IliToppingFileCache.clear_cache() + except Exception as exception: + QApplication.restoreOverrideCursor() + QMessageBox.critical( + self, + "Clear cache failed", + "Can't delete the ili topping cache folder '{}'\n\nDetail:\n{}".format( + IliToppingFileCache.CACHE_PATH, str(exception) + ), + ) diff --git a/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py b/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py index e49471084..7174fa38a 100644 --- a/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py +++ b/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py @@ -323,6 +323,20 @@ def id_changed(self, new_id): self.tr(f" > ---------- {self._current_page_title(self.current_id)}") ) + if self.current_id == PageIds.ImportSourceSelection: + # Add extra button Clear cache + self.setOption(QWizard.HaveCustomButton1, True) + self.setButton( + QWizard.CustomButton1, self.source_selection_page.clear_cache_button + ) + else: + # Remove extra button Clear cache + if ( + self.button(QWizard.CustomButton1) + == self.source_selection_page.clear_cache_button + ): + self.setOption(QWizard.HaveCustomButton1, False) + if self.current_id == PageIds.ImportDatabaseSelection: # use schema config to restore self.import_database_selection_page.restore_configuration(