diff --git a/geest/gui/dialogs/factor_aggregation_dialog.py b/geest/gui/dialogs/factor_aggregation_dialog.py index 9c0afa3..78dca9b 100644 --- a/geest/gui/dialogs/factor_aggregation_dialog.py +++ b/geest/gui/dialogs/factor_aggregation_dialog.py @@ -57,7 +57,7 @@ def __init__( # Layout setup layout = QVBoxLayout(self) self.resize(800, 600) - layout.setContentsMargins(20, 20, 20, 20) + layout.setContentsMargins(20, 20, 20, 20) # Add padding around the layout # Title label self.title_label = QLabel( @@ -143,7 +143,7 @@ def __init__( self.table.setRowCount(len(self.guids)) self.table.setColumnCount(6) self.table.setHorizontalHeaderLabels( - ["Source", "Indicator", "Weight 0-1", "Use", "GUID", ""] + ["Input", "Indicator", "Weight 0-1", "Use", "GUID", ""] ) self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) self.table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch) @@ -155,8 +155,11 @@ def __init__( self.table.setColumnWidth(3, 50) # Use column (checkbox) self.table.setColumnWidth(5, 75) # Reset column # hide weight and reset column if only one indicator - self.table.setColumnHidden(2, not self.weighting_column_visible) - self.table.setColumnHidden(5, not self.weighting_column_visible) + if not self.weighting_column_visible: + self.hide_widgets_in_column(2) + self.hide_widgets_in_column(5) + self.table.setColumnHidden(2, True) + self.table.setColumnHidden(5, True) layout.addWidget(self.table) @@ -257,6 +260,8 @@ def populate_table(self): data_source_widget = DataSourceWidgetFactory.create_widget( attributes["analysis_mode"], 1, attributes ) + # Expand the widget to fill the available horizontal space + data_source_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if not data_source_widget: continue data_source_widget.data_changed.connect(self.refresh_configuration) @@ -270,19 +275,21 @@ def populate_table(self): self.table.setItem(row, 1, name_item) # Weighting - weighting_value = float(attributes.get("factor_weighting", 0.0)) - weighting_item = QDoubleSpinBox() - weighting_item.setRange(0.0, 1.0) - weighting_item.setDecimals(4) - weighting_item.setSingleStep(0.01) - weighting_item.setValue(weighting_value) - weighting_item.valueChanged.connect(self.validate_weightings) - self.table.setCellWidget(row, 2, weighting_item) - self.weightings[guid] = weighting_item - - # Use (Checkbox) - checkbox_widget = self.create_checkbox_widget(row, weighting_value) - self.table.setCellWidget(row, 3, checkbox_widget) + if self.weighting_column_visible: + weighting_value = float(attributes.get("factor_weighting", 0.0)) + weighting_item = QDoubleSpinBox() + weighting_item.setRange(0.0, 1.0) + weighting_item.setDecimals(4) + weighting_item.setSingleStep(0.01) + weighting_item.setValue(weighting_value) + weighting_item.valueChanged.connect(self.validate_weightings) + self.table.setCellWidget(row, 2, weighting_item) + self.weightings[guid] = weighting_item + self.table.setCellWidget(row, 3, checkbox_widget) + # Use (Checkbox) + checkbox_widget = self.create_checkbox_widget(row, weighting_value) + else: + checkbox_widget = self.create_checkbox_widget(row, 1) # GUID guid_item = QTableWidgetItem(guid) @@ -291,13 +298,14 @@ def populate_table(self): self.table.setItem(row, 4, guid_item) # Reset Button - reset_button = QPushButton("Reset") - reset_button.clicked.connect( - lambda checked, item=weighting_item, value=default_factor_weighting: item.setValue( - value + if self.weighting_column_visible: + reset_button = QPushButton("Reset") + reset_button.clicked.connect( + lambda checked, item=weighting_item, value=default_factor_weighting: item.setValue( + value + ) ) - ) - self.table.setCellWidget(row, 5, reset_button) + self.table.setCellWidget(row, 5, reset_button) self.table.setColumnHidden( 4, not self.guid_column_visible @@ -312,6 +320,20 @@ def toggle_guid_column(self): self.guid_column_visible = not self.guid_column_visible self.table.setColumnHidden(4, not self.guid_column_visible) + def hide_widgets_in_column(self, column: int): + """Hide all widgets in the specified column.""" + for row in range(self.table.rowCount()): + widget = self.table.cellWidget(row, column) + if widget: + widget.setVisible(False) # Explicitly hide the widget + + def show_widgets_in_column(self, column: int): + """Show all widgets in the specified column.""" + for row in range(self.table.rowCount()): + widget = self.table.cellWidget(row, column) + if widget: + widget.setVisible(True) # Explicitly show the widget + def auto_calculate_weightings(self): enabled_rows = [ row for row in range(self.table.rowCount()) if self.is_checkbox_checked(row) diff --git a/geest/gui/widgets/datasource_widgets/base_datasource_widget.py b/geest/gui/widgets/datasource_widgets/base_datasource_widget.py index c44ee39..cf802bf 100644 --- a/geest/gui/widgets/datasource_widgets/base_datasource_widget.py +++ b/geest/gui/widgets/datasource_widgets/base_datasource_widget.py @@ -25,11 +25,7 @@ def __init__(self, widget_key: str, attributes: dict) -> None: self.layout: QHBoxLayout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) # Log creation of widget - log_message( - f"Creating DataSource Configuration Widget {widget_key}", - tag="Geest", - level=Qgis.Info, - ) + log_message(f"Creating DataSource Configuration Widget {widget_key}") try: self.add_internal_widgets() # implemented in subclasses diff --git a/geest/gui/widgets/datasource_widgets/vector_and_field_datasource_widget.py b/geest/gui/widgets/datasource_widgets/vector_and_field_datasource_widget.py index 4a4b100..de70c26 100644 --- a/geest/gui/widgets/datasource_widgets/vector_and_field_datasource_widget.py +++ b/geest/gui/widgets/datasource_widgets/vector_and_field_datasource_widget.py @@ -134,6 +134,7 @@ def select_shapefile(self): # Update the line edit with the selected file path self.shapefile_line_edit.setText(file_path) self.shapefile_line_edit.setVisible(True) + self.layer_combo.setCurrentIndex(-1) # Clear the layer combo selection # Save the directory of the selected file to QSettings settings.setValue("Geest/lastShapefileDir", os.path.dirname(file_path)) @@ -231,6 +232,7 @@ def update_field_combo(self) -> None: elif self.shapefile_line_edit.text(): # If shapefile is provided, populate the field combo self._populate_field_combo(self.shapefile_line_edit.text()) + self.layer_combo.setCurrentIndex(-1) # Clear the layer combo selection # After the field combo is repopulated, re-select the previously selected field if it exists if previous_field and self.field_selection_combo.findText(previous_field) != -1: