**Current extent support added to overview map

**Added acetate objects and support to QgsMapCanvas


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1555 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2004-06-11 01:04:08 +00:00
parent e8c159c7c8
commit 6bffe44f68
12 changed files with 376 additions and 27 deletions

View File

@ -1,9 +1,19 @@
QGIS Change Log
ChangeLog,v 1.123 2004/06/10 23:10:16 timlinux Exp
ChangeLog,v 1.124 2004/06/11 01:04:07 gsherman Exp
------------------------------------------------------------------------------
Version 0.3 'Madison' .... development version
2004-06-10 [gsherman] 0.3.0devel28
** Added display of extent rectangle in the overview map. Current
implementation is not optimized (requires repaint of the overview canvas to
display updated rectangle)
** Added acetate layer support to the map canvas. Currently there is only one
acetate object type - QgsAcetateRectangle, which inherits from
QgsAcetateObject. More acetate types will follow...
2004-06-10 [ts] 0.3.0devel27
** Modified projectio (serialisation and deserialisation of project files) to use maplayerregistry and not mapcanvas.
** Modified projectio (serialisation and deserialisation of project files) to
use maplayerregistry and not mapcanvas.
** Implemented state handling of 'showInOverview' property in project io.
2004-06-10 [petebr] 0.3.0devel26

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
dnl configure.in,v 1.126 2004/06/10 23:10:16 timlinux Exp
dnl configure.in,v 1.127 2004/06/11 01:04:07 gsherman Exp
AC_INIT
@ -24,7 +24,7 @@ dnl ---------------------------------------------------------------------------
MAJOR_VERSION=0
MINOR_VERSION=3
MICRO_VERSION=0
EXTRA_VERSION=27
EXTRA_VERSION=28
if test $EXTRA_VERSION -eq 0; then
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
else

View File

@ -96,7 +96,9 @@ headers = qgis.h \
qgisapp.h \
qgsscalecalculator.h \
qgsprojectproperties.h \
qgsoptions.h
qgsoptions.h \
qgsacetateobject.h \
qgsacetaterectangle.h
## qt designer files for all the GUI stuff
@ -237,7 +239,9 @@ qgis_SOURCES = main.cpp \
splashscreen.cpp \
qgsscalecalculator.cpp \
qgsprojectproperties.cpp \
qgsoptions.cpp
qgsoptions.cpp \
qgsacetateobject.cpp \
qgsacetaterectangle.cpp
postgresHEADERS = qgsdbsourceselect.h qgsnewconnection.h
postgresSOURCES = qgsdbsourceselect.cpp qgsnewconnection.cpp
@ -272,7 +276,7 @@ BUILT_SOURCES = $(qgis_MOC) $(qgis_UIMOC) $(qgis_UIHEADERS) $(qgis_UISOURCES) \
qgis_LDADD = $(LDADD) $(QT_LDADD) $(GDAL_LDADD) $(PG_LIB)
qgis_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS)
libqgis_la_SOURCES = qgsmapcanvas.cpp qgsmapcanvas.moc.cpp qgssymbol.cpp qgsmaplayer.cpp qgsrasterlayer.cpp qgsvectorlayer.cpp qgsmaplayer.moc.cpp qgsrasterlayer.moc.cpp qgsvectorlayer.moc.cpp qgsfield.cpp qgsfeature.cpp qgsfeatureattribute.cpp qgsrect.cpp qgscoordinatetransform.cpp qgsscalecalculator.cpp
libqgis_la_SOURCES = qgsmapcanvas.cpp qgsmapcanvas.moc.cpp qgssymbol.cpp qgsmaplayer.cpp qgsrasterlayer.cpp qgsvectorlayer.cpp qgsmaplayer.moc.cpp qgsrasterlayer.moc.cpp qgsvectorlayer.moc.cpp qgsfield.cpp qgsfeature.cpp qgsfeatureattribute.cpp qgsrect.cpp qgscoordinatetransform.cpp qgsscalecalculator.cpp qgsacetaterectangle.cpp qgsacetateobject.cpp
libqgis_la_LIBFLAGS = $(QT_LDADD)
libqgis_la_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS)

View File

