Skip to content

Commit

Permalink
Make QgsCustomDropHandler a QObject, and only store weak pointers to …
Browse files Browse the repository at this point in the history
…them

This means if a plugin registers a custom drop handler, but crashes
before it can deregister it, at least it won't leave the main
app in a crashy state.
  • Loading branch information
nyalldawson committed Sep 15, 2017
1 parent 527bce0 commit 0df4f4a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgscustomdrophandler.sip
Expand Up @@ -8,7 +8,7 @@






class QgsCustomDropHandler class QgsCustomDropHandler : QObject
{ {
%Docstring %Docstring
Abstract base class that may be implemented to handle new types of data to be dropped in QGIS. Abstract base class that may be implemented to handle new types of data to be dropped in QGIS.
Expand Down
11 changes: 6 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -1334,10 +1334,11 @@ void QgisApp::dropEvent( QDropEvent *event )
timer->setInterval( 50 ); timer->setInterval( 50 );


// first, allow custom handlers to directly operate on the mime data // first, allow custom handlers to directly operate on the mime data
const QList<QgsCustomDropHandler *> handlers = mCustomDropHandlers; const QList<QPointer<QgsCustomDropHandler >> handlers = mCustomDropHandlers;
for ( QgsCustomDropHandler *handler : handlers ) for ( QgsCustomDropHandler *handler : handlers )
{ {
handler->handleMimeData( event->mimeData() ); if ( handler )
handler->handleMimeData( event->mimeData() );
} }


// get the file list // get the file list
Expand Down Expand Up @@ -1415,10 +1416,10 @@ void QgisApp::dropEvent( QDropEvent *event )
bool handled = false; bool handled = false;


// give custom drop handlers first priority at handling the file // give custom drop handlers first priority at handling the file
const QList<QgsCustomDropHandler *> handlers = mCustomDropHandlers; const QList<QPointer<QgsCustomDropHandler >>handlers = mCustomDropHandlers;
for ( QgsCustomDropHandler *handler : handlers ) for ( QgsCustomDropHandler *handler : handlers )
{ {
if ( handler->handleFileDrop( file ) ) if ( handler && handler->handleFileDrop( file ) )
{ {
handled = true; handled = true;
break; break;
Expand Down Expand Up @@ -1490,7 +1491,7 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
{ {
Q_FOREACH ( QgsCustomDropHandler *handler, mCustomDropHandlers ) Q_FOREACH ( QgsCustomDropHandler *handler, mCustomDropHandlers )
{ {
if ( handler->key() == u.providerKey ) if ( handler && handler->key() == u.providerKey )
{ {
handler->handleDrop( u ); handler->handleDrop( u );
break; break;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -2048,7 +2048,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QList<QgsMapLayerConfigWidgetFactory *> mMapLayerPanelFactories; QList<QgsMapLayerConfigWidgetFactory *> mMapLayerPanelFactories;
QList<QPointer<QgsOptionsWidgetFactory>> mOptionsWidgetFactories; QList<QPointer<QgsOptionsWidgetFactory>> mOptionsWidgetFactories;


QList<QgsCustomDropHandler *> mCustomDropHandlers; QList<QPointer<QgsCustomDropHandler>> mCustomDropHandlers;


QDateTime mProjectLastModified; QDateTime mProjectLastModified;


Expand Down
2 changes: 1 addition & 1 deletion src/gui/CMakeLists.txt
Expand Up @@ -385,6 +385,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsconfigureshortcutsdialog.h qgsconfigureshortcutsdialog.h
qgscredentialdialog.h qgscredentialdialog.h
qgscurveeditorwidget.h qgscurveeditorwidget.h
qgscustomdrophandler.h
qgsdatumtransformdialog.h qgsdatumtransformdialog.h
qgsdetaileditemdelegate.h qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h qgsdetaileditemwidget.h
Expand Down Expand Up @@ -684,7 +685,6 @@ SET(QGIS_GUI_HDRS
qgsattributeforminterface.h qgsattributeforminterface.h
qgsattributeformlegacyinterface.h qgsattributeformlegacyinterface.h
qgscursors.h qgscursors.h
qgscustomdrophandler.h
qgsdetaileditemdata.h qgsdetaileditemdata.h
qgsexpressionbuilderdialog.h qgsexpressionbuilderdialog.h
qgsgeometryrubberband.h qgsgeometryrubberband.h
Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgscustomdrophandler.h
Expand Up @@ -30,8 +30,10 @@
* *
* \since QGIS 3.0 * \since QGIS 3.0
*/ */
class GUI_EXPORT QgsCustomDropHandler class GUI_EXPORT QgsCustomDropHandler : public QObject
{ {
Q_OBJECT

public: public:
virtual ~QgsCustomDropHandler() = default; virtual ~QgsCustomDropHandler() = default;


Expand Down

0 comments on commit 0df4f4a

Please sign in to comment.