From 534a43d16922e775b0e75895f7aba58e0d42b564 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 9 Dec 2024 18:29:53 +0100 Subject: [PATCH] Add a confirmation text input if the project has some "important" errors before generating CFG file --- lizmap/dialogs/confirmation_text_box.py | 84 +++++++++++++++++++++++++ lizmap/plugin.py | 12 ++++ lizmap/widgets/check_project.py | 8 +++ 3 files changed, 104 insertions(+) create mode 100644 lizmap/dialogs/confirmation_text_box.py diff --git a/lizmap/dialogs/confirmation_text_box.py b/lizmap/dialogs/confirmation_text_box.py new file mode 100644 index 00000000..bbf92e61 --- /dev/null +++ b/lizmap/dialogs/confirmation_text_box.py @@ -0,0 +1,84 @@ +from qgis.PyQt.QtCore import QSize +from qgis.PyQt.QtGui import QIcon, QPixmap +from qgis.PyQt.QtWidgets import ( + QDialog, + QDialogButtonBox, + QHBoxLayout, + QLabel, + QLineEdit, + QVBoxLayout, +) + +from lizmap.toolbelt.i18n import tr +from lizmap.toolbelt.resources import resources_path + +__copyright__ = 'Copyright 2024, 3Liz' +__license__ = 'GPL version 3' +__email__ = 'info@3liz.org' + + +class ConfirmationTextMessageBox(QDialog): + + def __init__(self, number: int, confirmation_text: str, *__args): + """ Constructor. """ + super().__init__(*__args) + + self.setWindowTitle(tr("Error(s) on the project")) + self.setWindowIcon(QIcon(resources_path('icons', 'icon.png')), ) + + # Text to use for enabling the OK button + self.confirmation_text = confirmation_text + + self.main_layout = QVBoxLayout(self) + self.horizontal_layout = QHBoxLayout(self) + + # Left side + self.icon = QLabel() + self.icon.setPixmap(QPixmap(":images/themes/default/mIconWarning.svg")) + self.icon.setMinimumSize(QSize(150, 150)) + self.horizontal_layout.addWidget(self.icon) + + # Right side, text and line edit + self.right_side_layout = QVBoxLayout(self) + + self.text = QLabel(self) + self.text.setWordWrap(True) + + message = tr('The project has at least one important issue :') + message += "" + message += " " + tr("{count} error(s)").format(count=number) + message += "

" + message += tr( + 'You should really consider fixing these "Important" issues to avoid technical problems ' + 'on Lizmap later.' + ) + message += "

" + message += tr( + 'You can decide to skip fixing these "Important" issues but you must write the name of the project with ' + 'the number of error in the input text below so as to generate the Lizmap configuration file.' + ) + message += "

" + message += tr("Please type :") + message += f"
{self.confirmation_text}" + self.text.setText(message) + + self.input_text = QLineEdit(self) + + self.right_side_layout.addWidget(self.text) + self.right_side_layout.addWidget(self.input_text) + self.horizontal_layout.addLayout(self.right_side_layout) + self.main_layout.addLayout(self.horizontal_layout) + + self.button_box = QDialogButtonBox(self) + self.button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) + self.button_box.button(QDialogButtonBox.StandardButton.Cancel).clicked.connect(self.close) + self.button_box.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.accept) + self.main_layout.addWidget(self.button_box) + + self.input_text.textEdited.connect(self.check_input_text) + self.check_input_text() + + def check_input_text(self): + """ Check the input text to enable or not the OK button.""" + self.button_box.button(QDialogButtonBox.StandardButton.Ok).setEnabled( + self.confirmation_text == self.input_text.text()) diff --git a/lizmap/plugin.py b/lizmap/plugin.py index 16a7796a..258defad 100755 --- a/lizmap/plugin.py +++ b/lizmap/plugin.py @@ -116,6 +116,7 @@ from lizmap.definitions.qgis_settings import Settings from lizmap.definitions.time_manager import TimeManagerDefinitions from lizmap.definitions.tooltip import ToolTipDefinitions +from lizmap.dialogs.confirmation_text_box import ConfirmationTextMessageBox from lizmap.dialogs.dock_html_preview import HtmlPreview from lizmap.dialogs.html_editor import HtmlEditorDialog from lizmap.dialogs.html_maptip import HtmlMapTipDialog @@ -3564,6 +3565,17 @@ def check_project( return False + important_issues = self.dlg.check_results.has_importants() + if important_issues >= 1 and lizmap_cloud: + base_name = self.project.baseName() + dialog = ConfirmationTextMessageBox(important_issues, f"{base_name}:{important_issues}") + result = dialog.exec() + self.dlg.log_panel.append(tr( + "{count} error(s) have been found on the project, user has agreed with these errors : {result}" + ).format(count=important_issues, result="" + tr("Yes") + "" if result else tr("No")), Html.P) + if not result: + return False + return True def project_config_file( diff --git a/lizmap/widgets/check_project.py b/lizmap/widgets/check_project.py index 65b93c3e..bdc60f2b 100644 --- a/lizmap/widgets/check_project.py +++ b/lizmap/widgets/check_project.py @@ -1083,6 +1083,14 @@ def has_blocking(self) -> bool: return True return False + def has_importants(self) -> int: + """ If the table has at least one important issue. """ + count = 0 + for row in range(self.rowCount()): + if self.item(row, 0).data(self.DATA) == 1: + count += 1 + return count + def has_rows(self) -> int: """ If the table has at least one row displayed. """ return self.rowCount()