Skip to content

Commit

Permalink
Merge pull request #57 from Samweli/version_updates
Browse files Browse the repository at this point in the history
Version updates
  • Loading branch information
Samweli committed Aug 5, 2024
2 parents f6c96c4 + 4dc947c commit 7947445
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 46 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Kartoza",
"email": "[email protected]",
"description": "View, browse and navigate through imagery.",
"version": "0.0.1",
"version": "0.0.14dev",
"changelog": ""
}
}
3 changes: 3 additions & 0 deletions src/qgis_gea_plugin/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Settings(enum.Enum):

PROJECT_FOLDER = 'project_folder'

ANIMATION_FRAME_RATE = 'frame_rate'
ANIMATION_LOOP = 'animation_loop'


class SettingsManager(QtCore.QObject):
"""Manages saving/loading settings for the plugin in QgsSettings."""
Expand Down
2 changes: 2 additions & 0 deletions src/qgis_gea_plugin/definitions/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
"United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan",
"Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe"
]

SITE_GROUP_NAME = "Proposed site boundaries"
121 changes: 99 additions & 22 deletions src/qgis_gea_plugin/gui/qgis_gea.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ANIMATION_PAUSE_ICON,
ANIMATION_PLAY_ICON,
COUNTRY_NAMES,
SITE_GROUP_NAME,
PLUGIN_ICON
)

Expand Down Expand Up @@ -97,7 +98,28 @@ def __init__(self, iface, parent=None):
QgsInterval(1, QgsUnitTypes.TemporalIrregularStep)
)

frame_rate = settings_manager.get_value(
Settings.ANIMATION_FRAME_RATE,
default=1.0,
setting_type=float
)

self.frame_rate_box.setValue(frame_rate) \
if frame_rate is not None else None

self.loop_box.setChecked(
settings_manager.get_value(
Settings.ANIMATION_LOOP,
default=False,
setting_type=bool
)
)
self.navigation_object.setLooping(self.loop_box.isChecked())
self.navigation_object.setFramesPerSecond(float(frame_rate)) \
if frame_rate is not None else None

self.frame_rate_box.valueChanged.connect(self.frame_rate_changed)
self.loop_box.toggled.connect(self.animation_loop_toggled)

self.current_imagery_type = IMAGERY.HISTORICAL

Expand Down Expand Up @@ -145,8 +167,12 @@ def __init__(self, iface, parent=None):

self.iface.projectRead.connect(self.prepare_time_slider)

def animation_loop_toggled(self, value):
self.save_settings()
self.navigation_object.setLooping(value)
def frame_rate_changed(self, value):
self.navigation_object.setFramesPerSecond(
self.save_settings()
self.navigation_object.setFramesPerSecond(
value
)

Expand All @@ -165,6 +191,9 @@ def save_settings(self):
settings_manager.set_value(Settings.REPORT_COUNTRY, self.country_cmb_box.currentText())
settings_manager.set_value(Settings.PROJECT_FOLDER, self.project_folder.filePath())

settings_manager.set_value(Settings.ANIMATION_FRAME_RATE, self.frame_rate_box.value())
settings_manager.set_value(Settings.ANIMATION_LOOP, self.loop_box.isChecked())

def restore_settings(self):
self.site_reference_le.setText(settings_manager.get_value(Settings.SITE_REFERENCE))
self.site_ref_version_le.setText(settings_manager.get_value(Settings.SITE_VERSION))
Expand Down Expand Up @@ -245,11 +274,12 @@ def temporal_range_changed(self, temporal_range):
:type temporal_range: QgsDateTimeRange
"""
self.iface.mapCanvas().setTemporalRange(temporal_range)
self.temporal_range_la.setText(
tr(
f'Current time range: '
f'<b>{temporal_range.begin().toString("yyyy-MM-ddTHH:mm:ss")}'
))
if temporal_range and temporal_range.begin():
self.temporal_range_la.setText(
tr(
f'Current time range: '
f'<b>{temporal_range.begin().toString("yyyy-MM")}'
))
self.time_slider.setValue(
self.navigation_object.currentFrameNumber()
)
Expand All @@ -258,7 +288,11 @@ def temporal_range_changed(self, temporal_range):
if self.navigation_object.currentFrameNumber() == \
len(self.navigation_object.availableTemporalRanges()) - 1:

self.play_btn.setToolTip(tr("Click to play animation"))
self.play_btn.setIcon(QtGui.QIcon(ANIMATION_PLAY_ICON))
else:
self.play_btn.setToolTip(tr("Pause animation"))
self.play_btn.setIcon(QtGui.QIcon(ANIMATION_PAUSE_ICON))

def prepare_time_slider(self):
"""
Expand All @@ -276,15 +310,22 @@ def prepare_time_slider(self):

self.current_imagery_type = IMAGERY.HISTORICAL
closed_imagery = IMAGERY.NICFI
else:
elif self.nicfi_imagery.isChecked():
settings_manager.set_value(Settings.NICFI_VIEW, True)
settings_manager.set_value(Settings.HISTORICAL_VIEW, False)

self.current_imagery_type = IMAGERY.NICFI
closed_imagery = IMAGERY.HISTORICAL
else:
settings_manager.set_value(Settings.HISTORICAL_VIEW, False)
settings_manager.set_value(Settings.NICFI_VIEW, False)

layers = QgsProject.instance().mapLayers()
for path, layer in layers.items():
if closed_imagery is None:
self.update_layer_group(layer, True)
continue

if layer.metadata().contains(
self.current_imagery_type.value.lower()
):
Expand All @@ -307,12 +348,12 @@ def prepare_time_slider(self):

temporal_range = sorted_date_time_ranges[0] if len(sorted_date_time_ranges) > 0 else None

if temporal_range:
if temporal_range and temporal_range.begin():
self.iface.mapCanvas().setTemporalRange(temporal_range)
self.temporal_range_la.setText(
tr(
f'Current time range: '
f'<b>{temporal_range.begin().toString("yyyy-MM-ddTHH:mm:ss")}'
f'<b>{temporal_range.begin().toString("yyyy-MM")}'
))

def update_layer_group(self, layer, show=False):
Expand All @@ -338,19 +379,19 @@ def start_drawing(self):

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 drawing the project area."),
tr("Please add the site reference before starting to draw the project area."),
Qgis.Warning
)
return
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 drawing the project area."),
tr("Please add the version of site reference before starting to draw the project area."),
Qgis.Warning
)
return
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 drawing the project area."),
tr("Please add the report generation author before starting to draw the project area."),
Qgis.Warning
)
return
Expand Down Expand Up @@ -401,8 +442,42 @@ def start_drawing(self):
)
self.drawing_layer.updateFields()

