Skip to content
Permalink
Browse files

Browser: correct drag&drop for canvas and browser itself

  • Loading branch information
wonder-sk committed Aug 12, 2011
1 parent f680e2f commit 173c72db48f89eb91a244ff6036b925a608b6ad9
Showing with 45 additions and 5 deletions.
  1. +34 −5 src/app/qgsbrowserdockwidget.cpp
  2. +8 −0 src/gui/qgsmapcanvas.cpp
  3. +3 −0 src/gui/qgsmapcanvas.h
@@ -11,16 +11,45 @@
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"

#include <QDragEnterEvent>
/**
Utility class for correct drag&drop handling.
We want to allow user to drag layers to qgis window. At the same time we do not
accept drops of the items on our view - but if we ignore the drag enter action
then qgis application consumes the drag events and it is possible to drop the
items on the tree view although the drop is actually managed by qgis app.
*/
class QgsBrowserTreeView : public QTreeView
{
public:
QgsBrowserTreeView( QWidget* parent ) : QTreeView(parent)
{
setDragDropMode( QTreeView::DragDrop ); // sets also acceptDrops + dragEnabled
setSelectionMode( QAbstractItemView::ExtendedSelection );
setContextMenuPolicy( Qt::CustomContextMenu );
}

void dragEnterEvent(QDragEnterEvent* e)
{
// accept drag enter so that our widget will not get ignored
// and drag events will not get passed to QgisApp
e->accept();
}
void dragMoveEvent(QDragMoveEvent* e)
{
// ignore all possibilities where an item could be dropped
// because we want that user drops the item on canvas / legend / app
e->ignore();
}
};

QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
QDockWidget( parent ), mModel( NULL )
{
setWindowTitle( tr( "Browser" ) );

mBrowserView = new QTreeView( this );
mBrowserView->setDragEnabled( true );
mBrowserView->setDragDropMode( QTreeView::DragOnly );
mBrowserView->setSelectionMode( QAbstractItemView::ExtendedSelection );
mBrowserView->setContextMenuPolicy( Qt::CustomContextMenu );
mBrowserView = new QgsBrowserTreeView( this );
setWidget( mBrowserView );

connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
@@ -1499,3 +1499,11 @@ void QgsMapCanvas::selectionChangedSlot()
emit selectionChanged( layer );
refresh();
}

void QgsMapCanvas::dragEnterEvent( QDragEnterEvent * e )
{
// By default graphics view delegates the drag events to graphics items.
// But we do not want that and by ignoring the drag enter we let the
// parent (e.g. QgisApp) to handle drops of map layers etc.
e->ignore();
}
@@ -376,6 +376,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Overridden paint event
void paintEvent( QPaintEvent * e );

//! Overridden drag enter event
void dragEnterEvent( QDragEnterEvent * e );

//! called when panning is in action, reset indicates end of panning
void moveCanvasContents( bool reset = false );

0 comments on commit 173c72d

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