QGIS Combo Manager is a python module to easily manage combo boxes for layer lists and field lists.
QGIS Combo Manager is a python module to easily manage a combo box with a layer list and eventually relate it with one or several combos with list of corresponding fields.
The field combos are filled with the names of columns of the currently selected layer in the layer combo.
In your plugin, create first a LayerCombo:
from qgiscombomanager import *
self.layerComboManager = VectorLayerCombo(self.layerComboWidget)
Then, associates some FieldCombo:
self.myFieldComboManager = FieldCombo(self.myFieldComboManager, self.layerComboManager)
The managers (layer or field) must be saved as a class property (self.something), so the variable is not getting out of scope in python.
The classes offers some convenience methods: getLayer()
and setLayer(layer)
, for layer combos, and getFieldName()
, getFieldAlias()
, getFieldIndex()
for field combos.
A combo box can be assigned to list the layers. Three classes are available:
LayerCombo(widget, initLayer="", options={}, layerType=None)
VectorLayerCombo(widget, initLayer="", options={})
RasterLayerCombo(widget, initLayer="", options={})
VectorLayerCombo
and RasterLayerCombo
are convenient classes which are calling the main LayerCombo class with the same parameters and specifying the layerType
.
Options are listed hereunder, default values being listed first:
groupLayers is True
, you must provide iface.legendInterface()
for this option.False
if the LayerCombo
object must be returned before its items are filled with layers.*used for vector layer combos
This class offer convenient methods:
getLayer()
: returns the layer currently selected in the combo boxsetLayer(layer)
: set the current layer in the combo box (layer can be a layer or a layer id).The LayerCombo will also emit signals:
layerChanged()
and layerChangedLayer(QgsMapLayer)
: whenever the layer changes.A combo box can be assigned to list the fields related to a given VectorLayerCombo.
FieldCombo(widget, vectorLayerCombo, initField="", fieldType=None)
Options are listed hereunder, default values being listed first:
This class offer convenient methods:
getFieldName()
: returns the name of the currently selected fieldgetFieldAlias()
: returns the alias of the currently selected fieldgetFieldIndex()
: returns the field index of the currently selected fieldsetField(fieldName)
: set the current field in the combo boxThe FieldCombo will also emit a signal:
fieldChanged(str)
, fieldChangedName(str)
and fieldChangedIndex(int)
: whenever the field changes it will emit these signals with the corresponding arguments.Similarly to field combos, a combo box can be assigned to list the bands related to a given RasterLayerCombo.
BandCombo(widget, rasterLayerCombo, initBand=None)
This class offer a convenient method:
getBand()
: returns the name of the currently selected bandThe BandCombo will also emit a signal:
bandChanged(str)
: whenever the band changes it will emit this signal with the new band name.To use this module you can easily copy the files and put them in your project. A more elegant way is to use git submodule. Hence, you can keep up with latest improvements. In you plugin directory, do
git submodule add git://github.com/3nids/qgiscombomanager.git
A folder qgiscombomanager will be added to your plugin directory. However, git only references the module, and you can git pull
in this folder to get the last changes.