@@ -995,6 +995,22 @@ void QgsComposer::on_mActionExportAsImage_triggered()
995
995
image.save ( outputFilePath, fileNExt.second .toLocal8Bit ().constData () );
996
996
}
997
997
}
998
+
999
+ //
1000
+ // Write the world file if asked to
1001
+ if ( mComposition ->generateWorldFile () )
1002
+ {
1003
+ double a, b, c, d, e, f;
1004
+ mComposition ->computeWorldFileParameters ( a, b, c, d, e, f );
1005
+
1006
+ QFileInfo fi ( fileNExt.first );
1007
+ // build the world file name
1008
+ QString worldFileName = fi.absolutePath () + " /" + fi.baseName () + " ."
1009
+ + fi.suffix ()[0 ] + fi.suffix ()[fi.suffix ().size ()-1 ] + " w" ;
1010
+
1011
+ writeWorldFile ( worldFileName, a, b, c, d, e, f );
1012
+ }
1013
+
998
1014
mView ->setPaintingEnabled ( true );
999
1015
}
1000
1016
else
@@ -1137,6 +1153,21 @@ void QgsComposer::on_mActionExportAsImage_triggered()
1137
1153
image.save ( outputFilePath, format.toLocal8Bit ().constData () );
1138
1154
}
1139
1155
}
1156
+
1157
+ //
1158
+ // Write the world file if asked to
1159
+ if ( mComposition ->generateWorldFile () )
1160
+ {
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 );
1170
+ }
1140
1171
}
1141
1172
atlasMap->endRender ();
1142
1173
mView ->setPaintingEnabled ( true );
@@ -1881,6 +1912,24 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
1881
1912
mComposition ->addItemsFromXML ( composerElem, doc, &mMapsToRestore );
1882
1913
}
1883
1914
1915
+ // look for world file composer map, if needed
1916
+ // Note: this must be done after maps have been added by addItemsFromXML
1917
+ if ( mComposition ->generateWorldFile () )
1918
+ {
1919
+ QDomElement compositionElem = compositionNodeList.at ( 0 ).toElement ();
1920
+ QgsComposerMap* worldFileMap = 0 ;
1921
+ QList<const QgsComposerMap*> maps = mComposition ->composerMapItems ();
1922
+ for ( QList<const QgsComposerMap*>::const_iterator it = maps.begin (); it != maps.end (); ++it )
1923
+ {
1924
+ if (( *it )->id () == compositionElem.attribute ( " worldFileMap" ).toInt () )
1925
+ {
1926
+ worldFileMap = const_cast <QgsComposerMap*>( *it );
1927
+ break ;
1928
+ }
1929
+ }
1930
+ mComposition ->setWorldFileMap ( worldFileMap );
1931
+ }
1932
+
1884
1933
mComposition ->sortZList ();
1885
1934
mView ->setComposition ( mComposition );
1886
1935
@@ -2304,3 +2353,22 @@ void QgsComposer::createComposerView()
2304
2353
mView ->setVerticalRuler ( mVerticalRuler );
2305
2354
mViewLayout ->addWidget ( mView , 1 , 1 );
2306
2355
}
2356
+
2357
+ void QgsComposer::writeWorldFile ( QString worldFileName, double a, double b, double c, double d, double e, double f ) const
2358
+ {
2359
+ QFile worldFile ( worldFileName );
2360
+ if ( !worldFile.open ( QIODevice::WriteOnly | QIODevice::Text ) )
2361
+ {
2362
+ return ;
2363
+ }
2364
+ QTextStream fout ( &worldFile );
2365
+
2366
+ // QString::number does not use locale settings (for the decimal point)
2367
+ // which is what we want here
2368
+ fout << QString::number ( a, ' f' ) << " \r\n " ;
2369
+ fout << QString::number ( d, ' f' ) << " \r\n " ;
2370
+ fout << QString::number ( b, ' f' ) << " \r\n " ;
2371
+ fout << QString::number ( e, ' f' ) << " \r\n " ;
2372
+ fout << QString::number ( c, ' f' ) << " \r\n " ;
2373
+ fout << QString::number ( f, ' f' ) << " \r\n " ;
2374
+ }
0 commit comments