@@ -1406,7 +1406,16 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
1406
1406
mComposition ->beginPrintAsPDF ( printer, outputFileName );
1407
1407
// set the correct resolution
1408
1408
mComposition ->beginPrint ( printer );
1409
- painter.begin ( &printer );
1409
+ bool printReady = painter.begin ( &printer );
1410
+ if ( !printReady )
1411
+ {
1412
+ QMessageBox::warning ( this , tr ( " Atlas processing error" ),
1413
+ QString ( tr ( " Error creating %1." ) ).arg ( outputFileName ),
1414
+ QMessageBox::Ok,
1415
+ QMessageBox::Ok );
1416
+ mView ->setPaintingEnabled ( true );
1417
+ return ;
1418
+ }
1410
1419
}
1411
1420
1412
1421
QProgressDialog progress ( tr ( " Rendering maps..." ), tr ( " Abort" ), 0 , atlasMap->numFeatures (), this );
@@ -1429,6 +1438,7 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
1429
1438
QMessageBox::Ok,
1430
1439
QMessageBox::Ok );
1431
1440
mView ->setPaintingEnabled ( true );
1441
+ QApplication::restoreOverrideCursor ();
1432
1442
return ;
1433
1443
}
1434
1444
if ( !atlasOnASingleFile )
@@ -1441,7 +1451,17 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
1441
1451
mComposition ->beginPrintAsPDF ( multiFilePrinter, outputFileName );
1442
1452
// set the correct resolution
1443
1453
mComposition ->beginPrint ( multiFilePrinter );
1444
- painter.begin ( &multiFilePrinter );
1454
+ bool printReady = painter.begin ( &multiFilePrinter );
1455
+ if ( !printReady )
1456
+ {
1457
+ QMessageBox::warning ( this , tr ( " Atlas processing error" ),
1458
+ QString ( tr ( " Error creating %1." ) ).arg ( outputFileName ),
1459
+ QMessageBox::Ok,
1460
+ QMessageBox::Ok );
1461
+ mView ->setPaintingEnabled ( true );
1462
+ QApplication::restoreOverrideCursor ();
1463
+ return ;
1464
+ }
1445
1465
mComposition ->doPrint ( multiFilePrinter, painter );
1446
1466
painter.end ();
1447
1467
}
@@ -1462,7 +1482,17 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
1462
1482
}
1463
1483
else
1464
1484
{
1465
- mComposition ->exportAsPDF ( outputFileName );
1485
+ bool exportOk = mComposition ->exportAsPDF ( outputFileName );
1486
+ if ( !exportOk )
1487
+ {
1488
+ QMessageBox::warning ( this , tr ( " Atlas processing error" ),
1489
+ QString ( tr ( " Error creating %1." ) ).arg ( outputFileName ),
1490
+ QMessageBox::Ok,
1491
+ QMessageBox::Ok );
1492
+ mView ->setPaintingEnabled ( true );
1493
+ QApplication::restoreOverrideCursor ();
1494
+ return ;
1495
+ }
1466
1496
}
1467
1497
1468
1498
if ( ! mComposition ->useAdvancedEffects () )
@@ -1547,6 +1577,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
1547
1577
QMessageBox::Ok,
1548
1578
QMessageBox::Ok );
1549
1579
mView ->setPaintingEnabled ( true );
1580
+ QApplication::restoreOverrideCursor ();
1550
1581
return ;
1551
1582
}
1552
1583
QProgressDialog progress ( tr ( " Rendering maps..." ), tr ( " Abort" ), 0 , atlasMap->numFeatures (), this );
@@ -1569,6 +1600,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
1569
1600
QMessageBox::Ok,
1570
1601
QMessageBox::Ok );
1571
1602
mView ->setPaintingEnabled ( true );
1603
+ QApplication::restoreOverrideCursor ();
1572
1604
return ;
1573
1605
}
1574
1606
@@ -1681,15 +1713,25 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
1681
1713
mView ->setPaintingEnabled ( true );
1682
1714
return ;
1683
1715
}
1716
+ bool saveOk;
1684
1717
if ( i == 0 )
1685
1718
{
1686
- image.save ( fileNExt.first , fileNExt.second .toLocal8Bit ().constData () );
1719
+ saveOk = image.save ( fileNExt.first , fileNExt.second .toLocal8Bit ().constData () );
1687
1720
}
1688
1721
else
1689
1722
{
1690
1723
QFileInfo fi ( fileNExt.first );
1691
1724
QString outputFilePath = fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix ();
1692
- image.save ( outputFilePath, fileNExt.second .toLocal8Bit ().constData () );
1725
+ saveOk = image.save ( outputFilePath, fileNExt.second .toLocal8Bit ().constData () );
1726
+ }
1727
+ if ( !saveOk )
1728
+ {
1729
+ QMessageBox::warning ( this , tr ( " Image export error" ),
1730
+ QString ( tr ( " Error creating %1." ) ).arg ( fileNExt.first ),
1731
+ QMessageBox::Ok,
1732
+ QMessageBox::Ok );
1733
+ mView ->setPaintingEnabled ( true );
1734
+ return ;
1693
1735
}
1694
1736
}
1695
1737
@@ -1800,6 +1842,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
1800
1842
QMessageBox::Ok,
1801
1843
QMessageBox::Ok );
1802
1844
mView ->setPaintingEnabled ( true );
1845
+ QApplication::restoreOverrideCursor ();
1803
1846
return ;
1804
1847
}
1805
1848
@@ -1823,6 +1866,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
1823
1866
QMessageBox::Ok,
1824
1867
QMessageBox::Ok );
1825
1868
mView ->setPaintingEnabled ( true );
1869
+ QApplication::restoreOverrideCursor ();
1826
1870
return ;
1827
1871
}
1828
1872
@@ -1831,16 +1875,25 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
1831
1875
for ( int i = 0 ; i < mComposition ->numPages (); ++i )
1832
1876
{
1833
1877
QImage image = mComposition ->printPageAsRaster ( i );
1878
+ QString imageFilename = filename;
1834
1879
1835
- if ( i = = 0 )
1880
+ if ( i ! = 0 )
1836
1881
{
1837
- image.save ( filename, format.toLocal8Bit ().constData () );
1882
+ // append page number
1883
+ QFileInfo fi ( filename );
1884
+ imageFilename = fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix ();
1838
1885
}
1839
- else
1886
+
1887
+ bool saveOk = image.save ( imageFilename, format.toLocal8Bit ().constData () );
1888
+ if ( !saveOk )
1840
1889
{
1841
- QFileInfo fi ( filename );
1842
- QString outputFilePath = fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix ();
1843
- image.save ( outputFilePath, format.toLocal8Bit ().constData () );
1890
+ QMessageBox::warning ( this , tr ( " Atlas processing error" ),
1891
+ QString ( tr ( " Error creating %1." ) ).arg ( imageFilename ),
1892
+ QMessageBox::Ok,
1893
+ QMessageBox::Ok );
1894
+ mView ->setPaintingEnabled ( true );
1895
+ QApplication::restoreOverrideCursor ();
1896
+ return ;
1844
1897
}
1845
1898
}
1846
1899
@@ -2098,14 +2151,16 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
2098
2151
{
2099
2152
QSvgGenerator generator;
2100
2153
generator.setTitle ( QgsProject::instance ()->title () );
2154
+ QString currentFileName = outputFileName;
2101
2155
if ( i == 0 )
2102
2156
{
2103
2157
generator.setFileName ( outputFileName );
2104
2158
}
2105
2159
else
2106
2160
{
2107
2161
QFileInfo fi ( outputFileName );
2108
- generator.setFileName ( fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix () );
2162
+ currentFileName = fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix ();
2163
+ generator.setFileName ( currentFileName );
2109
2164
}
2110
2165
2111
2166
// width in pixel
@@ -2116,7 +2171,17 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
2116
2171
generator.setViewBox ( QRect ( 0 , 0 , width, height ) );
2117
2172
generator.setResolution ( mComposition ->printResolution () ); // because the rendering is done in mm, convert the dpi
2118
2173
2119
- QPainter p ( &generator );
2174
+ QPainter p;
2175
+ bool createOk = p.begin ( &generator );
2176
+ if ( !createOk )
2177
+ {
2178
+ QMessageBox::warning ( this , tr ( " SVG export error" ),
2179
+ QString ( tr ( " Error creating %1." ) ).arg ( currentFileName ),
2180
+ QMessageBox::Ok,
2181
+ QMessageBox::Ok );
2182
+ mView ->setPaintingEnabled ( true );
2183
+ return ;
2184
+ }
2120
2185
2121
2186
mComposition ->renderPage ( &p, i );
2122
2187
p.end ();
@@ -2224,8 +2289,19 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
2224
2289
}
2225
2290
}
2226
2291
QFileInfo fi ( outputFileName );
2227
- QFile out ( i == 0 ? outputFileName : fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix () );
2228
- out.open ( QIODevice::WriteOnly | QIODevice::Text );
2292
+ QString currentFileName = i == 0 ? outputFileName : fi.absolutePath () + " /" + fi.baseName () + " _" + QString::number ( i + 1 ) + " ." + fi.suffix ();
2293
+ QFile out ( currentFileName );
2294
+ bool openOk = out.open ( QIODevice::WriteOnly | QIODevice::Text );
2295
+ if ( !openOk )
2296
+ {
2297
+ QMessageBox::warning ( this , tr ( " SVG export error" ),
2298
+ QString ( tr ( " Error creating %1." ) ).arg ( currentFileName ),
2299
+ QMessageBox::Ok,
2300
+ QMessageBox::Ok );
2301
+ mView ->setPaintingEnabled ( true );
2302
+ return ;
2303
+ }
2304
+
2229
2305
out.write ( svg.toByteArray () );
2230
2306
}
2231
2307
}
0 commit comments