mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Added zooming to 100%, i.e one raster pixel will occupy one screen pixel. Only supported for raster layers. Right-click on the layer in the legend, and select from pop-up menu
git-svn-id: http://svn.osgeo.org/qgis/trunk@6735 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
32c3743133
commit
d1d55984ba
@ -1696,6 +1696,34 @@ void QgsLegend::legendLayerZoom()
|
||||
QgsProject::instance()->dirty(true);
|
||||
}
|
||||
|
||||
void QgsLegend::legendLayerZoomNative()
|
||||
{
|
||||
QgsLegendItem* citem=dynamic_cast<QgsLegendItem*>(currentItem());
|
||||
if(!citem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(citem);
|
||||
if(!ll)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QgsRasterLayer *layer = dynamic_cast<QgsRasterLayer*>(ll->firstMapLayer());
|
||||
if(layer)
|
||||
{
|
||||
QgsDebugMsg("Raster units per pixel : " + QString::number(layer->rasterUnitsPerPixel()));
|
||||
QgsDebugMsg("Mupp before : " + QString::number(mMapCanvas->mupp()));
|
||||
|
||||
mMapCanvas->zoom(fabs( layer->rasterUnitsPerPixel() / mMapCanvas->mupp()));
|
||||
mMapCanvas->refresh();
|
||||
|
||||
QgsDebugMsg("Mupp after : " + QString::number(mMapCanvas->mupp()));
|
||||
|
||||
// notify the project we've made a change
|
||||
QgsProject::instance()->dirty(true);
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLegend::legendLayerAttributeTable()
|
||||
{
|
||||
|
||||
|
@ -217,6 +217,10 @@ public slots:
|
||||
legend layer files*/
|
||||
void legendLayerZoom();
|
||||
|
||||
/***Zooms so that the pixels of the raster layer occupies exactly one screen pixel.
|
||||
Only works on raster layers*/
|
||||
void legendLayerZoomNative();
|
||||
|
||||
/**Show attribute table*/
|
||||
void legendLayerAttributeTable();
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgslegendlayerfilegroup.h"
|
||||
#include "qgslegendsymbologyitem.h"
|
||||
#include "qgslogger.h"
|
||||
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsfield.h"
|
||||
@ -469,6 +470,10 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu)
|
||||
// zoom to layer extent
|
||||
theMenu.addAction(QIcon(iconsPath+QString("/mActionZoomToLayer.png")),
|
||||
tr("&Zoom to layer extent"), legend(), SLOT(legendLayerZoom()));
|
||||
if (firstLayer && firstLayer->type() == QgsMapLayer::RASTER)
|
||||
{
|
||||
theMenu.addAction(tr("&Zoom to best scale (100%)"), legend(), SLOT(legendLayerZoomNative()));
|
||||
}
|
||||
|
||||
// show in overview
|
||||
QAction* showInOverviewAction = theMenu.addAction(tr("&Show in overview"), this, SLOT(showInOverview()));
|
||||
|
@ -1057,10 +1057,10 @@ bool QgsRasterLayer::draw(QPainter * theQPainter,
|
||||
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform(myRasterExtent.xMin(), myRasterExtent.yMax());
|
||||
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform(myRasterExtent.xMax(), myRasterExtent.yMin());
|
||||
|
||||
myRasterViewPort->drawableAreaXDimInt =
|
||||
abs(static_cast<int> (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1]));
|
||||
myRasterViewPort->drawableAreaYDimInt =
|
||||
abs(static_cast<int> (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5]));
|
||||
myRasterViewPort->drawableAreaXDimInt = static_cast<int>
|
||||
(fabs( (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1])) + 0.5);
|
||||
myRasterViewPort->drawableAreaYDimInt = static_cast<int>
|
||||
(fabs( (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5])) + 0.5);
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
QgsLogger::debug("QgsRasterLayer::draw: mapUnitsPerPixel", theQgsMapToPixel->mapUnitsPerPixel(), 1, __FILE__,\
|
||||
@ -5262,5 +5262,17 @@ const unsigned int QgsRasterLayer::getBandCount()
|
||||
return rasterStatsVector.size();
|
||||
};
|
||||
|
||||
double QgsRasterLayer::rasterUnitsPerPixel()
|
||||
{
|
||||
|
||||
// We return one raster pixel per map unit pixel
|
||||
// One raster pixel can have several raster units...
|
||||
|
||||
// We can only use one of the adfGeoTransform[], so go with the
|
||||
// horisontal one.
|
||||
|
||||
return fabs(adfGeoTransform[1]);
|
||||
}
|
||||
|
||||
|
||||
// ENDS
|
||||
|
@ -294,6 +294,10 @@ public:
|
||||
/** \brief Query gdal to find out the WKT projection string for this layer. This implements the virtual method of the same name defined in QgsMapLayer*/
|
||||
QString getProjectionWKT();
|
||||
|
||||
/** \brief Returns the number of raster units per each raster pixel. For rasters with world file, this is
|
||||
normally the first row (without the sign) in that file */
|
||||
double rasterUnitsPerPixel();
|
||||
|
||||
/** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
|
||||
void drawThumbnail(QPixmap * theQPixmap);
|
||||
|
||||
|
@ -1073,3 +1073,13 @@ void QgsMapCanvas::writeProject(QDomDocument & doc)
|
||||
|
||||
|
||||
}
|
||||
|
||||
void QgsMapCanvas::zoom(double scaleFactor)
|
||||
{
|
||||
|
||||
QgsRect r = mMapRender->extent();
|
||||
r.scale(scaleFactor);
|
||||
setExtent(r);
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -230,6 +230,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
//! returns last position of mouse cursor
|
||||
QPoint mouseLastXY();
|
||||
|
||||
//! zooms with the factor supplied. Factor > 1 zooms in
|
||||
void zoom(double scaleFactor);
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
/**Sets dirty=true and calls render()*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user