Skip to content

Commit

Permalink
Pre-select checkboxes based on click position on reach
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 11, 2019
1 parent 999c4c1 commit edebeb8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/tools/qgepmaptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ def activate(self):
Called by QGIS whenever the tool is activated.
"""

def is_closer_to_start_of_edge(source, target):
feature = next(source.layer().getFeatures(QgsFeatureRequest(source.featureId())))
distance_from_start = feature.geometry().lineLocatePoint(QgsGeometry.fromPointXY(source.point()))
length = feature.geometry().length()

return distance_from_start < length / 2


# A dict of layers
# and for each layer the fields to use as foreign key
# as well as the possible target layers
Expand All @@ -603,14 +611,16 @@ def activate(self):
self.network_element_sources = {
QgepLayerManager.layer('vw_qgep_reach'): {
'fields': [
{
'id': 'rp_to_fk_wastewater_networkelement',
'name': QCoreApplication.translate('QgepMapToolConnectNetworkElements', 'Reach Point To')
},
{
'id': 'rp_from_fk_wastewater_networkelement',
'name': QCoreApplication.translate('QgepMapToolConnectNetworkElements', 'Reach Point From'),
'filter': lambda source, target: target.layer() != QgepLayerManager.layer('vw_qgep_reach')
'filter': lambda source, target: target.layer() != QgepLayerManager.layer('vw_qgep_reach'),
'is_checked': lambda source, target: is_closer_to_start_of_edge(source, target)
},
{
'id': 'rp_to_fk_wastewater_networkelement',
'name': QCoreApplication.translate('QgepMapToolConnectNetworkElements', 'Reach Point To'),
'is_checked': lambda source, target: not is_closer_to_start_of_edge(source, target)
}
],
'target_layers': [
Expand Down Expand Up @@ -779,6 +789,9 @@ def connect_features(self, source, target):
continue
cbx = QCheckBox(prop['name'])
cbx.setObjectName(prop['id'])

if 'is_checked' in prop.keys():
cbx.setChecked(prop['is_checked'](source, target))
properties.append(cbx)
dlg.layout().addWidget(cbx)

Expand Down

0 comments on commit edebeb8

Please sign in to comment.