Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tweaked numeric assistant for rotation properties
  • Loading branch information
nyalldawson committed Feb 14, 2017
1 parent a30fe35 commit c4ec256
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 15 deletions.
1 change: 1 addition & 0 deletions python/core/qgsproperty.sip
Expand Up @@ -14,6 +14,7 @@ class QgsPropertyDefinition
Double,
DoublePositive,
Double0To1,
Rotation,
String,
Transparency,
RenderUnits,
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerobject.cpp
Expand Up @@ -47,13 +47,13 @@ void QgsComposerObject::initPropertyDefinitions()
{ QgsComposerObject::PositionY, QgsPropertyDefinition( "dataDefinedPositionY" , QObject::tr( "Position (Y)" ), QgsPropertyDefinition::Double ) },
{ QgsComposerObject::ItemWidth, QgsPropertyDefinition( "dataDefinedWidth" , QObject::tr( "Width" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsComposerObject::ItemHeight, QgsPropertyDefinition( "dataDefinedHeight" , QObject::tr( "Height" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsComposerObject::ItemRotation, QgsPropertyDefinition( "dataDefinedRotation" , QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Double ) },
{ QgsComposerObject::ItemRotation, QgsPropertyDefinition( "dataDefinedRotation" , QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation ) },
{ QgsComposerObject::Transparency, QgsPropertyDefinition( "dataDefinedTransparency" , QObject::tr( "Transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsComposerObject::BlendMode, QgsPropertyDefinition( "dataDefinedBlendMode" , QObject::tr( "Blend mode" ), QgsPropertyDefinition::BlendMode ) },
{ QgsComposerObject::ExcludeFromExports, QgsPropertyDefinition( "dataDefinedExcludeExports", QObject::tr( "Exclude item from exports" ), QgsPropertyDefinition::Boolean ) },
{ QgsComposerObject::FrameColor, QgsPropertyDefinition( "dataDefinedFrameColor", QObject::tr( "Frame color" ), QgsPropertyDefinition::ColorWithAlpha ) },
{ QgsComposerObject::BackgroundColor, QgsPropertyDefinition( "dataDefinedBackgroundColor", QObject::tr( "Background color" ), QgsPropertyDefinition::ColorWithAlpha ) },
{ QgsComposerObject::MapRotation, QgsPropertyDefinition( "dataDefinedMapRotation" , QObject::tr( "Map rotation" ), QgsPropertyDefinition::Double ) },
{ QgsComposerObject::MapRotation, QgsPropertyDefinition( "dataDefinedMapRotation" , QObject::tr( "Map rotation" ), QgsPropertyDefinition::Rotation ) },
{ QgsComposerObject::MapScale, QgsPropertyDefinition( "dataDefinedMapScale" , QObject::tr( "Map scale" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsComposerObject::MapXMin, QgsPropertyDefinition( "dataDefinedMapXMin" , QObject::tr( "Extent minimum X" ), QgsPropertyDefinition::Double ) },
{ QgsComposerObject::MapYMin, QgsPropertyDefinition( "dataDefinedMapYMin" , QObject::tr( "Extent minimum Y" ), QgsPropertyDefinition::Double ) },
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdiagramrenderer.cpp
Expand Up @@ -45,7 +45,7 @@ void QgsDiagramLayerSettings::initPropertyDefinitions()
{ QgsDiagramLayerSettings::IsObstacle, QgsPropertyDefinition( "isObstacle", QObject::tr( "Diagram is an obstacle" ), QgsPropertyDefinition::Boolean ) },
{ QgsDiagramLayerSettings::Show, QgsPropertyDefinition( "show", QObject::tr( "Show diagram" ), QgsPropertyDefinition::Boolean ) },
{ QgsDiagramLayerSettings::AlwaysShow, QgsPropertyDefinition( "alwaysShow", QObject::tr( "Always show diagram" ), QgsPropertyDefinition::Boolean ) },
{ QgsDiagramLayerSettings::StartAngle, QgsPropertyDefinition( "startAngle", QObject::tr( "Pie chart start angle" ), QgsPropertyDefinition::Double ) },
{ QgsDiagramLayerSettings::StartAngle, QgsPropertyDefinition( "startAngle", QObject::tr( "Pie chart start angle" ), QgsPropertyDefinition::Rotation ) },
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/qgspallabeling.cpp
Expand Up @@ -142,7 +142,7 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::ShapeSizeY, QgsPropertyDefinition( "ShapeSizeY", QObject::tr( "Shape size (Y)" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::ShapeSizeUnits, QgsPropertyDefinition( "ShapeSizeUnits", QObject::tr( "Shape size units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShapeRotationType, QgsPropertyDefinition( "ShapeRotationType", QgsPropertyDefinition::DataTypeString, QObject::tr( "Shape rotation type" ), QObject::tr( "string " ) + "[<b>Sync</b>|<b>Offset</b>|<b>Fixed</b>]" ) },
{ QgsPalLayerSettings::ShapeRotation, QgsPropertyDefinition( "ShapeRotation", QObject::tr( "Shape rotation" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::ShapeRotation, QgsPropertyDefinition( "ShapeRotation", QObject::tr( "Shape rotation" ), QgsPropertyDefinition::Rotation ) },
{ QgsPalLayerSettings::ShapeOffset, QgsPropertyDefinition( "ShapeOffset", QObject::tr( "Shape offset" ), QgsPropertyDefinition::Offset ) },
{ QgsPalLayerSettings::ShapeOffsetUnits, QgsPropertyDefinition( "ShapeOffsetUnits", QObject::tr( "Shape offset units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShapeRadii, QgsPropertyDefinition( "ShapeRadii", QObject::tr( "Shape radii" ), QgsPropertyDefinition::Size2D ) },
Expand All @@ -157,7 +157,7 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::ShadowDraw, QgsPropertyDefinition( "ShadowDraw", QObject::tr( "Draw shadow" ), QgsPropertyDefinition::Boolean ) },
{ QgsPalLayerSettings::ShadowUnder, QgsPropertyDefinition( "ShadowUnder", QgsPropertyDefinition::DataTypeString, QObject::tr( "Symbol size" ), QObject::tr( "string " ) + QStringLiteral( "[<b>Lowest</b>|<b>Text</b>|<br>"
"<b>Buffer</b>|<b>Background</b>]" ) ) },
{ QgsPalLayerSettings::ShadowOffsetAngle, QgsPropertyDefinition( "ShadowOffsetAngle", QObject::tr( "Shadow offset angle" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::ShadowOffsetAngle, QgsPropertyDefinition( "ShadowOffsetAngle", QObject::tr( "Shadow offset angle" ), QgsPropertyDefinition::Rotation ) },
{ QgsPalLayerSettings::ShadowOffsetDist, QgsPropertyDefinition( "ShadowOffsetDist", QObject::tr( "Shadow offset distance" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsPalLayerSettings::ShadowOffsetUnits, QgsPropertyDefinition( "ShadowOffsetUnits", QObject::tr( "Shadow offset units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShadowRadius, QgsPropertyDefinition( "ShadowRadius", QObject::tr( "Shadow blur radius" ), QgsPropertyDefinition::DoublePositive ) },
Expand All @@ -175,7 +175,7 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::OffsetUnits, QgsPropertyDefinition( "OffsetUnits", QObject::tr( "Offset units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::LabelDistance, QgsPropertyDefinition( "LabelDistance", QObject::tr( "Label distance" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsPalLayerSettings::DistanceUnits, QgsPropertyDefinition( "DistanceUnits", QObject::tr( "Label distance units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::OffsetRotation, QgsPropertyDefinition( "OffsetRotation", QObject::tr( "Offset rotation" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::OffsetRotation, QgsPropertyDefinition( "OffsetRotation", QObject::tr( "Offset rotation" ), QgsPropertyDefinition::Rotation ) },
{ QgsPalLayerSettings::CurvedCharAngleInOut, QgsPropertyDefinition( "CurvedCharAngleInOut", QgsPropertyDefinition::DataTypeString, QObject::tr( "Curved character angles" ), QObject::tr( "double coord [<b>in,out</b> as 20.0-60.0,20.0-95.0]" ) ) },
{ QgsPalLayerSettings::RepeatDistance, QgsPropertyDefinition( "RepeatDistance", QObject::tr( "Repeat distance" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsPalLayerSettings::RepeatDistanceUnit, QgsPropertyDefinition( "RepeatDistanceUnit", QObject::tr( "Repeat distance unit" ), QgsPropertyDefinition::RenderUnits ) },
Expand All @@ -193,7 +193,7 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::Hali, QgsPropertyDefinition( "Hali", QgsPropertyDefinition::DataTypeString, QObject::tr( "Horizontal alignment" ), QObject::tr( "string " ) + "[<b>Left</b>|<b>Center</b>|<b>Right</b>]" ) },
{ QgsPalLayerSettings::Vali, QgsPropertyDefinition( "Vali", QgsPropertyDefinition::DataTypeString, QObject::tr( "Vertical alignment" ), QObject::tr( "string " ) + QStringLiteral( "[<b>Bottom</b>|<b>Base</b>|<br>"
"<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ) ) },
{ QgsPalLayerSettings::Rotation, QgsPropertyDefinition( "Rotation", QObject::tr( "Label rotation" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::Rotation, QgsPropertyDefinition( "Rotation", QObject::tr( "Label rotation" ), QgsPropertyDefinition::Rotation ) },
{ QgsPalLayerSettings::ScaleVisibility, QgsPropertyDefinition( "ScaleVisibility", QObject::tr( "Scale based visibility" ), QgsPropertyDefinition::Boolean ) },
{ QgsPalLayerSettings::MinScale, QgsPropertyDefinition( "MinScale", QObject::tr( "Minimum scale (denominator)" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::MaxScale, QgsPropertyDefinition( "MaxScale", QObject::tr( "Maximum scale (denominator)" ), QgsPropertyDefinition::Double ) },
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsproperty.cpp
Expand Up @@ -69,6 +69,11 @@ QgsPropertyDefinition::QgsPropertyDefinition( const QString& name, const QString
mHelpText = QObject::tr( "double [0.0-1.0]" );
break;

case Rotation:
mTypes = DataTypeNumeric;
mHelpText = QObject::tr( "double [0.0-360.0]" );
break;

case String:
mTypes = DataTypeString;
mHelpText = QObject::tr( "string of variable length" );
Expand Down Expand Up @@ -179,7 +184,8 @@ QgsPropertyDefinition::QgsPropertyDefinition( const QString& name, DataType data

bool QgsPropertyDefinition::supportsAssistant() const
{
return mTypes == DataTypeNumeric || mStandardType == Size || mStandardType == StrokeWidth || mStandardType == ColorNoAlpha || mStandardType == ColorWithAlpha;
return mTypes == DataTypeNumeric || mStandardType == Size || mStandardType == StrokeWidth || mStandardType == ColorNoAlpha || mStandardType == ColorWithAlpha
|| mStandardType == Rotation;
}

QString QgsPropertyDefinition::trString()
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsproperty.h
Expand Up @@ -56,6 +56,7 @@ class CORE_EXPORT QgsPropertyDefinition
Double, //!< Double value (including negative values)
DoublePositive, //!< Positive double value (including 0)
Double0To1, //!< Double value between 0-1 (inclusive)
Rotation, //!< Rotation (value between 0-360 degrees)
String, //!< Any string value
Transparency, //!< Transparency (0-100)
RenderUnits, //!< Render units (eg mm/pixels/map units)
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgssymbollayer.cpp
Expand Up @@ -41,7 +41,7 @@ void QgsSymbolLayer::initPropertyDefinitions()
sPropertyDefinitions = QgsPropertiesDefinition
{
{ QgsSymbolLayer::PropertySize, QgsPropertyDefinition( "size", QObject::tr( "Symbol size" ), QgsPropertyDefinition::Size ) },
{ QgsSymbolLayer::PropertyAngle, QgsPropertyDefinition( "angle", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Double ) },
{ QgsSymbolLayer::PropertyAngle, QgsPropertyDefinition( "angle", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation ) },
{ QgsSymbolLayer::PropertyName, QgsPropertyDefinition( "name", QObject::tr( "Symbol name" ), QgsPropertyDefinition::String ) },
{ QgsSymbolLayer::PropertyFillColor, QgsPropertyDefinition( "fillColor", QObject::tr( "Symbol fill color" ), QgsPropertyDefinition::ColorWithAlpha ) },
{ QgsSymbolLayer::PropertyOutlineColor, QgsPropertyDefinition( "outlineColor", QObject::tr( "Symbol outline color" ), QgsPropertyDefinition::ColorWithAlpha ) },
Expand All @@ -54,7 +54,7 @@ void QgsSymbolLayer::initPropertyDefinitions()
{ QgsSymbolLayer::PropertyFillStyle, QgsPropertyDefinition( "fillStyle", QObject::tr( "Symbol fill style" ), QgsPropertyDefinition::FillStyle )},
{ QgsSymbolLayer::PropertyJoinStyle, QgsPropertyDefinition( "joinStyle", QObject::tr( "Outline join style" ), QgsPropertyDefinition::PenJoinStyle )},
{ QgsSymbolLayer::PropertySecondaryColor, QgsPropertyDefinition( "color2", QObject::tr( "Secondary fill color" ), QgsPropertyDefinition::ColorWithAlpha )},
{ QgsSymbolLayer::PropertyLineAngle, QgsPropertyDefinition( "lineAngle", QObject::tr( "Angle for line fills" ), QgsPropertyDefinition::Double )},
{ QgsSymbolLayer::PropertyLineAngle, QgsPropertyDefinition( "lineAngle", QObject::tr( "Angle for line fills" ), QgsPropertyDefinition::Rotation )},
{ QgsSymbolLayer::PropertyGradientType, QgsPropertyDefinition( "gradientType", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient type" ), QObject::tr( "string " ) + QLatin1String( "[<b>linear</b>|<b>radial</b>|<b>conical</b>]" ) )},
{ QgsSymbolLayer::PropertyCoordinateMode, QgsPropertyDefinition( "gradientMode", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient mode" ), QObject::tr( "string " ) + QLatin1String( "[<b>feature</b>|<b>viewport</b>]" ) )},
{ QgsSymbolLayer::PropertyGradientSpread, QgsPropertyDefinition( "gradientSpread", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient spread" ), QObject::tr( "string " ) + QLatin1String( "[<b>pad</b>|<b>repeat</b>|<b>reflect</b>]" ) )},
Expand Down
32 changes: 30 additions & 2 deletions src/gui/qgspropertyassistantwidget.cpp
Expand Up @@ -87,6 +87,12 @@ QgsPropertyAssistantWidget::QgsPropertyAssistantWidget( QWidget* parent ,
break;
}

case QgsPropertyDefinition::Rotation:
{
mTransformerWidget = new QgsPropertyGenericNumericAssistantWidget( this, mDefinition, initialState );
break;
}

default:
{
if ( mDefinition.dataType() == QgsPropertyDefinition::DataTypeNumeric )
Expand Down Expand Up @@ -467,10 +473,32 @@ QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidg
layout()->setContentsMargins( 0, 0, 0, 0 );
layout()->setMargin( 0 );

minOutputSpinBox->setShowClearButton( false );
maxOutputSpinBox->setShowClearButton( false );
nullOutputSpinBox->setShowClearButton( false );

if ( definition.standardTemplate() == QgsPropertyDefinition::Rotation )
{
// tweak dialog for rotation
minOutputSpinBox->setMaximum( 360.0 );
minOutputSpinBox->setValue( 0.0 );
minOutputSpinBox->setShowClearButton( true );
minOutputSpinBox->setClearValue( 0.0 );
minOutputSpinBox->setSuffix( tr( " °" ) );
maxOutputSpinBox->setMaximum( 360.0 );
maxOutputSpinBox->setValue( 360.0 );
maxOutputSpinBox->setShowClearButton( true );
maxOutputSpinBox->setClearValue( 360.0 );
maxOutputSpinBox->setSuffix( tr( " °" ) );
exponentSpinBox->hide();
mExponentLabel->hide();
mLabelMinOutput->setText( tr( "Angle from" ) );
mLabelNullOutput->setText( tr( "Angle when NULL" ) );
}
else
{
minOutputSpinBox->setShowClearButton( false );
maxOutputSpinBox->setShowClearButton( false );
}

if ( const QgsGenericNumericTransformer* transform = dynamic_cast< const QgsGenericNumericTransformer* >( initialState.transformer() ) )
{
minOutputSpinBox->setValue( transform->minOutputValue() );
Expand Down
6 changes: 3 additions & 3 deletions src/ui/qgspropertygenericnumericassistantwidget.ui
Expand Up @@ -25,21 +25,21 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="mLabelMinOutput">
<property name="text">
<string>Output from</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<widget class="QLabel" name="mLabelNullOutput">
<property name="text">
<string>Output when NULL</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="mExponentLabel">
<property name="text">
<string>Exponent</string>
</property>
Expand Down

0 comments on commit c4ec256

Please sign in to comment.