19#include <QDragEnterEvent>
27 setModel( mProxyModel );
33 setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
35 setAcceptDrops(
true );
101 setCurrentIndex( -1 );
109 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
110 if ( proxyIdx.isValid() )
112 setCurrentIndex( proxyIdx.row() );
117 setCurrentIndex( -1 );
123 return layer( currentIndex() );
128 const QModelIndex proxyIndex = mProxyModel->index( layerIndex, 0 );
129 if ( !proxyIndex.isValid() )
134 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
135 if ( !index.isValid() )
162 else if ( count() == 0 )
168QgsMapLayer *QgsMapLayerComboBox::compatibleMapLayerFromMimeData(
const QMimeData *data )
const
185 if ( !( event->possibleActions() & Qt::CopyAction ) )
191 if ( compatibleMapLayerFromMimeData( event->mimeData() ) )
194 event->setDropAction( Qt::CopyAction );
221 if ( !( event->possibleActions() & Qt::CopyAction ) )
227 if (
QgsMapLayer *
layer = compatibleMapLayerFromMimeData( event->mimeData() ) )
230 setFocus( Qt::MouseFocusReason );
231 event->setDropAction( Qt::CopyAction );
246 QComboBox::paintEvent( e );
247 if ( mDragActive || mHighlight )
251 p.setPen( QPen( palette().highlight(), width ) );
252 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 registry).
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.
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the model's display role.
QModelIndex indexFromLayer(QgsMapLayer *layer) const
indexFromLayer returns the model index for a given layer
void setAllowEmptyLayer(bool allowEmpty, const QString &text=QString(), const QIcon &icon=QIcon())
Sets whether an optional empty layer ("not set") option is present in the model.
void setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the model.
QList< QgsMapLayer * > additionalLayers() const
Returns the list of additional layers added to the model.
QStringList additionalItems
void setAdditionalLayers(const QList< QgsMapLayer * > &layers)
Sets a list of additional layers to include in the model.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
bool acceptsLayer(QgsMapLayer *layer) const
Returns true if the proxy model accepts the specified map layer.
void setExcludedProviders(const QStringList &providers)
Sets a blocklist of data providers which should be excluded from the model.
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
void setProject(QgsProject *project)
Sets the project from which map layers are shown.
QStringList excludedProviders() const
Returns the blocklist of data providers which are excluded from the model.
Base class for all map layer types.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
QList< QgsMimeDataUtils::Uri > UriList
static UriList decodeUriList(const QMimeData *data)
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...