mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-19 00:02:48 -04:00
Avoid use of composition map settings to set initial composer map extent
This commit is contained in:
parent
a3dd380d35
commit
710a12cabd
@ -133,6 +133,9 @@ class QgsComposerView : QGraphicsView
|
||||
*/
|
||||
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
|
||||
|
||||
void setMapCanvas( QgsMapCanvas* canvas );
|
||||
QgsMapCanvas* mapCanvas() const;
|
||||
|
||||
protected:
|
||||
void mousePressEvent( QMouseEvent* );
|
||||
void mouseReleaseEvent( QMouseEvent* );
|
||||
|
@ -4027,6 +4027,7 @@ void QgsComposer::createComposerView()
|
||||
|
||||
delete mView;
|
||||
mView = new QgsComposerView();
|
||||
mView->setMapCanvas( mQgis->mapCanvas() );
|
||||
mView->setContentsMargins( 0, 0, 0, 0 );
|
||||
mView->setHorizontalRuler( mHorizontalRuler );
|
||||
mView->setVerticalRuler( mVerticalRuler );
|
||||
|
@ -85,9 +85,6 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
|
||||
int bgBlueInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
|
||||
setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
|
||||
|
||||
//calculate mExtent based on width/height ratio and map canvas extent
|
||||
mExtent = mComposition->mapSettings().visibleExtent();
|
||||
|
||||
init();
|
||||
|
||||
setSceneRect( QRectF( x, y, width, height ) );
|
||||
@ -775,9 +772,14 @@ void QgsComposerMap::setNewExtent( const QgsRectangle& extent )
|
||||
void QgsComposerMap::zoomToExtent( const QgsRectangle &extent )
|
||||
{
|
||||
QgsRectangle newExtent = extent;
|
||||
QgsRectangle currentExtent = *currentMapExtent();
|
||||
//Make sure the width/height ratio is the same as the current composer map extent.
|
||||
//This is to keep the map item frame size fixed
|
||||
double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
|
||||
double currentWidthHeightRatio = 1.0;
|
||||
if ( !currentExtent.isNull() )
|
||||
currentWidthHeightRatio = currentExtent.width() / currentExtent.height();
|
||||
else
|
||||
currentWidthHeightRatio = rect().width() / rect().height();
|
||||
double newWidthHeightRatio = newExtent.width() / newExtent.height();
|
||||
|
||||
if ( currentWidthHeightRatio < newWidthHeightRatio )
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include "qgscomposerattributetablev2.h"
|
||||
#include "qgsaddremovemultiframecommand.h"
|
||||
#include "qgspaperitem.h"
|
||||
#include "qgsmapcanvas.h" //for QgsMapCanvas::WheelAction
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgscursors.h"
|
||||
#include "qgscomposerutils.h"
|
||||
|
||||
@ -997,6 +997,9 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
|
||||
else
|
||||
{
|
||||
QgsComposerMap* composerMap = new QgsComposerMap( composition(), mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height() );
|
||||
if ( mCanvas )
|
||||
composerMap->zoomToExtent( mCanvas->mapSettings().visibleExtent() );
|
||||
|
||||
composition()->addComposerMap( composerMap );
|
||||
|
||||
composition()->setAllDeselected();
|
||||
@ -2103,6 +2106,16 @@ void QgsComposerView::setPreviewMode( QgsPreviewEffect::PreviewMode mode )
|
||||
mPreviewEffect->setMode( mode );
|
||||
}
|
||||
|
||||
void QgsComposerView::setMapCanvas( QgsMapCanvas* canvas )
|
||||
{
|
||||
mCanvas = canvas;
|
||||
}
|
||||
|
||||
QgsMapCanvas*QgsComposerView::mapCanvas() const
|
||||
{
|
||||
return mCanvas;
|
||||
}
|
||||
|
||||
void QgsComposerView::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
if ( mPaintingEnabled )
|
||||
|
@ -39,6 +39,7 @@ class QgsComposerScaleBar;
|
||||
class QgsComposerShape;
|
||||
class QgsComposerNodesItem;
|
||||
class QgsComposerAttributeTableV2;
|
||||
class QgsMapCanvas;
|
||||
|
||||
/** \ingroup gui
|
||||
* Widget to display the composer items. Manages the composer tools and the
|
||||
@ -170,6 +171,20 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
|
||||
*/
|
||||
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
|
||||
|
||||
/** Sets the map canvas associated with the view. This allows the
|
||||
* view to retrieve map settings from the canvas.
|
||||
* @note added in QGIS 3.0
|
||||
* @see mapCanvas()
|
||||
*/
|
||||
void setMapCanvas( QgsMapCanvas* canvas );
|
||||
|
||||
/**
|
||||
* Returns the map canvas associated with the view.
|
||||
* @see setMapCanvas()
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
QgsMapCanvas* mapCanvas() const;
|
||||
|
||||
protected:
|
||||
void mousePressEvent( QMouseEvent* ) override;
|
||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||
@ -218,6 +233,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
|
||||
QgsComposerRuler* mHorizontalRuler;
|
||||
QgsComposerRuler* mVerticalRuler;
|
||||
|
||||
QgsMapCanvas* mCanvas = nullptr;
|
||||
|
||||
//! Draw a shape on the canvas
|
||||
void addShape( Tool currentTool );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user