Skip to content

Commit 31a8e29

Browse files
author
mhugent
committedJan 14, 2010
[FEATURE]: choice between mm and map units for new symbology. Scaling to use new symbology in print composer as well
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12755 c8812cc2-4d05-0410-92ff-de0c093fc19c

23 files changed

+462
-149
lines changed
 

‎python/core/symbology-ng-core.sip

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,14 @@ public:
350350

351351
virtual QString layerType() const = 0;
352352

353-
virtual void startRender(QgsRenderContext& context) = 0;
354-
virtual void stopRender(QgsRenderContext& context) = 0;
353+
virtual void startRender(QgsSymbolV2RenderContext& context) = 0;
354+
virtual void stopRender(QgsSymbolV2RenderContext& context) = 0;
355355

356356
virtual QgsSymbolLayerV2* clone() const = 0 /Factory/;
357357

358358
virtual QgsStringMap properties() const = 0;
359359

360-
virtual void drawPreviewIcon(QPainter* painter, QSize size) = 0;
360+
virtual void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size) = 0;
361361

362362
virtual QgsSymbolV2* subSymbol();
363363
virtual bool setSubSymbol(QgsSymbolV2* symbol /Transfer/);
@@ -385,9 +385,9 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2
385385
%End
386386

387387
public:
388-
virtual void renderPoint(const QPointF& point, QgsRenderContext& context) = 0;
388+
virtual void renderPoint(const QPointF& point, QgsSymbolV2RenderContext& context) = 0;
389389

390-
void drawPreviewIcon(QPainter* painter, QSize size);
390+
void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);
391391

392392
void setAngle(double angle);
393393
double angle() const;
@@ -407,12 +407,12 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
407407
%End
408408

409409
public:
410-
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;
410+
virtual void renderPolyline(const QPolygonF& points, QgsSymbolV2RenderContext& context) = 0;
411411

412412
void setWidth(double width);
413413
double width() const;
414414

415-
void drawPreviewIcon(QPainter* painter, QSize size);
415+
void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);
416416

417417
protected:
418418
QgsLineSymbolLayerV2(bool locked = false);
@@ -426,15 +426,34 @@ class QgsFillSymbolLayerV2 : QgsSymbolLayerV2
426426
%End
427427

428428
public:
429-
virtual void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context) = 0;
429+
virtual void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context) = 0;
430430

431-
void drawPreviewIcon(QPainter* painter, QSize size);
431+
void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);
432432

433433
protected:
434434
QgsFillSymbolLayerV2(bool locked = false);
435435
};
436436

437437

438+
///////////////
439+
440+
class QgsSymbolV2RenderContext
441+
{
442+
%TypeHeaderCode
443+
#include <qgssymbolv2.h>
444+
%End
445+
446+
public:
447+
QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u);
448+
~QgsSymbolV2RenderContext();
449+
450+
QgsRenderContext* renderContext();
451+
void setRenderContext( QgsRenderContext* c );
452+
453+
QgsSymbolV2::OutputUnit outputUnit() const;
454+
void setOutputUnit( QgsSymbolV2::OutputUnit u );
455+
};
456+
438457
///////////////
439458

440459

@@ -458,6 +477,12 @@ class QgsSymbolV2
458477

459478
public:
460479

480+
enum OutputUnit
481+
{
482+
MM,
483+
MapUnit
484+
};
485+
461486
enum SymbolType
462487
{
463488
Marker,
@@ -508,6 +533,9 @@ public:
508533

509534
virtual QgsSymbolV2* clone() const = 0 /Factory/;
510535

536+
OutputUnit outputUnit() const;
537+
void setOutputUnit( OutputUnit u );
538+
511539
protected:
512540
QgsSymbolV2(SymbolType type, QgsSymbolLayerV2List layers /Transfer/); // can't be instantiated
513541

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,31 @@ QString QgsSimpleFillSymbolLayerV2::layerType() const
4141
return "SimpleFill";
4242
}
4343

44-
void QgsSimpleFillSymbolLayerV2::startRender( QgsRenderContext& context )
44+
void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
4545
{
4646
mBrush = QBrush( mColor, mBrushStyle );
4747
mPen = QPen( mBorderColor );
4848
mPen.setStyle( mBorderStyle );
49-
mPen.setWidthF( mBorderWidth );
49+
mPen.setWidthF( mBorderWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
5050
}
5151

52-
void QgsSimpleFillSymbolLayerV2::stopRender( QgsRenderContext& context )
52+
void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
5353
{
5454
}
5555

56-
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context )
56+
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
5757
{
58-
QPainter* p = context.painter();
58+
QgsRenderContext* rc = context.renderContext();
59+
if ( !rc )
60+
{
61+
return;
62+
}
63+
QPainter* p = rc->painter();
64+
if ( !p )
65+
{
66+
return;
67+
}
68+
5969
p->setBrush( mBrush );
6070
p->setPen( mPen );
6171

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
3030

3131
QString layerType() const;
3232

33-
void startRender( QgsRenderContext& context );
33+
void startRender( QgsSymbolV2RenderContext& context );
3434

35-
void stopRender( QgsRenderContext& context );
35+
void stopRender( QgsSymbolV2RenderContext& context );
3636

37-
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context );
37+
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
3838

3939
QgsStringMap properties() const;
4040

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,40 @@ QString QgsSimpleLineSymbolLayerV2::layerType() const
4747
}
4848

4949

