Skip to content

Commit

Permalink
Added a filter to the ARF WRF sampling (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpachaly authored Jan 14, 2025
1 parent 2e3c251 commit 20d1c70
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 48 deletions.
43 changes: 32 additions & 11 deletions flo2d/gui/dlg_arf_wrf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from qgis._core import QgsWkbTypes
# FLO-2D Preprocessor tools for QGIS
# Copyright © 2021 Lutra Consulting for FLO-2D

Expand All @@ -17,25 +17,46 @@


class EvaluateReductionFactorsDialog(qtBaseClass, uiDialog):
def __init__(self):
def __init__(self, lyrs):
qtBaseClass.__init__(self)
uiDialog.__init__(self)
self.lyrs = lyrs
self.setupUi(self)
self.external_lyr_cbo.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.collapse_cbo.setFilters(QgsFieldProxyModel.Numeric | QgsFieldProxyModel.String)
self.arf_cbo.setFilters(QgsFieldProxyModel.Numeric | QgsFieldProxyModel.String)
self.wrf_cbo.setFilters(QgsFieldProxyModel.Numeric | QgsFieldProxyModel.String)
self.external_layer_changed()

self.current_lyr = None

# connections
self.external_lyr_cbo.currentIndexChanged.connect(self.external_layer_changed)
self.setup_src_layer_cbo()
self.external_lyr_cbo.currentIndexChanged.connect(self.populate_src_field_cbo)
self.use_external_lyr_rb.toggled.connect(self.method_changed)
self.use_user_layer_rb.setChecked(True)

def external_layer_changed(self):
current_layer = self.external_lyr_cbo.currentLayer()
self.collapse_cbo.setLayer(current_layer)
self.arf_cbo.setLayer(current_layer)
self.wrf_cbo.setLayer(current_layer)
def setup_src_layer_cbo(self):
"""
Filter src layer combo for polygons and connect field cbo.
"""
self.external_lyr_cbo.addItem("", None)
poly_lyrs = self.lyrs.list_group_vlayers()
for l in poly_lyrs:
if l.geometryType() == QgsWkbTypes.PolygonGeometry:
l.reload() # force layer reload because sometimes featureCount does not work
if l.featureCount() > 0:
self.external_lyr_cbo.addItem(l.name(), l.dataProvider().dataSourceUri())
else:
pass

def populate_src_field_cbo(self, idx):
if idx == 0:
return
uri = self.external_lyr_cbo.itemData(idx)
lyr_id = self.lyrs.layer_exists_in_group(uri)
self.current_lyr = self.lyrs.get_layer_tree_item(lyr_id).layer()
self.collapse_cbo.setLayer(self.current_lyr)
self.arf_cbo.setLayer(self.current_lyr)
self.wrf_cbo.setLayer(self.current_lyr)

def method_changed(self):
if self.use_external_lyr_rb.isChecked():
Expand All @@ -47,7 +68,7 @@ def use_external_layer(self):
return self.use_external_lyr_rb.isChecked()

def external_layer_parameters(self):
current_layer = self.external_lyr_cbo.currentLayer()
current_layer = self.lyrs.get_layer_by_name(self.external_lyr_cbo.currentText()).layer()
collapse_field = self.collapse_cbo.currentField()
arf_field = self.arf_cbo.currentField()
wrf_field = self.wrf_cbo.currentField()
Expand Down
2 changes: 1 addition & 1 deletion flo2d/gui/grid_tools_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def get_tailings(self):
QApplication.restoreOverrideCursor()

def eval_arfwrf(self):
eval_dlg = EvaluateReductionFactorsDialog()
eval_dlg = EvaluateReductionFactorsDialog(self.lyrs)
ok = eval_dlg.exec_()
if not ok:
return
Expand Down
63 changes: 27 additions & 36 deletions flo2d/ui/evaluate_blocked_areas.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>381</width>
<height>205</height>
<height>226</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -56,15 +56,8 @@
<string>External layer</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>WRF field</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsFieldComboBox" name="collapse_cbo">
<item row="3" column="1">
<widget class="QgsFieldComboBox" name="wrf_cbo">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -76,20 +69,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Collapse field</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>ARF field</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsFieldComboBox" name="arf_cbo">
<property name="enabled">
Expand All @@ -103,15 +82,15 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QgsMapLayerComboBox" name="external_lyr_cbo">
<property name="enabled">
<bool>true</bool>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>ARF field</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsFieldComboBox" name="wrf_cbo">
<item row="1" column="1">
<widget class="QgsFieldComboBox" name="collapse_cbo">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -123,6 +102,23 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Collapse field</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>WRF field</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="external_lyr_cbo"/>
</item>
</layout>
</widget>
</item>
Expand All @@ -132,12 +128,7 @@
<customwidget>
<class>QgsFieldComboBox</class>
<extends>QComboBox</extends>
<header>qgis.gui</header>
</customwidget>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgsmaplayercombobox.h</header>
<header>qgsfieldcombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
Expand Down

0 comments on commit 20d1c70

Please sign in to comment.