[QGIS Commit] r8230 - in branches/rendercontext-branch: python/core
src/app src/app/composer src/core src/core/raster src/gui
src/plugins/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Mar 16 12:04:52 EDT 2008
Author: mhugent
Date: 2008-03-16 12:04:52 -0400 (Sun, 16 Mar 2008)
New Revision: 8230
Modified:
branches/rendercontext-branch/python/core/qgsmaplayer.sip
branches/rendercontext-branch/python/core/qgsrasterlayer.sip
branches/rendercontext-branch/python/core/qgsvectorlayer.sip
branches/rendercontext-branch/src/app/composer/qgscomposermap.cpp
branches/rendercontext-branch/src/app/qgsmaptoolselect.cpp
branches/rendercontext-branch/src/core/qgscoordinatetransform.cpp
branches/rendercontext-branch/src/core/qgscoordinatetransform.h
branches/rendercontext-branch/src/core/qgsmaplayer.cpp
branches/rendercontext-branch/src/core/qgsmaplayer.h
branches/rendercontext-branch/src/core/qgsmaprender.cpp
branches/rendercontext-branch/src/core/qgsmaprender.h
branches/rendercontext-branch/src/core/qgsmaptopixel.cpp
branches/rendercontext-branch/src/core/qgsmaptopixel.h
branches/rendercontext-branch/src/core/qgsrendercontext.cpp
branches/rendercontext-branch/src/core/qgsrendercontext.h
branches/rendercontext-branch/src/core/qgsscalecalculator.cpp
branches/rendercontext-branch/src/core/qgsscalecalculator.h
branches/rendercontext-branch/src/core/qgsvectorlayer.cpp
branches/rendercontext-branch/src/core/qgsvectorlayer.h
branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp
branches/rendercontext-branch/src/core/raster/qgsrasterlayer.h
branches/rendercontext-branch/src/gui/qgsmapcanvas.cpp
branches/rendercontext-branch/src/gui/qgsmapcanvas.h
branches/rendercontext-branch/src/gui/qgsmapoverviewcanvas.cpp
branches/rendercontext-branch/src/gui/qgsmaptoolzoom.cpp
branches/rendercontext-branch/src/plugins/grass/qgsgrassedit.h
Log:
Started transition to render context for vector layer. Most things don't work at the moment (e.g. rasters, labels, print composer). Added a lot of consts to several methods
Modified: branches/rendercontext-branch/python/core/qgsmaplayer.sip
===================================================================
--- branches/rendercontext-branch/python/core/qgsmaplayer.sip 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/python/core/qgsmaplayer.sip 2008-03-16 16:04:52 UTC (rev 8230)
@@ -56,13 +56,9 @@
const QString & name() const;
/** Render the layer, to be overridden in child classes
- * @param painter Painter that to be used for rendered output
- * @param rect Extent of the layer to be drawn
- * @param mtp Transformation class
- * @return FALSE if an error occurred during drawing
*/
- virtual bool draw(QPainter* painter, QgsRect& rect, QgsMapToPixel* mtp, QgsCoordinateTransform* ct, bool);
-
+ virtual bool draw(QPainter* painter, const QgsRenderContext& renderContext);
+
/** Draw labels
* @TODO to be removed: used only in vector layers
*/
Modified: branches/rendercontext-branch/python/core/qgsrasterlayer.sip
===================================================================
--- branches/rendercontext-branch/python/core/qgsrasterlayer.sip 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/python/core/qgsrasterlayer.sip 2008-03-16 16:04:52 UTC (rev 8230)
@@ -105,16 +105,8 @@
QPixmap getPaletteAsPixmap();
/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn).
-
- \param drawingToEditingCanvas Are we drawing to an editable canvas?
- currently not used, but retain to be similar to
- the QgsVectorLayer interface
*/
- bool draw(QPainter * theQPainter,
- QgsRect & theViewExtent,
- QgsMapToPixel * theQgsMapToPixel,
- QgsCoordinateTransform* ct,
- bool drawingToEditingCanvas);
+ bool draw(QPainter* painter, const QgsRenderContext& renderContext);
/** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */
void draw(QPainter * theQPainter, QgsRasterViewPort * myRasterViewPort,
Modified: branches/rendercontext-branch/python/core/qgsvectorlayer.sip
===================================================================
--- branches/rendercontext-branch/python/core/qgsvectorlayer.sip 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/python/core/qgsvectorlayer.sip 2008-03-16 16:04:52 UTC (rev 8230)
@@ -273,14 +273,10 @@
/** Draws the layer using coordinate transformation
* @return FALSE if an error occurred during drawing
*/
- bool draw(QPainter * p,
- QgsRect & viewExtent,
- QgsMapToPixel * cXf,
- QgsCoordinateTransform* ct,
- bool drawingToEditingCanvas);
+ bool draw(QPainter* painter, const QgsRenderContext& renderContext);
/** Draws the layer labels using coordinate transformation */
- void drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * cXf, QgsCoordinateTransform* ct);
+ void drawLabels(QPainter* painter, const QgsRenderContext& renderContext);
/** \brief Draws the layer using coordinate transformation
* \param widthScale line width scale
@@ -294,11 +290,6 @@
double widthScale,
double symbolScale);
- /** \brief Draws the layer labels using coordinate transformation
- * \param scale size scale, applied to all values in pixels
- */
- void drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * cXf, QgsCoordinateTransform* ct, double scale);
-
/** returns array of added features */
QList<QgsFeature>& addedFeatures();
Modified: branches/rendercontext-branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/rendercontext-branch/src/app/composer/qgscomposermap.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/app/composer/qgscomposermap.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -183,13 +183,13 @@
painter->save();
painter->scale( 1./multip, 1./multip);
- layer->draw( painter, extent, &trans, ct, FALSE);
+ //layer->draw( painter, extent, &trans, ct, FALSE);
painter->restore();
}
else
{
- layer->draw( painter, extent, transform, ct, FALSE);
+ //layer->draw( painter, extent, transform, ct, FALSE);
}
}
Modified: branches/rendercontext-branch/src/app/qgsmaptoolselect.cpp
===================================================================
--- branches/rendercontext-branch/src/app/qgsmaptoolselect.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/app/qgsmaptoolselect.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -81,7 +81,7 @@
mSelectRect.setRight(e->pos().x());
mSelectRect.setBottom(e->pos().y());
- QgsMapToPixel* transform = mCanvas->getCoordinateTransform();
+ const QgsMapToPixel* transform = mCanvas->getCoordinateTransform();
QgsPoint ll = transform->toMapCoordinates(mSelectRect.left(), mSelectRect.bottom());
QgsPoint ur = transform->toMapCoordinates(mSelectRect.right(), mSelectRect.top());
Modified: branches/rendercontext-branch/src/core/qgscoordinatetransform.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgscoordinatetransform.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgscoordinatetransform.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -208,7 +208,7 @@
//
-QgsPoint QgsCoordinateTransform::transform(const QgsPoint thePoint,TransformDirection direction)
+QgsPoint QgsCoordinateTransform::transform(const QgsPoint thePoint,TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag) return thePoint;
// transform x
@@ -233,7 +233,7 @@
}
-QgsPoint QgsCoordinateTransform::transform(const double theX, const double theY=0,TransformDirection direction)
+QgsPoint QgsCoordinateTransform::transform(const double theX, const double theY=0,TransformDirection direction) const
{
try
{
@@ -247,7 +247,7 @@
}
}
-QgsRect QgsCoordinateTransform::transform(const QgsRect theRect,TransformDirection direction)
+QgsRect QgsCoordinateTransform::transform(const QgsRect theRect,TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag) return theRect;
// transform x
@@ -287,7 +287,7 @@
}
void QgsCoordinateTransform::transformInPlace(double& x, double& y, double& z,
- TransformDirection direction)
+ TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag)
return;
@@ -309,7 +309,7 @@
void QgsCoordinateTransform::transformInPlace(std::vector<double>& x,
std::vector<double>& y, std::vector<double>& z,
- TransformDirection direction)
+ TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag)
return;
@@ -334,7 +334,7 @@
}
-QgsRect QgsCoordinateTransform::transformBoundingBox(const QgsRect rect, TransformDirection direction)
+QgsRect QgsCoordinateTransform::transformBoundingBox(const QgsRect rect, TransformDirection direction) const
{
// Calculate the bounding box of a QgsRect in the source SRS
// when projected to the destination SRS (or the inverse).
@@ -409,7 +409,7 @@
return bb_rect;
}
-void QgsCoordinateTransform::transformCoords( const int& numPoints, double *x, double *y, double *z,TransformDirection direction)
+void QgsCoordinateTransform::transformCoords( const int& numPoints, double *x, double *y, double *z,TransformDirection direction) const
{
// Refuse to transform the points if the srs's are invalid
if (!mSourceSRS.isValid())
Modified: branches/rendercontext-branch/src/core/qgscoordinatetransform.h
===================================================================
--- branches/rendercontext-branch/src/core/qgscoordinatetransform.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgscoordinatetransform.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -125,7 +125,7 @@
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsPoint in Destination Coordinate System
*/
- QgsPoint transform(const QgsPoint p,TransformDirection direction=FORWARD);
+ QgsPoint transform(const QgsPoint p,TransformDirection direction=FORWARD) const;
/*! Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
@@ -135,7 +135,7 @@
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsPoint in Destination Coordinate System
*/
- QgsPoint transform(const double x, const double y,TransformDirection direction=FORWARD);
+ QgsPoint transform(const double x, const double y,TransformDirection direction=FORWARD) const;
/*! Transform a QgsRect to the dest Coordinate system
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
@@ -147,15 +147,15 @@
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsRect in Destination Coordinate System
*/
- QgsRect transformBoundingBox(const QgsRect theRect,TransformDirection direction=FORWARD);
+ QgsRect transformBoundingBox(const QgsRect theRect,TransformDirection direction=FORWARD) const;
// Same as for the other transform() functions, but alters the x
// and y variables in place. The second one works with good old-fashioned
// C style arrays.
- void transformInPlace(double& x, double& y, double &z, TransformDirection direction = FORWARD);
+ void transformInPlace(double& x, double& y, double &z, TransformDirection direction = FORWARD) const;
void transformInPlace(std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
- TransformDirection direction = FORWARD);
+ TransformDirection direction = FORWARD) const;
/*! Transform a QgsRect to the dest Coordinate system
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
@@ -164,7 +164,7 @@
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsRect in Destination Coordinate System
*/
- QgsRect transform(const QgsRect theRect,TransformDirection direction=FORWARD);
+ QgsRect transform(const QgsRect theRect,TransformDirection direction=FORWARD) const;
/*! Transform an array of coordinates to a different Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
@@ -174,7 +174,7 @@
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsRect in Destination Coordinate System
*/
- void transformCoords( const int &numPoint, double *x, double *y, double *z,TransformDirection direction=FORWARD);
+ void transformCoords( const int &numPoint, double *x, double *y, double *z,TransformDirection direction=FORWARD) const;
/*!
* Flag to indicate whether the coordinate systems have been initialised
@@ -217,7 +217,7 @@
signals:
/** Signal when an invalid pj_transform() has occured */
- void invalidTransformInput();
+ void invalidTransformInput() const;
private:
Modified: branches/rendercontext-branch/src/core/qgsmaplayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaplayer.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaplayer.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -32,7 +32,6 @@
#include "qgslogger.h"
-#include "qgsmaptopixel.h"
#include "qgsrect.h"
#include "qgssymbol.h"
#include "qgsmaplayer.h"
@@ -127,14 +126,12 @@
return mLayerExtent;
}
-
-bool QgsMapLayer::draw(QPainter *, QgsRect &, QgsMapToPixel *, QgsCoordinateTransform *, bool)
+bool QgsMapLayer::draw(QPainter* painter, const QgsRenderContext& renderContext)
{
- // std::cout << "In QgsMapLayer::draw" << std::endl;
- return false;
+ return false;
}
-void QgsMapLayer::drawLabels(QPainter *, QgsRect &, QgsMapToPixel *, QgsCoordinateTransform *)
+void QgsMapLayer::drawLabels(QPainter* painter, const QgsRenderContext& renderContext)
{
// std::cout << "In QgsMapLayer::draw" << std::endl;
}
Modified: branches/rendercontext-branch/src/core/qgsmaplayer.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaplayer.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaplayer.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -26,8 +26,7 @@
#include "qgsrect.h"
-class QgsCoordinateTransform;
-class QgsMapToPixel;
+class QgsRenderContext;
class QgsSpatialRefSys;
class QDomNode;
@@ -72,18 +71,12 @@
*/
QString const & name() const;
- /** Render the layer, to be overridden in child classes
- * @param painter Painter that to be used for rendered output
- * @param rect Extent of the layer to be drawn
- * @param mtp Transformation class
- * @return FALSE if an error occurred during drawing
- */
- virtual bool draw(QPainter* painter, QgsRect& rect, QgsMapToPixel* mtp, QgsCoordinateTransform* ct, bool);
-
+ virtual bool draw(QPainter* painter, const QgsRenderContext& renderContext);
+
/** Draw labels
* @TODO to be removed: used only in vector layers
*/
- virtual void drawLabels(QPainter* painter, QgsRect& rect, QgsMapToPixel* mtp, QgsCoordinateTransform* ct);
+ virtual void drawLabels(QPainter* painter, const QgsRenderContext& renderContext);
/** Return the extent of the layer as a QRect */
const QgsRect extent();
Modified: branches/rendercontext-branch/src/core/qgsmaprender.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaprender.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaprender.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -36,7 +36,6 @@
QgsMapRender::QgsMapRender()
{
- mCoordXForm = new QgsMapToPixel;
mScaleCalculator = new QgsScaleCalculator;
mDistArea = new QgsDistanceArea;
@@ -55,7 +54,6 @@
QgsMapRender::~QgsMapRender()
{
- delete mCoordXForm;
delete mScaleCalculator;
delete mDistArea;
delete mDestSRS;
@@ -64,12 +62,13 @@
QgsRect QgsMapRender::extent()
{
- return mExtent;
+ return mRenderContext.extent();
}
void QgsMapRender::updateScale()
{
- mScale = mScaleCalculator->calculate(mExtent, mSize.width());
+
+ mScale = mScaleCalculator->calculate(mRenderContext.extent(), mSize.width());
}
bool QgsMapRender::setExtent(const QgsRect& extent)
@@ -104,8 +103,8 @@
return false;
}
- mExtent = extent;
- if (!mExtent.isEmpty())
+ mRenderContext.setExtent(extent);
+ if (!extent.isEmpty())
adjustExtentToSize();
return true;
}
@@ -131,19 +130,22 @@
{
int myHeight = mSize.height();
int myWidth = mSize.width();
+
+ QgsMapToPixel newCoordXForm;
+ QgsRect theExtent = mRenderContext.extent();
if (!myWidth || !myHeight)
{
mScale = 1;
- mCoordXForm->setParameters(0, 0, 0, 0);
+ newCoordXForm.setParameters(0, 0, 0, 0);
return;
}
// calculate the translation and scaling parameters
// mupp = map units per pixel
- double muppY = static_cast<double>(mExtent.height())
+ double muppY = static_cast<double>(theExtent.height())
/ static_cast<double>(myHeight);
- double muppX = static_cast<double>(mExtent.width())
+ double muppX = static_cast<double>(theExtent.width())
/ static_cast<double>(myWidth);
mMupp = muppY > muppX ? muppY : muppX;
@@ -152,39 +154,39 @@
if (muppY > muppX)
{
- dymin = mExtent.yMin();
- dymax = mExtent.yMax();
- whitespace = ((myWidth * mMupp) - mExtent.width()) * 0.5;
- dxmin = mExtent.xMin() - whitespace;
- dxmax = mExtent.xMax() + whitespace;
+ dymin = theExtent.yMin();
+ dymax = theExtent.yMax();
+ whitespace = ((myWidth * mMupp) - theExtent.width()) * 0.5;
+ dxmin = theExtent.xMin() - whitespace;
+ dxmax = theExtent.xMax() + whitespace;
}
else
{
- dxmin = mExtent.xMin();
- dxmax = mExtent.xMax();
- whitespace = ((myHeight * mMupp) - mExtent.height()) * 0.5;
- dymin = mExtent.yMin() - whitespace;
- dymax = mExtent.yMax() + whitespace;
+ dxmin = theExtent.xMin();
+ dxmax = theExtent.xMax();
+ whitespace = ((myHeight * mMupp) - theExtent.height()) * 0.5;
+ dymin = theExtent.yMin() - whitespace;
+ dymax = theExtent.yMax() + whitespace;
}
#ifdef QGISDEBUG
QgsDebugMsg("========== Current Scale ==========");
- QgsDebugMsg("Current extent is " + mExtent.stringRep());
+ QgsDebugMsg("Current extent is " + theExtent.stringRep());
QgsLogger::debug("MuppX", muppX, 1, __FILE__, __FUNCTION__, __LINE__);
QgsLogger::debug("MuppY", muppY, 1, __FILE__, __FUNCTION__, __LINE__);
QgsLogger::debug("Pixmap width", myWidth, 1, __FILE__, __FUNCTION__, __LINE__);
QgsLogger::debug("Pixmap height", myHeight, 1, __FILE__, __FUNCTION__, __LINE__);
- QgsLogger::debug("Extent width", mExtent.width(), 1, __FILE__, __FUNCTION__, __LINE__);
- QgsLogger::debug("Extent height", mExtent.height(), 1, __FILE__, __FUNCTION__, __LINE__);
+ QgsLogger::debug("Extent width", theExtent.width(), 1, __FILE__, __FUNCTION__, __LINE__);
+ QgsLogger::debug("Extent height", theExtent.height(), 1, __FILE__, __FUNCTION__, __LINE__);
QgsLogger::debug("whitespace: ", whitespace, 1, __FILE__, __FUNCTION__, __LINE__);
#endif
// update extent
- mExtent.setXmin(dxmin);
- mExtent.setXmax(dxmax);
- mExtent.setYmin(dymin);
- mExtent.setYmax(dymax);
+ theExtent.setXmin(dxmin);
+ theExtent.setXmax(dxmax);
+ theExtent.setYmin(dymin);
+ theExtent.setYmax(dymax);
// update the scale
updateScale();
@@ -193,7 +195,9 @@
QgsLogger::debug("Scale (assuming meters as map units) = 1", mScale, 1, __FILE__, __FUNCTION__, __LINE__);
#endif
- mCoordXForm->setParameters(mMupp, dxmin, dymin, myHeight);
+ newCoordXForm.setParameters(mMupp, dxmin, dymin, myHeight);
+ mRenderContext.setMapToPixel(newCoordXForm);
+ mRenderContext.setExtent(theExtent);
}
@@ -201,7 +205,7 @@
{
QgsDebugMsg("========== Rendering ==========");
- if (mExtent.isEmpty())
+ if (mRenderContext.extent().isEmpty())
{
QgsLogger::debug("empty extent... not rendering");
return;
@@ -258,7 +262,8 @@
{
connect(ml, SIGNAL(drawingProgress(int,int)), this, SLOT(onDrawingProgress(int,int)));
- QgsRect r1 = mExtent, r2;
+ QgsRect r1 = mRenderContext.extent();
+ QgsRect r2;
bool split = splitLayersExtent(ml, r1, r2);
//
// Now do the call to the layer that actually does
@@ -273,14 +278,20 @@
{
ct = NULL;
}
+
+ mRenderContext.setCoordTransform(ct);
+ mRenderContext.setDrawEditingInformation(!mOverview);
+
+ if (!ml->draw(painter, mRenderContext))
+ {
+ emit drawError(ml);
+ }
- if (!ml->draw(painter, r1, mCoordXForm, ct, !mOverview))
- emit drawError(ml);
-
if (split)
{
- if (!ml->draw(painter, r2, mCoordXForm, ct, !mOverview))
- emit drawError(ml);
+ //todo: set render context extent to r2
+ //if (!ml->draw(painter, r2, mCoordXForm, ct, !mOverview))
+ //emit drawError(ml);
}
delete ct;
@@ -315,7 +326,9 @@
if ((ml->scaleBasedVisibility() && ml->minScale() < mScale && ml->maxScale() > mScale)
|| (!ml->scaleBasedVisibility()))
{
- QgsRect r1 = mExtent, r2;
+ QgsRect r1 = mRenderContext.extent();
+ QgsRect r2;
+
bool split = splitLayersExtent(ml, r1, r2);
if (projectionsEnabled())
@@ -327,9 +340,9 @@
ct = NULL;
}
- ml->drawLabels(painter, r1, mCoordXForm, ct);
+ //ml->drawLabels(painter, r1, mCoordXForm, ct);
if (split)
- ml->drawLabels(painter, r2, mCoordXForm, ct);
+ //ml->drawLabels(painter, r2, mCoordXForm, ct);
delete ct;
}
Modified: branches/rendercontext-branch/src/core/qgsmaprender.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaprender.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaprender.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -21,6 +21,7 @@
#include "qgis.h"
#include "qgsrect.h"
+#include "qgsrendercontext.h"
class QDomDocument;
class QDomNode;
@@ -59,7 +60,7 @@
//! returns current extent
QgsRect extent();
- QgsMapToPixel* coordXForm() { return mCoordXForm; }
+ const QgsMapToPixel* coordXForm() { return &(mRenderContext.mapToPixel()); }
double scale() const { return mScale; }
double mupp() const { return mMupp; }
@@ -127,6 +128,9 @@
//! write settings
bool writeXML(QDomNode & theNode, QDomDocument & theDoc);
+ //! Accessor for render context
+ QgsRenderContext* renderContext(){return &mRenderContext;}
+
signals:
void drawingProgress(int current, int total);
@@ -175,10 +179,10 @@
QgsScaleCalculator * mScaleCalculator;
//! utility class for transformation between map and pixmap units
- QgsMapToPixel* mCoordXForm;
+ //QgsMapToPixel* mCoordXForm; //in mRenderContext
//! current extent to be drawn
- QgsRect mExtent;
+ //QgsRect mExtent; //in mRenderContext
//! indicates whether it's map image for overview
bool mOverview;
@@ -199,6 +203,9 @@
//! tool for measuring
QgsDistanceArea* mDistArea;
+
+ //!Encapsulates context of rendering
+ QgsRenderContext mRenderContext;
};
#endif
Modified: branches/rendercontext-branch/src/core/qgsmaptopixel.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaptopixel.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaptopixel.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -36,20 +36,20 @@
{
}
-QgsPoint QgsMapToPixel::toMapPoint(int x, int y)
+QgsPoint QgsMapToPixel::toMapPoint(int x, int y) const
{
double mx = x * mMapUnitsPerPixel + xMin;
double my = -1 * ((y - yMax) * mMapUnitsPerPixel - yMin);
return QgsPoint(mx, my);
}
-QgsPoint QgsMapToPixel::toMapCoordinates(QPoint p)
+QgsPoint QgsMapToPixel::toMapCoordinates(QPoint p) const
{
QgsPoint mapPt = toMapPoint(p.x(), p.y());
return QgsPoint(mapPt);
}
-QgsPoint QgsMapToPixel::toMapCoordinates(int x, int y)
+QgsPoint QgsMapToPixel::toMapCoordinates(int x, int y) const
{
return toMapPoint(x, y);
}
@@ -98,13 +98,13 @@
}
-QgsPoint QgsMapToPixel::transform(double x, double y)
+QgsPoint QgsMapToPixel::transform(double x, double y) const
{
transformInPlace(x,y);
return QgsPoint(x,y);
}
-QgsPoint QgsMapToPixel::transform(const QgsPoint& p)
+QgsPoint QgsMapToPixel::transform(const QgsPoint& p) const
{
double dx = p.x();
double dy = p.y();
@@ -114,7 +114,7 @@
return QgsPoint(dx, dy);
}
-void QgsMapToPixel::transform(QgsPoint* p)
+void QgsMapToPixel::transform(QgsPoint* p) const
{
double x = p->x();
double y = p->y();
@@ -126,14 +126,14 @@
p->set(x,y);
}
-void QgsMapToPixel::transformInPlace(double& x, double& y)
+void QgsMapToPixel::transformInPlace(double& x, double& y) const
{
x = (x - xMin) / mMapUnitsPerPixel;
y = yMax - (y - yMin) / mMapUnitsPerPixel;
}
void QgsMapToPixel::transformInPlace(std::vector<double>& x,
- std::vector<double>& y)
+ std::vector<double>& y) const
{
assert(x.size() == y.size());
for (unsigned int i = 0; i < x.size(); ++i)
Modified: branches/rendercontext-branch/src/core/qgsmaptopixel.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaptopixel.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsmaptopixel.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -47,15 +47,15 @@
* @param p Point to transform
* @return QgsPoint in device coordinates
*/
- QgsPoint transform(const QgsPoint& p);
- void transform(QgsPoint* p);
+ QgsPoint transform(const QgsPoint& p) const;
+ void transform(QgsPoint* p) const;
/*! Transform the point specified by x,y from map (world)
* coordinates to device coordinates
* @param x x cordinate o point to transform
* @param y y coordinate of point to transform
* @return QgsPoint in device coordinates
*/
- QgsPoint transform(double x, double y);
+ QgsPoint transform(double x, double y) const;
/*! Tranform device coordinates to map (world) coordinates
* @param x x coordinate of point to be converted to map cooordinates
* @param y y coordinate of point to be converted to map cooordinates
@@ -65,22 +65,22 @@
/* Transform device coordinates to map coordinates. Modifies the
given coordinates in place. Intended as a fast way to do the
transform. */
- void transformInPlace(double& x, double& y);
+ void transformInPlace(double& x, double& y) const;
/* Transform device coordinates to map coordinates. Modifies the
given coordinates in place. Intended as a fast way to do the
transform. */
void transformInPlace(std::vector<double>& x,
- std::vector<double>& y);
+ std::vector<double>& y) const;
- QgsPoint toMapCoordinates(int x, int y);
+ QgsPoint toMapCoordinates(int x, int y) const;
/*! Tranform device coordinates to map (world) coordinates
* @param p Point to be converted to map cooordinates
* @return QgsPoint in map coorndiates
*/
- QgsPoint toMapCoordinates(QPoint p);
+ QgsPoint toMapCoordinates(QPoint p) const;
- QgsPoint toMapPoint(int x, int y);
+ QgsPoint toMapPoint(int x, int y) const;
/*! Set map units per pixel
* @param mupp Map units per pixel
*/
Modified: branches/rendercontext-branch/src/core/qgsrendercontext.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsrendercontext.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsrendercontext.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -18,7 +18,7 @@
#include "qgsrendercontext.h"
-QgsRenderContext::QgsRenderContext(): mCoordTransform(0), mDrawEditingInformation(false), mForceVectorOutput(true), mRenderingStopped(false)
+QgsRenderContext::QgsRenderContext(): mCoordTransform(0), mDrawEditingInformation(false), mForceVectorOutput(true), mRenderingStopped(false), mScaleFactor(1.0)
{
}
Modified: branches/rendercontext-branch/src/core/qgsrendercontext.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsrendercontext.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsrendercontext.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -32,9 +32,9 @@
//getters
const QgsCoordinateTransform* coordTransform() const {return mCoordTransform;}
- const QgsRect* extent() const {return &mExtent;}
+ const QgsRect& extent() const {return mExtent;}
- const QgsMapToPixel* mapToPixel() const {return &mMapToPixel;}
+ const QgsMapToPixel& mapToPixel() const {return mMapToPixel;}
double scaleFactor() const {return mScaleFactor;}
Modified: branches/rendercontext-branch/src/core/qgsscalecalculator.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsscalecalculator.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsscalecalculator.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -50,7 +50,7 @@
return mMapUnits;
}
-double QgsScaleCalculator::calculate(QgsRect &mapExtent, int canvasWidth)
+double QgsScaleCalculator::calculate(const QgsRect &mapExtent, int canvasWidth)
{
double conversionFactor = 0;
double delta = 0;
@@ -87,7 +87,7 @@
}
-double QgsScaleCalculator::calculateGeographicDistance(QgsRect &mapExtent)
+double QgsScaleCalculator::calculateGeographicDistance(const QgsRect &mapExtent)
{
// need to calculate the x distance in meters
// We'll use the middle latitude for the calculation
Modified: branches/rendercontext-branch/src/core/qgsscalecalculator.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsscalecalculator.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsscalecalculator.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -72,7 +72,7 @@
* @param canvasWidth Width of the map canvas in pixel (physical) units
* @return scale of current map view
*/
- double calculate(QgsRect &mapExtent, int canvasWidth);
+ double calculate(const QgsRect &mapExtent, int canvasWidth);
/**
* Calculate the distance between two points in geographic coordinates.
@@ -80,7 +80,7 @@
* data.
* @param mapExtent QgsRect containing the current map extent
*/
- double calculateGeographicDistance(QgsRect &mapExtent);
+ double calculateGeographicDistance(const QgsRect &mapExtent);
private:
Modified: branches/rendercontext-branch/src/core/qgsvectorlayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsvectorlayer.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsvectorlayer.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -63,6 +63,7 @@
#include "qgspoint.h"
#include "qgsproviderregistry.h"
#include "qgsrect.h"
+#include "qgsrendercontext.h"
#include "qgssinglesymbolrenderer.h"
#include "qgsspatialrefsys.h"
#include "qgsvectordataprovider.h"
@@ -275,9 +276,12 @@
}
}
-void QgsVectorLayer::drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * theMapToPixelTransform, QgsCoordinateTransform* ct)
+//void QgsVectorLayer::drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * theMapToPixelTransform, QgsCoordinateTransform* ct)
+void QgsVectorLayer::drawLabels(QPainter* painter, const QgsRenderContext& renderContext)
{
+#if 0 //todo: adapt to render context
drawLabels(p, viewExtent, theMapToPixelTransform, ct, 1.);
+#endif //0
}
// NOTE this is a temporary method added by Tim to prevent label clipping
@@ -351,8 +355,8 @@
unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
QPainter* p,
- QgsMapToPixel* mtp,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* mtp,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas)
{
unsigned char *ptr = feature + 5;
@@ -458,8 +462,8 @@
unsigned char* QgsVectorLayer::drawPolygon(unsigned char* feature,
QPainter* p,
- QgsMapToPixel* mtp,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* mtp,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas)
{
typedef std::pair<std::vector<double>, std::vector<double> > ringType;
@@ -707,25 +711,22 @@
return ptr;
}
-
-bool QgsVectorLayer::draw(QPainter * p,
- QgsRect & viewExtent,
- QgsMapToPixel * theMapToPixelTransform,
- QgsCoordinateTransform* ct,
- bool drawingToEditingCanvas)
+bool QgsVectorLayer::draw(QPainter* painter, const QgsRenderContext& renderContext)
{
//set update threshold before each draw to make sure the current setting is picked up
QSettings settings;
mUpdateThreshold = settings.readNumEntry("Map/updateThreshold", 0);
- draw ( p, viewExtent, theMapToPixelTransform, ct, drawingToEditingCanvas, 1., 1.);
-
+ //draw ( p, viewExtent, theMapToPixelTransform, ct, drawingToEditingCanvas, 1., 1.);
+
+ draw(painter, renderContext.extent(), &(renderContext.mapToPixel()), renderContext.coordTransform(), \
+ renderContext.drawEditingInformation(), renderContext.scaleFactor(), renderContext.scaleFactor());
return TRUE; // Assume success always
}
void QgsVectorLayer::draw(QPainter * p,
- QgsRect & viewExtent,
- QgsMapToPixel * theMapToPixelTransform,
- QgsCoordinateTransform* ct,
+ const QgsRect& viewExtent,
+ const QgsMapToPixel * theMapToPixelTransform,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas,
double widthScale,
double symbolScale)
@@ -2935,8 +2936,8 @@
void QgsVectorLayer::drawFeature(QPainter* p,
QgsFeature& fet,
- QgsMapToPixel * theMapToPixelTransform,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* theMapToPixelTransform,
+ const QgsCoordinateTransform* ct,
QImage * marker,
double markerScaleFactor,
bool drawingToEditingCanvas)
@@ -3187,8 +3188,8 @@
// Convenience function to transform the given point
inline void QgsVectorLayer::transformPoint(double& x,
double& y,
- QgsMapToPixel* mtp,
- QgsCoordinateTransform* ct)
+ const QgsMapToPixel* mtp,
+ const QgsCoordinateTransform* ct)
{
// transform the point
if (ct)
@@ -3204,7 +3205,7 @@
inline void QgsVectorLayer::transformPoints(
std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
- QgsMapToPixel* mtp, QgsCoordinateTransform* ct)
+ const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct)
{
// transform the point
if (ct)
Modified: branches/rendercontext-branch/src/core/qgsvectorlayer.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsvectorlayer.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/qgsvectorlayer.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -33,6 +33,7 @@
class QImage;
class QgsAttributeAction;
+class QgsCoordinateTransform;
class QgsField;
class QgsFeature;
class QgsGeometry;
@@ -333,26 +334,22 @@
const QgsNewAttributesMap& added,
const QgsChangedAttributesMap& changed);
- /** Draws the layer using coordinate transformation
+ /** Draws the layer
* @return FALSE if an error occurred during drawing
*/
- bool draw(QPainter * p,
- QgsRect & viewExtent,
- QgsMapToPixel * cXf,
- QgsCoordinateTransform* ct,
- bool drawingToEditingCanvas);
+ bool draw(QPainter* painter, const QgsRenderContext& renderContext);
/** Draws the layer labels using coordinate transformation */
- void drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * cXf, QgsCoordinateTransform* ct);
+ void drawLabels(QPainter* painter, const QgsRenderContext& renderContext);
/** \brief Draws the layer using coordinate transformation
* \param widthScale line width scale
* \param symbolScale symbol scale
*/
void draw(QPainter * p,
- QgsRect & viewExtent,
- QgsMapToPixel * cXf,
- QgsCoordinateTransform* ct,
+ const QgsRect& viewExtent,
+ const QgsMapToPixel * cXf,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas,
double widthScale,
double symbolScale);
@@ -439,26 +436,26 @@
*/
void drawFeature(QPainter* p,
QgsFeature& fet,
- QgsMapToPixel * cXf,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* cXf,
+ const QgsCoordinateTransform* ct,
QImage* marker,
double markerScaleFactor,
bool drawingToEditingCanvas);
/** Convenience function to transform the given point */
void transformPoint(double& x, double& y,
- QgsMapToPixel* mtp, QgsCoordinateTransform* ct);
+ const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct);
void transformPoints(std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
- QgsMapToPixel* mtp, QgsCoordinateTransform* ct);
+ const QgsMapToPixel* mtp, const QgsCoordinateTransform* ct);
/** Draw the linestring as given in the WKB format. Returns a pointer
* to the byte after the end of the line string binary data stream (WKB).
*/
unsigned char* drawLineString(unsigned char* WKBlinestring,
QPainter* p,
- QgsMapToPixel* mtp,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* mtp,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas);
/** Draw the polygon as given in the WKB format. Returns a pointer to
@@ -466,8 +463,8 @@
*/
unsigned char* drawPolygon(unsigned char* WKBpolygon,
QPainter* p,
- QgsMapToPixel* mtp,
- QgsCoordinateTransform* ct,
+ const QgsMapToPixel* mtp,
+ const QgsCoordinateTransform* ct,
bool drawingToEditingCanvas);
/** Goes through all features and finds a free id (e.g. to give it temporarily to a not-commited feature) */
Modified: branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -1000,14 +1000,9 @@
}
}
-
-
-bool QgsRasterLayer::draw(QPainter * theQPainter,
- QgsRect & theViewExtent,
- QgsMapToPixel * theQgsMapToPixel,
- QgsCoordinateTransform*,
- bool drawingToEditingCanvas)
+bool QgsRasterLayer::draw(QPainter* painter, const QgsRenderContext& renderContext)
{
+#if 0 //todo: adapt to render context
QgsDebugMsg("QgsRasterLayer::draw(4 arguments): entered.");
//Dont waste time drawing if transparency is at 0 (completely transparent)
@@ -1283,6 +1278,7 @@
delete myRasterViewPort;
QgsDebugMsg("QgsRasterLayer::draw: exiting.");
+#endif //0
return TRUE;
Modified: branches/rendercontext-branch/src/core/raster/qgsrasterlayer.h
===================================================================
--- branches/rendercontext-branch/src/core/raster/qgsrasterlayer.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/core/raster/qgsrasterlayer.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -158,6 +158,7 @@
// Forward declarations
//
class QgsColorTable;
+class QgsMapToPixel;
class QgsRect;
class QgsRasterBandStats;
class QgsRasterPyramid;
@@ -275,16 +276,8 @@
QPixmap getPaletteAsPixmap();
/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn).
-
- \param drawingToEditingCanvas Are we drawing to an editable canvas?
- currently not used, but retain to be similar to
- the QgsVectorLayer interface
*/
- bool draw(QPainter * theQPainter,
- QgsRect & theViewExtent,
- QgsMapToPixel * theQgsMapToPixel,
- QgsCoordinateTransform* ct,
- bool drawingToEditingCanvas);
+ bool draw(QPainter* painter, const QgsRenderContext& renderContext);
/** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */
void draw(QPainter * theQPainter, QgsRasterViewPort * myRasterViewPort,
Modified: branches/rendercontext-branch/src/gui/qgsmapcanvas.cpp
===================================================================
--- branches/rendercontext-branch/src/gui/qgsmapcanvas.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/gui/qgsmapcanvas.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -213,7 +213,7 @@
// return the current coordinate transform based on the extents and
// device size
-QgsMapToPixel * QgsMapCanvas::getCoordinateTransform()
+const QgsMapToPixel * QgsMapCanvas::getCoordinateTransform()
{
return mMapRender->coordXForm();
}
Modified: branches/rendercontext-branch/src/gui/qgsmapcanvas.h
===================================================================
--- branches/rendercontext-branch/src/gui/qgsmapcanvas.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/gui/qgsmapcanvas.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -198,7 +198,7 @@
QGis::units mapUnits() const;
//! Get the current coordinate transform
- QgsMapToPixel * getCoordinateTransform();
+ const QgsMapToPixel* getCoordinateTransform();
//! true if canvas currently drawing
bool isDrawing();
Modified: branches/rendercontext-branch/src/gui/qgsmapoverviewcanvas.cpp
===================================================================
--- branches/rendercontext-branch/src/gui/qgsmapoverviewcanvas.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/gui/qgsmapoverviewcanvas.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -99,7 +99,7 @@
return;
}
- QgsMapToPixel* cXf = mMapRender->coordXForm();
+ const QgsMapToPixel* cXf = mMapRender->coordXForm();
QgsPoint ll(extent.xMin(), extent.yMin());
QgsPoint ur(extent.xMax(), extent.yMax());
if(cXf)
@@ -183,7 +183,7 @@
if ((e->state() && Qt::LeftButton) == Qt::LeftButton)
{
// set new extent
- QgsMapToPixel* cXf = mMapRender->coordXForm();
+ const QgsMapToPixel* cXf = mMapRender->coordXForm();
QRect rect = mPanningWidget->geometry();
QgsPoint center = cXf->toMapCoordinates(rect.center());
Modified: branches/rendercontext-branch/src/gui/qgsmaptoolzoom.cpp
===================================================================
--- branches/rendercontext-branch/src/gui/qgsmaptoolzoom.cpp 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/gui/qgsmaptoolzoom.cpp 2008-03-16 16:04:52 UTC (rev 8230)
@@ -76,7 +76,7 @@
mZoomRect.setRight(e->pos().x());
mZoomRect.setBottom(e->pos().y());
- QgsMapToPixel *coordXForm = mCanvas->getCoordinateTransform();
+ const QgsMapToPixel* coordXForm = mCanvas->getCoordinateTransform();
// set the extent to the zoomBox
QgsPoint ll = coordXForm->toMapCoordinates(mZoomRect.left(), mZoomRect.bottom());
Modified: branches/rendercontext-branch/src/plugins/grass/qgsgrassedit.h
===================================================================
--- branches/rendercontext-branch/src/plugins/grass/qgsgrassedit.h 2008-03-16 08:56:35 UTC (rev 8229)
+++ branches/rendercontext-branch/src/plugins/grass/qgsgrassedit.h 2008-03-16 16:04:52 UTC (rev 8230)
@@ -330,7 +330,7 @@
//QPixmap *mBackgroundPixmap;
//! Transformation
- QgsMapToPixel *mTransform;
+ const QgsMapToPixel* mTransform;
//! Last point where user clicked (map units)
QgsPoint mLastPoint;
More information about the QGIS-commit
mailing list