Skip to content

Commit 911038b

Browse files
author
mhugent
committed
Scale brush content for printing. Adresses ticket #454. Works for ps, but not for pdf output. A qt bug?
git-svn-id: http://svn.osgeo.org/qgis/trunk@9281 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5154596 commit 911038b

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

src/core/renderer/qgsgraduatedsymbolrenderer.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,28 @@ void QgsGraduatedSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QI
141141
QPen pen = theSymbol->pen();
142142
pen.setWidthF( widthScale * pen.widthF() );
143143
p->setPen( pen );
144-
p->setBrush( theSymbol->brush() );
144+
145+
if(mVectorType == QGis::Polygon)
146+
{
147+
QBrush brush = theSymbol->brush();
148+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
149+
p->setBrush(brush);
150+
}
145151
}
146152
else
147153
{
148154
QPen pen = theSymbol->pen();
149155
pen.setColor( mSelectionColor );
150156
pen.setWidthF( widthScale * pen.widthF() );
151-
QBrush brush = theSymbol->brush();
152-
brush.setColor( mSelectionColor );
153157
p->setPen( pen );
154-
p->setBrush( brush );
158+
159+
if(mVectorType == QGis::Polygon)
160+
{
161+
QBrush brush = theSymbol->brush();
162+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
163+
brush.setColor( mSelectionColor );
164+
p->setBrush( brush );
165+
}
155166
}
156167
}
157168
}

src/core/renderer/qgsrenderer.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
***************************************************************************/
1818
#include "qgsrenderer.h"
1919

20+
#include <QBrush>
2021
#include <QColor>
22+
#include <QMatrix>
2123
#include <QString>
2224

2325

@@ -48,3 +50,13 @@ bool QgsRenderer::containsPixmap() const
4850
return false;
4951
}
5052
}
53+
54+
void QgsRenderer::scaleBrush(QBrush& b, double rasterScaleFactor) const
55+
{
56+
if(rasterScaleFactor != 1.0)
57+
{
58+
QMatrix m;
59+
m.scale(1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor);
60+
b.setMatrix(m);
61+
}
62+
}

src/core/renderer/qgsrenderer.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class QColor;
3030
#include <QList>
3131

3232
class QgsSymbol;
33+
class QBrush;
3334

3435
typedef QList<int> QgsAttributeList;
3536

@@ -93,6 +94,9 @@ class CORE_EXPORT QgsRenderer
9394

9495
/**Layer type*/
9596
QGis::VectorType mVectorType;
97+
98+
/**Scales a brush to a given raster scale factor (e.g. for printing)*/
99+
void scaleBrush(QBrush& b, double rasterScaleFactor) const;
96100
};
97101

98102
#endif // QGSRENDERER_H

src/core/renderer/qgssinglesymbolrenderer.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ void QgsSingleSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QImag
125125
QPen pen = mSymbol->pen();
126126
pen.setWidthF( widthScale * pen.widthF() );
127127
p->setPen( pen );
128-
p->setBrush( mSymbol->brush() );
128+
129+
if(mVectorType == QGis::Polygon)
130+
{
131+
QBrush brush = mSymbol->brush();
132+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
133+
p->setBrush(brush);
134+
}
129135
}
130136
else
131137
{
@@ -134,10 +140,15 @@ void QgsSingleSymbolRenderer::renderFeature( QPainter * p, QgsFeature & f, QImag
134140
// We set pen color in case it is an area with no brush (transparent).
135141
// Previously, this was only done for lines. Why?
136142
pen.setColor( mSelectionColor );
137-
QBrush brush = mSymbol->brush();
138-
brush.setColor( mSelectionColor );
139143
p->setPen( pen );
140-
p->setBrush( brush );
144+
145+
if(mVectorType == QGis::Polygon)
146+
{
147+
QBrush brush = mSymbol->brush();
148+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
149+
brush.setColor( mSelectionColor );
150+
p->setBrush( brush );
151+
}
141152
}
142153
}
143154
}

src/core/renderer/qgsuniquevaluerenderer.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,26 @@ void QgsUniqueValueRenderer::renderFeature( QPainter* p, QgsFeature& f, QImage*
150150
QPen pen = symbol->pen();
151151
pen.setWidthF( widthScale * pen.widthF() );
152152
p->setPen( pen );
153-
p->setBrush( symbol->brush() );
153+
if(mVectorType == QGis::Polygon)
154+
{
155+
QBrush brush = symbol->brush();
156+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
157+
p->setBrush(brush);
158+
}
154159
}
155160
else
156161
{
157162
QPen pen = symbol->pen();
158163
pen.setWidthF( widthScale * pen.widthF() );
159164
pen.setColor( mSelectionColor );
160-
QBrush brush = symbol->brush();
161-
brush.setColor( mSelectionColor );
162165
p->setPen( pen );
163-
p->setBrush( brush );
166+
if(mVectorType == QGis::Polygon)
167+
{
168+
QBrush brush = symbol->brush();
169+
scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
170+
brush.setColor( mSelectionColor );
171+
p->setBrush( brush );
172+
}
164173
}
165174
}
166175
}

0 commit comments

Comments
 (0)