Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 6d973c92 authored by PIERSON Julie's avatar PIERSON Julie
Browse files

changing input layers adds its band names to the table

parent 56d5fcc8
......@@ -27,7 +27,6 @@ import codecs
from qgis.PyQt import uic
from qgis.PyQt.QtCore import pyqtSlot, QDir
from qgis.PyQt.QtGui import QColor, QBrush
from qgis.PyQt.QtWidgets import (QTreeWidgetItem,
QFileDialog,
QMessageBox,
......@@ -36,11 +35,14 @@ from qgis.PyQt.QtWidgets import (QTreeWidgetItem,
)
from qgis.PyQt.QtXml import QDomDocument
from qgis.core import QgsApplication, QgsMapLayer
from qgis.core import (QgsApplication,
QgsMapLayer,
QgsMapLayerProxyModel)
from qgis.analysis import QgsRelief
from processing.gui.wrappers import WidgetWrapper
from processing.tools import system
from osgeo import gdal
pluginPath = os.path.dirname(__file__)
WIDGET, BASE = uic.loadUiType(os.path.join(pluginPath, 'bandtablewidgetbase.ui'))
......@@ -52,12 +54,41 @@ class BandTableWidget(BASE, WIDGET):
super(BandTableWidget, self).__init__(None)
self.setupUi(self)
self.cmbLayers.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.cmbLayers.layerChanged.connect(self.layerChanged)
self.btnAdd.setIcon(QgsApplication.getThemeIcon('/symbologyAdd.svg'))
self.btnRemove.setIcon(QgsApplication.getThemeIcon('/symbologyRemove.svg'))
self.btnUp.setIcon(QgsApplication.getThemeIcon('/mActionArrowUp.svg'))
self.btnDown.setIcon(QgsApplication.getThemeIcon('/mActionArrowDown.svg'))
self.layer = None
# when user changes selected layer in combobox
def layerChanged(self):
# remove table content
self._removeBandData()
# get raster layer
layer = self.cmbLayers.currentLayer()
#QMessageBox.information(None, self.tr('tralala'), self.tr(str(layer)))
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 name to table in first column
self._addBandData(band.GetDescription())
# add selected raster band names to table
def _addBandData(self, bandname):
item = QTreeWidgetItem()
item.setText(0, bandname)
item.setText(1, '')
self.bandClassTree.addTopLevelItem(item)
# remove all rows from table
def _removeBandData(self,):
self.bandClassTree.clear()
@pyqtSlot()
def on_btnAdd_clicked(self):
item = QTreeWidgetItem()
......@@ -126,7 +157,15 @@ class BandTableWidget(BASE, WIDGET):
return colors
def setLayer(self, layer):
QMessageBox.information(None, self.tr('tralala'), self.tr('coucou'))
self.layer = layer
self.updateTable(layer)
def updateTable(self, layer):
item = QTreeWidgetItem()
item.setText(0, '0.00')
item.setText(1, '0.00')
self.bandClassTree.addTopLevelItem(item)
def setValue(self, value):
self.bandClassTree.clear()
......@@ -165,6 +204,7 @@ class BandTableWidgetWrapper(WidgetWrapper):
if isinstance(layer, QgsMapLayer):
layer = layer.source()
self.widget.setLayer(layer)
self.widget.updateTable(layer)
def setValue(self, value):
self.widget.setValue(value)
......
......@@ -48,17 +48,17 @@ from osgeo import gdal
# custom band table widget
class ParameterBandTable(QgsProcessingParameterDefinition):
def __init__(self, name='', description='', parent=None, optional=True):
def __init__(self, name='', description='', parent=None, optional=False):
super().__init__(name, description, None, optional)
self.parent = parent
self.setMetadata({'widget_wrapper': 'BandTableWidget.BandTableWidgetWrapper'})
def type(self):
return 'band table'
return 'Input parameters'
def clone(self):
return ParameterBandTable(self.name(), self.description(), self.parent,
self.flags() & QgsProcessingParameterDefinition.FlagOptional)
self.flags())
class TableWidget(WidgetWrapper):
......@@ -110,9 +110,9 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
self.addParameter(
ParameterBandTable(
self.INPUT,
self.tr('Band table'),
self.tr('Input parameters'),
self.INPUT,
True
False # True if optional
)
)
......@@ -131,10 +131,10 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
"""
# RETRIEVE INPUTS AND OUTPUT
input_raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
input_param = self.parameterAsRasterLayer(parameters, self.INPUT, context)
output_raster_path = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
# # GETTING USEFUL PAREMETERS
# # GETTING USEFUL PARAMETERS
#
# # number of columns in table is used later on, change it here if necessary
# nb_col = 2
......
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