Skip to content
Permalink
Browse files

QPrinter is unavailable on some platforms

  • Loading branch information
PeterPetrik committed Oct 11, 2018
1 parent 1559013 commit 75642769949b2b964a3b26183355e6098faa4d4b
@@ -8,6 +8,7 @@




class QgsLayoutExporter
{
%Docstring
@@ -363,6 +364,7 @@ Subclasses can override this method to customize page file naming.




/************************************************************************
* This file has been generated automatically from *
* *
@@ -15,6 +15,8 @@
***************************************************************************/

#include "qgslayoutexporter.h"
#ifndef QT_NO_PRINTER

#include "qgslayout.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutpagecollection.h"
@@ -1622,3 +1624,4 @@ bool QgsLayoutExporter::saveImage( const QImage &image, const QString &imageFile
return w.write( image );
}

#endif // ! QT_NO_PRINTER
@@ -16,14 +16,16 @@
#ifndef QGSLAYOUTEXPORTER_H
#define QGSLAYOUTEXPORTER_H

#include <QPrinter>
#include "qgis_core.h"
#include "qgsmargins.h"
#include "qgslayoutrendercontext.h"
#include "qgslayoutreportcontext.h"
#include <QPointer>
#include <QSize>
#include <QRectF>
#include <QPrinter>

#ifndef QT_NO_PRINTER

class QgsLayout;
class QPainter;
@@ -562,6 +564,8 @@ class CORE_EXPORT QgsLayoutExporter

};

#endif // ! QT_NO_PRINTER

#endif //QGSLAYOUTEXPORTER_H


@@ -72,10 +72,14 @@ bool QgsMapRendererTask::run()
QImage img;
std::unique_ptr< QPainter > tempPainter;
QPainter *destPainter = mPainter;

#ifndef QT_NO_PRINTER
std::unique_ptr< QPrinter > printer;
#endif // ! QT_NO_PRINTER

if ( mFileFormat == QStringLiteral( "PDF" ) )
{
#ifndef QT_NO_PRINTER
printer.reset( new QPrinter() );
printer->setOutputFileName( mFileName );
printer->setOutputFormat( QPrinter::PdfFormat );
@@ -90,6 +94,10 @@ bool QgsMapRendererTask::run()
tempPainter.reset( new QPainter( printer.get() ) );
destPainter = tempPainter.get();
}
#else
mError = ImageUnsupportedFormat;
return false;
#endif // ! QT_NO_PRINTER
}

if ( !destPainter )
@@ -173,11 +181,16 @@ bool QgsMapRendererTask::run()

if ( mForceRaster && mFileFormat == QStringLiteral( "PDF" ) )
{
#ifndef QT_NO_PRINTER
QPainter pp;
pp.begin( printer.get() );
QRectF rect( 0, 0, img.width(), img.height() );
pp.drawImage( rect, img, rect );
pp.end();
#else
mError = ImageUnsupportedFormat;
return false;
#endif // !QT_NO_PRINTER
}
else if ( mFileFormat != QStringLiteral( "PDF" ) )
{
@@ -46,8 +46,16 @@ class CORE_EXPORT QgsMapRendererTask : public QgsTask
//! \brief Error type
enum ErrorType
{
ImageAllocationFail = 1, // Image allocation failure
ImageSaveFail // Image save failure
//! Image allocation failure
ImageAllocationFail = 1,
//! Image save failure
ImageSaveFail,

/**
* Format is unsupported on the platform
* \since QGIS 3.4
*/
ImageUnsupportedFormat
};

/**
@@ -166,6 +166,7 @@ void QgsRunProcess::processError( QProcess::ProcessError err )
#else
QgsRunProcess::QgsRunProcess( const QString &action, bool )
{
Q_UNUSED( action )
QgsDebugMsg( "Skipping command: " + action );
}

@@ -28,6 +28,7 @@
#include "qgis_sip.h"

class QgsMessageOutput;

/**
* \ingroup core
* A class that executes an external program/script.
@@ -64,7 +65,7 @@ class CORE_EXPORT QgsRunProcess: public QObject SIP_NODEFAULTCTORS
QgsMessageOutput *mOutput = nullptr;
QString mCommand;

public slots:
public slots:
void stdoutAvailable();
void stderrAvailable();
void processError( QProcess::ProcessError );

0 comments on commit 7564276

Please sign in to comment.
You can’t perform that action at this time.