Commit 34c29dde authored by PIERSON Julie's avatar PIERSON Julie
Browse files

when user selects or unselect a layer in combobox, only this layer is added or removed from table

parent 3fa10398
......@@ -25,7 +25,7 @@ __copyright__ = '(C) 2021 by J. Pierson, UMR 6554 LETG, CNRS'
import os
from qgis.PyQt import uic
from qgis.PyQt.QtCore import pyqtSlot
from qgis.PyQt.QtCore import Qt, pyqtSlot
from qgis.PyQt.QtWidgets import (QTreeWidgetItem,
QMessageBox,
QInputDialog,
......@@ -39,6 +39,8 @@ from processing.gui.wrappers import WidgetWrapper
pluginPath = os.path.dirname(__file__)
WIDGET, BASE = uic.loadUiType(os.path.join(pluginPath, 'mergebandtablewidgetbase.ui'))
# global variable for selected layers in combobox
global selectedLayers
class MergeBandTableWidget(BASE, WIDGET):
......@@ -46,8 +48,9 @@ class MergeBandTableWidget(BASE, WIDGET):
super(MergeBandTableWidget, self).__init__(None)
self.setupUi(self)
#self.multiLayers.setLayerType(QgsProcessing.TypeRaster) # 3 for TypeRaster
self.multiLayers.checkedItemsChanged.connect(self.layersChanged)
selectedLayers = self.multiLayers.checkedItems()
#self.multiLayers.checkedItemsChanged.connect(self.layersChanged)
self.multiLayers.checkedItemsChanged.connect(lambda: self.layersChanged(selectedLayers))
self.btnUp.setIcon(QgsApplication.getThemeIcon('/mActionArrowUp.svg'))
self.btnDown.setIcon(QgsApplication.getThemeIcon('/mActionArrowDown.svg'))
self.layer = None
......@@ -69,16 +72,28 @@ class MergeBandTableWidget(BASE, WIDGET):
for r in rasterNames:
self.multiLayers.addItem(r)
# when user changes selected layer in combobox
def layersChanged(self):
# remove table content
self._removeBandData()
# get raster layers
# when user selects or unselects a layer in combobox, changes only this layer in table
def layersChanged(self, selectedLayers):
# get selected raster layers
rasterNames = self.multiLayers.checkedItems()
# if there is at least one selected raster
if len(rasterNames) != 0:
for r in rasterNames:
self._addBandData(r)
# if it was not selected before
if r not in selectedLayers:
# add it to table
self._addBandData(r)
# add it to list of selected layers
selectedLayers.append(r)
# if a layer was selected before but not anymore
for r in selectedLayers:
if r not in rasterNames:
# remove it from table
item = self.bandClassTree.findItems(r, Qt.MatchExactly, 0)[0]
self.bandClassTree.invisibleRootItem().removeChild(item)
item = None
# remove it from the list of selected layers
selectedLayers.remove(r)
# add selected raster names to table
def _addBandData(self, rastername):
......@@ -86,10 +101,6 @@ class MergeBandTableWidget(BASE, WIDGET):
item.setText(0, rastername)
self.bandClassTree.addTopLevelItem(item)
# remove all rows from table
def _removeBandData(self,):
self.bandClassTree.clear()
# move down selected line in table when down button is clicked
@pyqtSlot()
def on_btnDown_clicked(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment