Skip to content
Permalink
Browse files

refactor QgsPaintEngineHack into core and add python bindings

  • Loading branch information
jef-n committed Jul 5, 2012
1 parent b0034b1 commit 545220ec31339521947c11eb02ef6c81b631abb6
@@ -100,3 +100,5 @@
%Include qgsgpsdconnection.sip
%Include qgsnmeaconnection.sip
%Include qgsgpsdetector.sip

%Include qgspaintenginehack.sip
@@ -0,0 +1,8 @@
class CORE_EXPORT QgsPaintEngineHack : public QPaintEngine
{
%TypeHeaderCode
#include <qgspaintenginehack.h>
%End
public:
static void fixEngineFlags( QPaintEngine *engine );
};
@@ -45,6 +45,7 @@
#include "qgsmessageviewer.h"
#include "qgscontexthelp.h"
#include "qgscursors.h"
#include "qgspaintenginehack.h"

#include <QCloseEvent>
#include <QCheckBox>
@@ -524,38 +525,6 @@ void QgsComposer::on_mActionRefreshView_triggered()
mComposition->update();
}

// Hack to workaround Qt #5114 by disabling PatternTransform
class QgsPaintEngineHack : public QPaintEngine
{
public:
void fixFlags()
{
gccaps = 0;
gccaps |= ( QPaintEngine::PrimitiveTransform
// | QPaintEngine::PatternTransform
| QPaintEngine::PixmapTransform
| QPaintEngine::PatternBrush
// | QPaintEngine::LinearGradientFill
// | QPaintEngine::RadialGradientFill
// | QPaintEngine::ConicalGradientFill
| QPaintEngine::AlphaBlend
// | QPaintEngine::PorterDuff
| QPaintEngine::PainterPaths
| QPaintEngine::Antialiasing
| QPaintEngine::BrushStroke
| QPaintEngine::ConstantOpacity
| QPaintEngine::MaskedBrush
// | QPaintEngine::PerspectiveTransform
| QPaintEngine::BlendModes
// | QPaintEngine::ObjectBoundingModeGradients
#if QT_VERSION >= 0x040500
| QPaintEngine::RasterOpModes
#endif
| QPaintEngine::PaintOutsidePaintEvent
);
}
};

void QgsComposer::on_mActionExportAsPDF_triggered()
{
QSettings myQSettings; // where we keep last used filter in persistent state
@@ -582,13 +551,7 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
printer.setOutputFileName( outputFileName );
printer.setPaperSize( QSizeF( mComposition->paperWidth(), mComposition->paperHeight() ), QPrinter::Millimeter );

QPaintEngine *engine = printer.paintEngine();
if ( engine )
{
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
hack->fixFlags();
}

QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
print( printer );
}

@@ -186,6 +186,8 @@ SET(QGIS_CORE_SRCS
symbology/qgssymbologyutils.cpp

qgsspatialindex.cpp

qgspaintenginehack.cpp
)

IF(WIN32)
@@ -426,6 +428,8 @@ SET(QGIS_CORE_HDRS
qgsdiagramrendererv2.h

qgsspatialindex.h

qgspaintenginehack.h
)

IF (QT_MOBILITY_LOCATION_FOUND)
@@ -0,0 +1,55 @@
/***************************************************************************
qgspaintenginehack.cpp
Hack paint engine flags
-------------------
begin : July 2012
copyright : (C) Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgspaintenginehack.h"

// Hack to workaround Qt #5114 by disabling PatternTransform
void QgsPaintEngineHack::fixFlags()
{
gccaps = 0;
gccaps |= ( QPaintEngine::PrimitiveTransform
// | QPaintEngine::PatternTransform
| QPaintEngine::PixmapTransform
| QPaintEngine::PatternBrush
// | QPaintEngine::LinearGradientFill
// | QPaintEngine::RadialGradientFill
// | QPaintEngine::ConicalGradientFill
| QPaintEngine::AlphaBlend
// | QPaintEngine::PorterDuff
| QPaintEngine::PainterPaths
| QPaintEngine::Antialiasing
| QPaintEngine::BrushStroke
| QPaintEngine::ConstantOpacity
| QPaintEngine::MaskedBrush
// | QPaintEngine::PerspectiveTransform
| QPaintEngine::BlendModes
// | QPaintEngine::ObjectBoundingModeGradients
#if QT_VERSION >= 0x040500
| QPaintEngine::RasterOpModes
#endif
| QPaintEngine::PaintOutsidePaintEvent
);
}

void QgsPaintEngineHack::fixEngineFlags( QPaintEngine *engine )
{
if ( !engine )
return;

QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
hack->fixFlags();
}
@@ -0,0 +1,25 @@
/***************************************************************************
qgspaintenginehack.cpp - Hack paint engine flags
------------------------------------------------
begin : July 2012
copyright : (C) Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QPaintEngine>

// Hack to workaround Qt #5114 by disabling PatternTransform
class CORE_EXPORT QgsPaintEngineHack : public QPaintEngine
{
public:
void fixFlags();
static void fixEngineFlags( QPaintEngine *engine );
};
@@ -40,6 +40,8 @@
#include "qgslegendmodel.h"
#include "qgscomposerlegenditem.h"
#include "qgslogger.h"
#include "qgspaintenginehack.h"

#include <QImage>
#include <QPainter>
#include <QStringList>
@@ -505,38 +507,6 @@ QDomDocument QgsWMSServer::getStyle()
return mConfigParser->getStyle( styleName, layerName );
}

// Hack to workaround Qt #5114 by disabling PatternTransform
class QgsPaintEngineHack : public QPaintEngine
{
public:
void fixFlags()
{
gccaps = 0;
gccaps |= ( QPaintEngine::PrimitiveTransform
// | QPaintEngine::PatternTransform
| QPaintEngine::PixmapTransform
| QPaintEngine::PatternBrush
// | QPaintEngine::LinearGradientFill
// | QPaintEngine::RadialGradientFill
// | QPaintEngine::ConicalGradientFill
| QPaintEngine::AlphaBlend
// | QPaintEngine::PorterDuff
| QPaintEngine::PainterPaths
| QPaintEngine::Antialiasing
| QPaintEngine::BrushStroke
| QPaintEngine::ConstantOpacity
| QPaintEngine::MaskedBrush
// | QPaintEngine::PerspectiveTransform
| QPaintEngine::BlendModes
// | QPaintEngine::ObjectBoundingModeGradients
#if QT_VERSION >= 0x040500
| QPaintEngine::RasterOpModes
#endif
| QPaintEngine::PaintOutsidePaintEvent
);
}
};

QByteArray* QgsWMSServer::getPrint( const QString& formatString )
{
QStringList layersList, stylesList, layerIdList;
@@ -632,12 +602,7 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );

QPaintEngine *engine = printer.paintEngine();
if ( engine )
{
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
hack->fixFlags();
}
QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );

QPainter p( &printer );
if ( c->printAsRaster() ) //embed one raster into the pdf

0 comments on commit 545220e

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