Skip to content

Commit 545220e

Browse files
committed
refactor QgsPaintEngineHack into core and add python bindings
1 parent b0034b1 commit 545220e

File tree

7 files changed

+99
-77
lines changed

7 files changed

+99
-77
lines changed

python/core/core.sip

+2
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@
100100
%Include qgsgpsdconnection.sip
101101
%Include qgsnmeaconnection.sip
102102
%Include qgsgpsdetector.sip
103+
104+
%Include qgspaintenginehack.sip

python/core/qgspaintenginehack.sip

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CORE_EXPORT QgsPaintEngineHack : public QPaintEngine
2+
{
3+
%TypeHeaderCode
4+
#include <qgspaintenginehack.h>
5+
%End
6+
public:
7+
static void fixEngineFlags( QPaintEngine *engine );
8+
};

src/app/composer/qgscomposer.cpp

+2-39
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "qgsmessageviewer.h"
4646
#include "qgscontexthelp.h"
4747
#include "qgscursors.h"
48+
#include "qgspaintenginehack.h"
4849

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

527-
// Hack to workaround Qt #5114 by disabling PatternTransform
528-
class QgsPaintEngineHack : public QPaintEngine
529-
{
530-
public:
531-
void fixFlags()
532-
{
533-
gccaps = 0;
534-
gccaps |= ( QPaintEngine::PrimitiveTransform
535-
// | QPaintEngine::PatternTransform
536-
| QPaintEngine::PixmapTransform
537-
| QPaintEngine::PatternBrush
538-
// | QPaintEngine::LinearGradientFill
539-
// | QPaintEngine::RadialGradientFill
540-
// | QPaintEngine::ConicalGradientFill
541-
| QPaintEngine::AlphaBlend
542-
// | QPaintEngine::PorterDuff
543-
| QPaintEngine::PainterPaths
544-
| QPaintEngine::Antialiasing
545-
| QPaintEngine::BrushStroke
546-
| QPaintEngine::ConstantOpacity
547-
| QPaintEngine::MaskedBrush
548-
// | QPaintEngine::PerspectiveTransform
549-
| QPaintEngine::BlendModes
550-
// | QPaintEngine::ObjectBoundingModeGradients
551-
#if QT_VERSION >= 0x040500
552-
| QPaintEngine::RasterOpModes
553-
#endif
554-
| QPaintEngine::PaintOutsidePaintEvent
555-
);
556-
}
557-
};
558-
559528
void QgsComposer::on_mActionExportAsPDF_triggered()
560529
{
561530
QSettings myQSettings; // where we keep last used filter in persistent state
@@ -582,13 +551,7 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
582551
printer.setOutputFileName( outputFileName );
583552
printer.setPaperSize( QSizeF( mComposition->paperWidth(), mComposition->paperHeight() ), QPrinter::Millimeter );
584553

585-
QPaintEngine *engine = printer.paintEngine();
586-
if ( engine )
587-
{
588-
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
589-
hack->fixFlags();
590-
}
591-
554+
QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
592555
print( printer );
593556
}
594557

src/core/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ SET(QGIS_CORE_SRCS
186186
symbology/qgssymbologyutils.cpp
187187

188188
qgsspatialindex.cpp
189+
190+
qgspaintenginehack.cpp
189191
)
190192

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

428430
qgsspatialindex.h
431+
432+
qgspaintenginehack.h
429433
)
430434

431435
IF (QT_MOBILITY_LOCATION_FOUND)

