Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear ilicache button #811

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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