QGIS API Documentation  3.23.0-Master (dd0cd13a00)
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 : [email protected]
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 
21 #include "qgsmaplayerproxymodel.h"
22 #include "qgis_gui.h"
23 
24 #include "qgis_sip.h"
25 
26 class QgsMapLayer;
27 class QgsVectorLayer;
28 
34 class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
35 {
36  Q_OBJECT
37  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
38  Q_PROPERTY( bool allowEmptyLayer READ allowEmptyLayer WRITE setAllowEmptyLayer )
39  Q_PROPERTY( bool showCrs READ showCrs WRITE setShowCrs )
40  Q_PROPERTY( QStringList excludedProviders READ excludedProviders WRITE setExcludedProviders )
41 
42  public:
43 
48  explicit QgsMapLayerComboBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
49 
51  void setFilters( QgsMapLayerProxyModel::Filters filters ) { mProxyModel->setFilters( filters ); }
52 
54  QgsMapLayerProxyModel::Filters filters() const { return mProxyModel->filters(); }
55 
57  void setExceptedLayerList( const QList<QgsMapLayer *> &layerList ) { mProxyModel->setExceptedLayerList( layerList );}
58 
60  QList<QgsMapLayer *> exceptedLayerList() const {return mProxyModel->exceptedLayerList();}
61 
67  void setExcludedProviders( const QStringList &providers );
68 
74  QStringList excludedProviders() const;
75 
84  void setAllowEmptyLayer( bool allowEmpty, const QString &text = QString(), const QIcon &icon = QIcon() );
85 
91  bool allowEmptyLayer() const;
92 
98  void setShowCrs( bool showCrs );
99 
105  bool showCrs() const;
106 
114  void setAdditionalItems( const QStringList &items );
115 
121  QStringList additionalItems() const;
122 
132  void setAdditionalLayers( const QList<QgsMapLayer *> &layers );
133 
140  QList< QgsMapLayer * > additionalLayers() const;
141 
146  QgsMapLayer *currentLayer() const;
147 
154  QgsMapLayer *layer( int layerIndex ) const;
155 
156  public slots:
158  void setLayer( QgsMapLayer *layer );
159 
160  signals:
162  void layerChanged( QgsMapLayer *layer );
163 
164  protected:
165 
166  void dragEnterEvent( QDragEnterEvent *event ) override;
167  void dragLeaveEvent( QDragLeaveEvent *event ) override;
168  void dropEvent( QDropEvent *event ) override;
169  void paintEvent( QPaintEvent *e ) override;
170 
171  protected slots:
172  void indexChanged( int i );
173  void rowsChanged();
174 
175  private:
176  QgsMapLayerProxyModel *mProxyModel = nullptr;
177  bool mDragActive = false;
178  bool mHighlight = false;
179 
184  QgsMapLayer *compatibleMapLayerFromMimeData( const QMimeData *data ) const;
185 
186  friend class QgsProcessingMapLayerComboBox;
187 };
188 
189 #endif // QGSMAPLAYERCOMBOBOX_H
The QgsMapLayerComboBox class is a combo box which displays the list of layers.
void setFilters(QgsMapLayerProxyModel::Filters filters)
setFilters allows filtering according to layer type and/or geometry type.
QList< QgsMapLayer * > exceptedLayerList() const
returns the list of excepted layers
void setExceptedLayerList(const QList< QgsMapLayer * > &layerList)
except a list of layers not to be listed
QgsMapLayerProxyModel::Filters filters() const
currently used filter on list layers
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53