Skip to content

Commit

Permalink
other workaround for Qt#5114 (fixes #3250, #3028, #2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 3, 2011
1 parent 8eb7664 commit 55a1778
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/app/composer/qgscomposer.cpp 100644 → 100755
Expand Up @@ -66,9 +66,7 @@
#include <QToolBar>
#include <QToolButton>
#include <QUndoView>



#include <QPaintEngine>


QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title ), mUndoView( 0 )
Expand Down Expand Up @@ -486,6 +484,36 @@ 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
| QPaintEngine::RasterOpModes
| QPaintEngine::PaintOutsidePaintEvent
);
}
};

void QgsComposer::on_mActionExportAsPDF_triggered()
{
QSettings myQSettings; // where we keep last used filter in persistent state
Expand Down Expand Up @@ -521,6 +549,14 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
printer.setOutputFileName( myOutputFileNameQString );
printer.setPaperSize( QSizeF( mComposition->paperWidth(), mComposition->paperHeight() ), QPrinter::Millimeter );

QPaintEngine *engine = printer.paintEngine();
if ( engine && engine->hasFeature( QPaintEngine::PatternTransform ) )
{
QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack*>( engine );
hack->fixFlags();
Q_ASSERT( !engine->hasFeature( QPaintEngine::PatternTransform ) );
}

print( printer );
}

Expand Down
40 changes: 40 additions & 0 deletions src/mapserver/qgswmsserver.cpp 100644 → 100755
Expand Up @@ -51,6 +51,7 @@
#include <QPrinter>
#include <QSvgGenerator>
#include <QUrl>
#include <QPaintEngine>

QgsWMSServer::QgsWMSServer( std::map<QString, QString> parameters, QgsMapRenderer* renderer )
: mParameterMap( parameters )
Expand Down Expand Up @@ -337,6 +338,36 @@ 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
| QPaintEngine::RasterOpModes
| QPaintEngine::PaintOutsidePaintEvent
);
}
};

QByteArray* QgsWMSServer::getPrint( const QString& formatString )
{
QStringList layersList, stylesList, layerIdList;
Expand Down Expand Up @@ -429,6 +460,15 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
printer.setPaperSize( QSizeF( c->paperWidth(), c->paperHeight() ), QPrinter::Millimeter );
QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );

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

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

0 comments on commit 55a1778

Please sign in to comment.