19 #include <QDragEnterEvent> 26 setModel( mProxyModel );
32 setAcceptDrops(
true );
82 setCurrentIndex( -1 );
90 QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
91 if ( proxyIdx.isValid() )
93 setCurrentIndex( proxyIdx.row() );
98 setCurrentIndex( -1 );
104 return layer( currentIndex() );
109 const QModelIndex proxyIndex = mProxyModel->index( layerIndex, 0 );
110 if ( !proxyIndex.isValid() )
115 const QModelIndex index = mProxyModel->mapToSource( proxyIndex );
116 if ( !index.isValid() )
143 else if ( count() == 0 )
149 QgsMapLayer *QgsMapLayerComboBox::compatibleMapLayerFromMimeData(
const QMimeData *data )
const 166 if ( !( event->possibleActions() & Qt::CopyAction ) )
172 if ( compatibleMapLayerFromMimeData( event->mimeData() ) )
175 event->setDropAction( Qt::CopyAction );
202 if ( !( event->possibleActions() & Qt::CopyAction ) )
208 if (
QgsMapLayer *
layer = compatibleMapLayerFromMimeData( event->mimeData() ) )
211 setFocus( Qt::MouseFocusReason );
212 event->setDropAction( Qt::CopyAction );
227 QComboBox::paintEvent( e );
228 if ( mDragActive || mHighlight )
232 p.setPen( QPen( palette().highlight(), width ) );
233 QRect r = rect().adjusted( width, width, -width, -width );
QStringList excludedProviders() const
Returns the list of data providers which are excluded from the combobox.
QModelIndex indexFromLayer(QgsMapLayer *layer) const
indexFromLayer returns the model index for a given layer
Base class for all map layer types.
QStringList additionalItems
bool allowEmptyLayer() const
Returns true if the combo box allows the empty layer ("not set") choice.
void setExcludedProviders(const QStringList &providers)
Sets a list of data providers which should be excluded from the combobox.
static UriList decodeUriList(const QMimeData *data)
void dragEnterEvent(QDragEnterEvent *event) override
QStringList excludedProviders() const
Returns the blacklist of data providers which are excluded from the model.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
void setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the combobox.
bool acceptsLayer(QgsMapLayer *layer) const
Returns true if the proxy model accepts the specified map layer.
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the model's display role.
QStringList additionalItems() const
Returns the list of additional (non map layer) items included at the end of the combo box...
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
void setAllowEmptyLayer(bool allowEmpty)
Sets whether an optional empty layer ("not set") option is present in the model.
QgsMapLayerComboBox(QWidget *parent=nullptr)
QgsMapLayerComboBox creates a combo box to display the list of layers (currently in the registry)...
void setAllowEmptyLayer(bool allowEmpty)
Sets whether an optional empty layer ("not set") option is shown in the combo box.
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the combo box text.
void paintEvent(QPaintEvent *e) override
void setLayer(QgsMapLayer *layer)
setLayer set the current layer selected in the combo
bool showCrs() const
Returns true if the combo box shows the layer's CRS.
void setExcludedProviders(const QStringList &providers)
Sets a blacklist of data providers which should be excluded from the model.
QList< QgsMimeDataUtils::Uri > UriList
void setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the model.
void dragLeaveEvent(QDragLeaveEvent *event) override
void dropEvent(QDropEvent *event) override
QgsMapLayer * layer(int layerIndex) const
Returns the layer currently shown at the specified index within the combo box.
QgsMapLayer * currentLayer() const
Returns the current layer selected in the combo box.