Skip to content

Commit b18f273

Browse files
Hugo Merciermhugent
Hugo Mercier
authored andcommitted
Change computeWorldFileParameters signature and fix Python unit test
1 parent 50f86c8 commit b18f273

File tree

7 files changed

+61
-37
lines changed

7 files changed

+61
-37
lines changed

python/core/composer/qgscomposition.sip

+9
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ class QgsComposition : QGraphicsScene
133133
@note: added in version 1.9*/
134134
void setUseAdvancedEffects( bool effectsEnabled );
135135

136+
bool generateWorldFile() const;
137+
void setGenerateWorldFile( bool enabled );
138+
139+
QgsComposerMap* worldFileMap();
140+
void setWorldFileMap( QgsComposerMap* map );
141+
136142
double selectionTolerance() const;
137143
void setSelectionTolerance( double tol );
138144

@@ -303,6 +309,9 @@ class QgsComposition : QGraphicsScene
303309
@note added in version 1.9*/
304310
void renderPage( QPainter* p, int page );
305311

312+
/** Compute world file parameters */
313+
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;
314+
306315
QgsAtlasComposition& atlasComposition();
307316

308317
public slots:

src/app/composer/qgscomposer.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -1000,15 +1000,15 @@ void QgsComposer::on_mActionExportAsImage_triggered()
10001000
// Write the world file if asked to
10011001
if ( mComposition->generateWorldFile() )
10021002
{
1003-
double params[6];
1004-
mComposition->computeWorldFileParameters( params );
1003+
double a, b, c, d, e, f;
1004+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
10051005

10061006
QFileInfo fi( fileNExt.first );
10071007
// build the world file name
10081008
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
10091009
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
10101010

1011-
writeWorldFile( worldFileName, params );
1011+
writeWorldFile( worldFileName, a, b, c, d, e, f );
10121012
}
10131013

10141014
mView->setPaintingEnabled( true );
@@ -1158,15 +1158,15 @@ void QgsComposer::on_mActionExportAsImage_triggered()
11581158
// Write the world file if asked to
11591159
if ( mComposition->generateWorldFile() )
11601160
{
1161-
double params[6];
1162-
mComposition->computeWorldFileParameters( params );
1163-
1164-
QFileInfo fi( filename );
1165-
// build the world file name
1166-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
1167-
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
1168-
1169-
writeWorldFile( worldFileName, params );
1161+
double a, b, c, d, e, f;
1162+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
1163+
1164+
QFileInfo fi( filename );
1165+
// build the world file name
1166+
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
1167+
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
1168+
1169+
writeWorldFile( worldFileName, a, b, c, d, e, f );
11701170
}
11711171
}
11721172
atlasMap->endRender();
@@ -2354,7 +2354,7 @@ void QgsComposer::createComposerView()
23542354
mViewLayout->addWidget( mView, 1, 1 );
23552355
}
23562356

2357-
void QgsComposer::writeWorldFile( QString worldFileName, double p[6] ) const
2357+
void QgsComposer::writeWorldFile( QString worldFileName, double a, double b, double c, double d, double e, double f ) const
23582358
{
23592359
QFile worldFile( worldFileName );
23602360
if ( !worldFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
@@ -2365,10 +2365,10 @@ void QgsComposer::writeWorldFile( QString worldFileName, double p[6] ) const
23652365

23662366
// QString::number does not use locale settings (for the decimal point)
23672367
// which is what we want here
2368-
fout << QString::number( p[0] ) << "\r\n";
2369-
fout << QString::number( p[3] ) << "\r\n";
2370-
fout << QString::number( p[1] ) << "\r\n";
2371-
fout << QString::number( p[4] ) << "\r\n";
2372-
fout << QString::number( p[2] ) << "\r\n";
2373-
fout << QString::number( p[5] ) << "\r\n";
2368+
fout << QString::number(a) << "\r\n";
2369+
fout << QString::number(b) << "\r\n";
2370+
fout << QString::number(c) << "\r\n";
2371+
fout << QString::number(d) << "\r\n";
2372+
fout << QString::number(e) << "\r\n";
2373+
fout << QString::number(f) << "\r\n";
23742374
}

src/app/composer/qgscomposer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
335335
void createComposerView();
336336

337337
//! Write a world file
338-
void writeWorldFile( QString fileName, double params[6] ) const;
338+
void writeWorldFile( QString fileName, double a, double b, double c, double d, double e, double f ) const;
339339

340340
/**Composer title*/
341341
QString mTitle;

src/core/composer/qgscomposition.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ bool QgsComposition::nearestItem( const QMap< double, const QgsComposerItem* >&
21862186
}
21872187
}
21882188