50-
void QgsSimpleLineSymbolLayerV2::startRender( QgsRenderContext& context )
50+
void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
5151
{
5252
mPen.setColor( mColor );
53-
mPen.setWidth( mWidth );
53+
mPen.setWidthF( mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
5454
mPen.setStyle( mPenStyle );
5555
mPen.setJoinStyle( mPenJoinStyle );
5656
mPen.setCapStyle( mPenCapStyle );
5757
}
5858

59-
void QgsSimpleLineSymbolLayerV2::stopRender( QgsRenderContext& context )
59+
void QgsSimpleLineSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
6060
{
6161
}
6262

63-
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context )
63+
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
6464
{
65-
context.painter()->setPen( mPen );
65+
QgsRenderContext* rc = context.renderContext();
66+
if ( !rc )
67+
{
68+
return;
69+
}
70+
QPainter* p = rc->painter();
71+
if ( !p )
72+
{
73+
return;
74+
}
75+
76+
p->setPen( mPen );
6677
if ( mOffset == 0 )
6778
{
68-
context.painter()->drawPolyline( points );
79+
p->drawPolyline( points );
6980
}
7081
else
7182
{
72-
context.painter()->drawPolyline( ::offsetLine( points, mOffset ) );
83+
p->drawPolyline( ::offsetLine( points, mOffset ) );
7384
}
7485
}
7586

@@ -200,39 +211,59 @@ void QgsMarkerLineSymbolLayerV2::setColor( QColor color )
200211
mColor = color;
201212
}
202213

203-
void QgsMarkerLineSymbolLayerV2::startRender( QgsRenderContext& context )
214+
void QgsMarkerLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
204215
{
205216
// if being rotated, it gets initialized with every line segment
206217
if ( !mRotateMarker )
207-
mMarker->startRender( context );
218+
{
219+
QgsRenderContext* rc = context.renderContext();
220+
if ( rc )
221+
{
222+
mMarker->startRender( *rc );
223+
}
224+
}
208225
}
209226

210-
void QgsMarkerLineSymbolLayerV2::stopRender( QgsRenderContext& context )
227+
void QgsMarkerLineSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
211228
{
212229
if ( !mRotateMarker )
213-
mMarker->stopRender( context );
230+
{
231+
QgsRenderContext* rc = context.renderContext();
232+
if ( rc )
233+
{
234+
mMarker->stopRender( *rc );
235+
}
236+
}
214237
}
215238

216-
void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context )
239+
void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
217240
{
218241
if ( mOffset == 0 )
219242
{
220243
renderPolylineNoOffset( points, context );
221244
}
222245
else
223246
{
224-
QPolygonF points2 = ::offsetLine( points, mOffset );
247+
QPolygonF points2 = ::offsetLine( points, mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
225248
renderPolylineNoOffset( points2, context );
226249
}
227250
}
228251

229-
void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPolygonF& points, QgsRenderContext& context )
252+
void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPolygonF& points, QgsSymbolV2RenderContext& context )
230253
{
231254
QPointF lastPt = points[0];
232255
double lengthLeft = 0; // how much is left until next marker
233256
bool first = true;
234257
double origAngle = mMarker->angle();
235258

259+
double painterUnitInterval = mInterval * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() );
260+
261+
QgsRenderContext* rc = context.renderContext();
262+
if ( !rc )
263+
{
264+
return;
265+
}
266+
236267
for ( int i = 1; i < points.count(); ++i )
237268
{
238269
const QPointF& pt = points[i];
@@ -242,42 +273,42 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPolygonF& points
242273

243274
// for each line, find out dx and dy, and length
244275
MyLine l( lastPt, pt );
245-
QPointF diff = l.diffForInterval( mInterval );
276+
QPointF diff = l.diffForInterval( painterUnitInterval );
246277

247278
// if there's some length left from previous line
248279
// use only the rest for the first point in new line segment
249-
double c = 1 - lengthLeft / mInterval;
280+
double c = 1 - lengthLeft / painterUnitInterval;
250281

251282
lengthLeft += l.length();
252283

253284
// rotate marker (if desired)
254285
if ( mRotateMarker )
255286
{
256287
mMarker->setAngle( origAngle + ( l.angle() * 180 / M_PI ) );
257-
mMarker->startRender( context );
288+
mMarker->startRender( *rc );
258289
}
259290

260291
// draw first marker
261292
if ( first )
262293
{
263-
mMarker->renderPoint( lastPt, context );
294+
mMarker->renderPoint( lastPt, *rc );
264295
first = false;
265296
}
266297

267298
// while we're not at the end of line segment, draw!
268-
while ( lengthLeft > mInterval )
299+
while ( lengthLeft > painterUnitInterval )
269300
{
270301
// "c" is 1 for regular point or in interval (0,1] for begin of line segment
271302
lastPt += c * diff;
272-
lengthLeft -= mInterval;
273-
mMarker->renderPoint( lastPt, context );
303+
lengthLeft -= painterUnitInterval;
304+
mMarker->renderPoint( lastPt, *rc );
274305
c = 1; // reset c (if wasn't 1 already)
275306
}
276307

277308
lastPt = pt;
278309

279310
if ( mRotateMarker )
280-
mMarker->stopRender( context );
311+
mMarker->stopRender( *rc );
281312
}
282313

283314
// restore original rotation
@@ -347,12 +378,12 @@ QString QgsLineDecorationSymbolLayerV2::layerType() const
347378
return "LineDecoration";
348379
}
349380

350-
void QgsLineDecorationSymbolLayerV2::startRender( QgsRenderContext& context )
381+
void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
351382
{
352383
mPen.setColor( mColor );
353384
}
354385

355-
void QgsLineDecorationSymbolLayerV2::stopRender( QgsRenderContext& context )
386+
void QgsLineDecorationSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
356387
{
357388
}
358389

@@ -369,10 +400,21 @@ static double _calculateAngle( double x1, double y1, double x2, double y2 )
369400
return atan( t ) + ( y2 >= y1 ? M_PI : 0 ); // atan is positive / negative
370401
}
371402

