Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Data defined all the things!
Add a bunch of missing data defined options for symbology.
Also fix dialog sizing issues.
  • Loading branch information
nyalldawson committed Jan 22, 2015
1 parent 8216f7d commit df939c3
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 270 deletions.
4 changes: 4 additions & 0 deletions python/gui/symbology-ng/qgsdatadefinedsymboldialog.sip
Expand Up @@ -25,4 +25,8 @@ class QgsDataDefinedSymbolDialog : QDialog
static QString gradientCoordModeHelpText();
static QString gradientSpreadHelpText();
static QString boolHelpText();
static QString lineStyleHelpText();
static QString joinStyleHelpText();
static QString capStyleHelpText();
static QString fillStyleHelpText();
};
29 changes: 29 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -85,6 +85,11 @@ void QgsSimpleFillSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
{
brush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
QgsExpression* fillStyleExpression = expression( "fill_style" );
if ( fillStyleExpression )
{
brush.setStyle( QgsSymbolLayerV2Utils::decodeBrushStyle( fillStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
QgsExpression* colorBorderExpression = expression( "color_border" );
if ( colorBorderExpression )
{
Expand All @@ -98,6 +103,18 @@ void QgsSimpleFillSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
pen.setWidthF( width );
selPen.setWidthF( width );
}
QgsExpression* borderStyleExpression = expression( "border_style" );
if ( borderStyleExpression )
{
pen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( borderStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
selPen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( borderStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
QgsExpression* joinStyleExpression = expression( "join_style" );
if ( joinStyleExpression )
{
pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
selPen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
}


Expand Down Expand Up @@ -194,6 +211,18 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
{
sl->setDataDefinedProperty( "width_border", props["width_border_expression"] );
}
if ( props.contains( "fill_style_expression" ) )
{
sl->setDataDefinedProperty( "fill_style", props["fill_style_expression"] );
}
if ( props.contains( "border_style_expression" ) )
{
sl->setDataDefinedProperty( "border_style", props["border_style_expression"] );
}
if ( props.contains( "join_style_expression" ) )
{
sl->setDataDefinedProperty( "join_style", props["join_style_expression"] );
}
return sl;
}

Expand Down
10 changes: 10 additions & 0 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -187,6 +187,8 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props
l->setDataDefinedProperty( "joinstyle", props["joinstyle_expression"] );
if ( props.contains( "capstyle_expression" ) )
l->setDataDefinedProperty( "capstyle", props["capstyle_expression"] );
if ( props.contains( "line_style_expression" ) )
l->setDataDefinedProperty( "line_style", props["line_style_expression"] );

return l;
}
Expand Down Expand Up @@ -534,6 +536,14 @@ void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
pen.setDashPattern( dashVector );
}

//line style
QgsExpression* lineStyleExpression = expression( "line_style" );
if ( lineStyleExpression )
{
QString lineStyleString = lineStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
pen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( lineStyleString ) );
}

//join style
QgsExpression* joinStyleExpression = expression( "joinstyle" );
if ( joinStyleExpression )
Expand Down
14 changes: 13 additions & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -161,6 +161,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
{
m->setDataDefinedProperty( "color_border", props["color_border_expression"] );
}
if ( props.contains( "outline_style_expression" ) )
{
m->setDataDefinedProperty( "outline_style", props["outline_style_expression"] );
}
if ( props.contains( "outline_width_expression" ) )
{
m->setDataDefinedProperty( "outline_width", props["outline_width_expression"] );
Expand Down Expand Up @@ -226,7 +230,8 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
// - size, rotation, shape, color, border color is not data-defined
// - drawing to screen (not printer)
mUsingCache = !hasDataDefinedRotation && !hasDataDefinedSize && !context.renderContext().forceVectorOutput()
&& !dataDefinedProperty( "name" ) && !dataDefinedProperty( "color" ) && !dataDefinedProperty( "color_border" ) && !dataDefinedProperty( "outline_width" ) &&
&& !dataDefinedProperty( "name" ) && !dataDefinedProperty( "color" ) && !dataDefinedProperty( "color_border" )
&& !dataDefinedProperty( "outline_width" ) && !dataDefinedProperty( "outline_style" ) &&
!dataDefinedProperty( "size" );

// use either QPolygonF or QPainterPath for drawing
Expand Down Expand Up @@ -581,6 +586,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
QgsExpression* colorExpression = expression( "color" );
QgsExpression* colorBorderExpression = expression( "color_border" );
QgsExpression* outlineWidthExpression = expression( "outline_width" );
QgsExpression* outlineStyleExpression = expression( "outline_style" );
if ( colorExpression )
{
mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
Expand All @@ -596,6 +602,12 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
mPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit, mOutlineWidthMapUnitScale ) );
mSelPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit, mOutlineWidthMapUnitScale ) );
}
if ( outlineStyleExpression )
{
QString outlineStyle = outlineStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
mPen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( outlineStyle ) );
mSelPen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( outlineStyle ) );
}

p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( context.selected() ? mSelPen : mPen );
Expand Down
22 changes: 22 additions & 0 deletions src/gui/symbology-ng/qgsdatadefinedsymboldialog.cpp
Expand Up @@ -139,4 +139,26 @@ QString QgsDataDefinedSymbolDialog::boolHelpText()
return tr( "0 (false)|1 (true)" );
}

QString QgsDataDefinedSymbolDialog::lineStyleHelpText()
{
return "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'";
}

QString QgsDataDefinedSymbolDialog::joinStyleHelpText()
{
return "'bevel'|'miter'|'round'";
}