# Add the layer to the project
QgsProject.instance().addMapLayer(self.drawing_layer)
# Add the layer to the site boundaries
QgsProject.instance().addMapLayer(self.drawing_layer, False)

# Toggle layer editing
self.drawing_layer.startEditing()

root = QgsProject.instance().layerTreeRoot()

# Find or create the group
group = None
for layer_group in root.findGroups():
if layer_group.name().lower() == SITE_GROUP_NAME.lower():
group = layer_group
break

if not group:
group = root.addGroup(SITE_GROUP_NAME)


# Add the layer to the group
group.addLayer(self.drawing_layer)

# Move the group to the first position in the root layer tree
if group.parent() == root:
root.insertChildNode(0, group.clone())
root.removeChildNode(group)

# Select/highlight the added layer for editing
layer_tree_layer = root.findLayer(self.drawing_layer.id())
if layer_tree_layer:
layer_tree_layer.setItemVisibilityChecked(True)
self.iface.setActiveLayer(self.drawing_layer)

# Toggle layer editing
self.drawing_layer.startEditing()


# List of fields to disable editing on
fields_to_disable = [
Expand All @@ -418,9 +493,6 @@ def start_drawing(self):
# Disable editing for the specified fields
self.update_field_editing(self.drawing_layer, fields_to_disable, False)

# Toggle layer editing
self.drawing_layer.startEditing()

# Enable shape digitizing toolbar
self.iface.shapeDigitizeToolBar().setVisible(True)

Expand Down Expand Up @@ -538,23 +610,28 @@ def save_area(self):


def cancel_drawing(self):

self.site_reference_le.setText(None)
self.site_ref_version_le.setText(None)
self.report_author_le.setText(None)
self.project_inception_date.clear()
self.country_cmb_box.setCurrentIndex(-1)

if self.drawing_layer:
self.drawing_layer.commitChanges()

QgsProject.instance().removeMapLayer(self.drawing_layer)

self.iface.mapCanvas().refresh()

self.show_message(
tr("Cleared the project area successfully."),
tr("Cleared the project input fields and area successfully."),
Qgis.Info
)

self.drawing_layer = None
else:
self.show_message(
tr("There is no project area editing to clear!"),
Qgis.Warning
tr("Cleared the project input fields."),
Qgis.Info
)


Expand Down
46 changes: 34 additions & 12 deletions src/qgis_gea_plugin/ui/main_dockwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap>../../../../../../../../../../../../../../../../../../.designer/icons/icon.png</pixmap>
<pixmap>../../../../../../../../../../../../../../../../../../../../../../.designer/icons/icon.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
Expand Down Expand Up @@ -122,22 +122,19 @@
<property name="text">
<string>Historical Imagery (Landsat)</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="nicfi_imagery">
<property name="text">
<string>Current Imagery (NICIFI)</string>
<string>Recent Imagery (NICFI)</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="1" column="0">
Expand Down Expand Up @@ -182,6 +179,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="loop_box">
<property name="toolTip">
<string>Enable a loop when playing animation</string>
</property>
<property name="text">
<string>Loop</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -240,6 +247,9 @@
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Country where the project was conducted.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Country</string>
</property>
Expand All @@ -257,27 +267,39 @@
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Directory where all the corresponding sites layers will be saved.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Project folder</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'Slack-Lato','Slack-Fractions','appleLogo','sans-serif'; font-size:15px; color:#1d1c1d; background-color:#f8f8f8;&quot;&gt;Allows a user to track any updates to an already defined site boundary, and save the new boundary as a same-name, but with version 2,3,4 etc.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Version of the site reference</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'Slack-Lato','Slack-Fractions','appleLogo','sans-serif'; font-size:15px; color:#1d1c1d; background-color:#f8f8f8;&quot;&gt;The unique location / name of the user-defined polygon that represents a possible re-afforestation site&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Site reference</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The tool-user who created the site polygon and saved the site details.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Author of site capture</string>
</property>
Expand All @@ -295,6 +317,9 @@
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Refers to a fixed point in time, representing the inception date of the whole re-afforestation project.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Project inception date</string>
</property>
Expand Down Expand Up @@ -441,7 +466,4 @@
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
Loading

0 comments on commit 7947445

Please sign in to comment.