372-
void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context )
403+
void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
373404
{
374405
// draw arrow at the end of line
375406

407+
QgsRenderContext* rc = context.renderContext();
408+
if ( !rc )
409+
{
410+
return;
411+
}
412+
QPainter* p = rc->painter();
413+
if ( !p )
414+
{
415+
return;
416+
}
417+
376418
int cnt = points.count();
377419
QPointF p1 = points.at( cnt - 2 );
378420
QPointF p2 = points.at( cnt - 1 );
@@ -385,9 +427,9 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg
385427
QPointF p2_1 = p2 - QPointF( size * cos( angle1 ), size * sin( angle1 ) );
386428
QPointF p2_2 = p2 - QPointF( size * cos( angle2 ), size * sin( angle2 ) );
387429

388-
context.painter()->setPen( mPen );
389-
context.painter()->drawLine( p2, p2_1 );
390-
context.painter()->drawLine( p2, p2_2 );
430+
p->setPen( mPen );
431+
p->drawLine( p2, p2_1 );
432+
p->drawLine( p2, p2_2 );
391433
}
392434

393435
QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const

‎src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
2828

2929
QString layerType() const;
3030

31-
void startRender( QgsRenderContext& context );
31+
void startRender( QgsSymbolV2RenderContext& context );
3232

33-
void stopRender( QgsRenderContext& context );
33+
void stopRender( QgsSymbolV2RenderContext& context );
3434

35-
void renderPolyline( const QPolygonF& points, QgsRenderContext& context );
35+
void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
3636

3737
QgsStringMap properties() const;
3838

@@ -81,11 +81,11 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
8181

8282
QString layerType() const;
8383

84-
void startRender( QgsRenderContext& context );
84+
void startRender( QgsSymbolV2RenderContext& context );
8585

86-
void stopRender( QgsRenderContext& context );
86+
void stopRender( QgsSymbolV2RenderContext& context );
8787

88-
void renderPolyline( const QPolygonF& points, QgsRenderContext& context );
88+
void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
8989

9090
QgsStringMap properties() const;
9191

@@ -109,7 +109,7 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
109109

110110
protected:
111111

112-
void renderPolylineNoOffset( const QPolygonF& points, QgsRenderContext& context );
112+
void renderPolylineNoOffset( const QPolygonF& points, QgsSymbolV2RenderContext& context );
113113

114114
bool mRotateMarker;
115115
double mInterval;
@@ -136,11 +136,11 @@ class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2
136136

137137
QString layerType() const;
138138

139-
void startRender( QgsRenderContext& context );
139+
void startRender( QgsSymbolV2RenderContext& context );
140140

141-
void stopRender( QgsRenderContext& context );
141+
void stopRender( QgsSymbolV2RenderContext& context );
142142

143-
void renderPolyline( const QPolygonF& points, QgsRenderContext& context );
143+
void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
144144

145145
QgsStringMap properties() const;
146146

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ QString QgsSimpleMarkerSymbolLayerV2::layerType() const
6363
return "SimpleMarker";
6464
}
6565

66-
void QgsSimpleMarkerSymbolLayerV2::startRender( QgsRenderContext& context )
66+
void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
6767
{
6868
mBrush = QBrush( mColor );
6969
mPen = QPen( mBorderColor );
70+
mPen.setWidthF( mPen.widthF() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
7071

7172
mPolygon.clear();
7273

73-
double half = mSize / 2.0;
74+
double scaledSize = mSize * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( context.renderContext(), context.outputUnit() );
75+
double half = scaledSize / 2.0;
7476

7577
if ( mName == "rectangle" )
7678
{
@@ -157,8 +159,8 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsRenderContext& context )
157159
// TODO: decide whether to use QImage or QPixmap - based on the render context
158160

159161
// calculate necessary image size for the cache
160-
int pw = (( mPen.width() == 0 ? 1 : mPen.width() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen
161-
int imageSize = (( int ) mSize + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width
162+
double pw = (( mPen.widthF() == 0 ? 1 : mPen.widthF() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen
163+
int imageSize = (( int ) scaledSize + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width
162164

163165
double center = (( double ) imageSize / 2 ) + 0.5; // add 1/2 pixel for proper rounding when the figure's coordinates are added
164166

@@ -171,28 +173,39 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsRenderContext& context )
171173
p.setBrush( mBrush );
172174
p.setPen( mPen );
173175
p.translate( QPointF( center, center ) );
174-
drawMarker( &p );
176+
drawMarker( &p, context );
175177
p.end();
176178
}
177179

178-
void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsRenderContext& context )
180+
void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
179181
{
180182
}
181183

182-
void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsRenderContext& context )
184+
void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
183185
{
184-
QPainter* p = context.painter();
186+
QgsRenderContext* rc = context.renderContext();
187+
if ( !rc )
188+
{
189+
return;
190+
}
191+
QPainter* p = rc->painter();
192+
if ( !p )
193+
{
194+
return;
195+
}
196+
185197
//p->setBrush(mBrush);
186198
//p->setPen(mPen);
187199

188200
//p->save();
189201
//p->translate(point);
190202

191203
//drawMarker(p);
192-
double s = mCache.width();
193-
//if (mCache.isValid())
194-
p->drawImage( point + QPointF( -s / 2.0, -s / 2.0 ) + mOffset, mCache );
195-
204+
//mCache.save("/home/marco/tmp/marker.png", "PNG");
205+
double s = mCache.width() / context.renderContext()->rasterScaleFactor();
206+
p->drawImage( QRectF( point.x() - s / 2.0 + mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ), \
207+
point.y() - s / 2.0 + mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ), \
208+
s, s ), mCache );
196209
//p->restore();
197210
}
198211

@@ -216,15 +229,16 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
216229
return m;
217230
}
218231

219-
void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p )
232+
void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderContext& context )
220233
{
221234
if ( mPolygon.count() != 0 )
222235
{
223236
p->drawPolygon( mPolygon );
224237
}
225238
else
226239
{
227-
double half = mSize / 2.0;
240+
double scaledSize = mSize * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( context.renderContext(), context.outputUnit() );
241+
double half = scaledSize / 2.0;
228242
// TODO: rotate
229243

230244
if ( mName == "circle" )
@@ -283,24 +297,51 @@ QString QgsSvgMarkerSymbolLayerV2::layerType() const
283297
return "SvgMarker";
284298
}
285299

286-
void QgsSvgMarkerSymbolLayerV2::startRender( QgsRenderContext& context )
300+
void QgsSvgMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
287301
{
288-
QRectF rect( QPointF( -mSize / 2.0, -mSize / 2.0 ), QSizeF( mSize, mSize ) );
302+
double pictureSize = 0;
303+
QgsRenderContext* rc = context.renderContext();
304+
if ( !rc )
305+
{
306+
return;
307+
}
308+
309+
if ( rc->painter() && rc->painter()->device() )
310+
{
311+
//correct QPictures DPI correction
312+
pictureSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() ) \
313+
/ rc->painter()->device()->logicalDpiX() * mPicture.logicalDpiX();
314+
}
315+
else
316+
{
317+
pictureSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() );
318+
}
319+
QRectF rect( QPointF( -pictureSize / 2.0, -pictureSize / 2.0 ), QSizeF( pictureSize, pictureSize ) );
289320
QSvgRenderer renderer( mPath );
290321
QPainter painter( &mPicture );
291322
renderer.render( &painter, rect );
292323
}
293324

