Skip to content

Commit

Permalink
Update project auto fix : estimated MD, simplification, trust, review…
Browse files Browse the repository at this point in the history
… checks
  • Loading branch information
Gustry committed Oct 25, 2023
1 parent 920fa97 commit cc6f658
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 83 deletions.
73 changes: 72 additions & 1 deletion lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
from qgis.utils import OverrideCursor, iface

from lizmap.log_panel import LogPanel
from lizmap.project_checker_tools import (
project_trust_layer_metadata,
simplify_provider_side,
use_estimated_metadata,
)
from lizmap.saas import fix_ssl

try:
Expand Down Expand Up @@ -73,6 +78,10 @@ def __init__(self, parent=None):
self.feature_picker_layout.addWidget(self.dataviz_feature_picker)
self.feature_picker_layout.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))

# Make them hidden until we have the changelog URL
self.lwc_version_latest_changelog.setVisible(False)
self.lwc_version_oldest_changelog.setVisible(False)

# IGN and google
self.inIgnKey.textChanged.connect(self.check_ign_french_free_key)
self.inIgnKey.textChanged.connect(self.check_api_key_address)
Expand All @@ -94,9 +103,28 @@ def __init__(self, parent=None):
self.check_project_thumbnail()
self.setup_icons()

# Fixer tools
self.fixer_project_label.setText(tr(
'These tools can fix your current loaded layers in <b>this project only</b>. '
'You still need to update your connection or default settings in your QGIS global settings, to be be '
'applied automatically for new project or newly added layer.'))
self.enabled_ssl_button(False)
self.enabled_estimated_md_button(False)
self.enabled_trust_project(False)
self.enabled_simplify_geom(False)

self.button_convert_ssl.clicked.connect(self.fix_project_ssl)
self.button_convert_ssl.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))

self.button_use_estimated_md.clicked.connect(self.fix_project_estimated_md)
self.button_use_estimated_md.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))

self.button_trust_project.clicked.connect(self.fix_project_trust)
# self.button_trust_project.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))

self.button_simplify_geom.clicked.connect(self.fix_simplify_geom_provider)
self.button_simplify_geom.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))

self.buttonBox.button(QDialogButtonBox.Help).setToolTip(tr(
'Open the help in the web-browser'
))
Expand Down Expand Up @@ -201,6 +229,23 @@ def enabled_ssl_button(self, status: bool):

self.button_convert_ssl.setEnabled(status)

def enabled_estimated_md_button(self, status: bool):
""" Enable or not the button. """
if Qgis.QGIS_VERSION_INT <= 32200:
self.button_use_estimated_md.setToolTip(tr("QGIS 3.22 minimum is required"))
self.button_use_estimated_md.setEnabled(False)
return

self.button_use_estimated_md.setEnabled(status)

def enabled_trust_project(self, status: bool):
""" Enable or not the button. """
self.button_trust_project.setEnabled(status)

def enabled_simplify_geom(self, status: bool):
""" Enable or not the button. """
self.button_simplify_geom.setEnabled(status)

def follow_map_theme_toggled(self):
""" If the theme is loaded at startup, the UX is updated about the toggled checkbox and the legend option. """
text = ". " + tr("Overriden by the map theme")
Expand Down Expand Up @@ -676,7 +721,6 @@ def check_action_file_exists(self) -> bool:

def allow_navigation(self, allow_navigation: bool, message: str = ''):
""" Allow the navigation or not in the UI. """
self.enabled_ssl_button(False)
for i in range(1, self.mOptionsListWidget.count()):
item = self.mOptionsListWidget.item(i)
if allow_navigation:
Expand All @@ -702,6 +746,33 @@ def fix_project_ssl(self):
msg = tr('{} layer updated').format(count)
self.display_message_bar("SSL", msg, Qgis.Success)

def fix_project_estimated_md(self):
""" Fix the current project about estimated metadata. """
with OverrideCursor(Qt.WaitCursor):
count = len(use_estimated_metadata(self.project, fix=True))

if count >= 2:
msg = tr('{} layers updated').format(count)
else:
msg = tr('{} layer updated').format(count)
self.display_message_bar(tr("Estimated metadata"), msg, Qgis.Success)

def fix_project_trust(self):
""" Fix the current project trust metadata. """
project_trust_layer_metadata(self.project, True)
self.display_message_bar(tr("Trust metadata"), tr('Trust metadata is enabled'), Qgis.Success)

def fix_simplify_geom_provider(self):
""" Fix the current layers simplify geom. """
with OverrideCursor(Qt.WaitCursor):
count = len(simplify_provider_side(self.project, fix=True))

if count >= 2:
msg = tr('{} layers updated').format(count)
else:
msg = tr('{} layer updated').format(count)
self.display_message_bar(tr("Simplify geometry on the provider side"), msg, Qgis.Success)

def activateWindow(self):
""" When the dialog displayed, to trigger functions in the plugin when the dialog is opening. """
self.check_project_thumbnail()
Expand Down
7 changes: 6 additions & 1 deletion lizmap/log_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def append(
output = ''
if style in (Html.H1, Html.H2, Html.H3):
output += '<br>'
output += '<{0}>{1}</{0}>'.format(style.value, msg)
if level == Qgis.Warning:
output += '<{0} style="color: orange">{1}</{0}>'.format(style.value, msg)
elif level == Qgis.Critical:
output += '<{0} style="color: red">{1}</{0}>'.format(style.value, msg)
else:
output += '<{0}>{1}</{0}>'.format(style.value, msg)
msg = output

self.append_html(msg)
Expand Down
Loading

0 comments on commit cc6f658

Please sign in to comment.