@@ -37,23 +37,39 @@ class TestQgsComposerPicture: public QObject
3737 void pictureItemRotation (); // test if composer picture item rotation is functioning
3838 // void oldPictureRotationApi(); //test if old deprectated composer picture rotation api is functioning
3939
40+ void pictureResizeZoom ();
41+ void pictureResizeStretch ();
42+ void pictureResizeClip ();
43+ void pictureResizeZoomAndResize ();
44+ void pictureResizeFrameToImage ();
45+
46+ void pictureSvgZoom ();
47+ void pictureSvgStretch ();
48+ void pictureSvgZoomAndResize ();
49+ void pictureSvgFrameToImage ();
50+
4051 private:
4152 QgsComposition* mComposition ;
4253 QgsComposerPicture* mComposerPicture ;
4354 QgsMapSettings mMapSettings ;
4455 QString mReport ;
56+ QString mPngImage ;
57+ QString mSvgImage ;
4558};
4659
4760void TestQgsComposerPicture::initTestCase ()
4861{
4962 QgsApplication::init ();
5063 QgsApplication::initQgis ();
5164
65+ mPngImage = QString ( TEST_DATA_DIR ) + QDir::separator () + " sample_image.png" ;
66+ mSvgImage = QString ( TEST_DATA_DIR ) + QDir::separator () + " sample_svg.svg" ;
67+
5268 mComposition = new QgsComposition ( mMapSettings );
5369 mComposition ->setPaperSize ( 297 , 210 ); // A4 landscape
5470
5571 mComposerPicture = new QgsComposerPicture ( mComposition );
56- mComposerPicture ->setPictureFile ( QString ( TEST_DATA_DIR ) + QDir::separator () + " sample_image.png " );
72+ mComposerPicture ->setPictureFile ( mPngImage );
5773 mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
5874 mComposerPicture ->setFrameEnabled ( true );
5975
@@ -125,5 +141,139 @@ void TestQgsComposerPicture::oldPictureRotationApi()
125141}
126142#endif
127143
144+ void TestQgsComposerPicture::pictureResizeZoom ()
145+ {
146+ // test picture resize Zoom mode
147+ mComposition ->addComposerPicture ( mComposerPicture );
148+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
149+
150+ QgsCompositionChecker checker ( " composerpicture_resize_zoom" , mComposition );
151+ QVERIFY ( checker.testComposition ( mReport , 0 , 100 ) );
152+
153+ mComposition ->removeItem ( mComposerPicture );
154+ }
155+
156+ void TestQgsComposerPicture::pictureResizeStretch ()
157+ {
158+ // test picture resize Stretch mode
159+ mComposition ->addComposerPicture ( mComposerPicture );
160+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Stretch );
161+
162+ QgsCompositionChecker checker ( " composerpicture_resize_stretch" , mComposition );
163+ QVERIFY ( checker.testComposition ( mReport , 0 , 100 ) );
164+
165+ mComposition ->removeItem ( mComposerPicture );
166+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
167+ }
168+
169+ void TestQgsComposerPicture::pictureResizeClip ()
170+ {
171+ // test picture resize Clip mode
172+ mComposition ->addComposerPicture ( mComposerPicture );
173+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Clip );
174+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 30 , 50 ) );
175+
176+ QgsCompositionChecker checker ( " composerpicture_resize_clip" , mComposition );
177+ QVERIFY ( checker.testComposition ( mReport , 0 , 0 ) );
178+
179+ mComposition ->removeItem ( mComposerPicture );
180+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
181+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
182+ }
183+
184+ void TestQgsComposerPicture::pictureResizeZoomAndResize ()
185+ {
186+ // test picture resize ZoomResizeFrame mode
187+ mComposition ->addComposerPicture ( mComposerPicture );
188+ mComposerPicture ->setResizeMode ( QgsComposerPicture::ZoomResizeFrame );
189+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 50 , 300 ) );
190+
191+ QgsCompositionChecker checker ( " composerpicture_resize_zoomresize" , mComposition );
192+ QVERIFY ( checker.testComposition ( mReport , 0 , 0 ) );
193+
194+ mComposition ->removeItem ( mComposerPicture );
195+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
196+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
197+ }
198+
199+ void TestQgsComposerPicture::pictureResizeFrameToImage ()
200+ {
201+ // test picture resize FrameToImageSize mode
202+ mComposition ->addComposerPicture ( mComposerPicture );
203+ mComposerPicture ->setResizeMode ( QgsComposerPicture::FrameToImageSize );
204+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 50 , 300 ) );
205+
206+ QgsCompositionChecker checker ( " composerpicture_resize_frametoimage" , mComposition );
207+ QVERIFY ( checker.testComposition ( mReport , 0 , 0 ) );
208+
209+ mComposition ->removeItem ( mComposerPicture );
210+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
211+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
212+ }
213+
214+ void TestQgsComposerPicture::pictureSvgZoom ()
215+ {
216+ // test picture resize Zoom mode
217+ mComposition ->addComposerPicture ( mComposerPicture );
218+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
219+ mComposerPicture ->setPictureFile ( mSvgImage );
220+
221+ QgsCompositionChecker checker ( " composerpicture_svg_zoom" , mComposition );
222+ QVERIFY ( checker.testComposition ( mReport , 0 , 100 ) );
223+
224+ mComposition ->removeItem ( mComposerPicture );
225+ mComposerPicture ->setPictureFile ( mPngImage );
226+ }
227+
228+ void TestQgsComposerPicture::pictureSvgStretch ()
229+ {
230+ // test picture resize Stretch mode
231+ mComposition ->addComposerPicture ( mComposerPicture );
232+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Stretch );
233+ mComposerPicture ->setPictureFile ( mSvgImage );
234+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 20 , 100 ) );
235+
236+ QgsCompositionChecker checker ( " composerpicture_svg_stretch" , mComposition );
237+ QVERIFY ( checker.testComposition ( mReport , 0 , 100 ) );
238+
239+ mComposition ->removeItem ( mComposerPicture );
240+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
241+ mComposerPicture ->setPictureFile ( mPngImage );
242+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
243+ }
244+
245+ void TestQgsComposerPicture::pictureSvgZoomAndResize ()
246+ {
247+ // test picture resize ZoomResizeFrame mode
248+ mComposition ->addComposerPicture ( mComposerPicture );
249+ mComposerPicture ->setResizeMode ( QgsComposerPicture::ZoomResizeFrame );
250+ mComposerPicture ->setPictureFile ( mSvgImage );
251+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 50 , 300 ) );
252+
253+ QgsCompositionChecker checker ( " composerpicture_svg_zoomresize" , mComposition );
254+ QVERIFY ( checker.testComposition ( mReport , 0 , 0 ) );
255+
256+ mComposition ->removeItem ( mComposerPicture );
257+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
258+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
259+ mComposerPicture ->setPictureFile ( mPngImage );
260+ }
261+
262+ void TestQgsComposerPicture::pictureSvgFrameToImage ()
263+ {
264+ // test picture resize FrameToImageSize mode
265+ mComposition ->addComposerPicture ( mComposerPicture );
266+ mComposerPicture ->setResizeMode ( QgsComposerPicture::FrameToImageSize );
267+ mComposerPicture ->setPictureFile ( mSvgImage );
268+
269+ QgsCompositionChecker checker ( " composerpicture_svg_frametoimage" , mComposition );
270+ QVERIFY ( checker.testComposition ( mReport , 0 , 0 ) );
271+
272+ mComposition ->removeItem ( mComposerPicture );
273+ mComposerPicture ->setResizeMode ( QgsComposerPicture::Zoom );
274+ mComposerPicture ->setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) );
275+ mComposerPicture ->setPictureFile ( mPngImage );
276+ }
277+
128278QTEST_MAIN ( TestQgsComposerPicture )
129279#include " moc_testqgscomposerpicture.cxx"
0 commit comments