Skip to content

Commit 850eae1

Browse files
committedNov 1, 2018
[browser] Avoid expanding/collapsing nodes if the double click
was specifically handled by an item itself
1 parent 5c5f2ed commit 850eae1

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed
 

‎python/gui/auto_generated/qgsbrowserdockwidget.sip.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ Add directory to favorites
3737
%End
3838

3939
public slots:
40-
void addLayerAtIndex( const QModelIndex &index );
40+
41+
bool addLayerAtIndex( const QModelIndex &index );
4142
%Docstring
42-
Add layer at index
43+
Adds the layer corresponding to the specified model ``index``.
44+
45+
Returns true if the index was successfully intrepreted as a map layer and loaded, or
46+
false if the index is not a map layer or could not be loaded.
4347
%End
48+
4449
void showContextMenu( QPoint );
4550
%Docstring
4651
Show context menu

‎src/gui/qgsbrowserdockwidget.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserModel
9191
action->setCheckable( true );
9292
menu->addAction( action );
9393

94+
mBrowserView->setExpandsOnDoubleClick( false );
95+
9496
connect( mActionRefresh, &QAction::triggered, this, &QgsBrowserDockWidget::refresh );
9597
connect( mActionAddLayers, &QAction::triggered, this, &QgsBrowserDockWidget::addSelectedLayers );
9698
connect( mActionCollapse, &QAction::triggered, mBrowserView, &QgsDockBrowserTreeView::collapseAll );
@@ -169,8 +171,16 @@ void QgsBrowserDockWidget::itemDoubleClicked( const QModelIndex &index )
169171

170172
if ( item->handleDoubleClick() )
171173
return;
174+
else if ( addLayerAtIndex( index ) ) // default double-click handler
175+
return;
172176
else
173-
addLayerAtIndex( index ); // default double-click handler
177+
{
178+
// double click not handled by browser model, so use as default view expand behavior
179+
if ( mBrowserView->isExpanded( index ) )
180+
mBrowserView->collapse( index );
181+
else
182+
mBrowserView->expand( index );
183+
}
174184
}
175185

176186
void QgsBrowserDockWidget::renameFavorite()
@@ -416,7 +426,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
416426
emit handleDropUriList( list );
417427
}
418428

419-
void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
429+
bool QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
420430
{
421431
QgsDebugMsg( QStringLiteral( "rowCount() = %1" ).arg( mModel->rowCount( mProxyModel->mapToSource( index ) ) ) );
422432
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );
@@ -430,8 +440,9 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
430440
emit openFile( projectItem->path(), QStringLiteral( "project" ) );
431441
QApplication::restoreOverrideCursor();
432442
}
443+
return true;
433444
}
434-
if ( item && item->type() == QgsDataItem::Layer )
445+
else if ( item && item->type() == QgsDataItem::Layer )
435446
{
436447
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
437448
if ( layerItem )
@@ -440,7 +451,9 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
440451
addLayer( layerItem );
441452
QApplication::restoreOverrideCursor();
442453
}
454+
return true;
443455
}
456+
return false;
444457
}
445458

446459
void QgsBrowserDockWidget::addSelectedLayers()

‎src/gui/qgsbrowserdockwidget.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
5656
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );
5757

5858
public slots:
59-
//! Add layer at index
60-
void addLayerAtIndex( const QModelIndex &index );
59+
60+
/**
61+
* Adds the layer corresponding to the specified model \a index.
62+
*
63+
* Returns true if the index was successfully intrepreted as a map layer and loaded, or
64+
* false if the index is not a map layer or could not be loaded.
65+
*/
66+
bool addLayerAtIndex( const QModelIndex &index );
67+
6168
//! Show context menu
6269
void showContextMenu( QPoint );
6370

0 commit comments

Comments
 (0)
Please sign in to comment.