Skip to content

Commit

Permalink
force copy action when dragging layer to browser
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 21, 2017
1 parent 2fb0b16 commit c1d4862
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/gui/qgsbrowserdockwidget_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" ) ) )
{
Expand All @@ -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
//
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsbrowserdockwidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};

/**
Expand Down

0 comments on commit c1d4862

Please sign in to comment.