Skip to content

Commit

Permalink
Show marker sizes and line widths in composer in proportion to the page
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 8, 2011
1 parent 06bda9c commit 365c33d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const

/* This function is called by paint() and cache() to render the map. It does not override any functions
from QGraphicsItem. */
void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi )
void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale )
{
if ( !painter )
{
Expand Down Expand Up @@ -174,7 +174,14 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
bool bkLayerCaching = s.value( "/qgis/enable_render_caching", false ).toBool();
s.setValue( "/qgis/enable_render_caching", false );

theMapRenderer.render( painter );
if ( forceWidthScale ) //force wysiwyg line widths / marker sizes
{
theMapRenderer.render( painter, forceWidthScale );
}
else
{
theMapRenderer.render( painter );
}
s.setValue( "/qgis/enable_render_caching", bkLayerCaching );

theMapRenderer.setScale( bk_scale );
Expand Down Expand Up @@ -217,6 +224,8 @@ void QgsComposerMap::cache( void )
h = 5000;
}

double forcedWidthScaleFactor = w / requestExtent.width() / mapUnitsToMM();

mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
mCacheImage.fill( brush().color().rgb() ); //consider the item background brush
double mapUnitsPerPixel = mExtent.width() / w;
Expand All @@ -226,7 +235,7 @@ void QgsComposerMap::cache( void )

QPainter p( &mCacheImage );

draw( &p, requestExtent, QSizeF( w, h ), mCacheImage.logicalDpiX() );
draw( &p, requestExtent, QSizeF( w, h ), mCacheImage.logicalDpiX(), &forcedWidthScaleFactor );
p.end();
mCacheUpdated = true;

Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
@param extent map extent
@param size size in scene coordinates
@param dpi scene dpi*/
void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi );
void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 );

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
Expand Down
11 changes: 9 additions & 2 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void QgsMapRenderer::adjustExtentToSize()
}


void QgsMapRenderer::render( QPainter* painter )
void QgsMapRenderer::render( QPainter* painter, double* forceScaleFactor )
{
//Lock render method for concurrent threads (e.g. from globe)
QMutexLocker renderLock( &mRenderMutex );
Expand Down Expand Up @@ -282,7 +282,14 @@ void QgsMapRenderer::render( QPainter* painter )
double scaleFactor = 1.0;
if ( mOutputUnits == QgsMapRenderer::Millimeters )
{
scaleFactor = sceneDpi / 25.4;
if ( forceScaleFactor )
{
scaleFactor = *forceScaleFactor;
}
else
{
scaleFactor = sceneDpi / 25.4;
}
}
double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
if ( mRenderContext.rasterScaleFactor() != rasterScaleFactor )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
~QgsMapRenderer();

//! starts rendering
void render( QPainter* painter );
void render( QPainter* painter, double* forceScaleFactor = 0 );

//! sets extent and checks whether suitable (returns false if not)
bool setExtent( const QgsRectangle& extent );
Expand Down

0 comments on commit 365c33d

Please sign in to comment.