Skip to content
Permalink
Browse files

force copy action when dragging layer to browser

  • Loading branch information
blazek committed Jun 21, 2017
1 parent 2fb0b16 commit c1d48628404bd41618458b8aeac4f1183e85acfa
Showing with 17 additions and 14 deletions.
  1. +14 −14 src/gui/qgsbrowserdockwidget_p.cpp
  2. +3 −0 src/gui/qgsbrowserdockwidget_p.h
@@ -280,13 +280,20 @@ QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) : QgsBrowserTr

}

void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
void QgsDockBrowserTreeView::setAction( QDropEvent *e )
{
// if this mime data come from layer tree, the proposed action will be MoveAction
// but for browser we really need CopyAction
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
{
e->setDropAction( Qt::CopyAction );
}
}

void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
{
setAction( e );

// accept drag enter so that our widget will not get ignored
// and drag events will not get passed to QgisApp
@@ -303,13 +310,10 @@ void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
return;
}*/

// if this mime data come from layer tree, the proposed action will be MoveAction
// but for browser we really need CopyAction
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
e->setDropAction( Qt::CopyAction );

setAction( e );
QTreeView::dragMoveEvent( e );
// reset action because QTreeView::dragMoveEvent() accepts proposed action
setAction( e );

if ( !e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
{
@@ -320,16 +324,12 @@ void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )

void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
{
// if this mime data come from layer tree, the proposed action will be MoveAction
// but for browser we really need CopyAction
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
e->setDropAction( Qt::CopyAction );

setAction( e );
QTreeView::dropEvent( e );
// reset action because QTreeView::dropEvent() accepts proposed action
setAction( e );
}


//
// QgsBrowserTreeFilterProxyModel
//
@@ -195,6 +195,9 @@ class QgsDockBrowserTreeView : public QgsBrowserTreeView
void dragMoveEvent( QDragMoveEvent *e ) override;
//! Overrides drag stop event
void dropEvent( QDropEvent *e ) override;

private:
void setAction( QDropEvent *e );
};

/**

0 comments on commit c1d4862

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