Skip to content

Commit

Permalink
Merge pull request #811 from opengisch/clearIlicache
Browse files Browse the repository at this point in the history
Clear ilicache button
  • Loading branch information
domi4484 authored Jul 19, 2023
2 parents e339458 + 7cd1f8c commit d96785f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
54 changes: 52 additions & 2 deletions QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
),
)
14 changes: 14 additions & 0 deletions QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d96785f

Please sign in to comment.