| 1318 | } |
| 1319 | |
| 1320 | void PrintWidget::exportToPdf() |
| 1321 | { |
| 1322 | auto printer = map_printer->makePrinter(); |
| 1323 | if (!printer) |
| 1324 | { |
| 1325 | QMessageBox::warning(this, tr("Error"), tr("Failed to prepare the PDF export.")); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | printer->setOutputFormat(QPrinter::PdfFormat); |
| 1330 | printer->setNumCopies(copies_edit->value()); |
| 1331 | printer->setCreator(main_window->appName()); |
| 1332 | printer->setDocName(QFileInfo(main_window->currentPath()).baseName()); |
| 1333 | |
| 1334 | static const QString filter_template(QString::fromLatin1("%1 (%2)")); |
| 1335 | QStringList filters = { filter_template.arg(tr("PDF"), QString::fromLatin1("*.pdf")), |
| 1336 | tr("All files (*.*)") }; |
| 1337 | QString path = FileDialog::getSaveFileName(this, tr("Export map ..."), {}, filters.join(QString::fromLatin1(";;"))); |
| 1338 | if (path.isEmpty()) |
| 1339 | { |
| 1340 | return; |
| 1341 | } |
| 1342 | else if (!path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive)) |
| 1343 | { |
| 1344 | path.append(QLatin1String(".pdf")); |
| 1345 | } |
| 1346 | printer->setOutputFileName(path); |
| 1347 | |
| 1348 | PrintProgressDialog progress(map_printer, main_window); |
| 1349 | progress.setWindowTitle(tr("Export map ...")); |
| 1350 | |
| 1351 | // Export the map |
| 1352 | if (!map_printer->printMap(printer.get())) |
| 1353 | { |
| 1354 | QFile(path).remove(); |
| 1355 | QMessageBox::warning(this, tr("Error"), tr("Failed to finish the PDF export.")); |
| 1356 | } |
| 1357 | else if (!progress.wasCanceled()) |
| 1358 | { |
| 1359 | main_window->showStatusBarMessage(tr("Exported successfully to %1").arg(path), 4000); |
| 1360 | emit finished(0); |
| 1361 | } |
| 1362 | else |
| 1363 | { |
| 1364 | QFile(path).remove(); |
| 1365 | main_window->showStatusBarMessage(tr("Canceled."), 4000); |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | void PrintWidget::print() |
| 1370 | { |
nothing calls this directly
no test coverage detected