|
18 | 18 | #include "qgsapplication.h" //for standard test font |
19 | 19 | #include "qgscomposerutils.h" |
20 | 20 | #include "qgscomposition.h" |
| 21 | +#include "qgscomposermap.h" |
21 | 22 | #include "qgsmultirenderchecker.h" |
22 | 23 | #include "qgsdatadefined.h" |
23 | 24 | #include "qgsfontutils.h" |
24 | 25 | #include "qgsproject.h" |
| 26 | +#include "qgstestutils.h" |
25 | 27 | #include <QObject> |
26 | 28 | #include "qgstest.h" |
27 | 29 | #include <QMap> |
@@ -61,6 +63,7 @@ class TestQgsComposerUtils : public QObject |
61 | 63 | void textHeightMM(); //test calculating text height in mm |
62 | 64 | void drawTextPos(); //test drawing text at a pos |
63 | 65 | void drawTextRect(); //test drawing text in a rect |
| 66 | + void createRenderContext(); |
64 | 67 |
|
65 | 68 | private: |
66 | 69 | bool renderCheck( const QString& testName, QImage &image, int mismatchCount = 0 ); |
@@ -701,6 +704,42 @@ void TestQgsComposerUtils::drawTextRect() |
701 | 704 | QVERIFY( renderCheck( "composerutils_drawtext_rectflag", testImage, 100 ) ); |
702 | 705 | } |
703 | 706 |
|
| 707 | +void TestQgsComposerUtils::createRenderContext() |
| 708 | +{ |
| 709 | + QImage testImage = QImage( 250, 250, QImage::Format_RGB32 ); |
| 710 | + testImage.setDotsPerMeterX( 150 / 25.4 * 1000 ); |
| 711 | + testImage.setDotsPerMeterY( 150 / 25.4 * 1000 ); |
| 712 | + QPainter p( &testImage ); |
| 713 | + |
| 714 | + // no composition |
| 715 | + QgsRenderContext rc = QgsComposerUtils::createRenderContext( nullptr, p ); |
| 716 | + QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 ); |
| 717 | + QCOMPARE( rc.painter(), &p ); |
| 718 | + |
| 719 | + //create composition with no reference map |
| 720 | + QgsRectangle extent( 2000, 2800, 2500, 2900 ); |
| 721 | + QgsMapSettings ms; |
| 722 | + ms.setExtent( extent ); |
| 723 | + QgsComposition* composition = new QgsComposition( ms, QgsProject::instance() ); |
| 724 | + rc = QgsComposerUtils::createRenderContext( composition, p ); |
| 725 | + QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 ); |
| 726 | + QCOMPARE( rc.painter(), &p ); |
| 727 | + |
| 728 | + // add a reference map |
| 729 | + QgsComposerMap* map = new QgsComposerMap( composition ); |
| 730 | + map->setNewExtent( extent ); |
| 731 | + map->setSceneRect( QRectF( 30, 60, 200, 100 ) ); |
| 732 | + composition->addComposerMap( map ); |
| 733 | + composition->setReferenceMap( map ); |
| 734 | + |
| 735 | + rc = QgsComposerUtils::createRenderContext( composition, p ); |
| 736 | + QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 ); |
| 737 | + QGSCOMPARENEAR( rc.rendererScale(), map->scale(), 100000 ); |
| 738 | + QCOMPARE( rc.painter(), &p ); |
| 739 | + |
| 740 | + p.end(); |
| 741 | +} |
| 742 | + |
704 | 743 | bool TestQgsComposerUtils::renderCheck( const QString& testName, QImage &image, int mismatchCount ) |
705 | 744 | { |
706 | 745 | mReport += "<h2>" + testName + "</h2>\n"; |
|
0 commit comments