@ -72,6 +72,7 @@
#include "qgsrect.h"
#include "qgsmapcanvas.h"
#include "qgsacetaterectangle.h"
#include "qgsmaplayer.h"
#include "qgslegenditem.h"
#include "qgslegend.h"
@ -284,7 +285,7 @@ QgisApp::QgisApp(QWidget * parent, const char *name, WFlags fl):QgisAppBase(pare
setCaption(caption);
connect(mMapCanvas, SIGNAL(xyCoordinates(QgsPoint &)), this, SLOT(showMouseCoordinate(QgsPoint &)));
connect(mMapCanvas, SIGNAL(extentsChanged(QString )),this,SLOT(showExtents(QString )));
connect(mMapCanvas, SIGNAL(extentsChanged(QgsRect )),this,SLOT(showExtents(QgsRect )));
connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(showScale(QString)));
connect(mMapCanvas, SIGNAL(addedLayer(QgsMapLayer *)), mMapLegend, SLOT(addLayer(QgsMapLayer *)));
connect(mMapCanvas, SIGNAL(removedLayer(QString)), mMapLegend, SLOT(removeLayer(QString)));
@ -2949,10 +2950,49 @@ void QgisApp::showProgress(int theProgress, int theTotalSteps)
}
void QgisApp::showExtents(QString theExtents)
void QgisApp::showExtents(QgsRect theExtents)
{
statusBar()->message(QString(tr("Extents: ")) + theExtents);
// update the statusbar with the current extents
statusBar()->message(QString(tr("Extents: ")) + theExtents.stringRep(2));
// Update the extent rectangle in the overview map
QgsPoint origin(0,0);
// create the new acetate object
QgsAcetateRectangle *acRect = new QgsAcetateRectangle(origin, mMapCanvas->extent());
// add it to the acetate layer
mOverviewCanvas->addAcetateObject("extent", acRect);
// refresh the overview map
std::cerr << "Adding extent to acetate layer" << std::endl;
mOverviewCanvas->refresh();
}
void QgisApp::drawExtentRectangle(QPainter *painter)
{
//XXX - This code is not used but lets save it for a bit...
// Draw the current extents rectangle on the overview
// We don't care about the painter since we want to draw
// on a copy of the overview pixmap
/*
QgsCoordinateTransform *cXf = mOverviewCanvas->getCoordinateTransform();
// get the upper right and lower left corners of the extent rectangle
QgsRect theExtents = mMapCanvas->extent();
QgsPoint ul(theExtents.xMin(), theExtents.yMax());
QgsPoint lr(theExtents.xMax(), theExtents.yMin());
// transform the points from map coordinates to device coordinates
cXf->transform(&ul);
cXf->transform(&lr);
// copy the overview pixmap
QPixmap *overviewPixmap = new QPixmap(*mOverviewCanvas->canvasPixmap());
QPainter *canvasPainter = new QPainter();
canvasPainter->begin(overviewPixmap);
canvasPainter->setPen(QColor(255,0,0));
canvasPainter->drawRect(ul.xToInt(), lr.yToInt(),
lr.xToInt() - ul.xToInt(), ul.yToInt() - lr.yToInt());
canvasPainter->end();
delete canvasPainter;
// bitblt the new overview to the overview canvas
bitBlt(mOverviewCanvas,0,0, overviewPixmap, 0,0);
*/
}
void QgisApp::showStatusMessage(QString theMessage)

View File

@ -267,9 +267,10 @@ private slots:
/* void urlData(); */
public slots:
void showProgress(int theProgress, int theTotalSteps);
void showExtents(QString theExtents);
void showExtents(QgsRect theExtents);
void showStatusMessage(QString theMessage);
void setLayerOverviewStatus(QString theLayerId, bool theVisibilityFlag);
void drawExtentRectangle(QPainter *);
private:
//! A central registry that keeps track of all loaded layers.
QgsMapLayerRegistry * mMapLayerRegistry;

43
src/qgsacetateobject.cpp Normal file
View File