294-
void QgsSvgMarkerSymbolLayerV2::stopRender( QgsRenderContext& context )
325+
void QgsSvgMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
295326
{
296327
}
297328

298329

299-
void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsRenderContext& context )
330+
void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
300331
{
301-
QPainter* p = context.painter();
332+
QgsRenderContext* rc = context.renderContext();
333+
if ( !rc )
334+
{
335+
return;
336+
}
337+
QPainter* p = rc->painter();
338+
if ( !p )
339+
{
340+
return;
341+
}
342+
302343
p->save();
303-
p->translate( point + mOffset );
344+
p->translate( point + mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() ) );
304345

305346
if ( mAngle != 0 )
306347
p->rotate( mAngle );

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
3232

3333
QString layerType() const;
3434

35-
void startRender( QgsRenderContext& context );
35+
void startRender( QgsSymbolV2RenderContext& context );
3636

37-
void stopRender( QgsRenderContext& context );
37+
void stopRender( QgsSymbolV2RenderContext& context );
3838

39-
void renderPoint( const QPointF& point, QgsRenderContext& context );
39+
void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
4040

4141
QgsStringMap properties() const;
4242

@@ -50,7 +50,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
5050

5151
protected:
5252

53-
void drawMarker( QPainter* p );
53+
void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
5454

5555
QColor mBorderColor;
5656
QPen mPen;
@@ -90,11 +90,11 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
9090

9191
QString layerType() const;
9292

93-
void startRender( QgsRenderContext& context );
93+
void startRender( QgsSymbolV2RenderContext& context );
9494

95-
void stopRender( QgsRenderContext& context );
95+
void stopRender( QgsSymbolV2RenderContext& context );
9696

97-
void renderPoint( const QPointF& point, QgsRenderContext& context );
97+
void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
9898

9999
QgsStringMap properties() const;
100100

‎src/core/symbology-ng/qgssymbollayerv2.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <QPointF>
88
#include <QPolygonF>
99

10+
11+
1012
QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
1113
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
1214
{
@@ -22,39 +24,28 @@ QgsFillSymbolLayerV2::QgsFillSymbolLayerV2( bool locked )
2224
{
2325
}
2426

25-
26-
void QgsMarkerSymbolLayerV2::drawPreviewIcon( QPainter* painter, QSize size )
27+
void QgsMarkerSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
2728
{
28-
QgsRenderContext context;
29-
context.setPainter( painter );
30-
3129
startRender( context );
3230
renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
3331
stopRender( context );
3432
}
3533

36-
void QgsLineSymbolLayerV2::drawPreviewIcon( QPainter* painter, QSize size )
34+
void QgsLineSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
3735
{
3836
QPolygonF points;
3937
// we're adding 0.5 to get rid of blurred preview:
4038
// drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line
4139
points << QPointF( 0, size.height() / 2 + 0.5 ) << QPointF( size.width(), size.height() / 2 + 0.5 );
4240

43-
QgsRenderContext context;
44-
context.setPainter( painter );
45-
4641
startRender( context );
4742
renderPolyline( points, context );
4843
stopRender( context );
4944
}
5045

51-
void QgsFillSymbolLayerV2::drawPreviewIcon( QPainter* painter, QSize size )
46+
void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
5247
{
5348
QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
54-
55-
QgsRenderContext context;
56-
context.setPainter( painter );
57-
5849
startRender( context );
5950
renderPolygon( poly, NULL, context );
6051
stopRender( context );

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class CORE_EXPORT QgsSymbolLayerV2
3131

3232
virtual QString layerType() const = 0;
3333

34-
virtual void startRender( QgsRenderContext& context ) = 0;
35-
virtual void stopRender( QgsRenderContext& context ) = 0;
34+
virtual void startRender( QgsSymbolV2RenderContext& context ) = 0;
35+
virtual void stopRender( QgsSymbolV2RenderContext& context ) = 0;
3636

3737
virtual QgsSymbolLayerV2* clone() const = 0;
3838

3939
virtual QgsStringMap properties() const = 0;
4040

41-
virtual void drawPreviewIcon( QPainter* painter, QSize size ) = 0;
41+
virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0;
4242

4343
virtual QgsSymbolV2* subSymbol() { return NULL; }
4444
// set layer's subsymbol. takes ownership of the passed symbol
@@ -68,9 +68,9 @@ class CORE_EXPORT QgsSymbolLayerV2
6868
class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
6969
{
7070
public:
71-
virtual void renderPoint( const QPointF& point, QgsRenderContext& context ) = 0;
71+
virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
7272

73-
void drawPreviewIcon( QPainter* painter, QSize size );
73+
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
7474

7575
void setAngle( double angle ) { mAngle = angle; }
7676
double angle() const { return mAngle; }
@@ -92,12 +92,12 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
9292
class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
9393
{
9494
public:
95-
virtual void renderPolyline( const QPolygonF& points, QgsRenderContext& context ) = 0;
95+
virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
9696

9797
void setWidth( double width ) { mWidth = width; }
9898
double width() const { return mWidth; }
9999

100-
void drawPreviewIcon( QPainter* painter, QSize size );
100+
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
101101

102102
protected:
103103
QgsLineSymbolLayerV2( bool locked = false );
@@ -108,9 +108,9 @@ class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
108108
class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
109109
{
110110
public:
111-
virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context ) = 0;
111+
virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
112112

113-
void drawPreviewIcon( QPainter* painter, QSize size );
113+
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
114114

115115
protected:
116116
QgsFillSymbolLayerV2( bool locked = false );

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "qgsvectorcolorrampv2.h"
88

99
#include "qgslogger.h"
10+
#include "qgsrendercontext.h"
1011

1112
#include <QColor>
1213
#include <QDomNode>
@@ -165,14 +166,17 @@ QPixmap QgsSymbolLayerV2Utils::symbolPreviewPixmap( QgsSymbolV2* symbol, QSize s
165166
}
166167

167168

168-
QIcon QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QSize size )
169+
QIcon QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size )
169170
{
170171
QPixmap pixmap( size );
171172
QPainter painter;
172173
painter.begin( &pixmap );
173174
painter.setRenderHint( QPainter::Antialiasing );
174175
painter.eraseRect( QRect( QPoint( 0, 0 ), size ) );
175-
layer->drawPreviewIcon( &painter, size );
176+
QgsRenderContext renderContext;
177+
renderContext.setPainter( &painter );
178+
QgsSymbolV2RenderContext symbolContext( &renderContext, u );
179+
layer->drawPreviewIcon( symbolContext, size );
176180
painter.end();
177181
return QIcon( pixmap );
178182
}
@@ -339,17 +343,30 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
339343
}
340344

341345
QString symbolType = element.attribute( "type" );
346+
QString unitString = element.attribute( "outputUnit", "MM" );
347+
348+
QgsSymbolV2* symbol = 0;
342349
if ( symbolType == "line" )
343-
return new QgsLineSymbolV2( layers );
350+
symbol = new QgsLineSymbolV2( layers );
344351
else if ( symbolType == "fill" )
345-
return new QgsFillSymbolV2( layers );
352+
symbol = new QgsFillSymbolV2( layers );
346353
else if ( symbolType == "marker" )
347-
return new QgsMarkerSymbolV2( layers );
354+
symbol = new QgsMarkerSymbolV2( layers );
348355
else
349356
{
350357
QgsDebugMsg( "unknown symbol type " + symbolType );
351358
return NULL;
352359
}
360+
361+
if ( unitString == "MM" )
362+
{
363+
symbol->setOutputUnit( QgsSymbolV2::MM );
364+
}
365+
else
366+
{
367+
symbol->setOutputUnit( QgsSymbolV2::MapUnit );
368+
}
369+
return symbol;
353370
}
354371

355372
QgsSymbolLayerV2* QgsSymbolLayerV2Utils::loadSymbolLayer( QDomElement& element )
@@ -392,7 +409,12 @@ QDomElement QgsSymbolLayerV2Utils::saveSymbol( QString name, QgsSymbolV2* symbol
392409
QDomElement symEl = doc.createElement( "symbol" );
393410
symEl.setAttribute( "type", _nameForSymbolType( symbol->type() ) );
394411
symEl.setAttribute( "name", name );
395-
412+
QString unitString = "MM";
413+
if ( symbol->outputUnit() == QgsSymbolV2::MapUnit )
414+
{
415+
unitString = "MapUnit";
416+
}
417+
symEl.setAttribute( "outputUnit", unitString );
396418
QgsDebugMsg( "num layers " + QString::number( symbol->symbolLayerCount() ) );
397419
for ( int i = 0; i < symbol->symbolLayerCount(); i++ )
398420
{
@@ -589,3 +611,45 @@ QDomElement QgsSymbolLayerV2Utils::saveColorRamp( QString name, QgsVectorColorRa
589611
QgsSymbolLayerV2Utils::saveProperties( ramp->properties(), doc, rampEl );
590612
return rampEl;
591613
}
614+
615+
double QgsSymbolLayerV2Utils::lineWidthScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u )
616+
{
617+
if ( !c )
618+
{
619+
return 1.0;
620+
}
621+
622+
if ( u == QgsSymbolV2::MM )
623+
{
624+
return c->scaleFactor();
625+
}
626+
else //QgsSymbol::MapUnit
627+
{
628+
double mup = c->mapToPixel().mapUnitsPerPixel();
629+
if ( mup > 0 )
630+
{
631+
return 1.0 / mup;
632+
}
633+
else
634+
{
635+
return 1.0;
636+
}
637+
}
638+
}
639+
640+
double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u )
641+
{
642+
if ( !c )
643+
{
644+
return 1.0;
645+
}
646+
647+
if ( u == QgsSymbolV2::MM )
648+
{
649+
return ( c->scaleFactor() * c->rasterScaleFactor() );
650+
}
651+
else //QgsSymbol::MapUnit
652+
{
653+
return c->rasterScaleFactor() / c->mapToPixel().mapUnitsPerPixel();
654+
}
655+
}

