22#include <QDragEnterEvent>
25#include "moc_qgsmaplayercombobox.cpp"
31 setModel( mProxyModel );
37 setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
39 setAcceptDrops(
true );
44 mProxyModel->setExcludedProviders( providers );
49 mProxyModel->setProject( project );
55 return mProxyModel->excludedProviders();
60 mProxyModel->sourceLayerModel()->setAllowEmptyLayer( allowEmpty, text, icon );
65 return mProxyModel->sourceLayerModel()->allowEmptyLayer();
70 mProxyModel->sourceLayerModel()->setShowCrs(
showCrs );
75 return mProxyModel->sourceLayerModel()->showCrs();
80 mProxyModel->sourceLayerModel()->setAdditionalItems( items );
85 return mProxyModel->sourceLayerModel()->additionalItems();
90 mProxyModel->sourceLayerModel()->setAdditionalLayers( layers );
95 return mProxyModel->sourceLayerModel()->additionalLayers();
105 setCurrentIndex( -1 );
110 const QModelIndex idx = mProxyModel->sourceLayerModel()->indexFromLayer(
layer );
113 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
114 if ( proxyIdx.isValid() )
116 setCurrentIndex( proxyIdx.row() );
121 setCurrentIndex( -1 );
127 return layer( currentIndex() );
132 const QModelIndex proxyIndex = mProxyModel->index( layerIndex, 0 );
133 if ( !proxyIndex.isValid() )
138 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
139 if ( !index.isValid() )
166 else if ( count() == 0 )
172QgsMapLayer *QgsMapLayerComboBox::compatibleMapLayerFromMimeData(
const QMimeData *data )
const
189 if ( !( event->possibleActions() & Qt::CopyAction ) )
195 if ( compatibleMapLayerFromMimeData( event->mimeData() ) )
198 event->setDropAction( Qt::CopyAction );
225 if ( !( event->possibleActions() & Qt::CopyAction ) )
231 if (
QgsMapLayer *
layer = compatibleMapLayerFromMimeData( event->mimeData() ) )
234 setFocus( Qt::MouseFocusReason );
235 event->setDropAction( Qt::CopyAction );
250 QComboBox::paintEvent( e );
251 if ( mDragActive || mHighlight )
255 p.setPen( QPen( palette().highlight(), width ) );
256 const QRect r = rect().adjusted( width, width, -width, -width );
void dragLeaveEvent(QDragLeaveEvent *event) override
QStringList additionalItems() const
Returns the list of additional (non map layer) items included at the end of the combo box.
void setAdditionalLayers(const QList< QgsMapLayer * > &layers)
Sets a list of additional layers to include in the combobox.
QgsMapLayerComboBox(QWidget *parent=nullptr)
QgsMapLayerComboBox creates a combo box to display the list of layers currently in the project.
void paintEvent(QPaintEvent *e) override
void setLayer(QgsMapLayer *layer)
Sets the current layer selected in the combo box.
void setProject(QgsProject *project)
Sets the project from which map layers are shown.
QStringList excludedProviders
void setExcludedProviders(const QStringList &providers)
Sets a list of data providers which should be excluded from the combobox.
void dropEvent(QDropEvent *event) override
QgsMapLayer * layer(int layerIndex) const
Returns the layer currently shown at the specified index within the combo box.
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the combo box text.
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 setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the combobox.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
QList< QgsMapLayer * > additionalLayers() const
Returns the list of additional layers added to the combobox.
void dragEnterEvent(QDragEnterEvent *event) override
QgsMapLayer * currentLayer() const
Returns the current layer selected in the combo box.
A proxy model which provides an easy to use model to display the list of layers in widgets.
bool acceptsLayer(QgsMapLayer *layer) const
Returns true if the proxy model accepts the specified map layer.
Base class for all map layer types.
QList< QgsMimeDataUtils::Uri > UriList
static UriList decodeUriList(const QMimeData *data)
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.