Skip to content

Commit c84b2df

Browse files
committedSep 14, 2015
[composer] Fix world file filename for multipage compositions
also fix #11676
1 parent d897624 commit c84b2df

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,12 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
19721972

19731973
mView->setPaintingEnabled( false );
19741974

1975+
int worldFilePageNo = -1;
1976+
if ( mComposition->generateWorldFile() && mComposition->worldFileMap() )
1977+
{
1978+
worldFilePageNo = mComposition->worldFileMap()->page() - 1;
1979+
}
1980+
19751981
for ( int i = 0; i < mComposition->numPages(); ++i )
19761982
{
19771983
if ( !mComposition->shouldExportPage( i + 1 ) )
@@ -1991,16 +1997,19 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
19911997
return;
19921998
}
19931999
bool saveOk;
2000+
QString outputFilePath;
19942001
if ( i == 0 )
19952002
{
1996-
saveOk = image.save( fileNExt.first, fileNExt.second.toLocal8Bit().constData() );
2003+
outputFilePath = fileNExt.first;
19972004
}
19982005
else
19992006
{
20002007
QFileInfo fi( fileNExt.first );
2001-
QString outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
2002-
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
2008+
outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
20032009
}
2010+
2011+
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
2012+
20042013
if ( !saveOk )
20052014
{
20062015
QMessageBox::warning( this, tr( "Image export error" ),
@@ -2010,21 +2019,20 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
20102019
mView->setPaintingEnabled( true );
20112020
return;
20122021
}
2013-
}
20142022

2015-
//
2016-
// Write the world file if asked to
2017-
if ( mComposition->generateWorldFile() )
2018-
{
2019-
double a, b, c, d, e, f;
2020-
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
2023+
if ( i == worldFilePageNo )
2024+
{
2025+
// should generate world file for this page
2026+
double a, b, c, d, e, f;
2027+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
20212028

2022-
QFileInfo fi( fileNExt.first );
2023-
// build the world file name
2024-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2025-
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
2029+
QFileInfo fi( outputFilePath );
2030+
// build the world file name
2031+
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2032+
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
20262033

2027-
writeWorldFile( worldFileName, a, b, c, d, e, f );
2034+
writeWorldFile( worldFileName, a, b, c, d, e, f );
2035+
}
20282036
}
20292037

20302038
mView->setPaintingEnabled( true );
@@ -2150,6 +2158,12 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21502158

21512159
QString filename = QDir( dir ).filePath( atlasMap->currentFilename() ) + fileExt;
21522160

2161+
int worldFilePageNo = -1;
2162+
if ( mComposition->generateWorldFile() && mComposition->worldFileMap() )
2163+
{
2164+
worldFilePageNo = mComposition->worldFileMap()->page() - 1;
2165+
}
2166+
21532167
for ( int i = 0; i < mComposition->numPages(); ++i )
21542168
{
21552169
if ( !mComposition->shouldExportPage( i + 1 ) )
@@ -2177,21 +2191,20 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21772191
QApplication::restoreOverrideCursor();
21782192
return;
21792193
}
2180-
}
21812194

2182-
//
2183-
// Write the world file if asked to
2184-
if ( mComposition->generateWorldFile() )
2185-
{
2186-
double a, b, c, d, e, f;
2187-
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
2195+
if ( i == worldFilePageNo )
2196+
{
2197+
// should generate world file for this page
2198+
double a, b, c, d, e, f;
2199+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
21882200

2189-
QFileInfo fi( filename );
2190-
// build the world file name
2191-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2192-
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
2201+
QFileInfo fi( imageFilename );
2202+
// build the world file name
2203+
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2204+
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
21932205

2194-
writeWorldFile( worldFileName, a, b, c, d, e, f );
2206+
writeWorldFile( worldFileName, a, b, c, d, e, f );
2207+
}
21952208
}
21962209
}
21972210
atlasMap->endRender();

0 commit comments

Comments
 (0)
Please sign in to comment.