Class: QgsCustomDropHandler¶
-
class
qgis.gui.
QgsCustomDropHandler
¶ Bases:
PyQt5.QtCore.QObject
Abstract base class that may be implemented to handle new types of data to be dropped in QGIS.
Implementations have three approaches they can use to handle drops.
1. The simplest approach is to implement handeFileDrop() when they need to handle dropped files (i.e. with mime type “text/uri-list”).
2. Reimplement handleCustomUriDrop() when they want to handle dropped custom QgsMimeDataUtils.Uri entries, for instance handling dropping custom entries from the browser tree (with mime type “application/x-vnd.qgis.qgis.uri”). In this case the implementation’s customUriProviderKey() must match the uri entry’s providerKey.
3. Reimplement handleMimeData() to directly handle dropped QMimeData. Subclasses should take care when overriding this method. When a drop event occurs, Qt will lock the source application of the drag for the duration of the drop event handling via handleMimeData() (e.g. dragging files from explorer to QGIS will lock the explorer window until the drop handling has been complete). Accordingly handleMimeData() implementations must return quickly and defer any intensive or slow processing.
Methods
Returns
True
if the handler is capable of handling the provided mimeuri
when dropped onto a mapcanvas
.Returns
True
if the handler is capable of handling the provided mimedata
.Type of custom URI recognized by the handler.
Called from QGIS after a drop event with custom
uri
known by the handler occurs onto a mapcanvas
.Called from QGIS after a drop event with custom URI known by the handler.
Called when the specified
file
has been dropped onto QGIS.Called when the specified mime
data
has been dropped onto QGIS.Called when the specified mime
data
has been dropped onto QGIS.-
canHandleCustomUriCanvasDrop
(self, uri: QgsMimeDataUtils.Uri, canvas: QgsMapCanvas) → bool¶ Returns
True
if the handler is capable of handling the provided mimeuri
when dropped onto a mapcanvas
.The base class implementation returns
False
regardless of mime data.This method is called when mime data is dragged over a map canvas, in order to determine whether any handlers are capable of handling the data and to determine whether the drag action should be accepted.
Warning
Subclasses should be very careful about implementing this. If they incorrectly return
True
to auri
, it will prevent the default application drop handling from occurring and will break the ability to drag and drop layers and files onto QGIS.New in version 3.10.
- Parameters
uri (QgsMimeDataUtils.Uri) –
canvas (QgsMapCanvas) –
- Return type
bool
-
canHandleMimeData
(self, data: QMimeData) → bool¶ Returns
True
if the handler is capable of handling the provided mimedata
. The base class implementation returnsFalse
regardless of mime data.This method is called when mime data is dragged over the QGIS window, in order to determine whether any handlers are capable of handling the data and to determine whether the drag action should be accepted.
New in version 3.10.
- Parameters
data (QMimeData) –
- Return type
bool
-
childEvent
(self, QChildEvent)¶
-
connectNotify
(self, QMetaMethod)¶
-
customEvent
(self, QEvent)¶
-
customUriProviderKey
(self) → str¶ Type of custom URI recognized by the handler. This must match the URI entry’s providerKey in order for handleCustomUriDrop() to be called.
See also
- Return type
str
-
disconnectNotify
(self, QMetaMethod)¶
-
handleCustomUriCanvasDrop
(self, uri: QgsMimeDataUtils.Uri, canvas: QgsMapCanvas) → bool¶ Called from QGIS after a drop event with custom
uri
known by the handler occurs onto a mapcanvas
.In order for handleCustomUriCanvasDrop() to be called, subclasses must also implement customUriProviderKey() to indicate the providerKey value which the handler accepts.
If the function returns
True
, it means the handler has accepted the drop and it should not be further processed (e.g. by otherQgsCustomDropHandlers
).Subclasses which implement this must also implement corresponding versions of canHandleCustomUriCanvasDrop().
See also
See also
New in version 3.10.
- Parameters
uri (QgsMimeDataUtils.Uri) –
canvas (QgsMapCanvas) –
- Return type
bool
-
handleCustomUriDrop
(self, uri: QgsMimeDataUtils.Uri)¶ Called from QGIS after a drop event with custom URI known by the handler.
In order for handleCustomUriDrop() to be called, subclasses must also implement customUriProviderKey() to indicate the providerKey value which the handler accepts.
See also
- Parameters
uri (QgsMimeDataUtils.Uri) –
-
handleFileDrop
(self, file: str) → bool¶ Called when the specified
file
has been dropped onto QGIS. IfTrue
is returned, then the handler has accepted this file and it should not be further processed (e.g. by otherQgsCustomDropHandlers
).The base class implementation does nothing.
This method is not called directly while drop handling is occurring, so the limitations described in handleMimeData() about returning quickly do not apply.
- Parameters
file (str) –
- Return type
bool
-
handleMimeData
(self, data: QMimeData)¶ Called when the specified mime
data
has been dropped onto QGIS.The base class implementation does nothing.
Subclasses should take care when overriding this method. When a drop event occurs, Qt will lock the source application of the drag for the duration of the drop event handling (e.g. dragging files from explorer to QGIS will lock the explorer window until the drop handling has been complete).
Accordingly, only implementations must be lightweight and return ASAP. (For instance by copying the relevant parts of
data
and then handling the data after a short timeout).Deprecated since version QGIS: 3.10 - use handleMimeDataV2() instead.
- Parameters
data (QMimeData) –
-
handleMimeDataV2
(self, data: QMimeData) → bool¶ Called when the specified mime
data
has been dropped onto QGIS.The base class implementation does nothing.
Subclasses should take care when overriding this method. When a drop event occurs, Qt will lock the source application of the drag for the duration of the drop event handling (e.g. dragging files from explorer to QGIS will lock the explorer window until the drop handling has been complete).
Accordingly, only implementations must be lightweight and return ASAP. (For instance by copying the relevant parts of
data
and then handling the data after a short timeout).If the function returns
True
, it means the handler has accepted the drop and it should not be further processed (e.g. by otherQgsCustomDropHandlers
)New in version 3.10.
- Parameters
data (QMimeData) –
- Return type
bool
-
isSignalConnected
(self, QMetaMethod) → bool¶
-
receivers
(self, PYQT_SIGNAL) → int¶
-
sender
(self) → QObject¶
-
senderSignalIndex
(self) → int¶
-
timerEvent
(self, QTimerEvent)¶
-