-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP for #331
- Loading branch information
Showing
10 changed files
with
169 additions
and
1,160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from qgis.PyQt.QtWidgets import QWidget, QVBoxLayout, QButtonGroup | ||
from qgis.core import QgsMessageLog | ||
from .indicator_widget_factory import RadioButtonFactory | ||
|
||
|
||
class IndicatorConfigWidget(QWidget): | ||
""" | ||
Widget for configuring indicators based on a dictionary. | ||
""" | ||
def __init__(self, attributes_dict: dict) -> None: | ||
super().__init__() | ||
self.attributes_dict = attributes_dict | ||
self.layout: QVBoxLayout = QVBoxLayout() | ||
self.button_group: QButtonGroup = QButtonGroup(self) | ||
|
||
try: | ||
self.create_radio_buttons(attributes_dict) | ||
except Exception as e: | ||
QgsMessageLog.logMessage(f"Error in create_radio_buttons: {e}", "Geest") | ||
|
||
self.setLayout(self.layout) | ||
|
||
def create_radio_buttons(self, attributes_dict: dict) -> None: | ||
""" | ||
Uses the factory to create radio buttons from attributes dictionary. | ||
""" | ||
for key, value in attributes_dict.items(): | ||
radio_button_widget = RadioButtonFactory.create_radio_button(key, value) | ||
if radio_button_widget: | ||
self.button_group.addButton(radio_button_widget) | ||
self.layout.addWidget(radio_button_widget.get_container()) | ||
radio_button_widget.data_changed.connect(self.update_attributes) | ||
|
||
def update_attributes(self, new_data: dict) -> None: | ||
""" | ||
Updates the attributes dictionary with new data from radio buttons. | ||
""" | ||
self.attributes_dict.update(new_data) | ||
QgsMessageLog.logMessage(f"Updated attributes dictionary: {self.attributes_dict}", "Geest") |
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,24 @@ | ||
from qgis.core import QgsMessageLog | ||
from .widgets.indicator_index_score_widget import IndexScoreRadioButton | ||
from .widgets.widget_radio_button import WidgetRadioButton | ||
|
||
|
||
class RadioButtonFactory: | ||
""" | ||
Factory class for creating radio buttons based on key-value pairs. | ||
""" | ||
@staticmethod | ||
def create_radio_button(key: str, value: int): | ||
""" | ||
Factory method to create a radio button based on key-value pairs. | ||
""" | ||
try: | ||
if key == "UseIndexScore" and value == 1: | ||
return IndexScoreRadioButton("IndexScore") | ||
elif key == "UseWidget" and value == 1: | ||
return WidgetRadioButton("Widget") | ||
else: | ||
return None | ||
except Exception as e: | ||
QgsMessageLog.logMessage(f"Error in create_radio_button: {e}", "Geest") | ||
return None |
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 |
---|---|---|
@@ -1,7 +1 @@ | ||
from .geest_config_widget import GeestConfigWidget | ||
from .geest_widget_factory import GeestWidgetFactory | ||
|
||
__all__ = [ | ||
"GeestConfigWidget", | ||
"GeestWidgetFactory", | ||
] | ||
# Widgets package initialization file |
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,50 @@ | ||
from qgis.PyQt.QtWidgets import QRadioButton, QHBoxLayout, QWidget | ||
from qgis.PyQt.QtCore import pyqtSignal | ||
from qgis.core import QgsMessageLog | ||
|
||
|
||
class BaseIndicatorWidget(QRadioButton): | ||
""" | ||
Abstract base class for radio buttons with internal widgets. | ||
""" | ||
data_changed = pyqtSignal(dict) | ||
|
||
def __init__(self, label_text: str) -> None: | ||
super().__init__(label_text) | ||
self.container: QWidget = QWidget() | ||
self.layout: QHBoxLayout = QHBoxLayout(self.container) | ||
self.layout.addWidget(self) | ||
|
||
try: | ||
self.add_internal_widgets() | ||
except Exception as e: | ||
QgsMessageLog.logMessage(f"Error in add_internal_widgets: {e}", "Geest") | ||
|
||
def add_internal_widgets(self) -> None: | ||
""" | ||
Add internal widgets; to be implemented by subclasses. | ||
""" | ||
raise NotImplementedError("Subclasses must implement add_internal_widgets.") | ||
|
||
def get_container(self) -> QWidget: | ||
""" | ||
Returns the container holding the radio button and its internal widgets. | ||
""" | ||
return self.container | ||
|
||
def get_data(self) -> dict: | ||
""" | ||
Method to get data from internal widgets. | ||
To be implemented by subclasses. | ||
""" | ||
raise NotImplementedError("Subclasses must implement get_data.") | ||
|
||
def update_data(self) -> None: | ||
""" | ||
Gathers data from internal widgets and emits the data_changed signal. | ||
""" | ||
try: | ||
data = self.get_data() | ||
self.data_changed.emit(data) | ||
except Exception as e: | ||
QgsMessageLog.logMessage(f"Error in update_data: {e}", "Geest") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.