Skip to content

Commit ca97459

Browse files
committed
Moved some legend actions to QgisApp, added actions to layer tree view.
Still need to adjust action implementations in QgisApp to use layer tree view
1 parent f2b69e9 commit ca97459

File tree

7 files changed

+271
-163
lines changed

7 files changed

+271
-163
lines changed

src/app/legend/qgslegend.cpp

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
885885
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionRemoveLayer.svg" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
886886

887887
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ),
888-
tr( "&Set Group CRS" ), this, SLOT( legendGroupSetCRS() ) );
888+
tr( "&Set Group CRS" ), QgisApp::instance(), SLOT( legendGroupSetCRS() ) );
889889
}
890890

891891
if (( li->type() == QgsLegendItem::LEGEND_LAYER || li->type() == QgsLegendItem::LEGEND_GROUP ) && !groupEmbedded( li ) && !parentGroupEmbedded( li ) )
@@ -1621,29 +1621,6 @@ void QgsLegend::legendGroupRemove()
16211621
mMapCanvas->freeze( false );
16221622
}
16231623

1624-
void QgsLegend::legendGroupSetCRS()
1625-
{
1626-
if ( !mMapCanvas )
1627-
{
1628-
return;
1629-
}
1630-
1631-
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
1632-
mySelector->setMessage();
1633-
if ( mySelector->exec() )
1634-
{
1635-
QgsCoordinateReferenceSystem crs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
1636-
1637-
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( currentItem() );
1638-
setGroupCRS( lg, crs );
1639-
}
1640-
else
1641-
{
1642-
QApplication::restoreOverrideCursor();
1643-
}
1644-
1645-
delete mySelector;
1646-
}
16471624

16481625
void QgsLegend::removeGroup( QgsLegendGroup *lg )
16491626
{
@@ -1675,22 +1652,6 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )
16751652
adjustIconSize();
16761653
}
16771654

1678-
void QgsLegend::setGroupCRS( QgsLegendGroup *lg, const QgsCoordinateReferenceSystem &crs )
1679-
{
1680-
if ( !mMapCanvas )
1681-
{
1682-
return;
1683-
}
1684-
1685-
foreach ( QgsLegendLayer *cl, lg->legendLayers() )
1686-
{
1687-
if ( cl )
1688-
{
1689-
cl->layer()->setCrs( crs );
1690-
}
1691-
}
1692-
}
1693-
16941655
void QgsLegend::moveLayer( QgsMapLayer *ml, int groupIndex )
16951656
{
16961657
if ( !ml )
@@ -2834,62 +2795,6 @@ void QgsLegend::legendLayerZoom()
28342795
mMapCanvas->refresh();
28352796
}
28362797

2837-
void QgsLegend::legendLayerZoomNative()
2838-
{
2839-
//find current Layer
2840-
QgsLegendLayer* currentLayer = dynamic_cast<QgsLegendLayer *>( currentItem() );
2841-
if ( !currentLayer )
2842-
return;
2843-
2844-
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( currentLayer->layer() );
2845-
if ( layer )
2846-
{
2847-
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixelX() ) );
2848-
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
2849-
2850-
if ( mMapCanvas->hasCrsTransformEnabled() )
2851-
{
2852-
// get legth of central canvas pixel width in source raster crs
2853-
QgsRectangle e = mMapCanvas->extent();
2854-
QSize s = mMapCanvas->mapSettings().outputSize();
2855-
QgsPoint p1( e.center().x(), e.center().y() );
2856-
QgsPoint p2( e.center().x() + e.width() / s.width(), e.center().y() + e.height() / s.height() );
2857-
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), layer->crs() );
2858-
p1 = ct.transform( p1 );
2859-
p2 = ct.transform( p2 );
2860-
double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
2861-
// This is not perfect of course, we use the resolution in just one direction
2862-
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / width ) );
2863-
}
2864-
else
2865-
{
2866-
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / mMapCanvas->mapUnitsPerPixel() ) );
2867-
}
2868-
mMapCanvas->refresh();
2869-
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
2870-
}
2871-
}
2872-
2873-
void QgsLegend::legendLayerStretchUsingCurrentExtent()
2874-
{
2875-
//find current Layer
2876-
QgsLegendLayer* currentLayer = dynamic_cast<QgsLegendLayer *>( currentItem() );
2877-
if ( !currentLayer )
2878-
return;
2879-
2880-
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( currentLayer->layer() );
2881-
if ( layer )
2882-
{
2883-
QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm = QgsContrastEnhancement::StretchToMinimumMaximum;
2884-
2885-
QgsRectangle myRectangle;
2886-
myRectangle = mMapCanvas->mapSettings().outputExtentToLayerExtent( layer, mMapCanvas->extent() );
2887-
layer->setContrastEnhancement( contrastEnhancementAlgorithm, QgsRaster::ContrastEnhancementMinMax, myRectangle );
2888-
2889-
refreshLayerSymbology( layer->id() );
2890-
mMapCanvas->refresh();
2891-
}
2892-
}
28932798

28942799
void QgsLegend::readProject( const QDomDocument & doc )
28952800
{
@@ -3012,32 +2917,6 @@ void QgsLegend::removeSelectedLayers()
30122917
mMapCanvas->freeze( false );
30132918
}
30142919

3015-
void QgsLegend::setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs )
3016-
{
3017-
// Turn off rendering to improve speed.
3018-
mMapCanvas->freeze();
3019-
3020-
foreach ( QTreeWidgetItem * item, selectedItems() )
3021-
{
3022-
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item );
3023-
if ( lg )
3024-
{
3025-
setGroupCRS( lg, crs );
3026-
continue;
3027-
}
3028-
3029-
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
3030-
if ( ll && ll->layer() )
3031-
{
3032-
ll->layer()->setCrs( crs );
3033-
continue;
3034-
}
3035-
}
3036-
3037-
// Turn on rendering (if it was on previously)
3038-
mMapCanvas->freeze( false );
3039-
}
3040-
30412920
bool QgsLegend::parentGroupEmbedded( QTreeWidgetItem* item ) const
30422921
{
30432922
if ( !item )

src/app/legend/qgslegend.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,23 +339,12 @@ class QgsLegend : public QTreeWidget
339339
legend layer files*/
340340
void legendLayerZoom();
341341

342-
/**Zooms so that the pixels of the raster layer occupies exactly one screen pixel.
343-
Only works on raster layers*/
344-
void legendLayerZoomNative();
345-
346-
/**Stretches the raster layer, if stretching is active, based on the min and max of the current extent.
347-
Only workds on raster layers*/
348-
void legendLayerStretchUsingCurrentExtent();
349-
350342
/**Updates check states when the map canvas layer set is changed */
351343
void refreshCheckStates();
352344

353345
/** Remove selected layers */
354346
void removeSelectedLayers();
355347

356-
/** Set CRS for selected layers */
357-
void setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs );
358-
359348
/** Update drawing order */
360349
bool updateDrawingOrder();
361350

@@ -483,12 +472,8 @@ class QgsLegend : public QTreeWidget
483472
void handleRightClickEvent( QTreeWidgetItem* item, const QPoint& position );
484473
/**Removes the current legend group*/
485474
void legendGroupRemove();
486-
/**Set the CRS of the current legend group*/
487-
void legendGroupSetCRS();
488475
/**Removes a legend group and its layers*/
489476
void removeGroup( QgsLegendGroup * lg );
490-
/**Removes a legend group and its layers*/
491-
void setGroupCRS( QgsLegendGroup * lg, const QgsCoordinateReferenceSystem &crs );
492477
/**Sets all listview items to open*/
493478
void expandAll();
494479
/**Sets all listview items to closed*/

src/app/legend/qgslegendlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
369369
tr( "&Zoom to Layer Extent" ), legend(), SLOT( legendLayerZoom() ) );
370370
if ( lyr->type() == QgsMapLayer::RasterLayer )
371371
{
372-
theMenu.addAction( tr( "&Zoom to Best Scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );
372+
theMenu.addAction( tr( "&Zoom to Best Scale (100%)" ), QgisApp::instance(), SLOT( legendLayerZoomNative() ) );
373373

374374
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( lyr );
375375
if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
376376
{
377-
theMenu.addAction( tr( "&Stretch Using Current Extent" ), legend(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
377+
theMenu.addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
378378
}
379379
}
380380

0 commit comments

Comments
 (0)