@ -0,0 +1,43 @@
/***************************************************************************
qgsacetateobject.cpp
An object that can be drawn on the acetate layer of a QgsMapCanvas
-------------------
begin : June 10, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include <qgspoint.h>
#include <qpainter.h>
#include <qgscoordinatetransform.h>
#include "qgsacetateobject.h"
QgsAcetateObject::QgsAcetateObject(QgsPoint &origin) :
mOrigin(origin)
{
}
QgsAcetateObject::~QgsAcetateObject()
{
}
/*void QgsAcetateObject::draw(QPainter * painter, QgsCoordinateTransform * cXf)
{
}
*/
QgsPoint QgsAcetateObject::origin ( ) {
return mOrigin;
}
void QgsAcetateObject::setOrigin (QgsPoint value ) {
mOrigin = value;
}

73
src/qgsacetateobject.h Normal file
View File

@ -0,0 +1,73 @@
/***************************************************************************
qgsacetateobject.h
An object that can be drawn on the acetate layer of a QgsMapCanvas
-------------------
begin : June 10, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSACETATEOBJECT_H
#define QGSACETATEOBJECT_H
class QgsPoint;
class QPainter;
class QgsCoordinateTransform;
/** \class QgsAcetateObject
* \brief Base class for all objects that are drawn on the acetate layer of a map canvas.
*
* An acetate object is a graphic or text object that is drawn on top of the map canvas
* after rendering of all map elements is completed. Acetate objects can be drawn in
* device coordinates or map coordinates. Drawing in map coordinates requires passing
* a QgsCoordinateTransform object to the draw function.
*
* The draw function must be overridden in a subclass to provide the specfic logic for
* drawing the object.
*/
class QgsAcetateObject {
public:
/**
* Constructor. Constructs an object with the specified origin. If the object is
* spatially referenced, the origin should be in map coordinates.
*/
QgsAcetateObject(QgsPoint &origin);
/**
* Destructor
*/
~QgsAcetateObject();
/**
* Draw the object using the Qpainter and applying a coordinate transform if
* specified.
* @param painter Painter to use for drawing
* @param cXf Coordinate transform to use in drawing map coordinate on the device. If
* this parameter is not specified, coordinates are assumed to be device coordinates
* rather than map coordinates.
*/
virtual void draw (QPainter * painter, QgsCoordinateTransform * cXf=0)=0;
/**
* Set the origin point
* @param value Point of origin
*/
void setOrigin (QgsPoint value );
/**
* Returns the point of origin
*/
QgsPoint origin();
private:
//! Origin of the object in device or map coordinates
QgsPoint mOrigin;
};
#endif //QGSACETATEOBJECT_H

View File

