Skip to content

Commit fc8f30e

Browse files
committedSep 16, 2015
[composer] Fix world file filename for multipage compositions
also fix #11676 (cherry-picked from c84b2df)
1 parent 4fbff34 commit fc8f30e

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
@@ -1866,6 +1866,12 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
18661866

18671867
mView->setPaintingEnabled( false );
18681868

1869+
int worldFilePageNo = -1;
1870+
if ( mComposition->generateWorldFile() && mComposition->worldFileMap() )
1871+
{
1872+
worldFilePageNo = mComposition->worldFileMap()->page() - 1;
1873+
}
1874+
18691875
for ( int i = 0; i < mComposition->numPages(); ++i )
18701876
{
18711877
if ( !mComposition->shouldExportPage( i + 1 ) )
@@ -1885,16 +1891,19 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
18851891
return;
18861892
}
18871893
bool saveOk;
1894+
QString outputFilePath;
18881895
if ( i == 0 )
18891896
{
1890-
saveOk = image.save( fileNExt.first, fileNExt.second.toLocal8Bit().constData() );
1897+
outputFilePath = fileNExt.first;
18911898
}
18921899
else
18931900
{
18941901
QFileInfo fi( fileNExt.first );
1895-
QString outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
1896-
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
1902+
outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
18971903
}
1904+
1905+
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
1906+
18981907
if ( !saveOk )
18991908
{
19001909
QMessageBox::warning( this, tr( "Image export error" ),
@@ -1904,21 +1913,20 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
19041913
mView->setPaintingEnabled( true );
19051914
return;
19061915
}
1907-
}
19081916

1909-
//
1910-
// Write the world file if asked to
1911-
if ( mComposition->generateWorldFile() )
1912-
{
1913-
double a, b, c, d, e, f;
1914-
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
1917+
if ( i == worldFilePageNo )
1918+
{
1919+
// should generate world file for this page
1920+
double a, b, c, d, e, f;
1921+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
19151922

1916-
QFileInfo fi( fileNExt.first );
1917-
// build the world file name
1918-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
1919-
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
1923+
QFileInfo fi( outputFilePath );
1924+
// build the world file name
1925+
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
1926+
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
19201927

1921-
writeWorldFile( worldFileName, a, b, c, d, e, f );
1928+
writeWorldFile( worldFileName, a, b, c, d, e, f );
1929+
}
19221930
}
19231931

19241932
mView->setPaintingEnabled( true );
@@ -2044,6 +2052,12 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
20442052

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

2055+
int worldFilePageNo = -1;
2056+
if ( mComposition->generateWorldFile() && mComposition->worldFileMap() )
2057+
{
2058+
worldFilePageNo = mComposition->worldFileMap()->page() - 1;
2059+
}
2060+
20472061
for ( int i = 0; i < mComposition->numPages(); ++i )
20482062
{
20492063
if ( !mComposition->shouldExportPage( i + 1 ) )
@@ -2071,21 +2085,20 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
20712085
QApplication::restoreOverrideCursor();
20722086
return;
20732087
}
2074-
}
20752088

2076-
//
2077-
// Write the world file if asked to
2078-
if ( mComposition->generateWorldFile() )
2079-
{
2080-
double a, b, c, d, e, f;
2081-
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
2089+
if ( i == worldFilePageNo )
2090+
{
2091+
// should generate world file for this page
2092+
double a, b, c, d, e, f;
2093+
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
20822094

2083-
QFileInfo fi( filename );
2084-
// build the world file name
2085-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2086-
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
2095+
QFileInfo fi( imageFilename );
2096+
// build the world file name
2097+
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2098+
+ fi.suffix()[0] + fi.suffix()[fi.suffix().size()-1] + "w";
20872099

2088-
writeWorldFile( worldFileName, a, b, c, d, e, f );
2100+
writeWorldFile( worldFileName, a, b, c, d, e, f );
2101+
}
20892102
}
20902103
}
20912104
atlasMap->endRender();

0 commit comments

Comments
 (0)
Please sign in to comment.