src/core/qgspaintenginehack.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/***************************************************************************
2+
qgspaintenginehack.cpp
3+
Hack paint engine flags
4+
-------------------
5+
begin : July 2012
6+
copyright : (C) Juergen E. Fischer
7+
email : jef at norbit dot de
8+
9+
***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgspaintenginehack.h"
19+
20+
// Hack to workaround Qt #5114 by disabling PatternTransform
21+
void QgsPaintEngineHack::fixFlags()
22+
{
23+
gccaps = 0;
24+
gccaps |= ( QPaintEngine::PrimitiveTransform
25+
// | QPaintEngine::PatternTransform
26+
| QPaintEngine::PixmapTransform
27+
| QPaintEngine::PatternBrush
28+
// | QPaintEngine::LinearGradientFill
29+
// | QPaintEngine::RadialGradientFill
30+
// | QPaintEngine::ConicalGradientFill
31+
| QPaintEngine::AlphaBlend
32+
// | QPaintEngine::PorterDuff
33+
| QPaintEngine::PainterPaths
34+
| QPaintEngine::Antialiasing
35+
| QPaintEngine::BrushStroke
36+
| QPaintEngine::ConstantOpacity
37+
| QPaintEngine::MaskedBrush
38+
// | QPaintEngine::PerspectiveTransform
39+
| QPaintEngine::BlendModes
40+
// | QPaintEngine::ObjectBoundingModeGradients
41+
#if QT_VERSION >= 0x040500
42+
| QPaintEngine::RasterOpModes
43+
#endif
44+
| QPaintEngine::PaintOutsidePaintEvent
45+
);
46+
}
47+
48+
void QgsPaintEngineHack::fixEngineFlags( QPaintEngine *engine )
49+
{
50+
if ( !engine )
51+
return;
52+
53+
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
54+
hack->fixFlags();
55+
}

src/core/qgspaintenginehack.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************************************************************
2+
qgspaintenginehack.cpp - Hack paint engine flags
3+
------------------------------------------------
4+
begin : July 2012
5+
copyright : (C) Juergen E. Fischer
6+
email : jef at norbit dot de
7+
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include <QPaintEngine>
18+
19+
// Hack to workaround Qt #5114 by disabling PatternTransform
20+
class CORE_EXPORT QgsPaintEngineHack : public QPaintEngine
21+
{
22+
public:
23+
void fixFlags();
24+
static void fixEngineFlags( QPaintEngine *engine );
25+
};

src/mapserver/qgswmsserver.cpp

+3-38
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "qgslegendmodel.h"
4141
#include "qgscomposerlegenditem.h"
4242
#include "qgslogger.h"
43+
#include "qgspaintenginehack.h"
44+
4345
#include <QImage>
4446
#include <QPainter>
4547
#include <QStringList>
@@ -505,38 +507,6 @@ QDomDocument QgsWMSServer::getStyle()
505507
return mConfigParser->getStyle( styleName, layerName );
506508
}
507509

508-
// Hack to workaround Qt #5114 by disabling PatternTransform
509-
class QgsPaintEngineHack : public QPaintEngine
510-
{
511-
public:
512-
void fixFlags()
513-
{
514-
gccaps = 0;
515-
gccaps |= ( QPaintEngine::PrimitiveTransform
516-
// | QPaintEngine::PatternTransform
517-
| QPaintEngine::PixmapTransform
518-
| QPaintEngine::PatternBrush
519-
// | QPaintEngine::LinearGradientFill
520-
// | QPaintEngine::RadialGradientFill
521-
// | QPaintEngine::ConicalGradientFill
522-
| QPaintEngine::AlphaBlend
523-
// | QPaintEngine::PorterDuff
524-
| QPaintEngine::PainterPaths
525-
| QPaintEngine::Antialiasing
526-
| QPaintEngine::BrushStroke
527-
| QPaintEngine::ConstantOpacity
528-
| QPaintEngine::MaskedBrush
529-
// | QPaintEngine::PerspectiveTransform
530-
| QPaintEngine::BlendModes
531-
// | QPaintEngine::ObjectBoundingModeGradients
532-
#if QT_VERSION >= 0x040500
533-
| QPaintEngine::RasterOpModes
534-
#endif
535-
| QPaintEngine::PaintOutsidePaintEvent
536-
);
537-
}
538-
};
539-
540510
QByteArray* QgsWMSServer::getPrint( const QString& formatString )
541511
{
542512
QStringList layersList, stylesList, layerIdList;
@@ -632,12 +602,7 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
632602
QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
633603
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
634604

635-
QPaintEngine *engine = printer.paintEngine();
636-
if ( engine )
637-
{
638-
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
639-
hack->fixFlags();
640-
}
605+
QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
641606

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

0 commit comments

Comments
 (0)