I am creating a QGIS Plugin, in which the user can rename columns to specfied names depending on a certain policy. In the image you can see, that the user selects a layer in QGIS which field names will then populate a mFieldCombobox ('actual name') and in a second Combobox the user is provided with a list of names, defined in the plugin (and depending on the chosen policy).
However, the amount of columns in the layer, which should be renamed, depends on the needs of the user and so I want him/her to be able to add as much comboboxes ('actual name' and 'rename to') as needed. For this I added the '+'-button, which, when pressed, should generate a new 'actual name'-mFieldCombobox and a new 'rename to'-combobox.
Is this possible, and if so, how? Any help would be very welcome!
My code so far:
def run(self):
"""Run method that performs all the real work"""
# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start = False
self.dlg = ReformatToLKNamesDialog()
# Populate Richtlinien Combobox mit Richtliniennamen
self.populateRichtinie()
# Get value from Richtlinie
self.selected_RL = self.dlg.Richtlinie.currentText()
self.dlg.Richtlinie.currentTextChanged.connect(self.populateRLS19)
# Update the combobox with the field names
self.dlg.LayerName.layerChanged.connect(self.updateFields)
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
print(type(result))
# See if OK was pressed
if result:
# Write here your code which should run when you hit the button 'OK'
pass
def printRL(self):
self.selected_RL = self.dlg.Richtlinie.currentText()
if self.selected_RL:
print(self.dlg.Richtlinie.currentText())
def updateFields(self):
self.dlg.mFieldComboBox.clear()
selectedLayer = self.dlg.LayerName.currentLayer()
if selectedLayer:
self.dlg.mFieldComboBox.setLayer(selectedLayer)
def populateRichtinie(self):
richtlinien = [''] # may be added: 'All'
print(richtlinien)
self.dlg.Richtlinie.addItems([item for item in richtlinien])
def populateRLS19(self):
self.dlg.LKName.clear()
selectedRichtlinie = self.dlg.Richtlinie.currentText()
rlkurz = {'st':'sr', 'b':'ra', 'ls':'la'}
selctedRL_kurzel = rlkurz[selectedRichtlinie]
print(selctedRL_kurzel)
rl_kuerzel = [
'list', 'of', 'names']
rl_f = [selctedRL_kurzel+kuerzel for kuerzel in rl_kuerzel]
self.dlg.LKName.addItems([item for item in rl_f])
QTableWidget
to hold theQComboBox
. Something like stackoverflow.com/questions/46079378/…Refactor field
tool. Ceating a plugin for this is overkill. docs.qgis.org/testing/en/docs/user_manual/processing_algs/qgis/…