Skip to content

Commit

Permalink
human friendly messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli committed Dec 3, 2024
1 parent c131d78 commit a48718f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/qgis_gea_plugin/definitions/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

PROJECT_INSTANCE_STYLE = "project_instances_style.qml"

SATELLITE_IMAGERY = 'Google Satellite (latest)'

FARMER_ID_FIELD = "FarmerID"

Expand Down
72 changes: 54 additions & 18 deletions src/qgis_gea_plugin/gui/qgis_gea.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
REPORT_SITE_BOUNDARY_STYLE,
SITE_GROUP_NAME,
FARMER_ID_FIELD,
PROJECT_INSTANCE_STYLE,
PROJECT_INSTANCE_STYLE, SATELLITE_IMAGERY,
)
from .attribute_form import AttributeForm
from .report_progress_dialog import ReportProgressDialog
Expand Down Expand Up @@ -542,26 +542,44 @@ def start_drawing(self):
self.drawing_frame.setEnabled(True)
return

if self.site_reference_le.text() is None or self.site_reference_le.text().replace(' ', '') is '':
if (self.site_reference_le.text() is None or
self.site_reference_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the site reference before starting to draw the project area."),
tr(
"Action Required: Please complete the attributes"
" form before drawing the site polygon. "
"This ensures all necessary details are "
"captured accurately."
),
Qgis.Warning
)
return
if self.site_ref_version_le.text() is None or self.site_ref_version_le.text().replace(' ', '') is '':
if (self.site_ref_version_le.text() is None or
self.site_ref_version_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the version of site reference before starting to draw the project area."),
tr(
"Action Required: Please complete the attributes"
" form before drawing the site polygon. "
"This ensures all necessary details are "
"captured accurately."
),
Qgis.Warning
)
return
if self.report_author_le.text() is None or self.report_author_le.text().replace(' ', '') is '':
if (self.report_author_le.text() is None or
self.report_author_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the report generation author before starting to draw the project area."),
tr(
"Action Required: Please complete the attributes"
" form before drawing the site polygon. "
"This ensures all necessary details are "
"captured accurately."
),
Qgis.Warning
)
return

layers = QgsProject.instance().mapLayersByName('Google Satellite (latest)')
layers = QgsProject.instance().mapLayersByName(SATELLITE_IMAGERY)

if layers:
self.update_layer_group(layers[0], True)
Expand Down Expand Up @@ -675,7 +693,7 @@ def _get_area_name(self):
f"{self.capture_date}")
return area_name

def is_project_info_valid(self) -> bool:
def is_project_info_valid(self, message) -> bool:
"""Validates user input.
:returns: Returns True if the input is valid, else False.
:rtype: bool
Expand All @@ -685,25 +703,28 @@ def is_project_info_valid(self) -> bool:

if selected_date_time is None:
self.show_message(
tr("Please add the project inception date before saving the project area"),
message,
Qgis.Warning
)
return False
if self.site_reference_le.text() is None or self.site_reference_le.text().replace(' ', '') is '':
if (self.site_reference_le.text() is None or
self.site_reference_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the site reference before saving the project area"),
message,
Qgis.Warning
)
return False
if self.report_author_le.text() is None or self.report_author_le.text().replace(' ', '') is '':
if (self.report_author_le.text() is None or
self.report_author_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the report generation author before saving the project area"),
message,
Qgis.Warning
)
return False
if self.site_ref_version_le.text() is None or self.site_ref_version_le.text().replace(' ', '') is '':
if (self.site_ref_version_le.text() is None or
self.site_ref_version_le.text().replace(' ', '') is ''):
self.show_message(
tr("Please add the site reference version before saving the project area"),
message,
Qgis.Warning
)
return False
Expand Down Expand Up @@ -813,7 +834,14 @@ def save_area(self):
)
return

if not self.is_project_info_valid():
error_message = tr(
"Action Required: Please complete the"
" attributes form before saving the site polygon."
" This ensures all necessary details are"
" captured accurately."
)

if not self.is_project_info_valid(error_message):
return

selected_date_time = self.project_inception_date.dateTime()
Expand Down Expand Up @@ -1220,7 +1248,15 @@ def on_generate_report(self):
self.report_progress_dialog.show()

elif group == SITE_GROUP_NAME:
if not self.is_project_info_valid():
message = tr(
"Report Generation Error:"
" No site drawing has been created or saved. "
"To generate a report, please complete the "
"following steps: fill in the attributes, "
"draw a site polygon, save your work, and "
"then click to generate the report."
)
if not self.is_project_info_valid(message):
return

# Get capture date and area
Expand Down

0 comments on commit a48718f

Please sign in to comment.