Skip to content

Commit

Permalink
[layertree] Fix crash on zoom to layer
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 22, 2014
1 parent 2837778 commit 9cfaaf1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -6964,7 +6964,7 @@ void QgisApp::legendGroupSetCRS()


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


void QgisApp::showPluginManager() void QgisApp::showPluginManager()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -104,7 +104,7 @@ void QgsLayerTreeView::contextMenuEvent( QContextMenuEvent *event )
setCurrentIndex( QModelIndex() ); setCurrentIndex( QModelIndex() );


QMenu* menu = mMenuProvider->createContextMenu(); QMenu* menu = mMenuProvider->createContextMenu();
if ( menu ) if ( menu && menu->actions().count() != 0 )
menu->exec( mapToGlobal( event->pos() ) ); menu->exec( mapToGlobal( event->pos() ) );
delete menu; delete menu;
} }
Expand Down
25 changes: 17 additions & 8 deletions src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Expand Up @@ -153,11 +153,9 @@ void QgsLayerTreeViewDefaultActions::showFeatureCount()
mView->layerTreeModel()->refreshLayerSymbology( QgsLayerTree::toLayer( node ) ); 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(); QgsMapLayer* layer = mView->currentLayer();
if ( !layer ) if ( !layer )
return; return;
Expand All @@ -167,18 +165,29 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer()
zoomToLayers( canvas, layers ); 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; QList<QgsMapLayer*> layers;
foreach ( QString layerId, mView->currentGroupNode()->childLayerIds() ) foreach ( QString layerId, mView->currentGroupNode()->childLayerIds() )
layers << QgsMapLayerRegistry::instance()->mapLayer( layerId ); layers << QgsMapLayerRegistry::instance()->mapLayer( layerId );


zoomToLayers( canvas, layers ); 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 ) void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas* canvas, const QList<QgsMapLayer*>& layers )
{ {
Expand Down
7 changes: 6 additions & 1 deletion src/gui/layertree/qgslayertreeviewdefaultactions.h
Expand Up @@ -44,11 +44,16 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction* actionMakeTopLevel( QObject* parent = 0 ); QAction* actionMakeTopLevel( QObject* parent = 0 );
QAction* actionGroupSelected( QObject* parent = 0 ); QAction* actionGroupSelected( QObject* parent = 0 );


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

public slots: public slots:
void showInOverview();

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

0 comments on commit 9cfaaf1

Please sign in to comment.