28
28
29
29
30
30
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition ): QgsComposerItem( composition ), mMode( Unknown ), \
31
- mSvgCacheUpToDate( false ), mCachedDpi( 0 ), mCachedRotation( 0 ), mCachedViewScaleFactor( - 1 ), mRotationMap( 0 )
31
+ mRotationMap( 0 )
32
32
{
33
33
mPictureWidth = rect ().width ();
34
34
}
35
35
36
- QgsComposerPicture::QgsComposerPicture (): QgsComposerItem( 0 ), mMode( Unknown ), mSvgCacheUpToDate( false ), mCachedRotation( 0 ), mCachedViewScaleFactor( - 1 ), mRotationMap( 0 )
36
+ QgsComposerPicture::QgsComposerPicture (): QgsComposerItem( 0 ), mMode( Unknown ), mRotationMap( 0 )
37
37
{
38
38
mPictureHeight = rect ().height ();
39
39
}
40
40
41
+
41
42
QgsComposerPicture::~QgsComposerPicture ()
42
43
{
43
44
@@ -53,12 +54,6 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
53
54
drawBackground ( painter );
54
55
55
56
int newDpi = ( painter->device ()->logicalDpiX () + painter->device ()->logicalDpiY () ) / 2 ;
56
- double viewScaleFactor = horizontalViewScaleFactor ();
57
-
58
- if ( newDpi != mCachedDpi || mCachedRotation != mRotation || mCachedViewScaleFactor != viewScaleFactor )
59
- {
60
- mSvgCacheUpToDate = false ;
61
- }
62
57
63
58
if ( mMode != Unknown )
64
59
{
@@ -79,35 +74,23 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
79
74
double boundImageWidth = boundRect.width ();
80
75
double boundImageHeight = boundRect.height ();
81
76
82
- if ( mMode == SVG )
83
- {
84
- if ( !mSvgCacheUpToDate )
85
- {
86
- // make nicer preview
87
- if ( mComposition && mComposition ->plotStyle () == QgsComposition::Preview )
88
- {
89
- boundImageWidth *= qMin ( viewScaleFactor, 10.0 );
90
- boundImageHeight *= qMin ( viewScaleFactor, 10.0 );
91
- }
92
- mImage = QImage ( boundImageWidth, boundImageHeight, QImage::Format_ARGB32 );
93
- updateImageFromSvg ();
94
- }
95
- }
96
-
97
77
painter->save ();
98
78
painter->translate ( rect ().width () / 2.0 , rect ().height () / 2.0 );
99
79
painter->rotate ( mRotation );
100
80
painter->translate ( -boundRectWidthMM / 2.0 , -boundRectHeightMM / 2.0 );
101
81
102
- painter->drawImage ( QRectF ( 0 , 0 , boundRectWidthMM, boundRectHeightMM ), mImage , QRectF ( 0 , 0 , mImage .width (), mImage .height () ) );
82
+ if ( mMode == SVG )
83
+ {
84
+ mSVG .render ( painter, QRectF ( 0 , 0 , boundRectWidthMM, boundRectHeightMM ) );
85
+ }
86
+ else if ( mMode == RASTER )
87
+ {
88
+ painter->drawImage ( QRectF ( 0 , 0 , boundRectWidthMM, boundRectHeightMM ), mImage , QRectF ( 0 , 0 , mImage .width (), mImage .height () ) );
89
+ }
103
90
104
91
painter->restore ();
105
92
}
106
93
107
- mCachedDpi = newDpi;
108
- mCachedRotation = mRotation ;
109
- mCachedViewScaleFactor = viewScaleFactor;
110
-
111
94
// frame and selection boxes
112
95
drawFrame ( painter );
113
96
if ( isSelected () )
@@ -129,14 +112,13 @@ void QgsComposerPicture::setPictureFile( const QString& path )
129
112
if ( sourceFileSuffix.compare ( " svg" , Qt::CaseInsensitive ) == 0 )
130
113
{
131
114
// try to open svg
132
- QSvgRenderer validTestRenderer ( mSourceFile .fileName () );
133
- if ( validTestRenderer .isValid () )
115
+ mSVG . load ( mSourceFile .fileName () );
116
+ if ( mSVG .isValid () )
134
117
{
135
118
mMode = SVG;
136
- QRect viewBox = validTestRenderer .viewBox (); // take width/height ratio from view box instead of default size
119
+ QRect viewBox = mSVG .viewBox (); // take width/height ratio from view box instead of default size
137
120
mDefaultSvgSize .setWidth ( viewBox.width () );
138
121
mDefaultSvgSize .setHeight ( viewBox.height () );
139
- mSvgCacheUpToDate = false ;
140
122
}
141
123
else
142
124
{
@@ -217,21 +199,8 @@ QRectF QgsComposerPicture::boundedSVGRect( double deviceWidth, double deviceHeig
217
199
}
218
200
#endif // 0
219
201
220
- void QgsComposerPicture::updateImageFromSvg ()
221
- {
222
- mImage .fill ( 0 );
223
- QPainter p ( &mImage );
224
- p.setRenderHints ( QPainter::Antialiasing | QPainter::TextAntialiasing, true );
225
- QSvgRenderer theRenderer ( mSourceFile .fileName () );
226
- theRenderer.render ( &p );
227
- mSvgCacheUpToDate = true ;
228
- }
229
-
230
-
231
-
232
202
void QgsComposerPicture::setSceneRect ( const QRectF& rectangle )
233
203
{
234
- mSvgCacheUpToDate = false ;
235
204
QgsComposerItem::setSceneRect ( rectangle );
236
205
237
206
// consider to change size of the shape if the rectangle changes width and/or height
@@ -333,9 +302,7 @@ bool QgsComposerPicture::readXML( const QDomElement& itemElem, const QDomDocumen
333
302
}
334
303
335
304
336
- mSvgCacheUpToDate = false ;
337
305
mDefaultSvgSize = QSize ( 0 , 0 );
338
- mCachedDpi = 0 ;
339
306
340
307
QString fileName = QgsProject::instance ()->readPath ( itemElem.attribute ( " file" ) );
341
308
setPictureFile ( fileName );
0 commit comments