‎src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <QMap>
77
#include <Qt>
8+
#include "qgssymbolv2.h"
89

910
class QgsSymbolV2;
1011
class QgsSymbolLayerV2;
@@ -44,7 +45,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
4445
static QPointF decodePoint( QString str );
4546

4647
static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
47-
static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QSize size );
48+
static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
4849
static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
4950

5051
static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
@@ -64,6 +65,11 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
6465

6566
static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
6667
static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
68+
69+
/**Returns the line width scale factor depending on the unit and the paint device*/
70+
static double lineWidthScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
71+
/**Returns scale factor painter units -> pixel dimensions*/
72+
static double pixelSizeScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
6773
};
6874

6975
class QPolygonF;

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <cmath>
1818

1919
QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
20-
: mType( type ), mLayers( layers )
20+
: mType( type ), mLayers( layers ), mOutputUnit( MM )
2121
{
2222

2323
// check they're all correct symbol layers
@@ -126,14 +126,16 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )
126126

127127
void QgsSymbolV2::startRender( QgsRenderContext& context )
128128
{
129+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
129130
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
130-
( *it )->startRender( context );
131+
( *it )->startRender( symbolContext );
131132
}
132133

133134
void QgsSymbolV2::stopRender( QgsRenderContext& context )
134135
{
136+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
135137
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
136-
( *it )->stopRender( context );
138+
( *it )->stopRender( symbolContext );
137139
}
138140

139141
void QgsSymbolV2::setColor( const QColor& color )
@@ -158,9 +160,12 @@ QColor QgsSymbolV2::color()
158160

159161
void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
160162
{
163+
QgsRenderContext context;
164+
context.setPainter( painter );
165+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
161166
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
162167
{
163-
( *it )->drawPreviewIcon( painter, size );
168+
( *it )->drawPreviewIcon( symbolContext, size );
164169
}
165170
}
166171

@@ -240,6 +245,18 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
240245
return lst;
241246
}
242247

248+
////////////////////
249+
250+
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u ): mRenderContext( c ), mOutputUnit( u )
251+
{
252+
253+
}
254+
255+
QgsSymbolV2RenderContext::~QgsSymbolV2RenderContext()
256+
{
257+
258+
}
259+
243260

244261
///////////////////
245262

@@ -306,23 +323,26 @@ double QgsMarkerSymbolV2::size()
306323

307324
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, QgsRenderContext& context, int layer )
308325
{
326+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
309327
if ( layer != -1 )
310328
{
311329
if ( layer >= 0 && layer < mLayers.count() )
312-
(( QgsMarkerSymbolLayerV2* ) mLayers[layer] )->renderPoint( point, context );
330+
(( QgsMarkerSymbolLayerV2* ) mLayers[layer] )->renderPoint( point, symbolContext );
313331
return;
314332
}
315333

316334
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
317335
{
318336
QgsMarkerSymbolLayerV2* layer = ( QgsMarkerSymbolLayerV2* ) * it;
319-
layer->renderPoint( point, context );
337+
layer->renderPoint( point, symbolContext );
320338
}
321339
}
322340

323341
QgsSymbolV2* QgsMarkerSymbolV2::clone() const
324342
{
325-
return new QgsMarkerSymbolV2( cloneLayers() );
343+
QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
344+
cloneSymbol->setOutputUnit( mOutputUnit );
345+
return cloneSymbol;
326346
}
327347

328348

@@ -371,24 +391,27 @@ double QgsLineSymbolV2::width()
371391

