force copy action when dragging layer to browser

This commit is contained in:
Radim Blazek 2017-06-21 15:07:14 +02:00
parent 2fb0b16364
commit c1d4862840
2 changed files with 17 additions and 14 deletions

View File

@ -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
//

View File

@ -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 );
};
/**