Skip to content

Commit

Permalink
Merge pull request #547 from gkahiu/fix_report_scenario_layer
Browse files Browse the repository at this point in the history
Fix Scenario Layer in Analysis Report
  • Loading branch information
Samweli authored Oct 28, 2024
2 parents e646bac + e753f1b commit ee39595
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/cplus_plugin/lib/reports/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ def _load_template(self) -> bool:


class DuplicatableRepeatPageReportGenerator(BaseScenarioReportGenerator):
"""Incorporates extra functionality duplicating a repeat page.
"""Incorporates extra functionality for duplicating a repeat page.
Subclass must have `_repeat_gae` and `_repeat_page_num` members.
Subclass must have `_repeat_page` and `_repeat_page_num` members.
"""

def duplicate_repeat_page(self, position: int) -> bool:
Expand Down Expand Up @@ -1575,6 +1575,25 @@ def _get_activity_layer_in_project(

return matching_tree_layers[0].layer()

def _update_main_map_layer(self):
"""Update the main map to only contain the output scenario layer."""
main_map_item: QgsLayoutItemMap = self._layout.itemById("map_one_scenario")
if main_map_item is None:
tr_msg = tr("Could not find the main map")
self._error_messages.append(tr_msg)
return

if self._scenario_layer is None:
tr_msg = tr(
"Scenario layer is empty. Unable to set layer in the main map item."
)
self._error_messages.append(tr_msg)
return

main_map_item.setFollowVisibilityPreset(False)
main_map_item.setLayers([self._scenario_layer])
main_map_item.refresh()

def _update_main_map_legend(self):
"""Textual adjustments to the main map legend."""
legend_item: QgsLayoutItemLegend = self._layout.itemById("legend_main_map")
Expand Down Expand Up @@ -1614,7 +1633,7 @@ def _update_main_map_legend(self):
tree_layer, activity_node_indices
)

# Removing the tree layer band title
# Remove the tree layer band title
QgsLegendRenderer.setNodeLegendStyle(tree_layer, QgsLegendStyle.Hidden)

model.refreshLayerLegend(tree_layer)
Expand Down Expand Up @@ -1757,6 +1776,9 @@ def _run(self) -> ReportResult:
# Populate table with priority weighting values
self._populate_scenario_weighting_values()

# Set scenario layer in scenario map item
self._update_main_map_layer()

# Update the legend for the main map
self._update_main_map_legend()

Expand Down
7 changes: 6 additions & 1 deletion src/cplus_plugin/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,8 +2152,13 @@ def run_highest_position_analysis(self, temporary_output=False):
passed_extent_box[3],
)

# We explicitly set the created_date since the current implementation
# of the data model means that the attribute value is set only once when
# the class is loaded hence subsequent instances will have the same value.
self.scenario_result = ScenarioResult(
scenario=self.scenario, scenario_directory=self.scenario_directory
scenario=self.scenario,
scenario_directory=self.scenario_directory,
created_date=datetime.datetime.now(),
)

try:
Expand Down

0 comments on commit ee39595

Please sign in to comment.