372392
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer )
373393
{
394+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
374395
if ( layer != -1 )
375396
{
376397
if ( layer >= 0 && layer < mLayers.count() )
377-
(( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolyline( points, context );
398+
(( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolyline( points, symbolContext );
378399
return;
379400
}
380401

381402
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
382403
{
383404
QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
384-
layer->renderPolyline( points, context );
405+
layer->renderPolyline( points, symbolContext );
385406
}
386407
}
387408

388409

389410
QgsSymbolV2* QgsLineSymbolV2::clone() const
390411
{
391-
return new QgsLineSymbolV2( cloneLayers() );
412+
QgsSymbolV2* cloneSymbol = new QgsLineSymbolV2( cloneLayers() );
413+
cloneSymbol->setOutputUnit( mOutputUnit );
414+
return cloneSymbol;
392415
}
393416

394417
///////////////////
@@ -403,22 +426,25 @@ QgsFillSymbolV2::QgsFillSymbolV2( QgsSymbolLayerV2List layers )
403426

404427
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer )
405428
{
429+
QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
406430
if ( layer != -1 )
407431
{
408432
if ( layer >= 0 && layer < mLayers.count() )
409-
(( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, context );
433+
(( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, symbolContext );
410434
return;
411435
}
412436

413437
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
414438
{
415439
QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
416-
layer->renderPolygon( points, rings, context );
440+
layer->renderPolygon( points, rings, symbolContext );
417441
}
418442
}
419443

420444

421445
QgsSymbolV2* QgsFillSymbolV2::clone() const
422446
{
423-
return new QgsFillSymbolV2( cloneLayers() );
447+
QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
448+
cloneSymbol->setOutputUnit( mOutputUnit );
449+
return cloneSymbol;
424450
}

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class CORE_EXPORT QgsSymbolV2
2222
{
2323
public:
2424

25+
enum OutputUnit
26+
{
27+
MM,
28+
MapUnit
29+
};
30+
2531
enum SymbolType
2632
{
2733
Marker,
@@ -72,13 +78,37 @@ class CORE_EXPORT QgsSymbolV2
7278

7379
virtual QgsSymbolV2* clone() const = 0;
7480

81+
OutputUnit outputUnit() const { return mOutputUnit; }
82+
void setOutputUnit( OutputUnit u ) { mOutputUnit = u; }
83+
7584
protected:
7685
QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
7786

7887
QgsSymbolLayerV2List cloneLayers() const;
7988

8089
SymbolType mType;
8190
QgsSymbolLayerV2List mLayers;
91+
92+
OutputUnit mOutputUnit;
93+
};
94+
95+
///////////////////////
96+
97+
class CORE_EXPORT QgsSymbolV2RenderContext
98+
{
99+
public:
100+
QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
101+
~QgsSymbolV2RenderContext();
102+
103+
QgsRenderContext* renderContext() { return mRenderContext; }
104+
void setRenderContext( QgsRenderContext* c ) { mRenderContext = c;}
105+
106+
QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
107+
void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
108+
109+
private:
110+
QgsRenderContext* mRenderContext;
111+
QgsSymbolV2::OutputUnit mOutputUnit;
82112
};
83113

84114

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget( QWidget*
105105
for ( int i = 0; i < names.count(); ++i )
106106
{
107107
QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( names[i], QColor( 200, 200, 200 ), QColor( 0, 0, 0 ), markerSize );
108-
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( lyr, size );
108+
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( lyr, QgsSymbolV2::MM, size ); //todo: unit needs to be a parameter
109109
QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
110110
item->setData( Qt::UserRole, names[i] );
111111
delete lyr;

‎src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "qgsapplication.h"
1313

1414
#include "qgssymbollayerv2widget.h"
15+
#include "qgssymbolv2.h" //for the unit
1516

1617
static const int SymbolLayerItemType = QStandardItem::UserType + 1;
1718

@@ -31,7 +32,7 @@ class SymbolLayerItem : public QStandardItem
3132

3233
void updatePreview()
3334
{
34-
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( mLayer, QSize( 16, 16 ) );
35+
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( mLayer, QgsSymbolV2::MM, QSize( 16, 16 ) ); //todo: make unit a parameter
3536
setIcon( icon );
3637
}
3738

@@ -335,7 +336,7 @@ void QgsSymbolV2PropertiesDialog::removeLayer()
335336

336337
void QgsSymbolV2PropertiesDialog::moveLayerDown()
337338
{
338-
moveLayerByOffset( +1 );
339+
moveLayerByOffset( + 1 );
339340
}
340341

341342
void QgsSymbolV2PropertiesDialog::moveLayerUp()

‎src/gui/symbology-ng/qgssymbolv2selectordialog.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsSt
4141
updateSymbolPreview();
4242
updateSymbolInfo();
4343

44+
//output unit
45+
mSymbolUnitComboBox->blockSignals( true );
46+
mSymbolUnitComboBox->addItem( tr( "Millimeter" ) );
47+
mSymbolUnitComboBox->addItem( tr( "Map unit" ) );
48+
if ( mSymbol && mSymbol->outputUnit() == QgsSymbolV2::MM )
49+
{
50+
mSymbolUnitComboBox->setCurrentIndex( mSymbolUnitComboBox->findText( tr( "Millimeter" ) ) );
51+
}
52+
else
53+
{
54+
mSymbolUnitComboBox->setCurrentIndex( mSymbolUnitComboBox->findText( tr( "Map unit" ) ) );
55+
}
56+
mSymbolUnitComboBox->blockSignals( false );
57+
4458
// select correct page in stacked widget
4559
// there's a correspondence between symbol type number and page numbering => exploit it!
4660
stackedWidget->setCurrentIndex( symbol->type() );
@@ -224,3 +238,21 @@ void QgsSymbolV2SelectorDialog::keyPressEvent( QKeyEvent * e )
224238
QDialog::keyPressEvent( e );
225239
}
226240
}
241+
242+
void QgsSymbolV2SelectorDialog::on_mSymbolUnitComboBox_currentIndexChanged( const QString & text )
243+
{
244+
if ( !mSymbol )
245+
{
246+
return;
247+
}
248+
if ( text == tr( "Millimeter" ) )
249+
{
250+
mSymbol->setOutputUnit( QgsSymbolV2::MM );
251+
}
252+
else //map unit
253+
{
254+
mSymbol->setOutputUnit( QgsSymbolV2::MapUnit );
255+
}
256+
updateSymbolPreview();
257+
emit symbolModified();
258+
}

‎src/gui/symbology-ng/qgssymbolv2selectordialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymb
3333
void setMarkerSize( double size );
3434
void setLineWidth( double width );
3535
void addSymbolToStyle();
36+
void on_mSymbolUnitComboBox_currentIndexChanged( const QString & text );
3637

3738
signals:
3839
void symbolModified();

‎src/ui/qgssymbolv2selectordialogbase.ui

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>452</width>
9+
<width>331</width>
1010
<height>404</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Symbol selector</string>
1515
</property>
16-
<layout class="QVBoxLayout" name="verticalLayout">
17-
<item>
16+
<layout class="QGridLayout" name="gridLayout_3">
17+
<item row="0" column="0">
1818
<layout class="QHBoxLayout" name="horizontalLayout_3">
1919
<item>
2020
<widget class="QLabel" name="lblPreview">
@@ -164,7 +164,7 @@
164164
</item>
165165
</layout>
166166
</item>
167-
<item>
167+
<item row="1" column="0">
168168
<layout class="QHBoxLayout" name="horizontalLayout">
169169
<item>
170170
<widget class="QPushButton" name="btnSymbolProperties">
@@ -195,14 +195,28 @@
195195
</item>
196196
</layout>
197197
</item>
198-
<item>
198+
<item row="2" column="0">
199+
<layout class="QHBoxLayout" name="horizontalLayout_4">
200+
<item>
201+
<widget class="QLabel" name="mSymbolUnitLabel">
202+
<property name="text">
203+
<string>Symbol Unit:</string>
204+
</property>
205+
</widget>
206+
</item>
207+
<item>
208+
<widget class="QComboBox" name="mSymbolUnitComboBox"/>
209+
</item>
210+
</layout>
211+
</item>
212+
<item row="3" column="0">
199213
<widget class="QLabel" name="label">
200214
<property name="text">
201215
<string>Symbols from style:</string>
202216
</property>
203217
</widget>
204218
</item>
205-
<item>
219+
<item row="4" column="0">
206220
<widget class="QListView" name="viewSymbols">
207221
<property name="sizePolicy">
208222
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -230,7 +244,7 @@
230244
</property>
231245
</widget>
232246
</item>
233-
<item>
247+
<item row="5" column="0">
234248
<widget class="QDialogButtonBox" name="buttonBox">
235249
<property name="orientation">
236250
<enum>Qt::Horizontal</enum>

‎src/ui/symbollayer/widget_markerline.ui

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@
7373
<number>1</number>
7474
</property>
7575
<property name="minimum">
76-
<double>-100.000000000000000</double>
76+
<double>-100000.000000000000000</double>
77+
</property>
78+
<property name="maximum">
79+
<double>100000.000000000000000</double>
7780
</property>
7881
</widget>
7982
</item>
@@ -82,6 +85,9 @@
8285
<property name="decimals">
8386
<number>1</number>
8487
</property>
88+
<property name="maximum">
89+
<double>100000.000000000000000</double>
90+
</property>
8591
<property name="value">
8692
<double>1.000000000000000</double>
8793
</property>

‎src/ui/symbollayer/widget_simplefill.ui

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
<property name="decimals">
9393
<number>1</number>
9494
</property>
95+
<property name="maximum">
96+
<double>100000.000000000000000</double>
97+
</property>
9598
</widget>
9699
</item>
97100
</layout>
@@ -112,11 +115,6 @@
112115
</layout>
113116
</widget>
114117
<customwidgets>
115-
<customwidget>
116-
<class>QgsBrushStyleComboBox</class>
117-
<extends>QComboBox</extends>
118-
<header>qgsbrushstylecombobox.h</header>
119-
</customwidget>
120118
<customwidget>
121119
<class>QgsColorButtonV2</class>
122120
<extends>QPushButton</extends>
@@ -127,6 +125,11 @@
127125
<extends>QComboBox</extends>
128126
<header>qgspenstylecombobox.h</header>
129127
</customwidget>
128+
<customwidget>
129+
<class>QgsBrushStyleComboBox</class>
130+
<extends>QComboBox</extends>
131+
<header>qgsbrushstylecombobox.h</header>
132+
</customwidget>
130133
</customwidgets>
131134
<tabstops>
132135
<tabstop>btnChangeColor</tabstop>

‎src/ui/symbollayer/widget_simpleline.ui

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
<number>1</number>
8686
</property>
8787
<property name="minimum">
88-
<double>-100.000000000000000</double>
88+
<double>-100000.000000000000000</double>
89+
</property>
90+
<property name="maximum">
91+
<double>100000.000000000000000</double>
8992
</property>
9093
</widget>
9194
</item>
@@ -103,6 +106,9 @@
103106
<property name="decimals">
104107
<number>1</number>
105108
</property>
109+
<property name="maximum">
110+
<double>100000.000000000000000</double>
111+
</property>
106112
<property name="value">
107113
<double>1.000000000000000</double>
108114
</property>
@@ -166,6 +172,11 @@
166172
</layout>
167173
</widget>
168174
<customwidgets>
175+
<customwidget>
176+
<class>QgsColorButtonV2</class>
177+
<extends>QPushButton</extends>
178+
<header>qgscolorbutton.h</header>
179+
</customwidget>
169180
<customwidget>
170181
<class>QgsPenStyleComboBox</class>
171182
<extends>QComboBox</extends>
@@ -181,11 +192,6 @@
181192
<extends>QComboBox</extends>
182193
<header>qgspenstylecombobox.h</header>
183194
</customwidget>
184-
<customwidget>
185-
<class>QgsColorButtonV2</class>
186-
<extends>QPushButton</extends>
187-
<header>qgscolorbutton.h</header>
188-
</customwidget>
189195
</customwidgets>
190196
<resources/>
191197
<connections/>

‎src/ui/symbollayer/widget_simplemarker.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<property name="decimals">
124124
<number>1</number>
125125
</property>
126+
<property name="maximum">
127+
<double>100000.000000000000000</double>
128+
</property>
126129
<property name="value">
127130
<double>1.000000000000000</double>
128131
</property>

‎src/ui/symbollayer/widget_svgmarker.ui

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
<number>1</number>
7171
</property>
7272
<property name="minimum">
73-
<double>-100.000000000000000</double>
73+
<double>-100000.000000000000000</double>
74+
</property>
75+
<property name="maximum">
76+
<double>100000.000000000000000</double>
7477
</property>
7578
</widget>
7679
</item>
@@ -80,7 +83,10 @@
8083
<number>1</number>
8184
</property>
8285
<property name="minimum">
83-
<double>-100.000000000000000</double>
86+
<double>-100000.000000000000000</double>
87+
</property>
88+
<property name="maximum">
89+
<double>100000.000000000000000</double>
8490
</property>
8591
</widget>
8692
</item>
@@ -104,6 +110,9 @@
104110
<property name="decimals">
105111
<number>1</number>
106112
</property>
113+
<property name="maximum">
114+
<double>100000.000000000000000</double>
115+
</property>
107116
<property name="value">
108117
<double>1.000000000000000</double>
109118
</property>

0 commit comments

Comments
 (0)
Please sign in to comment.