Commit 9dba9ffe authored by PIERSON Julie's avatar PIERSON Julie
Browse files

remove bug when using history and bands are added twice + no error when using...

remove bug when using history and bands are added twice + no error when using history and previous input layer is not loaded
parent c3b57a8d
......@@ -54,6 +54,9 @@ class BandTableWidget(BASE, WIDGET):
self.btnUp.setIcon(QgsApplication.getThemeIcon('/mActionArrowUp.svg'))
self.btnDown.setIcon(QgsApplication.getThemeIcon('/mActionArrowDown.svg'))
self.layer = None
# when alg is launched by user, display bands in table of 1st raster layer
self.layerChanged()
# when user changes selected layer in combobox
def layerChanged(self):
......@@ -61,17 +64,19 @@ class BandTableWidget(BASE, WIDGET):
self._removeBandData()
# get raster layer
layer = self.cmbLayers.currentLayer()
#QMessageBox.information(None, self.tr('tralala'), self.tr(str(layer.name())))
input_raster = gdal.Open(layer.source())
# get number of bands in raster
nbands = input_raster.RasterCount
# for each band
for band_number in range(nbands):
band = input_raster.GetRasterBand(band_number + 1)
# add band number to table
bandnumber = str(band_number+1)
bandname = band.GetDescription()
self._addBandData(bandnumber, bandname)
# if there is one
if layer != None:
#QMessageBox.information(None, self.tr('tralala'), self.tr(str(layer.name())))
input_raster = gdal.Open(layer.source())
# get number of bands in raster
nbands = input_raster.RasterCount
# for each band
for band_number in range(nbands):
band = input_raster.GetRasterBand(band_number + 1)
# add band number to table
bandnumber = str(band_number+1)
bandname = band.GetDescription()
self._addBandData(bandnumber, bandname)
# add selected raster band number and names to table
def _addBandData(self, bandnumber, bandname):
......@@ -138,7 +143,7 @@ class BandTableWidget(BASE, WIDGET):
if item:
row = [item.text(0), item.text(1), item.text(2)]
band_names.append(row)
QMessageBox.information(None, self.tr('tralala'), self.tr(str(band_names)))
#QMessageBox.information(None, self.tr('tralala'), self.tr(str(band_names)))
return band_names
def setLayer(self, layer):
......@@ -156,17 +161,20 @@ class BandTableWidget(BASE, WIDGET):
param = value.split(';')
# setting input layer
layer_name = param[0]
layer = QgsProject.instance().mapLayersByName(layer_name)[0]
self.cmbLayers.setLayer(layer)
# setting table values
rows = param[2:]
for r in rows:
v = r.split(',')
item = QTreeWidgetItem()
item.setText(0, v[0])
item.setText(1, v[1])
item.setText(2, v[2])
self.bandClassTree.addTopLevelItem(item)
# if layer is loaded in project
if QgsProject.instance().mapLayersByName(layer_name):
layer = QgsProject.instance().mapLayersByName(layer_name)[0]
self.cmbLayers.setLayer(layer)
# setting table values
self.bandClassTree.clear()
rows = param[2:]
for r in rows:
v = r.split(',')
item = QTreeWidgetItem()
item.setText(0, v[0])
item.setText(1, v[1])
item.setText(2, v[2])
self.bandClassTree.addTopLevelItem(item)
# return a list where 1st element is input raster path
# and then each element for a table row
......
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