14 changes: 14 additions & 0 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
bool printAsRaster() const {return mPrintAsRaster;}
void setPrintAsRaster( bool enabled ) { mPrintAsRaster = enabled; }

bool generateWorldFile() const { return mGenerateWorldFile; }
void setGenerateWorldFile( bool enabled ) { mGenerateWorldFile = enabled; }

QgsComposerMap* worldFileMap() const { return mWorldFileMap; }
void setWorldFileMap( QgsComposerMap* map ) { mWorldFileMap = map; }

/**Returns true if a composition should use advanced effects such as blend modes
@note added in 1.9*/
bool useAdvancedEffects() const {return mUseAdvancedEffects;}
Expand Down Expand Up @@ -357,6 +363,9 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
@note added in version 1.9*/
void renderPage( QPainter* p, int page );

/** Compute world file parameters */
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;

QgsAtlasComposition& atlasComposition() { return mAtlasComposition; }

public slots:
Expand Down Expand Up @@ -384,6 +393,11 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Flag if map should be printed as a raster (via QImage). False by default*/
bool mPrintAsRaster;

/**Flag if a world file should be generated on raster export */
bool mGenerateWorldFile;
/** Composer map to use for the world file generation */
QgsComposerMap* mWorldFileMap;

/**Flag if advanced visual effects such as blend modes should be used. True by default*/
bool mUseAdvancedEffects;

Expand Down
21 changes: 19 additions & 2 deletions src/ui/qgscompositionwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mPrintAsRasterCheckBox">
<property name="text">
<string>Print as raster</string>
Expand All @@ -256,6 +256,23 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="mGenerateWorldFileCheckBox">
<property name="text">
<string>World file on</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="mWorldFileMapComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -302,7 +319,7 @@
<string> mm</string>
</property>
<property name="minimum">
<double>0.50000000000000</double>
<double>0.500000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
Expand Down
24 changes: 22 additions & 2 deletions tests/src/core/testqgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestQgsComposerMap: public QObject
void uniqueId(); //test if map id is adapted when doing copy paste
void zebraStyle(); //test zebra map border style
void overviewMapCenter(); //test if centering of overview map frame works
void worldFileGeneration(); // test world file generation

private:
QgsComposition* mComposition;
Expand Down Expand Up @@ -84,7 +85,6 @@ void TestQgsComposerMap::cleanupTestCase()

void TestQgsComposerMap::init()
{

}

void TestQgsComposerMap::cleanup()
Expand Down Expand Up @@ -223,7 +223,7 @@ void TestQgsComposerMap::overviewMapCenter()
QgsComposerMap* overviewMapCenter = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapCenter->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapCenter );
mComposerMap->setNewExtent( QgsRectangle( 785462.375+5000, 3341423.125, 789262.375+5000, 3343323.125 ) ); //zoom in
mComposerMap->setNewExtent( QgsRectangle( 785462.375 + 5000, 3341423.125, 789262.375 + 5000, 3343323.125 ) ); //zoom in
mComposerMap->setGridEnabled( false );
overviewMapCenter->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapCenter->setOverviewFrameMap( mComposerMap->id() );
Expand All @@ -235,5 +235,25 @@ void TestQgsComposerMap::overviewMapCenter()
mComposition->removeComposerItem( overviewMapCenter );
QVERIFY( testResult );
}

void TestQgsComposerMap::worldFileGeneration()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setRotation( 30.0 );

mComposition->setGenerateWorldFile( true );
mComposition->setWorldFileMap( mComposerMap );

double a, b, c, d, e, f;
mComposition->computeWorldFileParameters( a, b, c, d, e, f );

QVERIFY( fabs( a - 4.18048 ) < 0.001 );
QVERIFY( fabs( b - 2.41331 ) < 0.001 );
QVERIFY( fabs( c - 779444 ) < 1 );
QVERIFY( fabs( d - 2.4136 ) < 0.001 );
QVERIFY( fabs( e + 4.17997 ) < 0.001 );
QVERIFY( fabs( f - 3.34241e+06 ) < 1e+03 );
}

QTEST_MAIN( TestQgsComposerMap )
#include "moc_testqgscomposermap.cxx"
15 changes: 15 additions & 0 deletions tests/src/python/test_qgscomposermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ def testZebraStyle(self):
myPngPath)
assert testResult == True, myMessage

def testWorldFileGeneration( self ):
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)
self.mComposerMap.setNewExtent( myRectangle )
self.mComposerMap.setRotation( 30.0 )

self.mComposition.setGenerateWorldFile( True )
self.mComposition.setWorldFileMap( self.mComposerMap )

p = self.mComposition.computeWorldFileParameters()
pexpected = (4.180480199790922, 2.4133064516129026, 779443.7612381146,
2.4136013686911886, -4.179969388427311, 3342408.5663611)
ptolerance = (0.001, 0.001, 1, 0.001, 0.001, 1e+03)
for i in range(0,6):
assert abs(p[i]-pexpected[i]) < ptolerance[i]

if __name__ == '__main__':
unittest.main()