Skip to content

Commit

Permalink
[browser] Avoid expanding/collapsing nodes if the double click
Browse files Browse the repository at this point in the history
was specifically handled by an item itself
  • Loading branch information
nyalldawson committed Nov 1, 2018
1 parent 5c5f2ed commit 850eae1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 7 additions & 2 deletions python/gui/auto_generated/qgsbrowserdockwidget.sip.in
Expand Up @@ -37,10 +37,15 @@ Add directory to favorites
%End

public slots:
void addLayerAtIndex( const QModelIndex &index );

bool addLayerAtIndex( const QModelIndex &index );
%Docstring
Add layer at index
Adds the layer corresponding to the specified model ``index``.

Returns true if the index was successfully intrepreted as a map layer and loaded, or
false if the index is not a map layer or could not be loaded.
%End

void showContextMenu( QPoint );
%Docstring
Show context menu
Expand Down
19 changes: 16 additions & 3 deletions src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -91,6 +91,8 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserModel
action->setCheckable( true );
menu->addAction( action );

mBrowserView->setExpandsOnDoubleClick( false );

connect( mActionRefresh, &QAction::triggered, this, &QgsBrowserDockWidget::refresh );
connect( mActionAddLayers, &QAction::triggered, this, &QgsBrowserDockWidget::addSelectedLayers );
connect( mActionCollapse, &QAction::triggered, mBrowserView, &QgsDockBrowserTreeView::collapseAll );
Expand Down Expand Up @@ -169,8 +171,16 @@ void QgsBrowserDockWidget::itemDoubleClicked( const QModelIndex &index )

if ( item->handleDoubleClick() )
return;
else if ( addLayerAtIndex( index ) ) // default double-click handler
return;
else
addLayerAtIndex( index ); // default double-click handler
{
// double click not handled by browser model, so use as default view expand behavior
if ( mBrowserView->isExpanded( index ) )
mBrowserView->collapse( index );
else
mBrowserView->expand( index );
}
}

void QgsBrowserDockWidget::renameFavorite()
Expand Down Expand Up @@ -416,7 +426,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
emit handleDropUriList( list );
}

void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
{
QgsDebugMsg( QStringLiteral( "rowCount() = %1" ).arg( mModel->rowCount( mProxyModel->mapToSource( index ) ) ) );
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
Expand All @@ -430,8 +440,9 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
emit openFile( projectItem->path(), QStringLiteral( "project" ) );
QApplication::restoreOverrideCursor();
}
return true;
}
if ( item && item->type() == QgsDataItem::Layer )
else if ( item && item->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
if ( layerItem )
Expand All @@ -440,7 +451,9 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
addLayer( layerItem );
QApplication::restoreOverrideCursor();
}
return true;
}
return false;
}

void QgsBrowserDockWidget::addSelectedLayers()
Expand Down
11 changes: 9 additions & 2 deletions src/gui/qgsbrowserdockwidget.h
Expand Up @@ -56,8 +56,15 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );

public slots:
//! Add layer at index
void addLayerAtIndex( const QModelIndex &index );

/**
* Adds the layer corresponding to the specified model \a index.
*
* Returns true if the index was successfully intrepreted as a map layer and loaded, or
* false if the index is not a map layer or could not be loaded.
*/
bool addLayerAtIndex( const QModelIndex &index );

//! Show context menu
void showContextMenu( QPoint );

Expand Down

0 comments on commit 850eae1

Please sign in to comment.