2189-
void QgsComposition::computeWorldFileParameters( double p[6] ) const
2189+
void QgsComposition::computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const
21902190
{
21912191
//
21922192
// Word file parameters : affine transformation parameters from pixel coordinates to map coordinates
@@ -2240,10 +2240,10 @@ void QgsComposition::computeWorldFileParameters( double p[6] ) const
22402240
r[5] = - XC * sin( alpha ) + YC * ( 1 - cos( alpha ) );
22412241

22422242
// result = rotation x scaling = rotation(scaling(X))
2243-
p[0] = r[0] * s[0] + r[1] * s[3];
2244-
p[1] = r[0] * s[1] + r[1] * s[4];
2245-
p[2] = r[0] * s[2] + r[1] * s[5] + r[2];
2246-
p[3] = r[3] * s[0] + r[4] * s[3];
2247-
p[4] = r[3] * s[1] + r[4] * s[4];
2248-
p[5] = r[3] * s[2] + r[4] * s[5] + r[5];
2243+
a = r[0] * s[0] + r[1] * s[3];
2244+
b = r[0] * s[1] + r[1] * s[4];
2245+
c = r[0] * s[2] + r[1] * s[5] + r[2];
2246+
d = r[3] * s[0] + r[4] * s[3];
2247+
e = r[3] * s[1] + r[4] * s[4];
2248+
f = r[3] * s[2] + r[4] * s[5] + r[5];
22492249
}

src/core/composer/qgscomposition.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
364364
void renderPage( QPainter* p, int page );
365365

366366
/** Compute world file parameters */
367-
void computeWorldFileParameters( double p[6] ) const;
367+
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;
368368

369369
QgsAtlasComposition& atlasComposition() { return mAtlasComposition; }
370370

tests/src/core/testqgscomposermap.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void TestQgsComposerMap::overviewMapCenter()
223223
QgsComposerMap* overviewMapCenter = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
224224
overviewMapCenter->setFrameEnabled( true );
225225
mComposition->addComposerMap( overviewMapCenter );
226-
mComposerMap->setNewExtent( QgsRectangle( 785462.375+5000, 3341423.125, 789262.375+5000, 3343323.125 ) ); //zoom in
226+
mComposerMap->setNewExtent( QgsRectangle( 785462.375 + 5000, 3341423.125, 789262.375 + 5000, 3343323.125 ) ); //zoom in
227227
mComposerMap->setGridEnabled( false );
228228
overviewMapCenter->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
229229
overviewMapCenter->setOverviewFrameMap( mComposerMap->id() );
@@ -244,15 +244,15 @@ void TestQgsComposerMap::worldFileGeneration()
244244
mComposition->setGenerateWorldFile( true );
245245
mComposition->setWorldFileMap( mComposerMap );
246246

247-
double params[6];
248-
mComposition->computeWorldFileParameters( params );
247+
double a, b, c, d, e, f;
248+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
249249

250-
QVERIFY( fabs(params[0] - 4.18048) < 0.001 );
251-
QVERIFY( fabs(params[1] - 2.41331) < 0.001 );
252-
QVERIFY( fabs(params[2] - 779444) < 1 );
253-
QVERIFY( fabs(params[3] - 2.4136) < 0.001 );
254-
QVERIFY( fabs(params[4] + 4.17997) < 0.001 );
255-
QVERIFY( fabs(params[5] - 3.34241e+06) < 1e+03 );
250+
QVERIFY( fabs( a - 4.18048 ) < 0.001 );
251+
QVERIFY( fabs( b - 2.41331 ) < 0.001 );
252+
QVERIFY( fabs( c - 779444 ) < 1 );
253+
QVERIFY( fabs( d - 2.4136 ) < 0.001 );
254+
QVERIFY( fabs( e + 4.17997 ) < 0.001 );
255+
QVERIFY( fabs( f - 3.34241e+06 ) < 1e+03 );
256256
}
257257

258258
QTEST_MAIN( TestQgsComposerMap )

tests/src/python/test_qgscomposermap.py

+15
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ def testZebraStyle(self):
249249
myPngPath)
250250
assert testResult == True, myMessage
251251

252+
def testWorldFileGeneration( self ):
253+
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)
254+
self.mComposerMap.setNewExtent( myRectangle )
255+
self.mComposerMap.setRotation( 30.0 )
256+
257+
self.mComposition.setGenerateWorldFile( True )
258+
self.mComposition.setWorldFileMap( self.mComposerMap )
259+
260+
p = self.mComposition.computeWorldFileParameters()
261+
pexpected = (4.180480199790922, 2.4133064516129026, 779443.7612381146,
262+
2.4136013686911886, -4.179969388427311, 3342408.5663611)
263+
ptolerance = (0.001, 0.001, 1, 0.001, 0.001, 1e+03)
264+
for i in range(0,6):
265+
assert abs(p[i]-pexpected[i]) < ptolerance[i]
266+
252267
if __name__ == '__main__':
253268
unittest.main()
254269

0 commit comments

Comments
 (0)