Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make QgsCustomDropHandler a QObject, and only store weak pointers to …
…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
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 );

// 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 )
{
handler->handleMimeData( event->mimeData() );
if ( handler )
handler->handleMimeData( event->mimeData() );
}

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

// 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 )
{
if ( handler->handleFileDrop( file ) )
if ( handler && handler->handleFileDrop( file ) )
{
handled = true;
break;
Expand Down Expand Up @@ -1490,7 +1491,7 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
{
Q_FOREACH ( QgsCustomDropHandler *handler, mCustomDropHandlers )
{
if ( handler->key() == u.providerKey )
if ( handler && handler->key() == u.providerKey )
{
handler->handleDrop( u );
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<QPointer<QgsOptionsWidgetFactory>> mOptionsWidgetFactories;

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

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
qgscredentialdialog.h
qgscurveeditorwidget.h
qgscustomdrophandler.h
qgsdatumtransformdialog.h
qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h
Expand Down Expand Up @@ -684,7 +685,6 @@ SET(QGIS_GUI_HDRS
qgsattributeforminterface.h
qgsattributeformlegacyinterface.h
qgscursors.h
qgscustomdrophandler.h
qgsdetaileditemdata.h
qgsexpressionbuilderdialog.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
*/
class GUI_EXPORT QgsCustomDropHandler
class GUI_EXPORT QgsCustomDropHandler : public QObject
{
Q_OBJECT

public:
virtual ~QgsCustomDropHandler() = default;

Expand Down

0 comments on commit 0df4f4a

Please sign in to comment.