Skip to content

Commit

Permalink
Add a confirmation text input if the project has some "important" err…
Browse files Browse the repository at this point in the history
…ors before generating CFG file
  • Loading branch information
Gustry committed Dec 10, 2024
1 parent c7ba30e commit 534a43d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
84 changes: 84 additions & 0 deletions lizmap/dialogs/confirmation_text_box.py
Original file line number Diff line number Diff line change
@@ -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__ = '[email protected]'


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 += "<strong>"
message += " " + tr("{count} error(s)").format(count=number)
message += "</strong><br><br>"
message += tr(
'You should really consider fixing these "<strong>Important</strong>" issues to avoid technical problems '
'on Lizmap later.'
)
message += "<br><br>"
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 += "<br><br>"
message += tr("Please type :")
message += f"<br><strong>{self.confirmation_text}</strong>"
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())
12 changes: 12 additions & 0 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="<strong>" + tr("Yes") + "<strong>" if result else tr("No")), Html.P)
if not result:
return False

return True

def project_config_file(
Expand Down
8 changes: 8 additions & 0 deletions lizmap/widgets/check_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 534a43d

Please sign in to comment.