Skip to content

Commit

Permalink
Use QgsRatioLockButton for fixedAspectRatio in SVG marker
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Sep 28, 2017
1 parent 954d62f commit aee93b0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
5 changes: 2 additions & 3 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Expand Up @@ -2111,12 +2111,11 @@ double QgsSvgMarkerSymbolLayer::calculateSize( QgsSymbolRenderContext &context,

double QgsSvgMarkerSymbolLayer::calculateAspectRatio( QgsSymbolRenderContext &context, double scaledSize, bool &hasDataDefinedAspectRatio ) const
{
hasDataDefinedAspectRatio = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyPreserveAspectRatio ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight );
hasDataDefinedAspectRatio = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight );
if ( !hasDataDefinedAspectRatio )
return mFixedAspectRatio;

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

double scaledAspectRatio = mDefaultAspectRatio;
Expand Down
13 changes: 6 additions & 7 deletions src/gui/symbology/qgssymbollayerwidget.cpp
Expand Up @@ -1756,20 +1756,20 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( const QgsVectorLay
connect( viewGroups->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSvgMarkerSymbolLayerWidget::populateIcons );
connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setWidth );
connect( spinHeight, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setHeight );
connect( checkBoxAspectRatio, static_cast < void ( QCheckBox::* )( int ) > ( &QCheckBox::stateChanged ), this, &QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio );
connect( mLockAspectRatio, static_cast < void ( QgsRatioLockButton::* )( bool ) > ( &QgsRatioLockButton::lockChanged ), this, &QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio );
connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setAngle );
connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
connect( this, &QgsSymbolLayerWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol );


//make a temporary symbol for the size assistant preview
mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );

if ( vectorLayer() )
{
mWidthDDBtn->setSymbol( mAssistantPreviewSymbol );
mHeightDDBtn->setSymbol( mAssistantPreviewSymbol );
mAspectRatioDDBtn->setSymbol( mAssistantPreviewSymbol );
}
}

Expand Down Expand Up @@ -1878,7 +1878,7 @@ void QgsSvgMarkerSymbolLayerWidget::setGuiForSvg( const QgsSvgMarkerSymbolLayer
}
spinHeight->blockSignals( false );
spinHeight->setEnabled( !preservedAspectRatio );
checkBoxAspectRatio->setChecked( preservedAspectRatio );
mLockAspectRatio->setLocked( preservedAspectRatio );
}

void QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol()
Expand Down Expand Up @@ -1963,7 +1963,6 @@ void QgsSvgMarkerSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )

registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyWidth );
registerDataDefinedButton( mHeightDDBtn, QgsSymbolLayer::PropertyHeight );
registerDataDefinedButton( mAspectRatioDDBtn, QgsSymbolLayer::PropertyPreserveAspectRatio );
registerDataDefinedButton( mStrokeWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
registerDataDefinedButton( mAngleDDBtn, QgsSymbolLayer::PropertyAngle );
registerDataDefinedButton( mOffsetDDBtn, QgsSymbolLayer::PropertyOffset );
Expand Down Expand Up @@ -2000,7 +1999,7 @@ void QgsSvgMarkerSymbolLayerWidget::setWidth()
{
spinHeight->setValue( spinWidth->value() );
}
else if ( checkBoxAspectRatio->isChecked() )
else if ( mLockAspectRatio->locked() )
{
spinHeight->setValue( spinWidth->value() * defaultAspectRatio );
}
Expand All @@ -2023,7 +2022,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()
{
spinWidth->setValue( spinHeight->value() );
}
else if ( checkBoxAspectRatio->isChecked() )
else if ( mLockAspectRatio->locked() )
{
spinWidth->setValue( spinHeight->value() / defaultAspectRatio );
}
Expand All @@ -2039,7 +2038,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()

void QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio()
{
spinHeight->setEnabled( !checkBoxAspectRatio->isChecked() );
spinHeight->setEnabled( !mLockAspectRatio->locked() );
setWidth();
emit changed();
}
Expand Down
74 changes: 41 additions & 33 deletions src/ui/symbollayer/widget_svgmarker.ui
Expand Up @@ -30,13 +30,6 @@
</property>
</widget>
</item>
<item>
<widget class="QgsPropertyOverrideButton" name="mAspectRatioDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
Expand Down Expand Up @@ -86,12 +79,12 @@
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>width</string>
<string>Width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -115,8 +108,15 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinWidth">
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -140,30 +140,39 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>height</string>
<item row="0" column="2" rowspan="2">
<layout class="QHBoxLayout" name="_2">
<property name="leftMargin">
<number>2</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxAspectRatio">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="topMargin">
<number>2</number>
</property>
<property name="text">
<string>Preserve aspect ratio</string>
<property name="rightMargin">
<number>0</number>
</property>
<property name="checked">
<bool>true</bool>
<property name="bottomMargin">
<number>2</number>
</property>
</widget>
<item>
<widget class="QgsRatioLockButton" name="mLockAspectRatio">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Lock aspect ratio (including while drawing extent onto canvas)</string>
</property>
<property name="leftMargin" stdset="0">
<number>13</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2" rowspan="2">
<item row="0" column="3" rowspan="2">
<widget class="QgsUnitSelectionWidget" name="mSizeUnitWidget" native="true">
<property name="minimumSize">
<size>
Expand Down Expand Up @@ -608,11 +617,10 @@
<tabstops>
<tabstop>spinWidth</tabstop>
<tabstop>spinHeight</tabstop>
<tabstop>checkBoxAspectRatio</tabstop>
<tabstop>mLockAspectRatio</tabstop>
<tabstop>mSizeUnitWidget</tabstop>
<tabstop>mWidthDDBtn</tabstop>
<tabstop>mHeightDDBtn</tabstop>
<tabstop>mAspectRatioDDBtn</tabstop>
<tabstop>mChangeColorButton</tabstop>
<tabstop>mFillColorDDBtn</tabstop>
<tabstop>mChangeStrokeColorButton</tabstop>
Expand Down

0 comments on commit aee93b0

Please sign in to comment.