|
| 1 | +/*************************************************************************** |
| 2 | + testqgscomposerpaper.cpp |
| 3 | + ---------------------- |
| 4 | + begin : January 2014 |
| 5 | + copyright : (C) 2014 by Marco Hugentobler, Nyall Dawson |
| 6 | + email : nyall dot dawson at gmail.com |
| 7 | + ***************************************************************************/ |
| 8 | + |
| 9 | +/*************************************************************************** |
| 10 | + * * |
| 11 | + * This program is free software; you can redistribute it and/or modify * |
| 12 | + * it under the terms of the GNU General Public License as published by * |
| 13 | + * the Free Software Foundation; either version 2 of the License, or * |
| 14 | + * (at your option) any later version. * |
| 15 | + * * |
| 16 | + ***************************************************************************/ |
| 17 | + |
| 18 | +#include "qgsapplication.h" |
| 19 | +#include "qgscomposition.h" |
| 20 | +#include "qgscompositionchecker.h" |
| 21 | +#include "qgscomposershape.h" |
| 22 | +#include "qgssymbolv2.h" |
| 23 | +#include "qgssinglesymbolrendererv2.h" |
| 24 | +#include "qgsfillsymbollayerv2.h" |
| 25 | +#include "qgslinesymbollayerv2.h" |
| 26 | + |
| 27 | +#include <QObject> |
| 28 | +#include <QtTest> |
| 29 | +#include <QColor> |
| 30 | +#include <QPainter> |
| 31 | + |
| 32 | +class TestQgsComposerPaper: public QObject |
| 33 | +{ |
| 34 | + Q_OBJECT; |
| 35 | + private slots: |
| 36 | + void initTestCase();// will be called before the first testfunction is executed. |
| 37 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 38 | + void init();// will be called before each testfunction is executed. |
| 39 | + void cleanup();// will be called after every testfunction. |
| 40 | + void defaultPaper(); //test default paper style |
| 41 | + void transparentPaper(); //test totally transparent paper style |
| 42 | + void borderedPaper(); //test page with border |
| 43 | + void markerLinePaper(); //test page with marker line border |
| 44 | + |
| 45 | + private: |
| 46 | + QgsComposition* mComposition; |
| 47 | + QString mReport; |
| 48 | + QgsSimpleFillSymbolLayerV2* mSimpleFill; |
| 49 | + QgsMarkerLineSymbolLayerV2* mMarkerLine; |
| 50 | + QgsFillSymbolV2* mFillSymbol; |
| 51 | + QgsFillSymbolV2* mMarkerLineSymbol; |
| 52 | + QgsSingleSymbolRendererV2* mSymbolRenderer; |
| 53 | + |
| 54 | +}; |
| 55 | + |
| 56 | +void TestQgsComposerPaper::initTestCase() |
| 57 | +{ |
| 58 | + QgsApplication::init(); |
| 59 | + QgsApplication::initQgis(); |
| 60 | + |
| 61 | + //create empty composition |
| 62 | + mComposition = new QgsComposition( 0 ); |
| 63 | + mComposition->setPaperSize( 297, 210 ); //A4 landscape |
| 64 | + |
| 65 | + //setup simple fill |
| 66 | + mSimpleFill = new QgsSimpleFillSymbolLayerV2(); |
| 67 | + mFillSymbol = new QgsFillSymbolV2(); |
| 68 | + mFillSymbol->changeSymbolLayer( 0, mSimpleFill ); |
| 69 | + |
| 70 | + //setup marker line fill |
| 71 | + mMarkerLine = new QgsMarkerLineSymbolLayerV2(); |
| 72 | + mMarkerLineSymbol = new QgsFillSymbolV2(); |
| 73 | + mMarkerLineSymbol->changeSymbolLayer( 0, mMarkerLine ); |
| 74 | + |
| 75 | + mReport = "<h1>Composer Paper Tests</h1>\n"; |
| 76 | +} |
| 77 | + |
| 78 | +void TestQgsComposerPaper::cleanupTestCase() |
| 79 | +{ |
| 80 | + delete mComposition; |
| 81 | + |
| 82 | + QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html"; |
| 83 | + QFile myFile( myReportFile ); |
| 84 | + if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) |
| 85 | + { |
| 86 | + QTextStream myQTextStream( &myFile ); |
| 87 | + myQTextStream << mReport; |
| 88 | + myFile.close(); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +void TestQgsComposerPaper::init() |
| 93 | +{ |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | +void TestQgsComposerPaper::cleanup() |
| 98 | +{ |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | +void TestQgsComposerPaper::defaultPaper() |
| 103 | +{ |
| 104 | + QgsCompositionChecker checker( "composerpaper_default", mComposition ); |
| 105 | + QVERIFY( checker.testComposition( mReport ) ); |
| 106 | +} |
| 107 | + |
| 108 | +void TestQgsComposerPaper::transparentPaper() |
| 109 | +{ |
| 110 | + mSimpleFill->setColor( Qt::transparent ); |
| 111 | + mSimpleFill->setBorderColor( Qt::transparent ); |
| 112 | + mComposition->setPageStyleSymbol( mFillSymbol ); |
| 113 | + QgsCompositionChecker checker( "composerpaper_transparent", mComposition ); |
| 114 | + QVERIFY( checker.testComposition( mReport ) ); |
| 115 | +} |
| 116 | + |
| 117 | +void TestQgsComposerPaper::borderedPaper() |
| 118 | +{ |
| 119 | + mSimpleFill->setColor( Qt::white ); |
| 120 | + mSimpleFill->setBorderColor( Qt::black ); |
| 121 | + mSimpleFill->setBorderWidth( 6 ); |
| 122 | + QgsCompositionChecker checker( "composerpaper_bordered", mComposition ); |
| 123 | + QVERIFY( checker.testComposition( mReport ) ); |
| 124 | +} |
| 125 | + |
| 126 | +void TestQgsComposerPaper::markerLinePaper() |
| 127 | +{ |
| 128 | + mComposition->setPageStyleSymbol( mMarkerLineSymbol ); |
| 129 | + QgsCompositionChecker checker( "composerpaper_markerborder", mComposition ); |
| 130 | + QVERIFY( checker.testComposition( mReport ) ); |
| 131 | +} |
| 132 | + |
| 133 | +QTEST_MAIN( TestQgsComposerPaper ) |
| 134 | +#include "moc_testqgscomposerpaper.cxx" |
0 commit comments