diff --git a/src/app/qgslabelpropertydialog.h b/src/app/qgslabelpropertydialog.h index 65f4abd40fb..4b08e6efbf4 100644 --- a/src/app/qgslabelpropertydialog.h +++ b/src/app/qgslabelpropertydialog.h @@ -23,7 +23,6 @@ #include "qgspallabeling.h" #include -class QgsMapRenderer; /**A dialog to enter data defined label attributes*/ class APP_EXPORT QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPropertyDialogBase diff --git a/src/core/qgsmaprenderer.cpp b/src/core/qgsmaprenderer.cpp index 4a0ebd0a98a..e784b486907 100644 --- a/src/core/qgsmaprenderer.cpp +++ b/src/core/qgsmaprenderer.cpp @@ -117,6 +117,8 @@ bool QgsMapRenderer::setExtent( const QgsRectangle& extent ) mExtent = extent; if ( !extent.isEmpty() ) adjustExtentToSize(); + + emit extentsChanged(); return true; } diff --git a/src/core/qgsmaprenderer.h b/src/core/qgsmaprenderer.h index f1fb1fe1c47..099c0b2026c 100644 --- a/src/core/qgsmaprenderer.h +++ b/src/core/qgsmaprenderer.h @@ -164,129 +164,129 @@ class CORE_EXPORT QgsMapRenderer : public QObject //! starts rendering //! @ param forceWidthScale Force a specific scale factor for line widths and marker sizes. Automatically calculated from output device DPI if 0 - Q_DECL_DEPRECATED void render( QPainter* painter, double* forceWidthScale = 0 ); + void render( QPainter* painter, double* forceWidthScale = 0 ); //! sets extent and checks whether suitable (returns false if not) - Q_DECL_DEPRECATED bool setExtent( const QgsRectangle& extent ); + bool setExtent( const QgsRectangle& extent ); //! returns current extent - Q_DECL_DEPRECATED QgsRectangle extent() const; + QgsRectangle extent() const; - Q_DECL_DEPRECATED const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } + const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); } //! Scale denominator - Q_DECL_DEPRECATED double scale() const { return mScale; } + double scale() const { return mScale; } /**Sets scale for scale based visibility. Normally, the scale is calculated automatically. This function is only used to force a preview scale (e.g. for print composer)*/ - Q_DECL_DEPRECATED void setScale( double scale ) {mScale = scale;} - Q_DECL_DEPRECATED double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } + void setScale( double scale ) {mScale = scale;} + double mapUnitsPerPixel() const { return mMapUnitsPerPixel; } - Q_DECL_DEPRECATED int width() const { return mSize.width(); } - Q_DECL_DEPRECATED int height() const { return mSize.height(); } + int width() const { return mSize.width(); } + int height() const { return mSize.height(); } //! Recalculate the map scale - Q_DECL_DEPRECATED void updateScale(); + void updateScale(); - Q_DECL_DEPRECATED QGis::UnitType mapUnits() const; - Q_DECL_DEPRECATED void setMapUnits( QGis::UnitType u ); + QGis::UnitType mapUnits() const; + void setMapUnits( QGis::UnitType u ); //! sets whether map image will be for overview - Q_DECL_DEPRECATED void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } + void enableOverviewMode( bool isOverview = true ) { mOverview = isOverview; } - Q_DECL_DEPRECATED void setOutputSize( QSize size, int dpi ); - Q_DECL_DEPRECATED void setOutputSize( QSizeF size, double dpi ); + void setOutputSize( QSize size, int dpi ); + void setOutputSize( QSizeF size, double dpi ); //!accessor for output dpi - Q_DECL_DEPRECATED double outputDpi(); + double outputDpi(); //!accessor for output size - Q_DECL_DEPRECATED QSize outputSize(); - Q_DECL_DEPRECATED QSizeF outputSizeF(); + QSize outputSize(); + QSizeF outputSizeF(); /** * @brief transform bounding box from layer's CRS to output CRS * @see layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - Q_DECL_DEPRECATED QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); + QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ); /** * @brief transform bounding box from output CRS to layer's CRS * @see mapToLayerCoordinates( QgsMapLayer* theLayer,QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - Q_DECL_DEPRECATED QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ); + QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ); /** * @brief transform point coordinates from layer's CRS to output CRS * @return the transformed point */ - Q_DECL_DEPRECATED QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); + QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ); /** * @brief transform rectangle from layer's CRS to output CRS * @see layerExtentToOutputExtent() if you want to transform a bounding box * @return the transformed rectangle */ - Q_DECL_DEPRECATED QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); + QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); /** * @brief transform point coordinates from output CRS to layer's CRS * @return the transformed point */ - Q_DECL_DEPRECATED QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); + QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ); /** * @brief transform rectangle from output CRS to layer's CRS * @see outputExtentToLayerExtent() if you want to transform a bounding box * @return the transformed rectangle */ - Q_DECL_DEPRECATED QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); + QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ); //! sets whether to use projections for this layer set - Q_DECL_DEPRECATED void setProjectionsEnabled( bool enabled ); + void setProjectionsEnabled( bool enabled ); //! returns true if projections are enabled for this layer set - Q_DECL_DEPRECATED bool hasCrsTransformEnabled() const; + bool hasCrsTransformEnabled() const; //! sets destination coordinate reference system - Q_DECL_DEPRECATED void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); + void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ); //! returns CRS of destination coordinate reference system - Q_DECL_DEPRECATED const QgsCoordinateReferenceSystem& destinationCrs() const; + const QgsCoordinateReferenceSystem& destinationCrs() const; - Q_DECL_DEPRECATED void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} + void setOutputUnits( OutputUnits u ) {mOutputUnits = u;} - Q_DECL_DEPRECATED OutputUnits outputUnits() const {return mOutputUnits;} + OutputUnits outputUnits() const {return mOutputUnits;} //! returns current extent of layer set - Q_DECL_DEPRECATED QgsRectangle fullExtent(); + QgsRectangle fullExtent(); //! returns current layer set - Q_DECL_DEPRECATED QStringList& layerSet(); + QStringList& layerSet(); //! change current layer set - Q_DECL_DEPRECATED void setLayerSet( const QStringList& layers ); + void setLayerSet( const QStringList& layers ); //! updates extent of the layer set - Q_DECL_DEPRECATED void updateFullExtent(); + void updateFullExtent(); //! read settings - Q_DECL_DEPRECATED bool readXML( QDomNode & theNode ); + bool readXML( QDomNode & theNode ); //! write settings - Q_DECL_DEPRECATED bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); + bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); //! Accessor for render context - Q_DECL_DEPRECATED QgsRenderContext* rendererContext() {return &mRenderContext;} + QgsRenderContext* rendererContext() {return &mRenderContext;} //! Labeling engine (NULL if there's no custom engine) //! \note Added in QGIS v1.4 - Q_DECL_DEPRECATED QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } + QgsLabelingEngineInterface* labelingEngine() { return mLabelingEngine; } //! Set labeling engine. Previous engine (if any) is deleted. //! Takes ownership of the engine. //! Added in QGIS v1.4 - Q_DECL_DEPRECATED void setLabelingEngine( QgsLabelingEngineInterface* iface ); + void setLabelingEngine( QgsLabelingEngineInterface* iface ); //! Returns a QPainter::CompositionMode corresponding to a BlendMode //! Added in 1.9 @@ -315,6 +315,10 @@ class CORE_EXPORT QgsMapRenderer : public QObject //! emitted when layer's draw() returned false void drawError( QgsMapLayer* ); + //! emitted when the current extent gets changed + //! @note added in 2.1 + void extentsChanged(); + public slots: //! @deprecated in 2.1 - does nothing diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index c12a5ba4816..41f1ac34f71 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -81,6 +81,83 @@ class QgsMapCanvas::CanvasProperties +QgsMapCanvasRendererSync::QgsMapCanvasRendererSync( QgsMapCanvas* canvas, QgsMapRenderer* renderer ) + : QObject( canvas ) + , mCanvas( canvas ) + , mRenderer( renderer ) +{ + connect( mCanvas, SIGNAL(extentsChanged()), this, SLOT(onExtentC2R()) ); + connect( mRenderer, SIGNAL(extentsChanged()), this, SLOT(onExtentR2C()) ); + + connect( mCanvas, SIGNAL(mapUnitsChanged()), this, SLOT(onMapUnitsC2R()) ); + connect( mRenderer, SIGNAL(mapUnitsChanged()), this, SLOT(onMapUnitsR2C()) ); + + connect( mCanvas, SIGNAL(hasCrsTransformEnabled(bool)), this, SLOT(onCrsTransformC2R()) ); + connect( mRenderer, SIGNAL(hasCrsTransformEnabled(bool)), this, SLOT(onCrsTransformR2C()) ); + + connect( mCanvas, SIGNAL(destinationSrsChanged()), this, SLOT(onDestCrsC2R()) ); + connect( mRenderer, SIGNAL(destinationSrsChanged()), this, SLOT(onDestCrsR2C()) ); + + connect( mCanvas, SIGNAL(layersChanged()), this, SLOT(onLayersC2R()) ); + // TODO: layers R2C ? (should not happen!) + +} + +void QgsMapCanvasRendererSync::onExtentC2R() +{ + mRenderer->blockSignals( true ); + mRenderer->setExtent( mCanvas->mapSettings().extent() ); + mRenderer->blockSignals( false ); +} + +void QgsMapCanvasRendererSync::onExtentR2C() +{ + mCanvas->setExtent( mRenderer->extent() ); +} + +void QgsMapCanvasRendererSync::onMapUnitsC2R() +{ + mRenderer->blockSignals( true ); + mRenderer->setMapUnits( mCanvas->mapSettings().mapUnits() ); + mRenderer->blockSignals( false ); +} + +void QgsMapCanvasRendererSync::onMapUnitsR2C() +{ + mCanvas->setMapUnits( mRenderer->mapUnits() ); +} + +void QgsMapCanvasRendererSync::onCrsTransformC2R() +{ + mRenderer->blockSignals( true ); + mRenderer->setProjectionsEnabled( mCanvas->mapSettings().hasCrsTransformEnabled() ); + mRenderer->blockSignals( false ); +} + +void QgsMapCanvasRendererSync::onCrsTransformR2C() +{ + mCanvas->setCrsTransformEnabled( mRenderer->hasCrsTransformEnabled() ); +} + +void QgsMapCanvasRendererSync::onDestCrsC2R() +{ + mRenderer->blockSignals( true ); + mRenderer->setDestinationCrs( mCanvas->mapSettings().destinationCrs() ); + mRenderer->blockSignals( false ); +} + +void QgsMapCanvasRendererSync::onDestCrsR2C() +{ + mCanvas->setDestinationCrs( mRenderer->destinationCrs() ); +} + +void QgsMapCanvasRendererSync::onLayersC2R() +{ + mRenderer->setLayerSet( mCanvas->mapSettings().layers() ); +} + + + QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name ) : QGraphicsView( parent ) , mCanvasProperties( new CanvasProperties ) @@ -128,7 +205,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name ) mSettings.setFlag( QgsMapSettings::DrawEditingInfo ); + // class that will sync most of the changes between canvas and (legacy) map renderer + // it is parented to map canvas, will be deleted automatically + new QgsMapCanvasRendererSync( this, mMapRenderer ); + mSettings.setOutputSize( size() ); + mMapRenderer->setOutputSize( size(), mSettings.outputDpi() ); setSceneRect( 0, 0, size().width(), size().height() ); mScene->setSceneRect( QRectF( 0, 0, size().width(), size().height() ) ); @@ -776,24 +858,6 @@ bool QgsMapCanvas::hasCrsTransformEnabled() return mapSettings().hasCrsTransformEnabled(); } -void QgsMapCanvas::mapUnitsChanged() -{ - // We assume that if the map units have changed, the changed value - // will be accessible from QgsMapRenderer - - // And then force a redraw of the scale number in the status bar - updateScale(); - - // And then redraw the map to force the scale bar to update - // itself. This is less than ideal as the entire map gets redrawn - // just to get the scale bar to redraw itself. If we ask the scale - // bar to redraw itself without redrawing the map, the existing - // scale bar is not removed, and we end up with two scale bars in - // the same location. This can perhaps be fixed when/if the scale - // bar is done as a transparent layer on top of the map canvas. - refresh(); -} - void QgsMapCanvas::zoomToSelected( QgsVectorLayer* layer ) { if ( layer == NULL ) @@ -1076,6 +1140,7 @@ void QgsMapCanvas::resizeEvent( QResizeEvent * e ) QSize lastSize = size(); mSettings.setOutputSize( lastSize ); + mMapRenderer->setOutputSize( lastSize, mSettings.outputDpi() ); mScene->setSceneRect( QRectF( 0, 0, lastSize.width(), lastSize.height() ) ); @@ -1364,6 +1429,12 @@ void QgsMapCanvas::setMapUnits( QGis::UnitType u ) { QgsDebugMsg( "Setting map units to " + QString::number( static_cast( u ) ) ); mSettings.setMapUnits( u ); + + updateScale(); + + refresh(); // this will force the scale bar to be updated + + emit mapUnitsChanged(); } diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index e58d74274a8..b764b2b356c 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -318,9 +318,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView /** A simple helper method to find out if on the fly projections are enabled or not */ bool hasCrsTransformEnabled(); - /** The map units may have changed, so cope with that */ - void mapUnitsChanged(); - //! @deprecated in 2.1 - does nothing - kept for API compatibility Q_DECL_DEPRECATED void updateMap(); @@ -417,6 +414,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView //! @note added in 2.1 void destinationSrsChanged(); + //! Emmitted when map units are changed + //! @note added in 2.1 + void mapUnitsChanged(); + protected: #ifdef HAVE_TOUCH //! Overridden standard event to be gestures aware @@ -540,4 +541,40 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView }; // class QgsMapCanvas + + +/** Class that does synchronization between QgsMapCanvas and its associated QgsMapRenderer: + * - changes done in map canvas settings are pushed to map renderer + * - changes done in map renderer are pushed to map canvas settings + * + * This class can be removed within API cleanup when QgsMapRenderer will not be accessible from canvas API anymore. + * Added in 2.1. This class is not a part of public API! + */ +class QgsMapCanvasRendererSync : public QObject +{ + Q_OBJECT +public: + QgsMapCanvasRendererSync( QgsMapCanvas* canvas, QgsMapRenderer* renderer ); + +protected slots: + void onExtentC2R(); + void onExtentR2C(); + + void onMapUnitsC2R(); + void onMapUnitsR2C(); + + void onCrsTransformC2R(); + void onCrsTransformR2C(); + + void onDestCrsC2R(); + void onDestCrsR2C(); + + void onLayersC2R(); + +protected: + QgsMapCanvas* mCanvas; + QgsMapRenderer* mRenderer; +}; + + #endif diff --git a/src/gui/qgsmapoverviewcanvas.h b/src/gui/qgsmapoverviewcanvas.h index 572fdb5c9ad..db1881a07fd 100644 --- a/src/gui/qgsmapoverviewcanvas.h +++ b/src/gui/qgsmapoverviewcanvas.h @@ -27,7 +27,6 @@ #include class QgsMapCanvas; -class QgsMapRenderer; class QgsPanningWidget; // defined in .cpp class QgsRectangle;