Skip to content
Permalink
Browse files

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 0df4f4a9748f5543d6afd49697ac32d6c406c8bd
Showing with 12 additions and 9 deletions.
  1. +1 −1 python/gui/qgscustomdrophandler.sip
  2. +6 −5 src/app/qgisapp.cpp
  3. +1 −1 src/app/qgisapp.h
  4. +1 −1 src/gui/CMakeLists.txt
  5. +3 −1 src/gui/qgscustomdrophandler.h
@@ -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.
@@ -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
@@ -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;
@@ -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;
@@ -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;

@@ -385,6 +385,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsconfigureshortcutsdialog.h
qgscredentialdialog.h
qgscurveeditorwidget.h
qgscustomdrophandler.h
qgsdatumtransformdialog.h
qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h
@@ -684,7 +685,6 @@ SET(QGIS_GUI_HDRS
qgsattributeforminterface.h
qgsattributeformlegacyinterface.h
qgscursors.h
qgscustomdrophandler.h
qgsdetaileditemdata.h
qgsexpressionbuilderdialog.h
qgsgeometryrubberband.h
@@ -30,8 +30,10 @@
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsCustomDropHandler
class GUI_EXPORT QgsCustomDropHandler : public QObject
{
Q_OBJECT

public:
virtual ~QgsCustomDropHandler() = default;

0 comments on commit 0df4f4a

Please sign in to comment.
You can’t perform that action at this time.