Skip to content

Commit 01734bd

Browse files
committedMar 7, 2013
Separate units for line width, line offset, dash pattern
1 parent 7bc758e commit 01734bd

File tree

10 files changed

+312
-192
lines changed

10 files changed

+312
-192
lines changed
 

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2( QColor color, double wid
3333
mCustomDashVector << 5 << 2;
3434
}
3535

36+
void QgsSimpleLineSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
37+
{
38+
mWidthUnit = unit;
39+
mOffsetUnit = unit;
40+
mCustomDashPatternUnit = unit;
41+
}
42+
43+
QgsSymbolV2::OutputUnit QgsSimpleLineSymbolLayerV2::outputUnit() const
44+
{
45+
QgsSymbolV2::OutputUnit unit = mWidthUnit;
46+
if ( mOffsetUnit != unit || mCustomDashPatternUnit != unit )
47+
{
48+
return QgsSymbolV2::Mixed;
49+
}
50+
return unit;
51+
}
52+
3653

3754
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props )
3855
{
@@ -78,7 +95,7 @@ void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
7895
QColor penColor = mColor;
7996
penColor.setAlphaF( mColor.alphaF() * context.alpha() );
8097
mPen.setColor( penColor );
81-
double scaledWidth = context.outputLineWidth( mWidth );
98+
double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
8299
mPen.setWidthF( scaledWidth );
83100
if ( mUseCustomDashPattern && scaledWidth != 0 )
84101
{
@@ -90,7 +107,7 @@ void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
90107
for ( ; it != mCustomDashVector.constEnd(); ++it )
91108
{
92109
//the dash is specified in terms of pen widths, therefore the division
93-
scaledVector << context.outputLineWidth(( *it ) / scaledWidth );
110+
scaledVector << ( *it ) * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit ) / scaledWidth;
94111
}
95112
mPen.setDashPattern( scaledVector );
96113
}
@@ -123,7 +140,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
123140

124141
if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
125142
{
126-
double scaledWidth = context.outputLineWidth( mWidth );
143+
double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
127144
mPen.setWidthF( scaledWidth );
128145
mSelPen.setWidthF( scaledWidth );
129146
}
@@ -135,7 +152,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
135152
}
136153
else
137154
{
138-
double scaledOffset = context.outputLineWidth( mOffset );
155+
double scaledOffset = mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
139156
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
140157
}
141158
}
@@ -157,6 +174,9 @@ QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
157174
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::clone() const
158175
{
159176
QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2( mColor, mWidth, mPenStyle );
177+
l->setWidthUnit( mWidthUnit );
178+
l->setOffsetUnit( mOffsetUnit );
179+
l->setCustomDashPatternUnit( mCustomDashPatternUnit );
160180
l->setOffset( mOffset );
161181
l->setPenJoinStyle( mPenJoinStyle );
162182
l->setPenCapStyle( mPenCapStyle );

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
5858

5959
QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
6060

61+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
62+
QgsSymbolV2::OutputUnit outputUnit() const;
63+
6164
// new stuff
6265

6366
Qt::PenStyle penStyle() const { return mPenStyle; }
@@ -72,9 +75,15 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
7275
double offset() const { return mOffset; }
7376
void setOffset( double offset ) { mOffset = offset; }
7477

78+
QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
79+
void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
80+
7581
bool useCustomDashPattern() const { return mUseCustomDashPattern; }
7682
void setUseCustomDashPattern( bool b ) { mUseCustomDashPattern = b; }
7783

84+
QgsSymbolV2::OutputUnit customDashPatternUnit() const { return mCustomDashPatternUnit; }
85+
void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit ) { mCustomDashPatternUnit = unit; }
86+
7887
QVector<qreal> customDashVector() const { return mCustomDashVector; }
7988
void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }
8089

@@ -85,8 +94,12 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
8594
QPen mPen;
8695
QPen mSelPen;
8796
double mOffset;
97+
QgsSymbolV2::OutputUnit mOffsetUnit;
98+
8899
//use a custom dash dot pattern instead of the predefined ones
89100
bool mUseCustomDashPattern;
101+
QgsSymbolV2::OutputUnit mCustomDashPatternUnit;
102+
90103
/**Vector with an even number of entries for the */
91104
QVector<qreal> mCustomDashVector;
92105
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
3131
}
3232

