Skip to content
Permalink
Browse files

[browser] Avoid expanding/collapsing nodes if the double click

was specifically handled by an item itself
  • Loading branch information
nyalldawson committed Oct 30, 2018
1 parent 5c5f2ed commit 850eae1606a1c61897ec9d440df672bae5afc72a
@@ -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
@@ -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 );
@@ -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()
@@ -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 ) );
@@ -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 )
@@ -440,7 +451,9 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
addLayer( layerItem );
QApplication::restoreOverrideCursor();
}
return true;
}
return false;
}

void QgsBrowserDockWidget::addSelectedLayers()
@@ -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 );

0 comments on commit 850eae1

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