Skip to content

Commit

Permalink
Multiple debug about the new log panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Aug 10, 2023
1 parent 3ba8e01 commit 82f27a0
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 37 deletions.
2 changes: 2 additions & 0 deletions lizmap/definitions/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Html(Enum):
H4 = 'h4'
Strong = 'strong'
Li = 'li'
Td = 'td'
P = 'p'


@unique
Expand Down
30 changes: 29 additions & 1 deletion lizmap/log_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
from qgis.PyQt.QtWidgets import QTextEdit

from lizmap.definitions.definitions import Html
from lizmap.qgis_plugin_tools.tools.resources import resources_path


class LogPanel:

def __init__(self, widget: QTextEdit):
self.widget = widget
css_path = resources_path('css', 'log.css')
with open(css_path, encoding='utf8') as f:
css = f.read()
self.widget.document().setDefaultStyleSheet(css)
self.html = ''

def append_html(self, new: str):
self.html += new
# Do not use self.widget.html()
# Qt is adding a lot of things in the HTML
self.widget.setHtml(self.html)

def separator(self):
""" Add a horizontal separator. """
Expand Down Expand Up @@ -55,11 +67,27 @@ def append(
output += '<{0}>{1}</{0}>'.format(style.value, msg)
msg = output

self.widget.append(msg)
self.append_html(msg)

def start_table(self):
self.append_html("<table class=\"tabular-view\" width=\"100%\">")

def end_table(self):
self.append_html("</table>")

def add_row(self, index):
row_class = ''
if index % 2:
row_class = "class=\"odd-row\""
self.append_html("<tr {}>".format(row_class))

def end_row(self):
self.append_html("</tr>")

def clear(self):
""" Clear the content of the text area log. """
self.widget.clear()
self.html = ''


if __name__ == '__main__':
Expand Down
88 changes: 55 additions & 33 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ def read_cfg_file(self, skip_tables=False) -> dict:
'The previous .cfg has been saved as .cfg.back')
QMessageBox.critical(
self.dlg, tr('Lizmap Error'), message, QMessageBox.Ok)
self.dlg.log_panel.append(message, abort=True)
self.dlg.log_panel.append(message, abort=True, style=Html.P)
LOGGER.critical('Error while reading the CFG file')

else:
Expand Down Expand Up @@ -2055,7 +2055,7 @@ def read_lizmap_config_file(self) -> dict:
'Please re-configure the options in the Layers tab completely'
)
QMessageBox.critical(self.dlg, tr('Lizmap Error'), '', QMessageBox.Ok)
self.dlg.log_panel.append(message, abort=True)
self.dlg.log_panel.append(message, abort=True, style=Html.P)
return {}

def populate_layer_tree(self) -> dict:
Expand Down Expand Up @@ -2715,31 +2715,37 @@ def project_config_file(self, lwc_version: LwcVersions, with_gui: bool = True, c
self.dlg.log_panel.append(tr(
"These layers don't have a proper primary key in the database. So QGIS Desktop tried to set a "
"temporary field called '{}' to be a unique identifier. On QGIS Server, this will bring issues."
).format(field))
).format(field), Html.P)
self.dlg.log_panel.append("<br>")
layers.sort()
for layer_name in layers:
self.dlg.log_panel.append('⚫ {}'.format(layer_name))
self.dlg.log_panel.append("<br>")
self.dlg.log_panel.start_table()
for i, layer_name in enumerate(layers):
self.dlg.log_panel.add_row(i)
self.dlg.log_panel.append(layer_name, Html.Td)
self.dlg.log_panel.end_row()

self.dlg.log_panel.end_table()

if int8:
int8.sort()
self.dlg.log_panel.append(tr(
"The primary key has been detected as a bigint (integer8) for your layer :"))
self.dlg.log_panel.append("<br>")
for layer_name in int8:
self.dlg.log_panel.append("⚫ {}".format(layer_name))
"The primary key has been detected as a bigint (integer8) for your layer :"), Html.P)
self.dlg.log_panel.start_table()
for i, layer_name in enumerate(int8):
self.dlg.log_panel.add_row(i)
self.dlg.log_panel.append(layer_name, Html.Td)
self.dlg.log_panel.end_row()
self.dlg.log_panel.end_table()
self.dlg.log_panel.append("<br>")

self.dlg.log_panel.append("<br>")
self.dlg.log_panel.append(tr(
"We highly recommend you to set a proper integer field as a primary key, but neither a bigint nor an "
"integer8."))
self.dlg.log_panel.append("<br>")
self.dlg.log_panel.append(tr(
"The process is continuing but expect these layers to have some issues with some tools in "
"Lizmap Web Client: zoom to feature, filtering..."
))
if autogenerated_keys or int8:
self.dlg.log_panel.append(tr(
"We highly recommend you to set a proper integer field as a primary key, but neither a bigint nor "
"an integer8."), Html.P)
self.dlg.log_panel.append(tr(
"The process is continuing but expect these layers to have some issues with some tools in "
"Lizmap Web Client: zoom to feature, filtering..."
), style=Html.P)

if lwc_version >= LwcVersions.Lizmap_3_7:
text = duplicated_layer_with_filter(self.project)
Expand All @@ -2753,23 +2759,31 @@ def project_config_file(self, lwc_version: LwcVersions, with_gui: bool = True, c
if len(results):
self.dlg.log_panel.append(tr('Simplify on the provider side'), Html.H2)
self.dlg.log_panel.append(tr(
'These PostgreSQL vector layers can have the simplification on the provider side') + ':')
for layer in results:
self.dlg.log_panel.append('⚫ ' + layer)
self.dlg.log_panel.append(tr('Visit the layer properties, "Rendering" tab to enable it.'))
'These PostgreSQL vector layers can have the simplification on the provider side') + ':', Html.P)
self.dlg.log_panel.start_table()
for i, layer in enumerate(results):
self.dlg.log_panel.add_row(i)
self.dlg.log_panel.append(layer, Html.Td)
self.dlg.log_panel.end_row()
self.dlg.log_panel.end_table()
self.dlg.log_panel.append(tr('Visit the layer properties, "Rendering" tab to enable it.'), Html.P)
show_log = True

results = use_estimated_metadata(self.project)
if len(results):
self.dlg.log_panel.append(tr('Estimated metadata'), Html.H2)
self.dlg.log_panel.append(tr(
'These PostgreSQL layers can have the use estimated metadata option enabled') + ':')
for layer in results:
self.dlg.log_panel.append('⚫ ' + layer)
'These PostgreSQL layers can have the use estimated metadata option enabled') + ':', Html.P)
self.dlg.log_panel.start_table()
for i, layer in enumerate(results):
self.dlg.log_panel.add_row(i)
self.dlg.log_panel.append(layer, Html.Td)
self.dlg.log_panel.end_row()
self.dlg.log_panel.end_table()
self.dlg.log_panel.append(tr(
'Edit your PostgreSQL connection to enable this option, then change the datasource by right clicking '
'on each layer above, then click "Change datasource" in the menu. Finally reselect your layer in the '
'new dialog.'))
'new dialog.'), Html.P)
show_log = True

if with_gui and show_log:
Expand Down Expand Up @@ -3137,10 +3151,16 @@ def check_project_validity(self):

validator = QgsProjectServerValidator()
valid, results = validator.validate(self.project)
self.dlg.log_panel.append(tr("OGC validation"), style=Html.H2)
self.dlg.log_panel.append(tr("According to OGC standard : {}").format('VALID' if valid else 'NOT valid'))
# if not valid:
# self.dlg.log_panel.append(tr("According to OGC standard : {}").format('VALID' if valid else 'NOT valid'))
if not valid:
self.dlg.log_panel.append(tr("OGC validation"), style=Html.H2)
self.dlg.log_panel.append(
tr("According to OGC standard : {}").format(tr('Valid') if valid else tr('Not valid')), Html.P)
self.dlg.log_panel.append(
tr(
"Open the 'Project properties', then 'QGIS Server' tab, at the bottom, you can check your project "
"according to OGC standard. If you need to fix a layer shortname, go to the 'Layer properties' "
"for the given layer, then 'QGIS Server' tab, edit the shortname."
), Html.P)

LOGGER.info(f"Project has been detected : {'VALID' if valid else 'NOT valid'} according to OGC validation.")

Expand Down Expand Up @@ -3262,7 +3282,7 @@ def save_cfg_file(
Check the user defined data from GUI and save them to both global and project config files.
"""
self.dlg.log_panel.clear()
self.dlg.log_panel.append(tr('Start saving the Lizmap configuration'), time=True)
self.dlg.log_panel.append(tr('Start saving the Lizmap configuration'), style=Html.P, time=True)
variables = self.project.customVariables()
variables['lizmap_repository'] = self.dlg.current_repository()
self.project.setCustomVariables(variables)
Expand Down Expand Up @@ -3410,8 +3430,10 @@ def save_cfg_file(
# write data in the lizmap json config file
self.write_project_config_file(lwc_version, with_gui)

self.dlg.log_panel.append(tr('All the map parameters are correctly set'), abort=False, time=True)
# self.dlg.log_panel.append(tr('All the map parameters are correctly set'), abort=False, time=True)
self.dlg.log_panel.append("<p>")
self.dlg.log_panel.append(tr('Lizmap configuration file has been updated'), style=Html.Strong, abort=False)
self.dlg.log_panel.append("</p>")

self.get_min_max_scales()
msg = tr('Lizmap configuration file has been updated')
Expand Down
4 changes: 4 additions & 0 deletions lizmap/project_checker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def auto_generated_primary_key_field(layer: QgsVectorLayer) -> Tuple[bool, Optio
# )
# In QGIS source code, look for "Primary key is ctid"

if layer.dataProvider().uri().keyColumn() == '':
# GeoJSON etc
return False, None

# QgsVectorLayer.primaryKeyAttributes is returning a list.
if len(layer.primaryKeyAttributes()) >= 2:
# We don't check for composite keys here
Expand Down
77 changes: 77 additions & 0 deletions lizmap/resources/css/log.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.overview {
font: 1.82em;
font-weight: bold;
}
body{
background: white;
color: black;
font-family: 'Lato', 'Open Sans', 'Lucida Grande', 'Segoe UI', 'Arial', sans-serif;
width: 100%;
margin: 10px;
}
h1{
background-color: #F6F6F6;
font-weight: normal;
background: none;
padding: 0.75em 0 0;
margin: 0;
line-height: 3em;
}
h2{
background-color: #F6F6F6;
font-weight: normal;
background: none;
padding: 0.75em 0 0;
margin: 0;
line-height: 1.1em;
}
h3{
background-color: #F6F6F6;
font-weight: bold;
text-align: left;
border-bottom: 5px solid #DCEB5C;
}
h4{
background-color: #F6F6F6;
font-weight: bold;
text-align: left;
}
h5{
background-color: #F6F6F6;
font-weight: bold;
text-align: left;
}
a{
color: #729FCF;
font-family: arial,sans-serif;
}
label{
background-color: #FFFFCC;
border: 1px solid black;
margin: 1px;
padding: 0px 3px;
font-size: small;
}
th .strong {
font-weight: bold;
}
hr {
border: 0;
height: 0;
border-top: 1px solid black;
}
.list-view .highlight {
text-align: left;
border: 0px;
width: 20%;
padding-right: 15px;
padding-left: 20px;
font-weight: bold;
}
.tabular-view .odd-row {
background-color: #f9f9f9;
}
.section {
font-weight: bold;
padding-top:25px;
}
3 changes: 0 additions & 3 deletions lizmap/resources/ui/ui_lizmap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4378,9 +4378,6 @@ This is different to the map maximum extent (defined in QGIS project properties,
</property>
<item>
<widget class="QTextEdit" name="out_log">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
Expand Down
2 changes: 2 additions & 0 deletions lizmap/test/test_ogc_project_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_shortname_generation(self):
self.assertEqual("osm-mapnik", OgcProjectValidity.short_name("-osm-mapnik", []))
self.assertEqual("a_lAyer", OgcProjectValidity.short_name("à lÂyér", []))
self.assertEqual("l_123_a_layer", OgcProjectValidity.short_name("123 a layer", []))
# German Eszett
self.assertEqual("B_B", OgcProjectValidity.short_name("BßB", []))

shortname = OgcProjectValidity.short_name('こんにちは', [])
self.assertEqual(5, len(shortname))
Expand Down

0 comments on commit 82f27a0

Please sign in to comment.