-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fields WMS not published when generating the HTML maptip, add opt…
…ion empty value
- Loading branch information
Showing
4 changed files
with
129 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
__copyright__ = 'Copyright 2023, 3Liz' | ||
__license__ = 'GPL version 3' | ||
__email__ = '[email protected]' | ||
|
||
|
||
from qgis.core import QgsVectorLayer | ||
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox | ||
|
||
from lizmap.qgis_plugin_tools.tools.i18n import tr | ||
from lizmap.qgis_plugin_tools.tools.resources import load_ui | ||
|
||
FORM_CLASS = load_ui('ui_html_maptip.ui') | ||
|
||
|
||
class HtmlMapTipDialog(QDialog, FORM_CLASS): | ||
|
||
def __init__(self, layer: QgsVectorLayer): | ||
QDialog.__init__(self) | ||
self.setupUi(self) | ||
self.layer = layer | ||
|
||
accept_button = self.button_box.button(QDialogButtonBox.Ok) | ||
accept_button.clicked.connect(self.accept) | ||
cancel_button = self.button_box.button(QDialogButtonBox.Cancel) | ||
cancel_button.clicked.connect(self.reject) | ||
|
||
def map_tip(self) -> str: | ||
table_template = """<table class="table table-condensed table-striped table-bordered lizmapPopupTable"> | ||
<thead> | ||
<tr> | ||
<th>{field}</th> | ||
<th>{value}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{fields_template} | ||
</tbody> | ||
</table>""" | ||
|
||
if self.show_null.isChecked(): | ||
field_template = """ <tr> | ||
<th>{display}</th> | ||
<td>[% "{name}" %]</td> | ||
</tr> | ||
""" | ||
else: | ||
field_template = """ | ||
[% with_variable( | ||
'content', | ||
'<tr><th>{display}</th><td>' || "{name}" || '</td></tr>', | ||
if( "{name}" is not NULL or "{name}" <> '',@content,'') | ||
) | ||
%] | ||
""" | ||
|
||
fields = "" | ||
for field in self.layer.fields(): | ||
name = field.name() | ||
if name in self.layer.excludeAttributesWms(): | ||
fields += "<!-- Field {} excluded from WMS in the layer properties -->\n".format(name) | ||
else: | ||
fields += field_template.format(display=field.displayName(), name=name) | ||
|
||
result = table_template.format(field=tr("Field"), value=tr("Value"), fields_template=fields) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>391</width> | ||
<height>128</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>HTML Maptip</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QCheckBox" name="show_null"> | ||
<property name="text"> | ||
<string>Show a row when the value is empty or NULL</string> | ||
</property> | ||
<property name="checked"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="button_box"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |