zoom to selected features (the button is right to the 'zoom to previous' one

git-svn-id: http://svn.osgeo.org/qgis/trunk@262 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2003-09-05 08:41:58 +00:00
parent 66135f841f
commit 02c5e76b73
10 changed files with 132 additions and 1 deletions

View File

@ -433,6 +433,11 @@ void QgisApp::zoomOut()
}
void QgisApp::zoomToSelected()
{
mapCanvas->zoomToSelected();
}
void QgisApp::pan()
{
mapTool = QGis::Pan;

View File

@ -67,6 +67,8 @@ class QgisApp:public QgisAppBase
void zoomFull();
//! Zoom to the previous extent
void zoomPrevious();
//! Zoom to selected features
void zoomToSelected();
//! Set map tool to pan
void pan();
//! Identify feature(s) on the currently selected layer

View File

@ -119,6 +119,7 @@
<action name="actionPan"/>
<action name="actionZoomFullExtent"/>
<action name="actionZoomLast"/>
<action name="actionZoomToSelected"/>
<separator/>
<action name="actionIdentify"/>
<action name="actionSelect"/>
@ -250,6 +251,17 @@
<string>Zoom &amp;out</string>
</property>
</action>
<action>
<property name="name">
<cstring>actionZoomToSelected</cstring>
</property>
<property name="text">
<string>Zoom to selected features</string>
</property>
<property name="toolTip">
<string>Zooms to selected features</string>
</property>
</action>
<action>
<property name="name">
<cstring>actionIdentify</cstring>
@ -496,6 +508,12 @@
<receiver>QgisAppBase</receiver>
<slot>zoomIn()</slot>
</connection>
<connection>
<sender>actionZoomToSelected</sender>
<signal>activated()</signal>
<receiver>QgisAppBase</receiver>
<slot>zoomToSelected()</slot>
</connection>
<connection>
<sender>drawAction</sender>
<signal>activated()</signal>
@ -617,6 +635,7 @@
<slot>init()</slot>
<slot>drawLayers()</slot>
<slot>zoomFull()</slot>
<slot>zoomToSelected()</slot>
<slot>pan()</slot>
<slot>about()</slot>
<slot>testButton()</slot>

View File

@ -35,6 +35,11 @@ void QgisAppBase::zoomOut()
}
void QgisAppBase::zoomToSelected()
{
}
void QgisAppBase::init()

View File

@ -16,6 +16,7 @@
***************************************************************************/
/* $Id$ */
#include <iostream>
#include <cfloat>
#include <cmath>
#include <qstring.h>
#include <qpainter.h>
@ -305,6 +306,48 @@ void QgsMapCanvas::zoomPreviousExtent()
render2();
}
}
void QgsMapCanvas::zoomToSelected()
{
QgsMapLayer * lyr = mapLegend->currentLayer();
if(lyr)
{
QgsRect rect=lyr->bBoxOfSelected();
//no selected features
if(rect.xMin()==DBL_MAX&&rect.yMin()==DBL_MAX&&rect.xMax()==DBL_MIN&&rect.yMax()==DBL_MIN)
{
return;
}
//zoom to one single point
else if(rect.xMin()==rect.xMax()&&rect.yMin()==rect.yMax())
{
previousExtent=currentExtent;
currentExtent.setXmin(rect.xMin()-25);
currentExtent.setYmin(rect.yMin()-25);
currentExtent.setXmax(rect.xMax()+25);
currentExtent.setYmax(rect.yMax()+25);
clear();
render2();
return;
}
//zoom to an area
else
{
previousExtent=currentExtent;
currentExtent.setXmin(rect.xMin());
currentExtent.setYmin(rect.yMin());
currentExtent.setXmax(rect.xMax());
currentExtent.setYmax(rect.yMax());
clear();
render2();
return;
}
}
}
void QgsMapCanvas::mousePressEvent(QMouseEvent * e)
{
mouseButtonDown = true;

View File

@ -62,6 +62,8 @@ public:
void setExtent(QgsRect );
void zoomFullExtent();
void zoomPreviousExtent();
/**Zooms to the extend of the selected features*/
void zoomToSelected();
/** Sets the map tool currently being used on the canvas */
void setMapTool(int tool);
/** Write property of QColor bgColor. */

View File

@ -14,6 +14,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <cfloat>
#include <iostream>
#include <qdatetime.h>
#include "qgsrect.h"
@ -68,10 +69,17 @@ const QgsRect QgsMapLayer::extent()
return layerExtent;
}
QgsRect QgsMapLayer::calculateExtent()
QgsRect QgsMapLayer::bBoxOfSelected()
{
}
QgsRect QgsMapLayer::calculateExtent()
{
//just to prevent any crashes
QgsRect rect(DBL_MAX,DBL_MAX,DBL_MIN,DBL_MIN);
return rect;
}
void QgsMapLayer::draw(QPainter *, QgsRect * viewExtent, int yTransform)
{
// std::cout << "In QgsMapLayer::draw" << std::endl;

View File

@ -61,6 +61,8 @@ class QgsMapLayer:public QObject
* based on the layer type
*/
virtual QgsRect calculateExtent();
/**Returns the bounding box of the selected features. If there is no selection, the lower bounds are DBL_MAX and the upper bounds DBL_MIN*/
virtual QgsRect bBoxOfSelected();
virtual void draw(QPainter *, QgsRect *, int);
virtual void draw(QPainter *, QgsRect *, QgsCoordinateTransform * cXf);
/*! Identify the feature(s) in this layer that are contained in the search rectangle

View File

@ -17,6 +17,7 @@
***************************************************************************/
/* $Id$ */
#include <cfloat>
#include <iostream>
#include <strstream>
#include <qapplication.h>
@ -97,6 +98,48 @@ QgsShapeFileLayer::~QgsShapeFileLayer()
}
}
QgsRect QgsShapeFileLayer::bBoxOfSelected()
{
double xmin=DBL_MAX;//edge coordinates of the bounding box
double ymin=DBL_MAX;
double xmax=DBL_MIN;
double ymax=DBL_MIN;
//find the selected features and use their geometries to extend the bounding box
for(int i=0;i<selected->count();i++)
{
if((*selected)[i]==true)
{
OGRFeature* fet = ogrLayer->GetFeature(i);
OGRGeometry* geom = fet->GetGeometryRef();
OGRwkbGeometryType type=geom->getGeometryType();
OGREnvelope bbox;
geom->getEnvelope(&bbox);
if(bbox.MinX<xmin)
{
xmin=bbox.MinX;
}
if(bbox.MinY<ymin)
{
ymin=bbox.MinY;
}
if(bbox.MaxX>xmax)
{
xmax=bbox.MaxX;
}
if(bbox.MaxY>ymax)
{
ymax=bbox.MaxY;
}
}
}
QgsRect rect(xmin,ymin,xmax,ymax);
return rect;
}
/** No descriptions */
void QgsShapeFileLayer::registerFormats()
{

View File

@ -40,6 +40,8 @@ class QgsShapeFileLayer:public QgsMapLayer
QgsShapeFileLayer(QString baseName = 0, QString path = 0);
//! Destructor
~QgsShapeFileLayer();
/**Returns the bounding box of the selected features. If there is no selection, the lower bounds are DBL_MAX and the upper bounds DBL_MIN*/
QgsRect bBoxOfSelected();
//! Identify feature found within the search rectangle
void identify(QgsRect *);
//! Select features found within the search rectangle