@ -0,0 +1,52 @@
/***************************************************************************
qgsacetateobject.cpp
An object that can be drawn on the acetate layer of a QgsMapCanvas
-------------------
begin : June 10, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include <qstring.h>
#include <qpainter.h>
#include <qgscoordinatetransform.h>
#include <qgspoint.h>
#include <qgsrect.h>
#include "qgsacetaterectangle.h"
QgsAcetateRectangle::QgsAcetateRectangle(QgsPoint &origin, const QgsRect &rect) :
QgsAcetateObject(origin), mRectangle(rect)
{
}
QgsAcetateRectangle::~QgsAcetateRectangle()
{
}
void QgsAcetateRectangle::draw(QPainter *painter, QgsCoordinateTransform *cXf)
{
painter->setPen(QColor(255,0,0));
painter->setBrush(Qt::NoBrush);
// get the lower left (ll) and upper right (ur) points of the rectangle
QgsPoint ll(mRectangle.xMin(), mRectangle.yMin());
QgsPoint ur(mRectangle.xMax(), mRectangle.yMax());
if(cXf)
{
// transform the points before drawing
cXf->transform(&ll);
cXf->transform(&ur);
}
painter->drawRect(ll.xToInt(), ll.yToInt(),
ur.xToInt() - ll.xToInt(), ur.yToInt() - ll.yToInt());
}

82
src/qgsacetaterectangle.h Normal file
View File

@ -0,0 +1,82 @@
/***************************************************************************
qgsacetaterectangle.h
A rectangle that can be drawn on the acetate layer of a QgsMapCanvas
-------------------
begin : June 10, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSACETATERECTANGLE_H
#define QGSACETATERECTANGLE_H
class QgsPoint;
class QPainter;
class QgsCoordinateTransform;
#include <qgsrect.h>
#include "qgsacetateobject.h"
/** \class QgsAcetateRectangle
* \brief A rectangle drawn on the acetate layer of a map canvas
*
* An acetate object is a graphic or text object that is drawn on top of the map canvas
* after rendering of all map elements is completed. Acetate objects can be drawn in
* device coordinates or map coordinates. Drawing in map coordinates requires passing
* a QgsCoordinateTransform object to the draw function.
*
*/
class QgsAcetateRectangle : public QgsAcetateObject {
public:
/**
* Constructor. Constructs an object with the specified origin. If the object is
* spatially referenced, the origin should be in map coordinates.
*/
QgsAcetateRectangle(QgsPoint &origin, const QgsRect &rectangle);
/**
* Destructor
*/
~QgsAcetateRectangle();
/**
* Draw the rectangle using the Qpainter and applying a coordinate transform if
* specified.
* @param painter Painter to use for drawing
* @param cXf Coordinate transform to use in drawing map coordinate on the device. If
* this parameter is not specified, coordinates are assumed to be device coordinates
* rather than map coordinates.
*/
void draw (QPainter * painter, QgsCoordinateTransform * cXf=0);
/**
* Set the origin point
* @param value Point of origin
*/
void setOrigin (QgsPoint value );
/**
* Returns the point of origin
*/
QgsPoint origin();
/**
* Returns the current rectangle
*/
QgsRect rectangle();
/** Sets the rectangle
* @param rect The rectanlge
*/
void setRectangle(QgsRect value);
private:
//! Origin of the object in device or map coordinates
QgsPoint mOrigin;
//! Rectangle
QgsRect mRectangle;
};
#endif //QGSACETATERECTANGLE_H

View File

