Skip to content

Commit

Permalink
Scale brush content for printing. Adresses ticket #454. Works for ps,…
Browse files Browse the repository at this point in the history
… but not for pdf output. A qt bug?

git-svn-id: http://svn.osgeo.org/qgis/trunk@9281 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 7, 2008
1 parent 5154596 commit 911038b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
19 changes: 15 additions & 4 deletions src/core/renderer/qgsgraduatedsymbolrenderer.cpp
Expand Up @@ -141,17 +141,28 @@ void QgsGraduatedSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QI
QPen pen = theSymbol->pen();
pen.setWidthF( widthScale * pen.widthF() );
p->setPen( pen );
p->setBrush( theSymbol->brush() );

if(mVectorType == QGis::Polygon)
{
QBrush brush = theSymbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
p->setBrush(brush);
}
}
else
{
QPen pen = theSymbol->pen();
pen.setColor( mSelectionColor );
pen.setWidthF( widthScale * pen.widthF() );
QBrush brush = theSymbol->brush();
brush.setColor( mSelectionColor );
p->setPen( pen );
p->setBrush( brush );

if(mVectorType == QGis::Polygon)
{
QBrush brush = theSymbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
brush.setColor( mSelectionColor );
p->setBrush( brush );
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/core/renderer/qgsrenderer.cpp
Expand Up @@ -17,7 +17,9 @@
***************************************************************************/
#include "qgsrenderer.h"

#include <QBrush>
#include <QColor>
#include <QMatrix>
#include <QString>


Expand Down Expand Up @@ -48,3 +50,13 @@ bool QgsRenderer::containsPixmap() const
return false;
}
}

void QgsRenderer::scaleBrush(QBrush& b, double rasterScaleFactor) const
{
if(rasterScaleFactor != 1.0)
{
QMatrix m;
m.scale(1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor);
b.setMatrix(m);
}
}
4 changes: 4 additions & 0 deletions src/core/renderer/qgsrenderer.h
Expand Up @@ -30,6 +30,7 @@ class QColor;
#include <QList>

class QgsSymbol;
class QBrush;

typedef QList<int> QgsAttributeList;

Expand Down Expand Up @@ -93,6 +94,9 @@ class CORE_EXPORT QgsRenderer

/**Layer type*/
QGis::VectorType mVectorType;

/**Scales a brush to a given raster scale factor (e.g. for printing)*/
void scaleBrush(QBrush& b, double rasterScaleFactor) const;
};

#endif // QGSRENDERER_H
19 changes: 15 additions & 4 deletions src/core/renderer/qgssinglesymbolrenderer.cpp
Expand Up @@ -125,7 +125,13 @@ void QgsSingleSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QImag
QPen pen = mSymbol->pen();
pen.setWidthF( widthScale * pen.widthF() );
p->setPen( pen );
p->setBrush( mSymbol->brush() );

if(mVectorType == QGis::Polygon)
{
QBrush brush = mSymbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
p->setBrush(brush);
}
}
else
{
Expand All @@ -134,10 +140,15 @@ void QgsSingleSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QImag
// We set pen color in case it is an area with no brush (transparent).
// Previously, this was only done for lines. Why?
pen.setColor( mSelectionColor );
QBrush brush = mSymbol->brush();
brush.setColor( mSelectionColor );
p->setPen( pen );
p->setBrush( brush );

if(mVectorType == QGis::Polygon)
{
QBrush brush = mSymbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
brush.setColor( mSelectionColor );
p->setBrush( brush );
}
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/core/renderer/qgsuniquevaluerenderer.cpp
Expand Up @@ -150,17 +150,26 @@ void QgsUniqueValueRenderer::renderFeature( QPainter* p, QgsFeature& f, QImage*
QPen pen = symbol->pen();
pen.setWidthF( widthScale * pen.widthF() );
p->setPen( pen );
p->setBrush( symbol->brush() );
if(mVectorType == QGis::Polygon)
{
QBrush brush = symbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
p->setBrush(brush);
}
}
else
{
QPen pen = symbol->pen();
pen.setWidthF( widthScale * pen.widthF() );
pen.setColor( mSelectionColor );
QBrush brush = symbol->brush();
brush.setColor( mSelectionColor );
p->setPen( pen );
p->setBrush( brush );
if(mVectorType == QGis::Polygon)
{
QBrush brush = symbol->brush();
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
brush.setColor( mSelectionColor );
p->setBrush( brush );
}
}
}
}
Expand Down

0 comments on commit 911038b

Please sign in to comment.