QGIS API Documentation 3.43.0-Master (e737cc10456)
qgsmaplayercombobox.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayercombobox.h
3 --------------------------------------
4 Date : 01.04.2014
5 Copyright : (C) 2014 Denis Rouzaud
6 Email : denis.rouzaud@gmail.com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
16#ifndef QGSMAPLAYERCOMBOBOX_H
17#define QGSMAPLAYERCOMBOBOX_H
18
19#include <QComboBox>
20
22#include "qgis_gui.h"
23
24#include "qgis_sip.h"
25
26class QgsMapLayer;
27class QgsVectorLayer;
28
53class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
54{
55 Q_OBJECT
56 Q_PROPERTY( Qgis::LayerFilters filters READ filters WRITE setFilters )
57 Q_PROPERTY( bool allowEmptyLayer READ allowEmptyLayer WRITE setAllowEmptyLayer )
58 Q_PROPERTY( bool showCrs READ showCrs WRITE setShowCrs )
59 Q_PROPERTY( QStringList excludedProviders READ excludedProviders WRITE setExcludedProviders )
60
61 public:
67 explicit QgsMapLayerComboBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
68
76 void setFilters( Qgis::LayerFilters filters ) { mProxyModel->setFilters( filters ); }
77
84 Q_DECL_DEPRECATED void setFilters( int filters ) SIP_DEPRECATED { setFilters( static_cast<Qgis::LayerFilters>( filters ) ); }
85
91 Qgis::LayerFilters filters() const { return mProxyModel->filters(); }
92
98 void setExceptedLayerList( const QList<QgsMapLayer *> &layerList ) { mProxyModel->setExceptedLayerList( layerList ); }
99
105 QList<QgsMapLayer *> exceptedLayerList() const { return mProxyModel->exceptedLayerList(); }
106
111 void setExcludedProviders( const QStringList &providers );
112
117 QStringList excludedProviders() const;
118
126 void setProject( QgsProject *project );
127
128
136 void setAllowEmptyLayer( bool allowEmpty, const QString &text = QString(), const QIcon &icon = QIcon() );
137
142 bool allowEmptyLayer() const;
143
148 void setShowCrs( bool showCrs );
149
154 bool showCrs() const;
155
162 void setAdditionalItems( const QStringList &items );
163
168 QStringList additionalItems() const;
169
179 void setAdditionalLayers( const QList<QgsMapLayer *> &layers );
180
187 QList<QgsMapLayer *> additionalLayers() const;
188
193 QgsMapLayer *currentLayer() const;
194
200 QgsMapLayer *layer( int layerIndex ) const;
201
202 public slots:
203
207 void setLayer( QgsMapLayer *layer );
208
209 signals:
211 void layerChanged( QgsMapLayer *layer );
212
213 protected:
214 void dragEnterEvent( QDragEnterEvent *event ) override;
215 void dragLeaveEvent( QDragLeaveEvent *event ) override;
216 void dropEvent( QDropEvent *event ) override;
217 void paintEvent( QPaintEvent *e ) override;
218
219 protected slots:
220 void indexChanged( int i );
221 void rowsChanged();
222
223 private:
224 QgsMapLayerProxyModel *mProxyModel = nullptr;
225 bool mDragActive = false;
226 bool mHighlight = false;
227
232 QgsMapLayer *compatibleMapLayerFromMimeData( const QMimeData *data ) const;
233
234 friend class QgsProcessingMapLayerComboBox;
235};
236
237#endif // QGSMAPLAYERCOMBOBOX_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
QFlags< LayerFilter > LayerFilters
Definition qgis.h:206
A combobox which displays a dynamic list of layers from a QGIS project.
void setFilters(Qgis::LayerFilters filters)
Sets filters for the layers displayed in the combo box.
QList< QgsMapLayer * > exceptedLayerList() const
Returns a list of layers which should be excluded from the combo box.
void setExceptedLayerList(const QList< QgsMapLayer * > &layerList)
Sets a list of layers which should be excluded from the combo box.
Q_DECL_DEPRECATED void setFilters(int filters)
Filters according to layer type and/or geometry type.
Qgis::LayerFilters filters() const
Returns any currently used filters on the listed layers.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
A proxy model which provides an easy to use model to display the list of layers in widgets.
Base class for all map layer types.
Definition qgsmaplayer.h:77
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53