_layer_selection_changed
This commit is contained in:
parent
804390756d
commit
586faff00f
44
po_runner.py
44
po_runner.py
@ -22,7 +22,7 @@ class PoRunner(object):
|
||||
self.iface = iface
|
||||
self.local_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# Sperre für Pegelverlauf-Stationsliste
|
||||
# während dem Aktualisieren der Stationsliste treten change-signale auf, die werden so abgefangen
|
||||
self._history_stations_lock = True
|
||||
|
||||
# Layer
|
||||
@ -320,6 +320,7 @@ class PoRunner(object):
|
||||
|
||||
# disconnect Signal verbinden
|
||||
layer.willBeDeleted.connect(disconnect)
|
||||
layer.selectionChanged.connect(self._layer_selection_changed)
|
||||
|
||||
# zur Instanz hinzufügen
|
||||
QgsProject.instance().addMapLayer(layer, False)
|
||||
@ -328,6 +329,23 @@ class PoRunner(object):
|
||||
layer_tree = self.iface.layerTreeCanvasBridge().rootGroup()
|
||||
layer_tree.insertChildNode(0, QgsLayerTreeLayer(layer)) # am oberen Ende anhängen → liegt somit über basemap
|
||||
|
||||
def _layer_selection_changed(self):
|
||||
print("_layer_selection_changed")
|
||||
if self.waterlevels is None or self.waterlevels != self.iface.activeLayer():
|
||||
print("_layer_selection_changed: Aktueller Layer ist nicht unser Pegelstands-Layer")
|
||||
return
|
||||
|
||||
selected = self.waterlevels.selectedFeatures()
|
||||
if len(selected) == 1:
|
||||
if self.ui.slHistoryStation.count() == 0:
|
||||
self._history_load_stations()
|
||||
|
||||
selected_shortname = selected[0].attribute("shortname")
|
||||
print("_layer_selection_changed: Lade Pegelstandsverlauf zur Auswahl: %s" % (selected_shortname))
|
||||
self._historyStation_set_by_shortname(selected_shortname)
|
||||
else:
|
||||
print("_layer_selection_changed: Anzahl ausgewählter Elemente ist NICHT 1, lade Pegelstandsverlauf NICHT!")
|
||||
|
||||
def _layer_update_labels(self, layer, fields):
|
||||
print("_layer_update_labels")
|
||||
labeling = QgsVectorLayerSimpleLabeling(QgsPalLayerSettings())
|
||||
@ -374,7 +392,7 @@ class PoRunner(object):
|
||||
def _history_load_graph(self):
|
||||
print("_history_load_graph")
|
||||
|
||||
if self._history_stations_lock:
|
||||
if self._history_stations_lock: # während dem Aktualisieren der Stationsliste treten change-signale auf, die werden hier abgefangen
|
||||
print("_history_load_graph: Stationsliste ist aktuell gesperrt")
|
||||
return
|
||||
|
||||
@ -414,7 +432,7 @@ class PoRunner(object):
|
||||
|
||||
def _history_load_stations(self):
|
||||
print("_history_load_stations")
|
||||
self._history_stations_lock = True
|
||||
self._history_stations_lock = True # während dem Aktualisieren der Stationsliste treten change-signale auf, die werden so abgefangen
|
||||
|
||||
# behalte die aktuelle Station, um sie (mit eventuell neuem Index) wiederherzustellen
|
||||
current_station = self.ui.slHistoryStation.currentText()
|
||||
@ -436,8 +454,7 @@ class PoRunner(object):
|
||||
self.ui.slHistoryStation.addItem(shortname)
|
||||
index += 1
|
||||
|
||||
if neuer_index is not None:
|
||||
self.ui.slHistoryStation.setCurrentIndex(neuer_index)
|
||||
if self._historyStation_set_by_shortname(current_station):
|
||||
print("_history_load_stations: Bisherige Station \"%s\" mit neuem index=%d wiederhergestellt" % (current_station, neuer_index))
|
||||
else:
|
||||
self.ui.slHistoryStation.setCurrentIndex(0)
|
||||
@ -445,3 +462,20 @@ class PoRunner(object):
|
||||
print("_history_load_stations: Bisherige Station \"%s\" nicht wiedergefunden. Nehme erste Station: %s" % (current_station, station))
|
||||
|
||||
self._history_stations_lock = False
|
||||
|
||||
def _historyStation_set_by_shortname(self, shortname):
|
||||
index = self._historyStation_get_index_by_shortname(shortname)
|
||||
if index is None:
|
||||
return False
|
||||
self.ui.slHistoryStation.setCurrentIndex(index)
|
||||
return True
|
||||
|
||||
def _historyStation_get_index_by_shortname(self, shortname):
|
||||
print("_historyStation_get_index_by_shortname: shortname=%s" % (shortname,))
|
||||
for index in range(self.ui.slHistoryStation.count()):
|
||||
text = self.ui.slHistoryStation.itemText(index)
|
||||
if shortname == text:
|
||||
print("_historyStation_get_index_by_shortname: index=%d" % (index,))
|
||||
return index
|
||||
print("_historyStation_get_index_by_shortname: Nicht gefunden")
|
||||
return None
|
||||
|
||||
Loading…
Reference in New Issue
Block a user