Skip to content

Commit

Permalink
Merge pull request #727 from kartoza/timlinux/issue706
Browse files Browse the repository at this point in the history
Implement UI for insights as per wireframes
  • Loading branch information
timlinux authored Dec 16, 2024
2 parents e2d4129 + 583043d commit c77ae26
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
77 changes: 76 additions & 1 deletion geest/gui/dialogs/analysis_aggregation_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
QSpacerItem,
QSizePolicy,
QFileDialog,
QLineEdit,
)
from qgis.PyQt.QtGui import QPixmap, QDesktopServices
from qgis.PyQt.QtCore import Qt, QUrl, QSettings
from qgis.core import Qgis, QgsMapLayerProxyModel
from qgis.core import Qgis, QgsMapLayerProxyModel, QgsProject
from geest.utilities import (
resources_path,
log_message,
Expand Down Expand Up @@ -68,38 +69,60 @@ def __init__(self, analysis_item, parent=None):

# Set up the aggregation layer widgets
self.aggregation_combo.setAllowEmptyLayer(True)
self.aggregation_combo.setCurrentIndex(-1)
self.aggregation_combo.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.aggregation_combo.currentIndexChanged.connect(self.aggregation_selected)
self.aggregation_toolbutton.clicked.connect(self.aggregation_toolbutton_clicked)
self.aggregation_lineedit.textChanged.connect(
self.aggregation_lineedit_text_changed
)
self.load_combo_from_model(
self.aggregation_combo, self.aggregation_lineedit, "aggregation"
)

# Set up the population raster widgets
self.population_combo.setAllowEmptyLayer(True)
self.population_combo.setCurrentIndex(-1)
self.population_combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.population_combo.currentIndexChanged.connect(self.population_selected)
self.population_toolbutton.clicked.connect(self.population_toolbutton_clicked)
self.population_lineedit.textChanged.connect(
self.population_lineedit_text_changed
)
self.load_combo_from_model(
self.population_combo, self.population_lineedit, "population"
)

# Set up the point layer widgets
self.point_combo.setAllowEmptyLayer(True)
self.point_combo.setCurrentIndex(-1)
self.point_combo.setFilters(QgsMapLayerProxyModel.PointLayer)
self.point_combo.currentIndexChanged.connect(self.point_selected)
self.population_toolbutton.clicked.connect(self.point_toolbutton_clicked)
self.point_lineedit.textChanged.connect(self.point_lineedit_text_changed)
self.load_combo_from_model(self.point_combo, self.point_lineedit, "point_mask")

# set up the polygon layer widgets
self.polygon_combo.setAllowEmptyLayer(True)
self.polygon_combo.setCurrentIndex(-1)
self.polygon_combo.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.polygon_combo.currentIndexChanged.connect(self.polygon_selected)
self.polygon_toolbutton.clicked.connect(self.polygon_toolbutton_clicked)
self.polygon_lineedit.textChanged.connect(self.polygon_lineedit_text_changed)
self.load_combo_from_model(
self.polygon_combo, self.polygon_lineedit, "polygon_mask"
)

# Set up the raster layer widgets
self.raster_combo.setAllowEmptyLayer(True)
self.raster_combo.setCurrentIndex(-1)
self.raster_combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.raster_combo.currentIndexChanged.connect(self.raster_selected)
self.raster_toolbutton.clicked.connect(self.raster_toolbutton_clicked)
self.raster_lineedit.textChanged.connect(self.raster_lineedit_text_changed)
self.load_combo_from_model(
self.raster_combo, self.raster_lineedit, "raster_mask"
)

help_layout = QHBoxLayout()
help_layout.addItem(
Expand Down Expand Up @@ -533,8 +556,60 @@ def validate_weightings(self):
def accept_changes(self):
"""Handle the OK button by applying changes and closing the dialog."""
self.saveWeightingsToModel() # Assign weightings when changes are accepted
self.save_combo_to_model(
self.aggregation_combo, self.aggregation_lineedit, "aggregation"
)
self.save_combo_to_model(
self.population_combo, self.population_lineedit, "population"
)
self.save_combo_to_model(self.point_combo, self.point_lineedit, "point_mask")
self.save_combo_to_model(
self.polygon_combo, self.polygon_lineedit, "polygon_mask"
)
self.save_combo_to_model(self.raster_combo, self.raster_lineedit, "raster_mask")

# Save the dialog geometry
settings = QSettings()
settings.setValue("AnalysisAggregationDialog/geometry", self.saveGeometry())

self.accept()

def save_combo_to_model(
self, combo: QgsMapLayerComboBox, lineedit: QLineEdit, prefix: str
):
"""Save the state of a QgsMapLayerComboBox to the json tree item.
Args:
combo (_type_): _description_
"""
item = self.tree_item
layer = combo.currentLayer()
if not layer:
item.setAttribute(f"{prefix}_layer", None)
else:
item.setAttribute(f"{prefix}_layer_name", layer.name())
item.setAttribute(f"{prefix}_layer_source", layer.source())
item.setAttribute(f"{prefix}_layer_provider_type", layer.providerType())
item.setAttribute(f"{prefix}_layer_crs", layer.crs().authid())
if layer.providerType() != "gdal":
item.setAttribute(f"{prefix}_layer_wkb_type", layer.wkbType())
item.setAttribute(f"{prefix}_layer_id", layer.id())
item.setAttribute(f"{prefix}_shapefile", lineedit.text())

def load_combo_from_model(
self, combo: QgsMapLayerComboBox, lineedit: QLineEdit, prefix: str
):
"""Load the state of a QgsMapLayerComboBox from the json tree item.
Args:
combo (_type_): _description_
"""
item = self.tree_item
layer_id = item.attribute(f"{prefix}_layer_id", None)
if layer_id:
layer = QgsProject.instance().mapLayer(layer_id)
if layer:
combo.setLayer(layer)
if item.attribute(f"{prefix}_shapefile", False):
lineedit.setText(self.attributes[f"{prefix}_shapefile"])
lineedit.setVisible(True)
32 changes: 31 additions & 1 deletion geest/gui/views/treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,37 @@ def loadJsonData(self, json_data):
"error": analysis_error,
"error_file": analysis_error_file,
}

for prefix in [
"aggregation",
"population",
"point_mask",
"polygon_mask",
"raster_mask",
]:
analysis_attributes[f"{prefix}_layer"] = json_data.get(
f"{prefix}_layer", ""
)
analysis_attributes[f"{prefix}_layer_name"] = json_data.get(
f"{prefix}_layer_name", ""
)
analysis_attributes[f"{prefix}_layer_source"] = json_data.get(
f"{prefix}_layer_source", ""
)
analysis_attributes[f"{prefix}_layer_provider_type"] = json_data.get(
f"{prefix}_layer_provider_type", ""
)
analysis_attributes[f"{prefix}_layer_crs"] = json_data.get(
f"{prefix}_layer_crs", ""
)
analysis_attributes[f"{prefix}_layer_wkb_type"] = json_data.get(
f"{prefix}_layer_wkb_type", ""
)
analysis_attributes[f"{prefix}_layer_id"] = json_data.get(
f"{prefix}_layer_id", ""
)
analysis_attributes[f"{prefix}_shapefile"] = json_data.get(
f"{prefix}_shapefile", ""
)
# Create the "Analysis" item
status = ""
weighting = ""
Expand Down

0 comments on commit c77ae26

Please sign in to comment.