Skip to content

Commit

Permalink
QPrinter is unavailable on some platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Nov 13, 2018
1 parent 1559013 commit 7564276
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/layout/qgslayoutexporter.sip.in
Expand Up @@ -8,6 +8,7 @@




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




/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
3 changes: 3 additions & 0 deletions src/core/layout/qgslayoutexporter.cpp
Expand Up @@ -15,6 +15,8 @@
***************************************************************************/

#include "qgslayoutexporter.h"
#ifndef QT_NO_PRINTER

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

#endif // ! QT_NO_PRINTER
6 changes: 5 additions & 1 deletion src/core/layout/qgslayoutexporter.h
Expand Up @@ -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;
Expand Down Expand Up @@ -562,6 +564,8 @@ class CORE_EXPORT QgsLayoutExporter

};

#endif // ! QT_NO_PRINTER

#endif //QGSLAYOUTEXPORTER_H


Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsmaprenderertask.cpp
Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -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" ) )
{
Expand Down
12 changes: 10 additions & 2 deletions src/core/qgsmaprenderertask.h
Expand Up @@ -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
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrunprocess.cpp
Expand Up @@ -166,6 +166,7 @@ void QgsRunProcess::processError( QProcess::ProcessError err )
#else
QgsRunProcess::QgsRunProcess( const QString &action, bool )
{
Q_UNUSED( action )
QgsDebugMsg( "Skipping command: " + action );
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsrunprocess.h
Expand Up @@ -28,6 +28,7 @@
#include "qgis_sip.h"

class QgsMessageOutput;

/**
* \ingroup core
* A class that executes an external program/script.
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 7564276

Please sign in to comment.