QString QgsDataDefinedSymbolDialog::capStyleHelpText()
{
return "'square'|'flat'|'round'";
}

QString QgsDataDefinedSymbolDialog::fillStyleHelpText()
{
return "'solid'|'horizontal'|'vertical'|'cross'|'b_diagonal'|'f_diagonal'|"
"'diagonal_x'|'dense1'|'dense2'|'dense3'|'dense4'|'dense5'|"
"'dense6'|'dense7'|'no'";
}


4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsdatadefinedsymboldialog.h
Expand Up @@ -39,6 +39,10 @@ class GUI_EXPORT QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsData
static QString gradientCoordModeHelpText();
static QString gradientSpreadHelpText();
static QString boolHelpText();
static QString lineStyleHelpText();
static QString joinStyleHelpText();
static QString capStyleHelpText();
static QString fillStyleHelpText();

private:
const QgsVectorLayer* mVectorLayer;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Expand Up @@ -116,7 +116,7 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
registerDataDefinedButton( mOutlineWidthDDBtn, "outline_width", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mFillColorDDBtn, "fill_color", QgsDataDefinedButton::String, "'red,green,blue,alpha' e.g. '255,0,0,255'" );
registerDataDefinedButton( mBorderColorDDBtn, "outline_color", QgsDataDefinedButton::String, "'red,green,blue,alpha' e.g. '255,0,0,255'" );
registerDataDefinedButton( mOutlineStyleDDBtn, "outline_style", QgsDataDefinedButton::String, "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'" );
registerDataDefinedButton( mOutlineStyleDDBtn, "outline_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::lineStyleHelpText() );
registerDataDefinedButton( mShapeDDBtn, "symbol_name", QgsDataDefinedButton::String, "'circle', 'rectangle', 'cross', 'triangle'" );
registerDataDefinedButton( mOffsetDDBtn, "offset", QgsDataDefinedButton::String, "'x,y' e.g. '2,3.5'" );
registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, "'left', 'center' or 'right'" );
Expand Down
10 changes: 8 additions & 2 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -186,8 +186,9 @@ void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
registerDataDefinedButton( mPenWidthDDBtn, "width", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mOffsetDDBtn, "offset", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::offsetHelpText() );
registerDataDefinedButton( mDashPatternDDBtn, "customdash", QgsDataDefinedButton::String, tr( "'<dash>;<space>' e.g. '8;2;1;2'" ) );
registerDataDefinedButton( mJoinStyleDDBtn, "joinstyle", QgsDataDefinedButton::String, tr( "'bevel'|'miter'|'round'" ) );
registerDataDefinedButton( mCapStyleDDBtn, "capstyle", QgsDataDefinedButton::String, tr( "'square'|'flat'|'round'" ) );
registerDataDefinedButton( mPenStyleDDBtn, "line_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::lineStyleHelpText() );
registerDataDefinedButton( mJoinStyleDDBtn, "joinstyle", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::joinStyleHelpText() );
registerDataDefinedButton( mCapStyleDDBtn, "capstyle", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::capStyleHelpText() );
}

QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -425,6 +426,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
registerDataDefinedButton( mFillColorDDBtn, "color", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::colorHelpText() );
registerDataDefinedButton( mBorderColorDDBtn, "color_border", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::colorHelpText() );
registerDataDefinedButton( mOutlineWidthDDBtn, "outline_width", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mOutlineStyleDDBtn, "outline_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::lineStyleHelpText() );
registerDataDefinedButton( mSizeDDBtn, "size", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mAngleDDBtn, "angle", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mOffsetDDBtn, "offset", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::offsetHelpText() );
Expand Down Expand Up @@ -626,6 +628,10 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
registerDataDefinedButton( mFillColorDDBtn, "color", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::colorHelpText() );
registerDataDefinedButton( mBorderColorDDBtn, "color_border", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::colorHelpText() );
registerDataDefinedButton( mBorderWidthDDBtn, "width_border", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mFillStyleDDBtn, "fill_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::fillStyleHelpText() );
registerDataDefinedButton( mBorderStyleDDBtn, "border_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::lineStyleHelpText() );
registerDataDefinedButton( mJoinStyleDDBtn, "join_style", QgsDataDefinedButton::String, QgsDataDefinedSymbolDialog::joinStyleHelpText() );

}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2Widget::symbolLayer()
Expand Down
8 changes: 4 additions & 4 deletions src/ui/symbollayer/widget_gradientfill.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<height>657</height>
<width>556</width>
<height>342</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -139,7 +139,7 @@
<item>
<widget class="QCheckBox" name="checkRefPoint1Centroid">
<property name="text">
<string>Feature centroid</string>
<string>Centroid</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -411,7 +411,7 @@
<item>
<widget class="QCheckBox" name="checkRefPoint2Centroid">
<property name="text">
<string>Feature centroid</string>
<string>Centroid</string>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions src/ui/symbollayer/widget_linepatternfill.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>387</height>
<width>345</width>
<height>176</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
4 changes: 2 additions & 2 deletions src/ui/symbollayer/widget_markerline.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>765</width>
<height>404</height>
<width>377</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
4 changes: 2 additions & 2 deletions src/ui/symbollayer/widget_pointpatternfill.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>497</width>
<height>271</height>
<width>389</width>
<height>189</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
4 changes: 2 additions & 2 deletions src/ui/symbollayer/widget_rasterfill.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>649</width>
<height>384</height>
<width>453</width>
<height>269</height>
</rect>
</property>
<property name="windowTitle">
Expand Down

0 comments on commit df939c3

Please sign in to comment.