From 5a22d4dfe5a9087deeb8649231388e3b2c39822f Mon Sep 17 00:00:00 2001 From: Samweli Date: Tue, 7 Nov 2023 08:58:25 +0300 Subject: [PATCH] logic for handling not fetching styles --- src/cplus_plugin/gui/qgis_cplus_main.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cplus_plugin/gui/qgis_cplus_main.py b/src/cplus_plugin/gui/qgis_cplus_main.py index 1c45c0cdd..bac0b7608 100644 --- a/src/cplus_plugin/gui/qgis_cplus_main.py +++ b/src/cplus_plugin/gui/qgis_cplus_main.py @@ -11,6 +11,7 @@ import datetime from functools import partial +from random import randint from pathlib import Path @@ -2348,7 +2349,28 @@ def style_models_layer(self, layer, models): im_name = model.name raster_val = model.style_pixel_value - color = model.scenario_fill_symbol().color() + + model_fill_symbol = model.scenario_fill_symbol() + if model_fill_symbol is None: + self.show_message( + tr( + f"Couldn't fetch color for the implementation model {im_name}," + f" using a random color instead." + ), + level=Qgis.Warning, + ) + log( + tr( + f"Couldn't fetch color for the implementation model {im_name}," + f" using a random color instead, fill symbol is None" + ) + ) + color_names = QtGui.QColor.colorNames() + color_name = color_names[randint(0, len(color_names))] + color = QtGui.QColor(color_name) + else: + color = model_fill_symbol.color() + color_ramp_shader = QgsColorRampShader.ColorRampItem( float(raster_val), QtGui.QColor(color), im_name )