Skip to content
Permalink
Browse files
[layertree] Fix crash on zoom to layer
  • Loading branch information
wonder-sk committed May 22, 2014
1 parent 2837778 commit 9cfaaf17a3d85716e23ac24a3a8ec91dcdc21055
@@ -6964,7 +6964,7 @@ void QgisApp::legendGroupSetCRS()

void QgisApp::zoomToLayerExtent()
{
mLayerTreeView->defaultActions()->zoomToLayer();
mLayerTreeView->defaultActions()->zoomToLayer( mMapCanvas );
}

void QgisApp::showPluginManager()
@@ -104,7 +104,7 @@ void QgsLayerTreeView::contextMenuEvent( QContextMenuEvent *event )
setCurrentIndex( QModelIndex() );

QMenu* menu = mMenuProvider->createContextMenu();
if ( menu )
if ( menu && menu->actions().count() != 0 )
menu->exec( mapToGlobal( event->pos() ) );
delete menu;
}
@@ -153,11 +153,9 @@ void QgsLayerTreeViewDefaultActions::showFeatureCount()
mView->layerTreeModel()->refreshLayerSymbology( QgsLayerTree::toLayer( node ) );
}

void QgsLayerTreeViewDefaultActions::zoomToLayer()
{
QAction* s = qobject_cast<QAction*>( sender() );
QgsMapCanvas* canvas = reinterpret_cast<QgsMapCanvas*>( s->data().value<void*>() );

void QgsLayerTreeViewDefaultActions::zoomToLayer( QgsMapCanvas* canvas )
{
QgsMapLayer* layer = mView->currentLayer();
if ( !layer )
return;
@@ -167,18 +165,29 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer()
zoomToLayers( canvas, layers );
}

void QgsLayerTreeViewDefaultActions::zoomToGroup()
void QgsLayerTreeViewDefaultActions::zoomToGroup( QgsMapCanvas* canvas )
{
QAction* s = qobject_cast<QAction*>( sender() );
QgsMapCanvas* canvas = reinterpret_cast<QgsMapCanvas*>( s->data().value<void*>() );

QList<QgsMapLayer*> layers;
foreach ( QString layerId, mView->currentGroupNode()->childLayerIds() )
layers << QgsMapLayerRegistry::instance()->mapLayer( layerId );

zoomToLayers( canvas, layers );
}

void QgsLayerTreeViewDefaultActions::zoomToLayer()
{
QAction* s = qobject_cast<QAction*>( sender() );
QgsMapCanvas* canvas = reinterpret_cast<QgsMapCanvas*>( s->data().value<void*>() );
zoomToLayer( canvas );
}

void QgsLayerTreeViewDefaultActions::zoomToGroup()
{
QAction* s = qobject_cast<QAction*>( sender() );
QgsMapCanvas* canvas = reinterpret_cast<QgsMapCanvas*>( s->data().value<void*>() );
zoomToGroup( canvas );
}


void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const QList<QgsMapLayer*>& layers )
{
@@ -44,11 +44,16 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction* actionMakeTopLevel( QObject* parent = 0 );
QAction* actionGroupSelected( QObject* parent = 0 );

void zoomToLayer( QgsMapCanvas* canvas );
void zoomToGroup( QgsMapCanvas* canvas );

public slots:
void showInOverview();

protected slots:
void addGroup();
void removeGroupOrLayer();
void renameGroupOrLayer();
void showInOverview();
void showFeatureCount();
void zoomToLayer();
void zoomToGroup();

0 comments on commit 9cfaaf1

Please sign in to comment.