QGIS API Documentation 3.43.0-Master (69d1901085b)
|
A combobox which displays a dynamic list of layers from a QGIS project. More...
#include <qgsmaplayercombobox.h>
Public Slots | |
void | setLayer (QgsMapLayer *layer) |
Sets the current layer selected in the combo box. | |
Signals | |
void | layerChanged (QgsMapLayer *layer) |
Emitted whenever the currently selected layer changes. | |
Public Member Functions | |
QgsMapLayerComboBox (QWidget *parent=nullptr) | |
QgsMapLayerComboBox creates a combo box to display the list of layers currently in the project. | |
QStringList | additionalItems () const |
Returns the list of additional (non map layer) items included at the end of the combo box. | |
QList< QgsMapLayer * > | additionalLayers () const |
Returns the list of additional layers added to the combobox. | |
bool | allowEmptyLayer () const |
Returns true if the combo box allows the empty layer ("not set") choice. | |
QgsMapLayer * | currentLayer () const |
Returns the current layer selected in the combo box. | |
QList< QgsMapLayer * > | exceptedLayerList () const |
Returns a list of layers which should be excluded from the combo box. | |
QStringList | excludedProviders () const |
Returns the list of data providers which are excluded from the combobox. | |
Qgis::LayerFilters | filters () const |
Returns any currently used filters on the listed layers. | |
QgsMapLayer * | layer (int layerIndex) const |
Returns the layer currently shown at the specified index within the combo box. | |
void | setAdditionalItems (const QStringList &items) |
Sets a list of additional (non map layer) items to include at the end of the combobox. | |
void | setAdditionalLayers (const QList< QgsMapLayer * > &layers) |
Sets a list of additional layers to include in the combobox. | |
void | setAllowEmptyLayer (bool allowEmpty, const QString &text=QString(), const QIcon &icon=QIcon()) |
Sets whether an optional empty layer ("not set") option is shown in the combo box. | |
void | setExceptedLayerList (const QList< QgsMapLayer * > &layerList) |
Sets a list of layers which should be excluded from the combo box. | |
void | setExcludedProviders (const QStringList &providers) |
Sets a list of data providers which should be excluded from the combobox. | |
Q_DECL_DEPRECATED void | setFilters (int filters) |
Filters according to layer type and/or geometry type. | |
void | setFilters (Qgis::LayerFilters filters) |
Sets filters for the layers displayed in the combo box. | |
void | setProject (QgsProject *project) |
Sets the project from which map layers are shown. | |
void | setShowCrs (bool showCrs) |
Sets whether the CRS of layers is also included in the combo box text. | |
bool | showCrs () const |
Returns true if the combo box shows the layer's CRS. | |
Protected Slots | |
void | indexChanged (int i) |
void | rowsChanged () |
Protected Member Functions | |
void | dragEnterEvent (QDragEnterEvent *event) override |
void | dragLeaveEvent (QDragLeaveEvent *event) override |
void | dropEvent (QDropEvent *event) override |
void | paintEvent (QPaintEvent *e) override |
Properties | |
bool | allowEmptyLayer |
QStringList | excludedProviders |
Qgis::LayerFilters | filters |
bool | showCrs |
Friends | |
class | QgsProcessingMapLayerComboBox |
A combobox which displays a dynamic list of layers from a QGIS project.
QgsMapLayerComboBox is automatically populated with all the layers from the project. Any changes to the project's layers are immediately reflected in the combobox, such as addition of new layers, layer renaming, or layer removal. Accordingly, this widget should ALWAYS be used when presenting a choice of layers to a user, instead of manually populated comboboxes.
In addition to the automatic layer population, QgsMapLayerComboBox also presents a user-friendly choice of layers by showing standard icons representing the different layer types (eg raster, mesh, or polygon/point/line icons for vector layers). Helpful tooltips will be shown if the user hovers over any of the layers, helping guide the user to the correct layer choice.
Optionally, the list of available layers can be filtered to a subset of the project's layers (such as only showing raster layers, or only spatial layers) by calling setFilters().
By default, the combobox will be populated using layers from the current project (see QgsProject::instance()), however a specific source project can be set via setProject().
Definition at line 53 of file qgsmaplayercombobox.h.
|
explicit |
QgsMapLayerComboBox creates a combo box to display the list of layers currently in the project.
The layers can be filtered and/or ordered.
Definition at line 24 of file qgsmaplayercombobox.cpp.
QStringList QgsMapLayerComboBox::additionalItems | ( | ) | const |
Returns the list of additional (non map layer) items included at the end of the combo box.
Definition at line 80 of file qgsmaplayercombobox.cpp.
QList< QgsMapLayer * > QgsMapLayerComboBox::additionalLayers | ( | ) | const |
Returns the list of additional layers added to the combobox.
Definition at line 90 of file qgsmaplayercombobox.cpp.
bool QgsMapLayerComboBox::allowEmptyLayer | ( | ) | const |
Returns true
if the combo box allows the empty layer ("not set") choice.
Definition at line 60 of file qgsmaplayercombobox.cpp.
QgsMapLayer * QgsMapLayerComboBox::currentLayer | ( | ) | const |
Returns the current layer selected in the combo box.
Definition at line 122 of file qgsmaplayercombobox.cpp.
|
overrideprotected |
Definition at line 184 of file qgsmaplayercombobox.cpp.
|
overrideprotected |
Definition at line 206 of file qgsmaplayercombobox.cpp.
|
overrideprotected |
Definition at line 220 of file qgsmaplayercombobox.cpp.
|
inline |
Returns a list of layers which should be excluded from the combo box.
Definition at line 105 of file qgsmaplayercombobox.h.
QStringList QgsMapLayerComboBox::excludedProviders | ( | ) | const |
Returns the list of data providers which are excluded from the combobox.
Definition at line 50 of file qgsmaplayercombobox.cpp.
|
inline |
Returns any currently used filters on the listed layers.
Definition at line 91 of file qgsmaplayercombobox.h.
|
protectedslot |
Definition at line 149 of file qgsmaplayercombobox.cpp.
QgsMapLayer * QgsMapLayerComboBox::layer | ( | int | layerIndex | ) | const |
Returns the layer currently shown at the specified index within the combo box.
layerIndex | position of layer to return |
Definition at line 127 of file qgsmaplayercombobox.cpp.
|
signal |
Emitted whenever the currently selected layer changes.
|
overrideprotected |
Definition at line 245 of file qgsmaplayercombobox.cpp.
|
protectedslot |
Definition at line 156 of file qgsmaplayercombobox.cpp.
void QgsMapLayerComboBox::setAdditionalItems | ( | const QStringList & | items | ) |
Sets a list of additional (non map layer) items to include at the end of the combobox.
These may represent additional layers such as layers which are not included in the project, or paths to layers which have not yet been loaded into QGIS.
Definition at line 75 of file qgsmaplayercombobox.cpp.
void QgsMapLayerComboBox::setAdditionalLayers | ( | const QList< QgsMapLayer * > & | layers | ) |
Sets a list of additional layers to include in the combobox.
This method allows adding additional layers, which are not part of a project's layers, into the combobox.
Definition at line 85 of file qgsmaplayercombobox.cpp.
void QgsMapLayerComboBox::setAllowEmptyLayer | ( | bool | allowEmpty, |
const QString & | text = QString() , |
||
const QIcon & | icon = QIcon() |
||
) |
Sets whether an optional empty layer ("not set") option is shown in the combo box.
Since QGIS 3.20, the optional text and icon arguments allows the text and icon for the empty layer item to be set.
Definition at line 55 of file qgsmaplayercombobox.cpp.
|
inline |
Sets a list of layers which should be excluded from the combo box.
Definition at line 98 of file qgsmaplayercombobox.h.
void QgsMapLayerComboBox::setExcludedProviders | ( | const QStringList & | providers | ) |
Sets a list of data providers which should be excluded from the combobox.
Definition at line 39 of file qgsmaplayercombobox.cpp.
|
inline |
Filters according to layer type and/or geometry type.
Definition at line 84 of file qgsmaplayercombobox.h.
|
inline |
Sets filters for the layers displayed in the combo box.
This method allows filtering layers according to layer type and/or geometry type.
Definition at line 76 of file qgsmaplayercombobox.h.
|
slot |
Sets the current layer selected in the combo box.
Definition at line 95 of file qgsmaplayercombobox.cpp.
void QgsMapLayerComboBox::setProject | ( | QgsProject * | project | ) |
Sets the project from which map layers are shown.
If project is nullptr
then QgsProject::instance() will be used.
Definition at line 44 of file qgsmaplayercombobox.cpp.
void QgsMapLayerComboBox::setShowCrs | ( | bool | showCrs | ) |
Sets whether the CRS of layers is also included in the combo box text.
Definition at line 65 of file qgsmaplayercombobox.cpp.
bool QgsMapLayerComboBox::showCrs | ( | ) | const |
Returns true
if the combo box shows the layer's CRS.
Definition at line 70 of file qgsmaplayercombobox.cpp.
|
friend |
Definition at line 234 of file qgsmaplayercombobox.h.
|
readwrite |
Definition at line 57 of file qgsmaplayercombobox.h.
|
readwrite |
Definition at line 59 of file qgsmaplayercombobox.h.
|
readwrite |
Definition at line 56 of file qgsmaplayercombobox.h.
|
readwrite |
Definition at line 58 of file qgsmaplayercombobox.h.