Commit 87347d2a authored by PIERSON Julie's avatar PIERSON Julie
Browse files

alg can now be launched using history with parameters ok

parent 66fc768d
......@@ -32,11 +32,9 @@ from qgis.PyQt.QtWidgets import (QTreeWidgetItem,
)
from qgis.core import (QgsApplication,
QgsProject,
QgsMapLayer,
QgsProcessing,
QgsMapLayerProxyModel)
QgsMapLayer
)
from processing.gui.wrappers import WidgetWrapper
from osgeo import gdal
pluginPath = os.path.dirname(__file__)
WIDGET, BASE = uic.loadUiType(os.path.join(pluginPath, 'mergebandtablewidgetbase.ui'))
......@@ -81,18 +79,6 @@ class MergeBandTableWidget(BASE, WIDGET):
if len(rasterNames) != 0:
for r in rasterNames:
self._addBandData(r)
# # if there is one
# if layer != None:
# 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 names to table
def _addBandData(self, rastername):
......@@ -161,35 +147,26 @@ class MergeBandTableWidget(BASE, WIDGET):
item.setText(1, '0.00')
self.bandClassTree.addTopLevelItem(item)
# when launching alg from history in processing, setting parameters
def setValue(self, value):
self.bandClassTree.clear()
# getting raster names
param = value.split(';')
# setting input layer
layer_name = param[0]
# # if layer is loaded in project
# if QgsProject.instance().mapLayersByName(layer_name):
# layer = QgsProject.instance().mapLayersByName(layer_name)[0]
# self.multiLayers.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
param = [i.split(',') for i in param]
rasterNames = [i[0] for i in param]
QMessageBox.information(None, self.tr('hop'), self.tr(str(param)))
# checking items in combobox
self.multiLayers.setCheckedItems(rasterNames)
# populating second column in table with band future name
bandNames = [i[1] for i in param]
root = self.bandClassTree.invisibleRootItem()
for i in range(len(bandNames)):
item = item = root.child(i)
item.setText(1, bandNames[i])
# return a list each element for a table row
# ['band 1, new name 1', 'band 2, new name 2']
def value(self):
# # adding input layer names to values (useful to select again this layer when using toolbox history)
# allValues = self.multiLayers.currentLayer().name()
# allValues += ';'
# # adding input layer path to values
# allValues += self.multiLayers.currentLayer().source()
# allValues += ';'
allValues = ''
# adding table content to values
for b in self.bandNames():
......
......@@ -53,9 +53,8 @@ class ParameterMergeBandTable(QgsProcessingParameterDefinition):
return ParameterMergeBandTable(self.name(), self.description(), self.parent, self.flags())
# getting output values as a list, 1st element for layer name, 2nd for layer path,
# then one element for each row :
# ['mylayer', '/path/to/mylayer.tif', 'band 1, old name 1, new name 1', 'band 2, old name 2, new name 2']
# getting output values as a list, one element for each row in table :
# ['band 1, new name 1', 'band 2, new name 2']
# (see BandTableWidget.py to change this)
@staticmethod
def tableValuesAsList(value):
......
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