3333
QgsLineSymbolLayerV2::QgsLineSymbolLayerV2( bool locked )
34-
: QgsSymbolLayerV2( QgsSymbolV2::Line, locked )
34+
: QgsSymbolLayerV2( QgsSymbolV2::Line, locked ), mWidthUnit( QgsSymbolV2::MM )
3535
{
3636
}
3737

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class CORE_EXPORT QgsSymbolLayerV2
6969
void setLocked( bool locked ) { mLocked = locked; }
7070
bool isLocked() const { return mLocked; }
7171

72+
virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) {} //= 0;
73+
virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;
74+
7275
// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
7376
void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; }
7477
int renderingPass() const { return mRenderingPass; }
@@ -138,12 +141,16 @@ class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
138141
virtual void setWidth( double width ) { mWidth = width; }
139142
virtual double width() const { return mWidth; }
140143

144+
void setWidthUnit( QgsSymbolV2::OutputUnit unit ) { mWidthUnit = unit; }
145+
QgsSymbolV2::OutputUnit widthUnit() const { return mWidthUnit; }
146+
141147
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
142148

143149
protected:
144150
QgsLineSymbolLayerV2( bool locked = false );
145151

146152
double mWidth;
153+
QgsSymbolV2::OutputUnit mWidthUnit;
147154
};
148155

149156
class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <cmath>
3636

3737
QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
38-
: mType( type ), mLayers( layers ), mOutputUnit( MM ), mAlpha( 1.0 ), mRenderHints( 0 )
38+
: mType( type ), mLayers( layers ), mAlpha( 1.0 ), mRenderHints( 0 )
3939
{
4040

4141
// check they're all correct symbol layers
@@ -61,6 +61,38 @@ QgsSymbolV2::~QgsSymbolV2()
6161
delete *it;
6262
}
6363

64+
QgsSymbolV2::OutputUnit QgsSymbolV2::outputUnit() const
65+
{
66+
QgsSymbolV2::OutputUnit unit;
67+
68+
QgsSymbolLayerV2List::const_iterator it = mLayers.constBegin();
69+
for ( ; it != mLayers.constEnd(); ++it )
70+
{
71+
if ( it == mLayers.constBegin() )
72+
{
73+
unit = ( *it )->outputUnit();
74+
}
75+
else
76+
{
77+
if (( *it )->outputUnit() != unit )
78+
{
79+
return QgsSymbolV2::Mixed;
80+
}
81+
}
82+
}
83+
84+
return unit;
85+
}
86+
87+
void QgsSymbolV2::setOutputUnit( QgsSymbolV2::OutputUnit u )
88+
{
89+
QgsSymbolLayerV2List::iterator it = mLayers.begin();
90+
for ( ; it != mLayers.end(); ++it )
91+
{
92+
( *it )->setOutputUnit( u );
93+
}
94+
}
95+
6496
QgsSymbolV2* QgsSymbolV2::defaultSymbol( QGis::GeometryType geomType )
6597
{
6698
QgsSymbolV2* s = 0;
@@ -184,15 +216,15 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )
184216

185217
void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsVectorLayer* layer )
186218
{
187-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, false, mRenderHints );
219+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
188220
symbolContext.setLayer( layer );
189221
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
190222
( *it )->startRender( symbolContext );
191223
}
192224

193225
void QgsSymbolV2::stopRender( QgsRenderContext& context )
194226
{
195-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, false, mRenderHints );
227+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
196228
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
197229
( *it )->stopRender( symbolContext );
198230
}
@@ -220,7 +252,7 @@ QColor QgsSymbolV2::color()
220252
void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
221253
{
222254
QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( painter );
223-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, false, mRenderHints );
255+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
224256
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
225257
{
226258
if ( mType == Fill && ( *it )->type() == Line )
@@ -504,7 +536,7 @@ QgsSymbolV2::ScaleMethod QgsMarkerSymbolV2::scaleMethod()
504536

505537
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
506538
{
507-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
539+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
508540
if ( layer != -1 )
509541
{
510542
if ( layer >= 0 && layer < mLayers.count() )
@@ -522,7 +554,7 @@ void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f,
522554
QgsSymbolV2* QgsMarkerSymbolV2::clone() const
523555
{
524556
QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
525-
cloneSymbol->setOutputUnit( mOutputUnit );
557+
cloneSymbol->setOutputUnit( outputUnit() );
526558
cloneSymbol->setAlpha( mAlpha );
527559
return cloneSymbol;
528560
}
@@ -573,7 +605,7 @@ double QgsLineSymbolV2::width()
573605

574606
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
575607
{
576-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
608+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
577609
if ( layer != -1 )
578610
{
579611
if ( layer >= 0 && layer < mLayers.count() )
@@ -592,7 +624,6 @@ void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature*
592624
QgsSymbolV2* QgsLineSymbolV2::clone() const
593625
{
594626
QgsSymbolV2* cloneSymbol = new QgsLineSymbolV2( cloneLayers() );
595-
cloneSymbol->setOutputUnit( mOutputUnit );
596627
cloneSymbol->setAlpha( mAlpha );
597628
return cloneSymbol;
598629
}
@@ -609,7 +640,7 @@ QgsFillSymbolV2::QgsFillSymbolV2( QgsSymbolLayerV2List layers )
609640

610641
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
611642
{
612-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
643+
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
613644
if ( layer != -1 )
614645
{
615646
if ( layer >= 0 && layer < mLayers.count() )
@@ -643,7 +674,7 @@ void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>*
643674
QgsSymbolV2* QgsFillSymbolV2::clone() const
644675
{
645676
QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
646-
cloneSymbol->setOutputUnit( mOutputUnit );
677+
cloneSymbol->setOutputUnit( outputUnit() );
647678
cloneSymbol->setAlpha( mAlpha );
648679
return cloneSymbol;
649680
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class CORE_EXPORT QgsSymbolV2
4444

4545
enum OutputUnit
4646
{
47-
MM,
48-
MapUnit
47+
MM = 0,
48+
MapUnit,
49+
Mixed //mixed units in symbol layers
4950
};
5051

5152
enum SymbolType
@@ -112,8 +113,8 @@ class CORE_EXPORT QgsSymbolV2
112113

113114
void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
114115

115-
OutputUnit outputUnit() const { return mOutputUnit; }
116-
void setOutputUnit( OutputUnit u ) { mOutputUnit = u; }
116+
QgsSymbolV2::OutputUnit outputUnit() const;
117+
void setOutputUnit( QgsSymbolV2::OutputUnit u );
117118

118119
//! Get alpha transparency 1 for opaque, 0 for invisible
119120
qreal alpha() const { return mAlpha; }
@@ -140,8 +141,6 @@ class CORE_EXPORT QgsSymbolV2
140141
SymbolType mType;
141142
QgsSymbolLayerV2List mLayers;
142143

143-
OutputUnit mOutputUnit;
144-
145144
/**Symbol opacity (in the range 0 - 1)*/
146145
qreal mAlpha;
147146

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget( const QgsVec
6363

6464
void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
6565
{
66-
if ( layer->layerType() != "SimpleLine" )
66+
if ( !layer || layer->layerType() != "SimpleLine" )
6767
return;
6868

6969
// layer type is correct, we can do the cast
7070
mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>( layer );
7171

72+
// set units
73+
mPenWidthUnitComboBox->blockSignals( true );
74+
mPenWidthUnitComboBox->setCurrentIndex( mLayer->widthUnit() );
75+
mPenWidthUnitComboBox->blockSignals( false );
76+
mOffsetUnitComboBox->blockSignals( true );
77+
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
78+
mOffsetUnitComboBox->blockSignals( false );
79+
7280
// set values
7381
spinWidth->setValue( mLayer->width() );
7482
btnChangeColor->setColor( mLayer->color() );
@@ -161,6 +169,22 @@ void QgsSimpleLineSymbolLayerV2Widget::on_mChangePatternButton_clicked()
161169
}
162170
}
163171

172+
void QgsSimpleLineSymbolLayerV2Widget::on_mPenWidthUnitComboBox_currentIndexChanged( int index )
173+
{
174+
if ( mLayer )
175+
{
176+
mLayer->setWidthUnit(( QgsSymbolV2::OutputUnit )index );
177+
}
178+
}
179+
180+
void QgsSimpleLineSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
181+
{
182+
if ( mLayer )
183+
{
184+
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit )index );
185+
}
186+
}
187+
164188
void QgsSimpleLineSymbolLayerV2Widget::updatePatternIcon()
165189
{
166190
if ( !mLayer )

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class GUI_EXPORT QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
6767
void offsetChanged();
6868
void on_mCustomCheckBox_stateChanged( int state );
6969
void on_mChangePatternButton_clicked();
70+
void on_mPenWidthUnitComboBox_currentIndexChanged( int index );
71+
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
7072

7173

7274
protected:

0 commit comments

Comments
 (0)