|
11 | 11 | #include "qgsrasterlayer.h"
|
12 | 12 | #include "qgsvectorlayer.h"
|
13 | 13 |
|
| 14 | +#include <QDragEnterEvent> |
| 15 | +/** |
| 16 | +Utility class for correct drag&drop handling. |
| 17 | +
|
| 18 | +We want to allow user to drag layers to qgis window. At the same time we do not |
| 19 | +accept drops of the items on our view - but if we ignore the drag enter action |
| 20 | +then qgis application consumes the drag events and it is possible to drop the |
| 21 | +items on the tree view although the drop is actually managed by qgis app. |
| 22 | + */ |
| 23 | +class QgsBrowserTreeView : public QTreeView |
| 24 | +{ |
| 25 | +public: |
| 26 | + QgsBrowserTreeView( QWidget* parent ) : QTreeView(parent) |
| 27 | + { |
| 28 | + setDragDropMode( QTreeView::DragDrop ); // sets also acceptDrops + dragEnabled |
| 29 | + setSelectionMode( QAbstractItemView::ExtendedSelection ); |
| 30 | + setContextMenuPolicy( Qt::CustomContextMenu ); |
| 31 | + } |
| 32 | + |
| 33 | + void dragEnterEvent(QDragEnterEvent* e) |
| 34 | + { |
| 35 | + // accept drag enter so that our widget will not get ignored |
| 36 | + // and drag events will not get passed to QgisApp |
| 37 | + e->accept(); |
| 38 | + } |
| 39 | + void dragMoveEvent(QDragMoveEvent* e) |
| 40 | + { |
| 41 | + // ignore all possibilities where an item could be dropped |
| 42 | + // because we want that user drops the item on canvas / legend / app |
| 43 | + e->ignore(); |
| 44 | + } |
| 45 | +}; |
| 46 | + |
14 | 47 | QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
|
15 | 48 | QDockWidget( parent ), mModel( NULL )
|
16 | 49 | {
|
17 | 50 | setWindowTitle( tr( "Browser" ) );
|
18 | 51 |
|
19 |
| - mBrowserView = new QTreeView( this ); |
20 |
| - mBrowserView->setDragEnabled( true ); |
21 |
| - mBrowserView->setDragDropMode( QTreeView::DragOnly ); |
22 |
| - mBrowserView->setSelectionMode( QAbstractItemView::ExtendedSelection ); |
23 |
| - mBrowserView->setContextMenuPolicy( Qt::CustomContextMenu ); |
| 52 | + mBrowserView = new QgsBrowserTreeView( this ); |
24 | 53 | setWidget( mBrowserView );
|
25 | 54 |
|
26 | 55 | connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
|
|
0 commit comments