Skip to content
Permalink
Browse files

Use QgsRatioLockButton for fixedAspectRatio in SVG marker

  • Loading branch information
rldhont committed Sep 28, 2017
1 parent 954d62f commit aee93b0c1b12d9a86b6534eb60750b4d12510ce2
@@ -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;
@@ -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 );
}
}

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

void QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol()
@@ -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 );
@@ -2000,7 +1999,7 @@ void QgsSvgMarkerSymbolLayerWidget::setWidth()
{
spinHeight->setValue( spinWidth->value() );
}
else if ( checkBoxAspectRatio->isChecked() )
else if ( mLockAspectRatio->locked() )
{
spinHeight->setValue( spinWidth->value() * defaultAspectRatio );
}
@@ -2023,7 +2022,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()
{
spinWidth->setValue( spinHeight->value() );
}
else if ( checkBoxAspectRatio->isChecked() )
else if ( mLockAspectRatio->locked() )
{
spinWidth->setValue( spinHeight->value() / defaultAspectRatio );
}
@@ -2039,7 +2038,7 @@ void QgsSvgMarkerSymbolLayerWidget::setHeight()

void QgsSvgMarkerSymbolLayerWidget::stateChangedAspectRatio()
{
spinHeight->setEnabled( !checkBoxAspectRatio->isChecked() );
spinHeight->setEnabled( !mLockAspectRatio->locked() );
setWidth();
emit changed();
}
@@ -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">
@@ -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>
@@ -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>
@@ -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>
@@ -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>

0 comments on commit aee93b0

Please sign in to comment.
You can’t perform that action at this time.