Skip to content

Commit f204329

Browse files
author
mhugent
committed
Better preview for composer picture
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12186 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8d7c478 commit f204329

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/core/composer/qgscomposerpicture.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
#include <QPainter>
2727
#include <QSvgRenderer>
2828

29+
2930
QgsComposerPicture::QgsComposerPicture( QgsComposition *composition ): QgsComposerItem( composition ), mMode( Unknown ), \
30-
mSvgCacheUpToDate( false ), mCachedDpi( 0 ), mCachedRotation( 0 ), mRotationMap( 0 )
31+
mSvgCacheUpToDate( false ), mCachedDpi( 0 ), mCachedRotation( 0 ), mCachedViewScaleFactor( -1 ), mRotationMap( 0 )
3132
{
3233
}
3334

34-
QgsComposerPicture::QgsComposerPicture(): QgsComposerItem( 0 ), mMode( Unknown ), mSvgCacheUpToDate( false ), mCachedRotation( 0 ), mRotationMap( 0 )
35+
QgsComposerPicture::QgsComposerPicture(): QgsComposerItem( 0 ), mMode( Unknown ), mSvgCacheUpToDate( false ), mCachedRotation( 0 ), mCachedViewScaleFactor( -1 ), mRotationMap( 0 )
3536
{
3637

3738
}
@@ -51,7 +52,9 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
5152
drawBackground( painter );
5253

5354
int newDpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
54-
if ( newDpi != mCachedDpi || mCachedRotation != mRotation )
55+
double viewScaleFactor = horizontalViewScaleFactor();
56+
57+
if ( newDpi != mCachedDpi || mCachedRotation != mRotation || mCachedViewScaleFactor != viewScaleFactor )
5558
{
5659
mSvgCacheUpToDate = false;
5760
}
@@ -82,6 +85,12 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
8285
{
8386
if ( !mSvgCacheUpToDate )
8487
{
88+
//make nicer preview
89+
if ( mComposition && mComposition->plotStyle() == QgsComposition::Preview )
90+
{
91+
rotatedBoundImageWidth *= std::min( viewScaleFactor, 10.0 );
92+
rotatedBoundImageHeight *= std::min( viewScaleFactor, 10.0 );
93+
}
8594
mImage = QImage( rotatedBoundImageWidth, rotatedBoundImageHeight, QImage::Format_ARGB32 );
8695
updateImageFromSvg();
8796
}
@@ -91,13 +100,20 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
91100
painter->translate( boundRectWidthMM / 2.0, boundRectHeightMM / 2.0 );
92101
painter->rotate( mRotation );
93102
painter->translate( -rotatedBoundImageWidthMM / 2.0, -rotatedBoundImageHeightMM / 2.0 );
103+
104+
/*if ( mComposition && mComposition->plotStyle() == QgsComposition::Preview )
105+
{
106+
rotatedBoundImageWidthMM /= std::min( viewScaleFactor, 10.0 );
107+
rotatedBoundImageHeightMM /= std::min( viewScaleFactor, 10.0 );
108+
}*/
94109
painter->drawImage( QRectF( 0, 0, rotatedBoundImageWidthMM, rotatedBoundImageHeightMM ), mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
95110

96111
painter->restore();
97112
}
98113

99114
mCachedDpi = newDpi;
100115
mCachedRotation = mRotation;
116+
mCachedViewScaleFactor = viewScaleFactor;
101117

102118
//frame and selection boxes
103119
drawFrame( painter );

src/core/composer/qgscomposerpicture.h

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
8989
bool mSvgCacheUpToDate;
9090
int mCachedDpi; //store dpis for which the svg cache is valid
9191
double mCachedRotation; //store last rotation value to generate new pixmap from svg on change
92+
double mCachedViewScaleFactor;
93+
9294
QSize mDefaultSvgSize;
9395
/**Map that sets the rotation (or 0 if this picture uses map independent rotation)*/
9496
const QgsComposerMap* mRotationMap;

0 commit comments

Comments
 (0)