|
165 | 165 | from lizmap.table_manager.layouts import TableManagerLayouts |
166 | 166 | from lizmap.toolbelt.convert import cast_to_group, cast_to_layer |
167 | 167 | from lizmap.widgets.check_project import Check, SourceField |
| 168 | +from lizmap.widgets.primary_key_field import enable_primary_key_field |
168 | 169 | from lizmap.widgets.project_tools import ( |
169 | 170 | empty_baselayers, |
170 | 171 | is_layer_published_wfs, |
@@ -529,6 +530,7 @@ def write_log_message(message, tag, level): |
529 | 530 |
|
530 | 531 | self.layer_options_list = lizmap_config.layerOptionDefinitions |
531 | 532 | # Add widget information |
| 533 | + self.layer_options_list['primary_key']['widget'] = self.dlg.primary_key |
532 | 534 | self.layer_options_list['title']['widget'] = self.dlg.inLayerTitle |
533 | 535 | self.layer_options_list['abstract']['widget'] = self.dlg.teLayerAbstract |
534 | 536 | self.layer_options_list['link']['widget'] = self.dlg.inLayerLink |
@@ -699,23 +701,30 @@ def write_log_message(message, tag, level): |
699 | 701 |
|
700 | 702 | # Connect widget signals to setLayerProperty method depending on widget type |
701 | 703 | for key, item in self.layer_options_list.items(): |
702 | | - if item.get('widget'): |
703 | | - control = item['widget'] |
704 | | - slot = partial(self.save_value_layer_group_data, key) |
705 | | - if item['wType'] in ('text', 'spinbox'): |
706 | | - control.editingFinished.connect(slot) |
707 | | - elif item['wType'] == 'textarea': |
708 | | - control.textChanged.connect(slot) |
709 | | - elif item['wType'] == 'checkbox': |
710 | | - control.stateChanged.connect(slot) |
711 | | - elif item['wType'] == 'radio': |
712 | | - control.toggled.connect(slot) |
713 | | - elif item['wType'] == 'list': |
714 | | - control.currentIndexChanged.connect(slot) |
715 | | - elif item['wType'] == 'layers': |
716 | | - control.layerChanged.connect(slot) |
717 | | - elif item['wType'] == 'fields': |
| 704 | + control = item.get('widget') |
| 705 | + if not isinstance(control, QWidget): |
| 706 | + # Be careful, big waste of time if control is not checked to be a QWidget for QgsFieldComboBox |
| 707 | + # https://github.com/qgis/QGIS/issues/62317 |
| 708 | + continue |
| 709 | + |
| 710 | + slot = partial(self.save_value_layer_group_data, key) |
| 711 | + if item['wType'] in ('text', 'spinbox'): |
| 712 | + control.editingFinished.connect(slot) |
| 713 | + elif item['wType'] == 'textarea': |
| 714 | + control.textChanged.connect(slot) |
| 715 | + elif item['wType'] == 'checkbox': |
| 716 | + control.stateChanged.connect(slot) |
| 717 | + elif item['wType'] == 'radio': |
| 718 | + control.toggled.connect(slot) |
| 719 | + elif item['wType'] == 'list': |
| 720 | + if item['type'] == 'field': |
718 | 721 | control.fieldChanged.connect(slot) |
| 722 | + else: |
| 723 | + control.currentIndexChanged.connect(slot) |
| 724 | + elif item['wType'] == 'layers': |
| 725 | + control.layerChanged.connect(slot) |
| 726 | + elif item['wType'] == 'fields': |
| 727 | + control.fieldChanged.connect(slot) |
719 | 728 |
|
720 | 729 | self.crs_3857_base_layers_list = { |
721 | 730 | 'osm-mapnik': self.dlg.cbOsmMapnik, |
@@ -2243,9 +2252,13 @@ def set_tree_item_data(self, item_type, item_key, json_layers): |
2243 | 2252 | self.myDic[item_key][key] = json_layers[json_key][key] |
2244 | 2253 | # lists |
2245 | 2254 | elif item['wType'] == 'list': |
2246 | | - # New way with data, label, tooltip and icon |
2247 | | - datas = [j[0] for j in item['list']] |
2248 | | - if json_layers[json_key][key] in datas: |
| 2255 | + if item.get('list'): |
| 2256 | + # New way with data, label, tooltip and icon |
| 2257 | + datas = [j[0] for j in item['list']] |
| 2258 | + if json_layers[json_key][key] in datas: |
| 2259 | + self.myDic[item_key][key] = json_layers[json_key][key] |
| 2260 | + else: |
| 2261 | + # The list is managed by the layer and function enable_primary_key_field() |
2249 | 2262 | self.myDic[item_key][key] = json_layers[json_key][key] |
2250 | 2263 |
|
2251 | 2264 | else: |
@@ -2414,6 +2427,8 @@ def from_data_to_ui_for_layer_group(self): |
2414 | 2427 | # if val.get('widget'): |
2415 | 2428 | # val.get('widget').setEnabled(True) |
2416 | 2429 |
|
| 2430 | + self.dlg.group_box_primary_key.setVisible(False) |
| 2431 | + |
2417 | 2432 | i_key = self._current_selected_item_in_config() |
2418 | 2433 | if i_key: |
2419 | 2434 | self.enable_check_box_in_layer_tab(True) |
@@ -2501,6 +2516,11 @@ def from_data_to_ui_for_layer_group(self): |
2501 | 2516 | self.dlg.button_generate_html_table.setEnabled(is_vector) |
2502 | 2517 | self.layer_options_list['popupSource']['widget'].setEnabled(is_vector) |
2503 | 2518 |
|
| 2519 | + if is_vector: |
| 2520 | + self.dlg.primary_key.setLayer(layer) |
| 2521 | + enable_primary_key_field(self.dlg.primary_key, layer) |
| 2522 | + self.dlg.group_box_primary_key.setVisible(is_vector) |
| 2523 | + |
2504 | 2524 | if self.current_lwc_version() >= LwcVersions.Lizmap_3_7 and not self.dlg.cbLayerIsBaseLayer.isChecked(): |
2505 | 2525 | # Starting from LWC 3.7, this checkbox is deprecated |
2506 | 2526 | self.dlg.cbLayerIsBaseLayer.setEnabled(False) |
@@ -2555,9 +2575,13 @@ def from_data_to_ui_for_layer_group(self): |
2555 | 2575 | val['widget'].setChecked(val['default']) |
2556 | 2576 | elif val['wType'] == 'list': |
2557 | 2577 |
|
2558 | | - # New way with data, label, tooltip and icon |
2559 | | - index = val['widget'].findData(val['default']) |
2560 | | - val['widget'].setCurrentIndex(index) |
| 2578 | + if val.get('default'): |
| 2579 | + # New way with data, label, tooltip and icon |
| 2580 | + index = val['widget'].findData(val['default']) |
| 2581 | + val['widget'].setCurrentIndex(index) |
| 2582 | + else: |
| 2583 | + # The list is managed by the layer and function enable_primary_key_field() |
| 2584 | + val['widget'].setCurrentIndex(0) |
2561 | 2585 |
|
2562 | 2586 | self.enable_popup_source_button() |
2563 | 2587 | self.dlg.follow_map_theme_toggled() |
@@ -2806,9 +2830,13 @@ def save_value_layer_group_data(self, key: str): |
2806 | 2830 | if self.layer_options_list[children]['widget'].isChecked(): |
2807 | 2831 | self.layer_options_list[children]['widget'].setChecked(False) |
2808 | 2832 | elif layer_option['wType'] == 'list': |
2809 | | - # New way with data, label, tooltip and icon |
2810 | | - datas = [j[0] for j in layer_option['list']] |
2811 | | - self.layerList[layer_or_group_text][key] = datas[layer_option['widget'].currentIndex()] |
| 2833 | + if layer_option.get('list'): |
| 2834 | + # New way with data, label, tooltip and icon |
| 2835 | + datas = [j[0] for j in layer_option['list']] |
| 2836 | + self.layerList[layer_or_group_text][key] = datas[layer_option['widget'].currentIndex()] |
| 2837 | + else: |
| 2838 | + # The list is managed by the layer and function enable_primary_key_field() |
| 2839 | + self.layerList[layer_or_group_text][key] = layer_option['widget'].currentField() |
2812 | 2840 |
|
2813 | 2841 | # Deactivate the "exclude" widget if necessary |
2814 | 2842 | if 'exclude' in layer_option \ |
|
0 commit comments