Skip to content
Permalink
Browse files

Allow QgsDataItems to override default double click behavior

  • Loading branch information
nyalldawson committed Sep 20, 2017
1 parent fcf2fca commit 8bce7a62a790b50261d8a878e41b8d77e527ed11
@@ -153,6 +153,15 @@ Create new data item.
:rtype: bool
%End

virtual bool handleDoubleClick();
%Docstring
Called when a user double clicks on the item. Subclasses should return true
if they have implemented a double click handler and do not want the default
double click behaviour for items.
.. versionadded:: 3.0
:rtype: bool
%End

virtual bool hasDragEnabled() const;
%Docstring
Returns true if the item may be dragged.
@@ -510,6 +510,11 @@ bool QgsDataItem::equal( const QgsDataItem *other )
mPath == other->path() );
}

bool QgsDataItem::handleDoubleClick()
{
return false;
}

QgsDataItem::State QgsDataItem::state() const
{
return mState;
@@ -155,6 +155,14 @@ class CORE_EXPORT QgsDataItem : public QObject
*/
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }

/**
* Called when a user double clicks on the item. Subclasses should return true
* if they have implemented a double click handler and do not want the default
* double click behaviour for items.
* \since QGIS 3.0
*/
virtual bool handleDoubleClick();

/** Returns true if the item may be dragged.
* Default implementation returns false.
* A draggable item has to implement mimeUri() that will be used to pass data.
@@ -97,7 +97,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserModel
connect( mLeFilter, &QgsFilterLineEdit::textChanged, this, &QgsBrowserDockWidget::setFilter );
connect( group, &QActionGroup::triggered, this, &QgsBrowserDockWidget::setFilterSyntax );
connect( mBrowserView, &QgsDockBrowserTreeView::customContextMenuRequested, this, &QgsBrowserDockWidget::showContextMenu );
connect( mBrowserView, &QgsDockBrowserTreeView::doubleClicked, this, &QgsBrowserDockWidget::addLayerAtIndex );
connect( mBrowserView, &QgsDockBrowserTreeView::doubleClicked, this, &QgsBrowserDockWidget::itemDoubleClicked );
connect( mSplitter, &QSplitter::splitterMoved, this, &QgsBrowserDockWidget::splitterMoved );
}

@@ -155,6 +155,18 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
QgsDockWidget::showEvent( e );
}

void QgsBrowserDockWidget::itemDoubleClicked( const QModelIndex &index )
{
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
if ( !item )
return;

if ( item->handleDoubleClick() )
return;
else
addLayerAtIndex( index ); // default double click handler
}

void QgsBrowserDockWidget::showContextMenu( QPoint pt )
{
QModelIndex index = mProxyModel->mapToSource( mBrowserView->indexAt( pt ) );
@@ -110,6 +110,9 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
//! Show event override
void showEvent( QShowEvent *event ) override;

private slots:
void itemDoubleClicked( const QModelIndex &index );

private:
//! Refresh the model
void refreshModel( const QModelIndex &index );

0 comments on commit 8bce7a6

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