Skip to content

Commit 59ed0d0

Browse files
authored
Merge pull request #716 from 3liz/plugin_refactoring
Simplify plugin.py
2 parents 6677881 + d42c863 commit 59ed0d0

38 files changed

+6784
-5871
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ tests/data/shortnames.qgs.cfg
5050
tests/credentials.py
5151
**/symbology-style.db
5252
**/*.qgs.bak
53+
54+
lizmap/plugin_refactoring

lizmap/config/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
from .config import LizmapConfig as LizmapConfig
2-
from .models import MappingQgisGeometryType as MappingQgisGeometryType
1+
from .config import LizmapConfig
2+
from .global_options import GlobalOptionsDefinitions, globalOptionDefinitions
3+
from .layer_options import LayerOptionDefinitions, layerOptionDefinitions
4+
from .models import MappingQgisGeometryType
5+
6+
__all__ = (
7+
"GlobalOptionsDefinitions",
8+
"LayerOptionDefinitions",
9+
"LizmapConfig",
10+
"MappingQgisGeometryType",
11+
"globalOptionDefinitions",
12+
"layerOptionDefinitions",
13+
)

lizmap/definitions/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def general_config(self) -> OrderedDict:
5757

5858
@staticmethod
5959
def primary_keys() -> tuple:
60-
return tuple()
60+
return ()
6161

6262
def add_layer_widget(self, key, widget):
6363
if key not in self._layer_config:

lizmap/definitions/dataviz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def __init__(self):
359359

360360
@staticmethod
361361
def primary_keys() -> tuple:
362-
return tuple()
362+
return ()
363363

364364
def key(self) -> str:
365365
return 'datavizLayers'

lizmap/definitions/lizmap_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
UPLOAD_MAX_SIZE = 11000000 # 11 Mb
1919

2020
# Excluded domains from Plausible
21-
EXCLUDED_DOMAINS = ('demo.snap.lizmap.com', 'demo.lizmap.com', 'localhost:8130' )
21+
EXCLUDED_DOMAINS = ('demo.snap.lizmap.com', 'demo.lizmap.com', 'localhost:8130')
2222
# Domains which are designed for workshops
2323
# For the "Training" panel and excluded from Plausible as well
2424
WORKSHOP_DOMAINS = (

lizmap/dialogs/confirmation_text_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, number: int, confirmation_text: str, *__args):
2424
super().__init__(*__args)
2525

2626
self.setWindowTitle(tr("Error(s) on the project"))
27-
self.setWindowIcon(QIcon(resources_path('icons', 'icon.png')) )
27+
self.setWindowIcon(QIcon(resources_path('icons', 'icon.png')))
2828

2929
# Text to use for enabling the OK button
3030
self.confirmation_text = confirmation_text

lizmap/dialogs/server_wizard.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,8 @@ def override_url(cls, base_url: str, metadata: bool = True) -> Optional[str]:
10441044
# We can either have [https://ilovecookie.org/] or [https://ilovecookie.org] in the urls.ini
10451045
config = configparser.ConfigParser()
10461046
config.read(ini)
1047-
if base_url not in config.sections():
1048-
if base_url[0:-1] not in config.sections():
1049-
return None
1047+
if base_url not in config.sections() and base_url[0:-1] not in config.sections():
1048+
return None
10501049

10511050
LOGGER.info("Found a server override for server <a href='{0}'>{0}</a>".format(base_url))
10521051

lizmap/drag_drop_dataviz_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def remove_item(self):
218218

219219
box = QMessageBox(self.parent)
220220
box.setIcon(QMessageBox.Icon.Question)
221-
box.setWindowIcon(QIcon(resources_path('icons', 'icon.png')) )
221+
box.setWindowIcon(QIcon(resources_path('icons', 'icon.png')))
222222
box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
223223
box.setDefaultButton(QMessageBox.StandardButton.No)
224224

lizmap/forms/base_edition_dialog.py

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -92,61 +92,57 @@ def setup_ui(self):
9292
if widget:
9393
widget.setToolTip(tooltip)
9494

95-
if layer_config['type'] in (InputType.List, InputType.CheckBoxAsDropdown):
96-
if widget is not None:
97-
items = layer_config.get('items')
98-
if items:
99-
for item in items:
100-
icon = item.value.get('icon')
101-
if icon:
102-
widget.addItem(QIcon(icon), item.value['label'], item.value['data'])
103-
else:
104-
widget.addItem(item.value['label'], item.value['data'])
105-
index = widget.findData(item.value['data'])
106-
tooltip = item.value.get('tooltip')
107-
if tooltip:
108-
widget.setItemData(index, tooltip, Qt.ItemDataRole.ToolTipRole)
109-
default = layer_config.get('default')
110-
if default and not isinstance(default, (list, tuple)):
111-
index = widget.findData(default.value['data'])
112-
widget.setCurrentIndex(index)
95+
if layer_config['type'] in (InputType.List, InputType.CheckBoxAsDropdown) and widget is not None:
96+
items = layer_config.get('items')
97+
if items:
98+
for item in items:
99+
icon = item.value.get('icon')
100+
if icon:
101+
widget.addItem(QIcon(icon), item.value['label'], item.value['data'])
102+
else:
103+
widget.addItem(item.value['label'], item.value['data'])
104+
index = widget.findData(item.value['data'])
105+
tooltip = item.value.get('tooltip')
106+
if tooltip:
107+
widget.setItemData(index, tooltip, Qt.ItemDataRole.ToolTipRole)
108+
default = layer_config.get('default')
109+
if default and not isinstance(default, (list, tuple)):
110+
index = widget.findData(default.value['data'])
111+
widget.setCurrentIndex(index)
113112

114113
if layer_config['type'] == InputType.CheckBox:
115114
default_value = layer_config['default']
116115
if widget is not None and not hasattr(default_value, '__call__'):
117116
widget.setChecked(default_value)
118117

119-
if layer_config['type'] == InputType.SpinBox:
120-
if widget is not None:
121-
unit = layer_config.get('unit')
122-
if unit:
123-
widget.setSuffix(unit)
118+
if widget is not None and layer_config['type'] == InputType.SpinBox:
119+
unit = layer_config.get('unit')
120+
if unit:
121+
widget.setSuffix(unit)
124122

125-
default = layer_config.get('default')
126-
if unit:
127-
widget.setValue(default)
123+
default = layer_config.get('default')
124+
if unit:
125+
widget.setValue(default)
128126

129-
if layer_config['type'] == InputType.Color:
130-
if widget is not None:
131-
if layer_config['default'] == '':
132-
widget.setShowNull(True)
133-
widget.setToNull()
134-
else:
135-
widget.setDefaultColor(QColor(layer_config['default']))
136-
widget.setToDefaultColor()
137-
138-
if layer_config.get('read_only'):
139-
if widget is not None:
140-
if layer_config['type'] == InputType.Text:
141-
widget.setReadOnly(True)
142-
elif layer_config['type'] == InputType.CheckBox:
143-
# Some UX issues #338
144-
# The disabled is not possible somehow ?
145-
# The tooltip is not showing
146-
widget.setText(tr('Read only, check the tooltip on the label'))
147-
widget.setStyleSheet("font: italic;")
148-
widget.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
149-
widget.setFocusPolicy(Qt.FocusPolicy.NoFocus)
127+
if widget is not None and layer_config['type'] == InputType.Color:
128+
if layer_config['default'] == '':
129+
widget.setShowNull(True)
130+
widget.setToNull()
131+
else:
132+
widget.setDefaultColor(QColor(layer_config['default']))
133+
widget.setToDefaultColor()
134+
135+
if widget is not None and layer_config.get('read_only'):
136+
if layer_config['type'] == InputType.Text:
137+
widget.setReadOnly(True)
138+
elif layer_config['type'] == InputType.CheckBox:
139+
# Some UX issues #338
140+
# The disabled is not possible somehow ?
141+
# The tooltip is not showing
142+
widget.setText(tr('Read only, check the tooltip on the label'))
143+
widget.setStyleSheet("font: italic;")
144+
widget.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
145+
widget.setFocusPolicy(Qt.FocusPolicy.NoFocus)
150146

151147
if not layer_config.get('visible', True):
152148
if widget is not None:
@@ -279,13 +275,12 @@ def validate(self):
279275
else:
280276
raise Exception('InputType "{}" not implemented'.format(layer_config['type']))
281277

282-
if self.primary_key_valid is not None:
283-
if not self.primary_key_valid:
284-
return tr(
285-
"The primary key defined in your datasource for the layer '{}' "
286-
"is not valid. The layer is stored "
287-
"in a database and must have a valid primary key defined in the project."
288-
).format(self.layer.currentLayer().name())
278+
if self.primary_key_valid is not None and not self.primary_key_valid:
279+
return tr(
280+
"The primary key defined in your datasource for the layer '{}' "
281+
"is not valid. The layer is stored "
282+
"in a database and must have a valid primary key defined in the project."
283+
).format(self.layer.currentLayer().name())
289284

290285
for k, layer_config in self.config.layer_config.items():
291286
if layer_config['type'] in (InputType.Field, InputType.PrimaryKeyField):
@@ -295,11 +290,10 @@ def validate(self):
295290
# Dataviz does not have widget for Y, Z
296291
continue
297292

298-
if not widget.allowEmptyFieldName():
299-
if widget.currentField() == '':
300-
names = re.findall(r'.[^A-Z]*', k)
301-
names = [n.lower().replace('_', ' ') for n in names]
302-
return tr('The field "{}" is mandatory.').format(' '.join(names))
293+
if not widget.allowEmptyFieldName() and widget.currentField() == '':
294+
names = re.findall(r'.[^A-Z]*', k)
295+
names = [n.lower().replace('_', ' ') for n in names]
296+
return tr('The field "{}" is mandatory.').format(' '.join(names))
303297

304298
return None
305299

lizmap/forms/dataviz_edition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def load_collection(self, value: Any) -> None:
144144

145145
def primary_keys_collection(self) -> list:
146146
"""Return the list of unique values in the collection."""
147-
values = list()
147+
values = []
148148
for row in range(self.traces.rowCount()):
149149
item = self.traces.item(row, 0)
150150
cell = item.data(Qt.ItemDataRole.UserRole)
@@ -153,12 +153,12 @@ def primary_keys_collection(self) -> list:
153153

154154
def save_collection(self) -> list:
155155
"""Save a collection into JSON"""
156-
value = list()
156+
value = []
157157
rows = self.traces.rowCount()
158158

159159
collection_definition = self.config.layer_config['traces']
160160
for row in range(rows):
161-
trace_data = dict()
161+
trace_data = {}
162162
for i, sub_key in enumerate(collection_definition['items']):
163163

164164
input_type = self.config.layer_config[sub_key]['type']

0 commit comments

Comments
 (0)