@ -47,7 +47,7 @@
#include "qgsmaplayerinterface.h"
#include "qgsvectorlayer.h"
#include "qgsscalecalculator.h"
#include "qgsacetaterectangle.h"
/**
Implementation struct for QgsMapCanvas
@ -106,6 +106,9 @@ struct QgsMapCanvas::CanvasProperties
//! map containing the layers by name
std::map < QString, QgsMapLayer * >layers;
//! map containing the acetate objects by key (name)
std::map <QString, QgsAcetateObject *> acetateObjects;
//! list containing the names of layers in zorder
std::list < QString > zOrder;
@ -302,6 +305,19 @@ void QgsMapCanvas::addLayer(QgsMapLayer * lyr)
} // addLayer
void QgsMapCanvas::addAcetateObject(QString key, QgsAcetateObject *obj)
{
// since we are adding pointers, check to see if the object
// referenced by key already exists and if so, delete it prior
// to adding the new object with the same key
QgsAcetateObject *oldObj = mCanvasProperties->acetateObjects[key];
if(oldObj)
{
delete oldObj;
}
mCanvasProperties->acetateObjects[key] = obj;
}
QgsMapLayer *QgsMapCanvas::getZpos(int idx)
{
@ -487,9 +503,23 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
#ifdef QGISDEBUG
std::cout << "Done rendering map layers...emitting renderComplete(paint)\n";
#endif
emit renderComplete(paint);
// draw the acetate layer
std::map <QString, QgsAcetateObject *>::iterator ai = mCanvasProperties->acetateObjects.begin();
while(ai != mCanvasProperties->acetateObjects.end())
{
QgsAcetateObject *acObj = ai->second;
if(acObj)
{
acObj->draw(paint, mCanvasProperties->coordXForm);
}
ai++;
}
// notify any listeners that rendering is complete
//note that pmCanvas is not draw to gui yet
emit renderComplete(paint);
//emit renderComplete(paint);
paint->end();
mCanvasProperties->drawing = false;
}
@ -499,7 +529,12 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
} // render
// return the current coordinate transform based on the extents and
// device size
QgsCoordinateTransform * QgsMapCanvas::getCoordinateTransform()
{
return mCanvasProperties->coordXForm;
}
void QgsMapCanvas::currentScale(int thePrecision)
{
@ -607,7 +642,7 @@ QgsRect const & QgsMapCanvas::extent() const
void QgsMapCanvas::setExtent(QgsRect const & r)
{
mCanvasProperties->currentExtent = r;
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(r);
} // setExtent
@ -626,7 +661,7 @@ void QgsMapCanvas::zoomFullExtent()
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
} // zoomFullExtent
@ -640,7 +675,7 @@ void QgsMapCanvas::zoomPreviousExtent()
mCanvasProperties->previousExtent = tempRect;
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
}
} // zoomPreviousExtent
@ -672,9 +707,9 @@ void QgsMapCanvas::zoomToSelected()
mCanvasProperties->currentExtent.setYmin(rect.yMin() - 25);
mCanvasProperties->currentExtent.setXmax(rect.xMax() + 25);
mCanvasProperties->currentExtent.setYmax(rect.yMax() + 25);
emit extentsChanged(mCanvasProperties->currentExtent);
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
return;
}
//zoom to an area
@ -685,9 +720,9 @@ void QgsMapCanvas::zoomToSelected()
mCanvasProperties->currentExtent.setYmin(rect.yMin());
mCanvasProperties->currentExtent.setXmax(rect.xMax());
mCanvasProperties->currentExtent.setYmax(rect.yMax());
emit extentsChanged(mCanvasProperties->currentExtent);
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
return;
}
}
@ -747,7 +782,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
mCanvasProperties->currentExtent.setXmax(ur.x());
mCanvasProperties->currentExtent.setYmax(ur.y());
mCanvasProperties->currentExtent.normalize();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
clear();
render();
@ -798,7 +833,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
#endif
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
}
break;
@ -837,7 +872,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
}
clear();
render();
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
}
break;
@ -921,7 +956,7 @@ void QgsMapCanvas::resizeEvent(QResizeEvent * e)
{
mCanvasProperties->dirty = true;
mCanvasProperties->pmCanvas->resize(e->size());
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
} // resizeEvent
@ -1036,7 +1071,7 @@ void QgsMapCanvas::updateFullExtent(QgsRect const & r)
mCanvasProperties->fullExtent.setYmax(r.yMax());
}
emit extentsChanged(mCanvasProperties->currentExtent.stringRep(2));
emit extentsChanged(mCanvasProperties->currentExtent);
} // updateFullExtent

View File

@ -41,6 +41,7 @@ class QgsLegendView;
class QColor;
class QgsPoint;
class QgsScaleCalculator;
class QgsAcetateObject;
/*! \class QgsMapCanvas
* \brief Map canvas class for displaying all GIS data types.
@ -78,7 +79,7 @@ class QgsMapCanvas : public QWidget
//! Returns the mupp (map units per pixel) for the canvas
double mupp() const;
//! Returns the exent for all layers on the map canvased
//! Returns the exent for all layers on the map canvas
QgsRect const & extent() const;
//! Set the extent of the map canvas
@ -135,6 +136,8 @@ class QgsMapCanvas : public QWidget
//! Get the current canvas map units
int mapUnits();
//! Get the current coordinate transform
QgsCoordinateTransform * getCoordinateTransform();
//! Declare the legend class as a friend of the map canvas
//friend class QgsLegend;
@ -159,6 +162,12 @@ public slots:
/**Sets dirty=true and calls render()*/
void refresh();
/**
* Add an acetate object to the collection
* @param key Key used to identify the object
* @param obj Acetate object to add to the collection
*/
void addAcetateObject(QString key, QgsAcetateObject *obj);
//! The painter device parameter is optional - if ommitted it will default
// to the pmCanvas (ie the gui map display). The idea is that you can pass
@ -184,7 +193,7 @@ signals:
void scaleChanged(QString);
//! Emitted when the extents of the map change
void extentsChanged(QString);
void extentsChanged(QgsRect);
/** Emitted when the canvas has rendered.
/* Passes a pointer to the painter on

View File

@ -19,7 +19,7 @@
#ifndef QGSPOINT_H
#define QGSPOINT_H
#include <iostream>
class QString;
#include <qstring.h>
class QgsPoint {
private: