Skip to content

Commit aee93b0

Browse files
committedSep 28, 2017
Use QgsRatioLockButton for fixedAspectRatio in SVG marker
1 parent 954d62f commit aee93b0

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed
 

‎src/core/symbology/qgsmarkersymbollayer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,12 +2111,11 @@ double QgsSvgMarkerSymbolLayer::calculateSize( QgsSymbolRenderContext &context,
21112111

21122112
double QgsSvgMarkerSymbolLayer::calculateAspectRatio( QgsSymbolRenderContext &context, double scaledSize, bool &hasDataDefinedAspectRatio ) const
21132113
{
2114-
hasDataDefinedAspectRatio = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyPreserveAspectRatio ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight );
2114+
hasDataDefinedAspectRatio = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight );
21152115
if ( !hasDataDefinedAspectRatio )
21162116
return mFixedAspectRatio;
21172117

2118-
context.setOriginalValueVariable( mFixedAspectRatio <= 0.0 );
2119-
if ( mDataDefinedProperties.valueAsBool( QgsSymbolLayer::PropertyPreserveAspectRatio, context.renderContext().expressionContext(), mFixedAspectRatio <= 0.0 ) )
2118+
if ( !mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight ) && mFixedAspectRatio <= 0.0 )
21202119
return 0.0;
21212120

21222121
double scaledAspectRatio = mDefaultAspectRatio;

‎src/gui/symbology/qgssymbollayerwidget.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,20 +1756,20 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( const QgsVectorLay
17561756
connect( viewGroups->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSvgMarkerSymbolLayerWidget::populateIcons );
17571757
connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setWidth );
17581758
connect( spinHeight, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setHeight );
1759-
connect( checkBoxAspectRatio, static_cast < void ( QCheckBox::* )( int ) > ( &QCheckBox::stateChanged ), this, &QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio );
1759+
connect( mLockAspectRatio, static_cast < void ( QgsRatioLockButton::* )( bool ) > ( &QgsRatioLockButton::lockChanged ), this, &QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio );
17601760
connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setAngle );
17611761
connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
17621762
connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
17631763
connect( this, &QgsSymbolLayerWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol );
17641764

1765+
17651766
//make a temporary symbol for the size assistant preview
17661767
mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );
17671768

17681769
if ( vectorLayer() )
17691770
{
17701771
mWidthDDBtn->setSymbol( mAssistantPreviewSymbol );
17711772
mHeightDDBtn->setSymbol( mAssistantPreviewSymbol );
1772-
mAspectRatioDDBtn->setSymbol( mAssistantPreviewSymbol );
17731773
}
17741774
}
17751775

@@ -1878,7 +1878,7 @@ void QgsSvgMarkerSymbolLayerWidget::setGuiForSvg( const QgsSvgMarkerSymbolLayer
18781878
}
18791879
spinHeight->blockSignals( false );
18801880
spinHeight->setEnabled( !preservedAspectRatio );
1881-
checkBoxAspectRatio->setChecked( preservedAspectRatio );
1881+
mLockAspectRatio->setLocked( preservedAspectRatio );
18821882
}
18831883

18841884
void QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol()
@@ -1963,7 +1963,6 @@ void QgsSvgMarkerSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
19631963

19641964
registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyWidth );
19651965
registerDataDefinedButton( mHeightDDBtn, QgsSymbolLayer::PropertyHeight );
1966-
registerDataDefinedButton( mAspectRatioDDBtn, QgsSymbolLayer::PropertyPreserveAspectRatio );
19671966
registerDataDefinedButton( mStrokeWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
19681967
registerDataDefinedButton( mAngleDDBtn, QgsSymbolLayer::PropertyAngle );
19691968
registerDataDefinedButton( mOffsetDDBtn, QgsSymbolLayer::PropertyOffset );
@@ -2000,7 +1999,7 @@ void QgsSvgMarkerSymbolLayerWidget::setWidth()
20001999
{
20012000
spinHeight->setValue( spinWidth->value() );
20022001
}
2003-
else if ( checkBoxAspectRatio->isChecked() )
2002+
else if ( mLockAspectRatio->locked() )
20042003
{
20052004
spinHeight->setValue( spinWidth->value() * defaultAspectRatio );
20062005
}
@@ -2023,7 +2022,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()
20232022
{
20242023
spinWidth->setValue( spinHeight->value() );
20252024
}
2026-
else if ( checkBoxAspectRatio->isChecked() )
2025+
else if ( mLockAspectRatio->locked() )
20272026
{
20282027
spinWidth->setValue( spinHeight->value() / defaultAspectRatio );
20292028
}
@@ -2039,7 +2038,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()
20392038

20402039
void QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio()
20412040
{
2042-
spinHeight->setEnabled( !checkBoxAspectRatio->isChecked() );
2041+
spinHeight->setEnabled( !mLockAspectRatio->locked() );
20432042
setWidth();
20442043
emit changed();
20452044
}

‎src/ui/symbollayer/widget_svgmarker.ui

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030
</property>
3131
</widget>
3232
</item>
33-
<item>
34-
<widget class="QgsPropertyOverrideButton" name="mAspectRatioDDBtn">
35-
<property name="text">
36-
<string>…</string>
37-
</property>
38-
</widget>
39-
</item>
4033
</layout>
4134
</item>
4235
<item row="5" column="0">
@@ -86,12 +79,12 @@
8679
<item row="0" column="0">
8780
<widget class="QLabel" name="label_10">
8881
<property name="text">
89-
<string>width</string>
82+
<string>Width</string>
9083
</property>
9184
</widget>
9285
</item>
93-
<item row="1" column="1">
94-
<widget class="QgsDoubleSpinBox" name="spinHeight">
86+
<item row="0" column="1">
87+
<widget class="QgsDoubleSpinBox" name="spinWidth">
9588
<property name="sizePolicy">
9689
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
9790
<horstretch>0</horstretch>
@@ -115,8 +108,15 @@
115108
</property>
116109
</widget>
117110
</item>
118-
<item row="0" column="1">
119-
<widget class="QgsDoubleSpinBox" name="spinWidth">
111+
<item row="1" column="0">
112+
<widget class="QLabel" name="label_11">
113+
<property name="text">
114+
<string>Height</string>
115+
</property>
116+
</widget>
117+
</item>
118+
<item row="1" column="1">
119+
<widget class="QgsDoubleSpinBox" name="spinHeight">
120120
<property name="sizePolicy">
121121
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
122122
<horstretch>0</horstretch>
@@ -140,30 +140,39 @@
140140
</property>
141141
</widget>
142142
</item>
143-
<item row="1" column="0">
144-
<widget class="QLabel" name="label_11">
145-
<property name="text">
146-
<string>height</string>
143+
<item row="0" column="2" rowspan="2">
144+
<layout class="QHBoxLayout" name="_2">
145+
<property name="leftMargin">
146+
<number>2</number>
147147
</property>
148-
</widget>
149-
</item>
150-
<item row="2" column="1">
151-
<widget class="QCheckBox" name="checkBoxAspectRatio">
152-
<property name="sizePolicy">
153-
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
154-
<horstretch>0</horstretch>
155-
<verstretch>0</verstretch>
156-
</sizepolicy>
148+
<property name="topMargin">
149+
<number>2</number>
157150
</property>
158-
<property name="text">
159-
<string>Preserve aspect ratio</string>
151+
<property name="rightMargin">
152+
<number>0</number>
160153
</property>
161-
<property name="checked">
162-
<bool>true</bool>
154+
<property name="bottomMargin">
155+
<number>2</number>
163156
</property>
164-
</widget>
157+
<item>
158+
<widget class="QgsRatioLockButton" name="mLockAspectRatio">
159+
<property name="sizePolicy">
160+
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
161+
<horstretch>0</horstretch>
162+
<verstretch>0</verstretch>
163+
</sizepolicy>
164+
</property>
165+
<property name="toolTip">
166+
<string>Lock aspect ratio (including while drawing extent onto canvas)</string>
167+
</property>
168+
<property name="leftMargin" stdset="0">
169+
<number>13</number>
170+
</property>
171+
</widget>
172+
</item>
173+
</layout>
165174
</item>
166-
<item row="0" column="2" rowspan="2">
175+
<item row="0" column="3" rowspan="2">
167176
<widget class="QgsUnitSelectionWidget" name="mSizeUnitWidget" native="true">
168177
<property name="minimumSize">
169178
<size>
@@ -608,11 +617,10 @@
608617
<tabstops>
609618
<tabstop>spinWidth</tabstop>
610619
<tabstop>spinHeight</tabstop>
611-
<tabstop>checkBoxAspectRatio</tabstop>
620+
<tabstop>mLockAspectRatio</tabstop>
612621
<tabstop>mSizeUnitWidget</tabstop>
613622
<tabstop>mWidthDDBtn</tabstop>
614623
<tabstop>mHeightDDBtn</tabstop>
615-
<tabstop>mAspectRatioDDBtn</tabstop>
616624
<tabstop>mChangeColorButton</tabstop>
617625
<tabstop>mFillColorDDBtn</tabstop>
618626
<tabstop>mChangeStrokeColorButton</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.