mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Allow QgsDataItems to override default double click behavior
This commit is contained in:
parent
fcf2fcae5a
commit
8bce7a62a7
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user