Skip to content

Commit

Permalink
Better preview for composer picture
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12186 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 19, 2009
1 parent dc1b892 commit a5574d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -26,12 +26,13 @@
#include <QPainter>
#include <QSvgRenderer>


QgsComposerPicture::QgsComposerPicture( QgsComposition *composition ): QgsComposerItem( composition ), mMode( Unknown ), \
mSvgCacheUpToDate( false ), mCachedDpi( 0 ), mCachedRotation( 0 ), mRotationMap( 0 )
mSvgCacheUpToDate( false ), mCachedDpi( 0 ), mCachedRotation( 0 ), mCachedViewScaleFactor( -1 ), mRotationMap( 0 )
{
}

QgsComposerPicture::QgsComposerPicture(): QgsComposerItem( 0 ), mMode( Unknown ), mSvgCacheUpToDate( false ), mCachedRotation( 0 ), mRotationMap( 0 )
QgsComposerPicture::QgsComposerPicture(): QgsComposerItem( 0 ), mMode( Unknown ), mSvgCacheUpToDate( false ), mCachedRotation( 0 ), mCachedViewScaleFactor( -1 ), mRotationMap( 0 )
{

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

int newDpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
if ( newDpi != mCachedDpi || mCachedRotation != mRotation )
double viewScaleFactor = horizontalViewScaleFactor();

if ( newDpi != mCachedDpi || mCachedRotation != mRotation || mCachedViewScaleFactor != viewScaleFactor )
{
mSvgCacheUpToDate = false;
}
Expand Down Expand Up @@ -82,6 +85,12 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
{
if ( !mSvgCacheUpToDate )
{
//make nicer preview
if ( mComposition && mComposition->plotStyle() == QgsComposition::Preview )
{
rotatedBoundImageWidth *= std::min( viewScaleFactor, 10.0 );
rotatedBoundImageHeight *= std::min( viewScaleFactor, 10.0 );
}
mImage = QImage( rotatedBoundImageWidth, rotatedBoundImageHeight, QImage::Format_ARGB32 );
updateImageFromSvg();
}
Expand All @@ -91,13 +100,20 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
painter->translate( boundRectWidthMM / 2.0, boundRectHeightMM / 2.0 );
painter->rotate( mRotation );
painter->translate( -rotatedBoundImageWidthMM / 2.0, -rotatedBoundImageHeightMM / 2.0 );

/*if ( mComposition && mComposition->plotStyle() == QgsComposition::Preview )
{
rotatedBoundImageWidthMM /= std::min( viewScaleFactor, 10.0 );
rotatedBoundImageHeightMM /= std::min( viewScaleFactor, 10.0 );
}*/
painter->drawImage( QRectF( 0, 0, rotatedBoundImageWidthMM, rotatedBoundImageHeightMM ), mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );

painter->restore();
}

mCachedDpi = newDpi;
mCachedRotation = mRotation;
mCachedViewScaleFactor = viewScaleFactor;

//frame and selection boxes
drawFrame( painter );
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposerpicture.h
Expand Up @@ -89,6 +89,8 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
bool mSvgCacheUpToDate;
int mCachedDpi; //store dpis for which the svg cache is valid
double mCachedRotation; //store last rotation value to generate new pixmap from svg on change
double mCachedViewScaleFactor;

QSize mDefaultSvgSize;
/**Map that sets the rotation (or 0 if this picture uses map independent rotation)*/
const QgsComposerMap* mRotationMap;
Expand Down

0 comments on commit a5574d1

Please sign in to comment.