Skip to content

Commit 5fe3391

Browse files
authored
Complete and reorganize theme options in configuration (#102)
1 parent b22d51c commit 5fe3391

File tree

8 files changed

+464
-27
lines changed

8 files changed

+464
-27
lines changed

src/plugins/themes/controllers/themes_controller.py

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ def create_form(self, theme=None):
442442
form.url.data = None
443443
if "title" in theme:
444444
form.title.data = theme["title"]
445+
if "description" in theme:
446+
form.description.data = theme["description"]
445447
if "disabled" in theme:
446448
form.disabled.data = theme["disabled"]
447449
if "default" in theme:
@@ -453,18 +455,24 @@ def create_form(self, theme=None):
453455
if "thumbnail" in theme:
454456
form.thumbnail.data = theme["thumbnail"]
455457
if "attribution" in theme:
456-
form.attribution.data = theme["attribution"]
457-
# TODO: FORM attributionUrl
458-
# if "attributionUrl" in theme:
459-
# form.attribution.data = theme["attributionUrl"]
458+
form.attribution.data = theme["attribution"]
459+
if "attributionUrl" in theme:
460+
form.attributionUrl.data = theme["attributionUrl"]
460461
if "format" in theme:
461462
form.format.data = theme["format"]
462463
if "mapCrs" in theme:
463464
form.mapCrs.data = theme["mapCrs"]
465+
if "extent" in theme:
466+
form.extent.data = ", ".join(map(str, theme[
467+
"extent"]))
464468
if "additionalMouseCrs" in theme:
465469
form.additionalMouseCrs.data = theme["additionalMouseCrs"]
466470
if "searchProviders" in theme:
467471
form.searchProviders.data = theme["searchProviders"]
472+
if "minSearchScaleDenom" in theme:
473+
form.minSearchScaleDenom.data = theme["minSearchScaleDenom"]
474+
if "tileSize" in theme:
475+
form.tileSize.data = ", ".join(map(str, theme["tileSize"]))
468476
if "scales" in theme:
469477
form.scales.data = ", ".join(map(str, theme["scales"]))
470478
if "printScales" in theme:
@@ -476,6 +484,24 @@ def create_form(self, theme=None):
476484
if "printLabelBlacklist" in theme:
477485
form.printLabelBlacklist.data = ", ".join(map(str, theme[
478486
"printLabelBlacklist"]))
487+
if "extraPrintLayers" in theme:
488+
form.extraPrintLayers.data = ", ".join(map(str, theme["extraPrintLayers"]))
489+
if "flags" in theme:
490+
form.flags.data = ", ".join(map(str, theme["flags"]))
491+
if "layerTreeHiddenSublayers" in theme:
492+
form.layerTreeHiddenSublayers.data = ", ".join(map(str, theme["layerTreeHiddenSublayers"]))
493+
if "extraPrintParameters" in theme:
494+
form.extraPrintParameters.data = ", ".join(theme["extraPrintParameters"].split('&'))
495+
if "extraLegendParameters" in theme:
496+
form.extraLegendParameters.data = ", ".join(theme["extraLegendParameters"].split('&'))
497+
if "extraDxfParameters" in theme:
498+
form.extraDxfParameters.data = ", ".join(theme["extraDxfParameters"].split('&'))
499+
if "defaultPrintLayout" in theme:
500+
form.defaultPrintLayout.data = theme["defaultPrintLayout"]
501+
if "printLabelForSearchResult" in theme:
502+
form.printLabelForSearchResult.data = theme["printLabelForSearchResult"]
503+
if "printLabelForAttribution" in theme:
504+
form.printLabelForAttribution.data = theme["printLabelForAttribution"]
479505
if "skipEmptyFeatureAttributes" in theme:
480506
form.skipEmptyFeatureAttributes.data = theme["skipEmptyFeatureAttributes"]
481507
if "collapseLayerGroupsBelowLevel" in theme:
@@ -550,6 +576,10 @@ def create_or_update_theme(self, theme, form, tid=None, gid=None):
550576
else:
551577
if "title" in item: del item["title"]
552578

579+
item["description"] = ""
580+
if form.description.data:
581+
item["description"] = form.description.data
582+
553583
item["disabled"] = False
554584
if form.disabled.data:
555585
item["disabled"] = True
@@ -573,8 +603,9 @@ def create_or_update_theme(self, theme, form, tid=None, gid=None):
573603
if form.attribution.data:
574604
item["attribution"] = form.attribution.data
575605

576-
# TODO: FORM attributionUrl
577606
item["attributionUrl"] = ""
607+
if form.attributionUrl.data:
608+
item["attributionUrl"] = form.attributionUrl.data
578609

579610
if form.format.data:
580611
item["format"] = form.format.data
@@ -586,6 +617,12 @@ def create_or_update_theme(self, theme, form, tid=None, gid=None):
586617
else:
587618
if item in "mapCrs": del item["mapCrs"]
588619

620+
if form.extent.data:
621+
item["extent"] = list(map(
622+
float, form.extent.data.replace(" ", "").split(",")))
623+
else:
624+
if "extent" in item: del item["extent"]
625+
589626
if form.additionalMouseCrs.data:
590627
item["additionalMouseCrs"] = form.additionalMouseCrs.data
591628
else:
@@ -612,6 +649,16 @@ def create_or_update_theme(self, theme, form, tid=None, gid=None):
612649
if not form.qgisSearchProvider.data and not form.searchProviders.data:
613650
if "searchProviders" in item: del item["searchProviders"]
614651

652+
item["minSearchScaleDenom"] = ""
653+
if form.minSearchScaleDenom.data:
654+
item["minSearchScaleDenom"] = form.minSearchScaleDenom.data
655+
656+
if form.tileSize.data:
657+
item["tileSize"] = list(map(
658+
int, form.tileSize.data.replace(" ", "").split(",")))
659+
else:
660+
if "tileSize" in item: del item["tileSize"]
661+
615662
if form.scales.data:
616663
item["scales"] = list(map(int, form.scales.data.replace(
617664
" ", "").split(",")))
@@ -637,6 +684,51 @@ def create_or_update_theme(self, theme, form, tid=None, gid=None):
637684
else:
638685
if "printLabelBlacklist" in item: del item["printLabelBlacklist"]
639686

687+
if form.extraPrintLayers.data:
688+
item["extraPrintLayers"] = list(map(
689+
str, form.extraPrintLayers.data.replace(" ", "").split(",")))
690+
else:
691+
if "extraPrintLayers" in item: del item["extraPrintLayers"]
692+
693+
if form.flags.data:
694+
item["flags"] = list(map(
695+
str, form.flags.data.replace(" ", "").split(",")))
696+
else:
697+
if "flags" in item: del item["flags"]
698+
699+
if form.layerTreeHiddenSublayers.data:
700+
item["layerTreeHiddenSublayers"] = list(map(
701+
str, form.layerTreeHiddenSublayers.data.replace(" ", "").split(",")))
702+
else:
703+
if "layerTreeHiddenSublayers" in item: del item["layerTreeHiddenSublayers"]
704+
705+
item["extraPrintParameters"] = ""
706+
if form.extraPrintParameters.data:
707+
item["extraPrintParameters"] = "&".join(list(map(
708+
str, form.extraPrintParameters.data.replace(" ", "").split(","))))
709+
710+
item["extraLegendParameters"] = ""
711+
if form.extraLegendParameters.data:
712+
item["extraLegendParameters"] = "&".join(list(map(
713+
str, form.extraLegendParameters.data.replace(" ", "").split(","))))
714+
715+
item["extraDxfParameters"] = ""
716+
if form.extraDxfParameters.data:
717+
item["extraDxfParameters"] = "&".join(list(map(
718+
str, form.extraDxfParameters.data.replace(" ", "").split(","))))
719+
720+
item["defaultPrintLayout"] = ""
721+
if form.defaultPrintLayout.data:
722+
item["defaultPrintLayout"] = form.defaultPrintLayout.data
723+
724+
item["printLabelForSearchResult"] = ""
725+
if form.printLabelForSearchResult.data:
726+
item["printLabelForSearchResult"] = form.printLabelForSearchResult.data
727+
728+
item["printLabelForAttribution"] = ""
729+
if form.printLabelForAttribution.data:
730+
item["printLabelForAttribution"] = form.printLabelForAttribution.data
731+
640732
item["skipEmptyFeatureAttributes"] = False
641733
if form.skipEmptyFeatureAttributes.data:
642734
item["skipEmptyFeatureAttributes"] = True

src/plugins/themes/forms/theme_form.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from wtforms import FieldList, FormField, SelectField, BooleanField, \
55
SelectMultipleField, IntegerField, StringField, SubmitField, \
66
TextAreaField
7-
from wtforms.validators import DataRequired, Optional, Regexp
7+
from wtforms.validators import DataRequired, Optional, Regexp, URL
88
from utils import i18n
99

1010

@@ -54,11 +54,21 @@ class ThemeForm(FlaskForm):
5454
description=i18n('plugins.themes.theme.form_title_description'),
5555
validators=[Optional()]
5656
)
57+
description = StringField(
58+
i18n('interface.common.description'),
59+
description=i18n('plugins.themes.theme.form_description_description'),
60+
validators=[Optional()]
61+
)
5762
attribution = StringField(
5863
i18n('plugins.themes.common.form_attribution'),
5964
description=(i18n('plugins.themes.theme.form_attribution_description')),
6065
validators=[Optional()]
6166
)
67+
attributionUrl = StringField(
68+
i18n('plugins.themes.theme.form_attributionUrl'),
69+
description=(i18n('plugins.themes.theme.form_attributionUrl_description')),
70+
validators=[Optional(), URL()]
71+
)
6272
thumbnail = SelectField(
6373
i18n('plugins.themes.common.form_thumbnail'),
6474
description=(i18n('plugins.themes.theme.form_thumbnail_description')),
@@ -75,6 +85,13 @@ class ThemeForm(FlaskForm):
7585
default=("EPSG:3857"),
7686
validators=[Optional()]
7787
)
88+
extent = StringField(
89+
i18n('plugins.themes.theme.form_extent'),
90+
description=i18n('plugins.themes.theme.form_extent_description'),
91+
default=(""),
92+
validators=[Optional(), Regexp(r'^(\d+(\.\d*)?)(,\s*\d+(\.\d*)?){3}$',
93+
message=i18n('plugins.themes.theme.form_extent_message'))]
94+
)
7895
additionalMouseCrs = SelectMultipleField(
7996
i18n('plugins.themes.theme.form_additionalMouseCrs'),
8097
description=(i18n('plugins.themes.theme.form_additionalMouseCrs_description')),
@@ -87,6 +104,18 @@ class ThemeForm(FlaskForm):
87104
default=("coordinates")
88105
)
89106
qgisSearchProvider = FieldList(FormField(QgisSearchForm))
107+
minSearchScaleDenom = IntegerField(
108+
i18n('plugins.themes.theme.form_minSearchScaleDenom'),
109+
description=i18n('plugins.themes.theme.form_minSearchScaleDenom_description'),
110+
validators=[Optional()]
111+
)
112+
tileSize = StringField(
113+
i18n('plugins.themes.theme.form_tileSize'),
114+
description=i18n('plugins.themes.theme.form_tileSize_description'),
115+
default=(""),
116+
validators=[Optional(), Regexp(r'^\d+,\s*\d+$',
117+
message=i18n('plugins.themes.theme.form_tileSize_message'))]
118+
)
90119
scales = StringField(
91120
i18n('plugins.themes.theme.form_scales'),
92121
description=i18n('plugins.themes.theme.form_scales_description'),
@@ -114,6 +143,64 @@ class ThemeForm(FlaskForm):
114143
validators=[Optional(), Regexp(r'^(\w+)(,\s*\w+)*$',
115144
message=i18n('plugins.themes.theme.form_printLabelBlacklist_message'))]
116145
)
146+
extraPrintLayers = StringField(
147+
i18n('plugins.themes.theme.form_extraPrintLayers'),
148+
description=i18n('plugins.themes.theme.form_extraPrintLayers_description'),
149+
default=(""),
150+
validators=[Optional(), Regexp(r'^(\w+)(,\s*\w+)*$',
151+
message=i18n('plugins.themes.theme.form_extraPrintLayers_message'))]
152+
)
153+
flags = StringField(
154+
i18n('plugins.themes.theme.form_flags'),
155+
description=i18n('plugins.themes.theme.form_flags_description'),
156+
default=(""),
157+
validators=[Optional(), Regexp(r'^(\w+)(,\s*\w+)*$',
158+
message=i18n('plugins.themes.theme.form_flags_message'))]
159+
)
160+
layerTreeHiddenSublayers = StringField(
161+
i18n('plugins.themes.theme.form_layerTreeHiddenSublayers'),
162+
description=i18n('plugins.themes.theme.form_layerTreeHiddenSublayers_description'),
163+
default=(""),
164+
validators=[Optional(), Regexp(r'^(\w+)(,\s*\w+)*$',
165+
message=i18n('plugins.themes.theme.form_layerTreeHiddenSublayers_message'))]
166+
)
167+
extraPrintParameters = StringField(
168+
i18n('plugins.themes.theme.form_extraPrintParameters'),
169+
description=i18n('plugins.themes.theme.form_extraPrintParameters_description'),
170+
default=(""),
171+
validators=[Optional(), Regexp(r'^(\w+=\w+)(,\s*\w+=\w+)*$',
172+
message=i18n('plugins.themes.theme.form_extraPrintParameters_message'))]
173+
)
174+
extraLegendParameters = StringField(
175+
i18n('plugins.themes.theme.form_extraLegendParameters'),
176+
description=i18n('plugins.themes.theme.form_extraLegendParameters_description'),
177+
default=(""),
178+
validators=[Optional(), Regexp(r'^(\w+=\w+)(,\s*\w+=\w+)*$',
179+
message=i18n('plugins.themes.theme.form_extraLegendParameters_message'))]
180+
)
181+
extraDxfParameters = StringField(
182+
i18n('plugins.themes.theme.form_extraDxfParameters'),
183+
description=i18n('plugins.themes.theme.form_extraDxfParameters_description'),
184+
default=(""),
185+
validators=[Optional(), Regexp(r'^(\w+=\w+)(,\s*\w+=\w+)*$',
186+
message=i18n('plugins.themes.theme.form_extraDxfParameters_message'))]
187+
)
188+
189+
defaultPrintLayout = StringField(
190+
i18n('plugins.themes.theme.form_defaultPrintLayout'),
191+
description=(i18n('plugins.themes.theme.form_defaultPrintLayout_description')),
192+
validators=[Optional()]
193+
)
194+
printLabelForSearchResult = StringField(
195+
i18n('plugins.themes.theme.form_printLabelForSearchResult'),
196+
description=(i18n('plugins.themes.theme.form_printLabelForSearchResult_description')),
197+
validators=[Optional()]
198+
)
199+
printLabelForAttribution = StringField(
200+
i18n('plugins.themes.theme.form_printLabelForAttribution'),
201+
description=(i18n('plugins.themes.theme.form_printLabelForAttribution_description')),
202+
validators=[Optional()]
203+
)
117204
collapseLayerGroupsBelowLevel = IntegerField(
118205
i18n('plugins.themes.theme.form_collapseLayerGroupsBelowLevel'),
119206
description=i18n('plugins.themes.theme.form_collapseLayerGroupsBelowLevel_description'),

0 commit comments

Comments
 (0)