Skip to content

Commit c1d4862

Browse files
committed
force copy action when dragging layer to browser
1 parent 2fb0b16 commit c1d4862

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/gui/qgsbrowserdockwidget_p.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,20 @@ QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) : QgsBrowserTr
280280

281281
}
282282

283-
void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
283+
void QgsDockBrowserTreeView::setAction( QDropEvent *e )
284284
{
285285
// if this mime data come from layer tree, the proposed action will be MoveAction
286286
// but for browser we really need CopyAction
287287
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
288288
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
289+
{
289290
e->setDropAction( Qt::CopyAction );
291+
}
292+
}
293+
294+
void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
295+
{
296+
setAction( e );
290297

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

306-
// if this mime data come from layer tree, the proposed action will be MoveAction
307-
// but for browser we really need CopyAction
308-
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
309-
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
310-
e->setDropAction( Qt::CopyAction );
311-
313+
setAction( e );
312314
QTreeView::dragMoveEvent( e );
315+
// reset action because QTreeView::dragMoveEvent() accepts proposed action
316+
setAction( e );
313317

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

321325
void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
322326
{
323-
// if this mime data come from layer tree, the proposed action will be MoveAction
324-
// but for browser we really need CopyAction
325-
if ( e->mimeData()->hasFormat( QStringLiteral( "application/qgis.layertreemodeldata" ) ) &&
326-
e->mimeData()->hasFormat( QStringLiteral( "application/x-vnd.qgis.qgis.uri" ) ) )
327-
e->setDropAction( Qt::CopyAction );
328-
327+
setAction( e );
329328
QTreeView::dropEvent( e );
329+
// reset action because QTreeView::dropEvent() accepts proposed action
330+
setAction( e );
330331
}
331332

332-
333333
//
334334
// QgsBrowserTreeFilterProxyModel
335335
//

src/gui/qgsbrowserdockwidget_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class QgsDockBrowserTreeView : public QgsBrowserTreeView
195195
void dragMoveEvent( QDragMoveEvent *e ) override;
196196
//! Overrides drag stop event
197197
void dropEvent( QDropEvent *e ) override;
198+
199+
private:
200+
void setAction( QDropEvent *e );
198201
};
199202

200203
/**

0 commit comments

Comments
 (0)