Skip to content
Permalink
Browse files

[FEATURE] Option to put marker only on first/last vertex of a line (#…

…3279) - contributed by Cedric Moeri - thanks!

git-svn-id: http://svn.osgeo.org/qgis/trunk@14836 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 4, 2010
1 parent 1539985 commit f99179eeed7392ae0c90a8a0bfb6e5276fdcf303
@@ -13,6 +13,7 @@ Brent Wood
Brook Milligan
Carl Anderson
Carlos Dávila
Cédric Möri
Christian Ferreira
Diego Moreira
Duarte Carreira
@@ -239,7 +239,14 @@ QgsSymbolLayerV2* QgsMarkerLineSymbolLayerV2::create( const QgsStringMap& props
if ( props.contains( "offset" ) )
x->setOffset( props["offset"].toDouble() );
if ( props.contains( "placement" ) )
x->setPlacement( props["placement"] == "vertex" ? Vertex : Interval );
if ( props["placement"] == "vertex" )
x->setPlacement( Vertex );
else if ( props["placement"] == "lastvertex" )
x->setPlacement( LastVertex );
else if ( props["placement"] == "firstvertex" )
x->setPlacement( FirstVertex );
else
x->setPlacement( Interval );
return x;
}

@@ -279,18 +286,18 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
{
if ( mOffset == 0 )
{
if ( mPlacement == Vertex )
renderPolylineVertex( points, context );
else
if ( mPlacement == Interval )
renderPolylineInterval( points, context );
else
renderPolylineVertex( points, context );
}
else
{
QPolygonF points2 = ::offsetLine( points, context.outputLineWidth( mOffset ) );
if ( mPlacement == Vertex )
renderPolylineVertex( points2, context );
else
if ( mPlacement == Interval )
renderPolylineInterval( points2, context );
else
renderPolylineVertex( points2, context );
}
}

@@ -360,8 +367,25 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,

double origAngle = mMarker->angle();
double angle;
int i, maxCount;

for ( int i = 0; i < points.count(); ++i )
if ( mPlacement == FirstVertex )
{
i = 0;
maxCount = 1;
}
else if ( mPlacement == LastVertex )
{
i = points.count() - 1;
maxCount = points.count();
}
else
{
i = 0;
maxCount = points.count();
}

for ( ; i < maxCount; ++i )
{
const QPointF& pt = points[i];

@@ -395,7 +419,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
double unitX = cos( a1 ) + cos( a2 ), unitY = sin( a1 ) + sin( a2 );
angle = atan2( unitY, unitX );
}
mMarker->setAngle( angle * 180 / M_PI );
mMarker->setAngle( origAngle + angle * 180 / M_PI );
}

mMarker->renderPoint( points.at( i ), rc, -1, context.selected() );
@@ -411,7 +435,14 @@ QgsStringMap QgsMarkerLineSymbolLayerV2::properties() const
map["rotate"] = ( mRotateMarker ? "1" : "0" );
map["interval"] = QString::number( mInterval );
map["offset"] = QString::number( mOffset );
map["placement"] = ( mPlacement == Vertex ? "vertex" : "interval" );
if ( mPlacement == Vertex )
map["placement"] = "vertex";
else if ( mPlacement == LastVertex )
map["placement"] = "lastvertex";
else if ( mPlacement == FirstVertex )
map["placement"] = "firstvertex";
else
map["placement"] = "interval";
return map;
}

@@ -88,7 +88,9 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
enum Placement
{
Interval,
Vertex
Vertex,
LastVertex,
FirstVertex
};

// static stuff
@@ -361,6 +361,8 @@ QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget( QWidget* par
connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
connect( radInterval, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
connect( radVertex, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
connect( radVertexLast, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
connect( radVertexFirst, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
}

void QgsMarkerLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
@@ -377,8 +379,12 @@ void QgsMarkerLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
spinOffset->setValue( mLayer->offset() );
if ( mLayer->placement() == QgsMarkerLineSymbolLayerV2::Interval )
radInterval->setChecked( true );
else
else if ( mLayer->placement() == QgsMarkerLineSymbolLayerV2::Vertex )
radVertex->setChecked( true );
else if ( mLayer->placement() == QgsMarkerLineSymbolLayerV2::LastVertex )
radVertexLast->setChecked( true );
else
radVertexFirst->setChecked( true );
updateMarker();
setPlacement(); // update gui
}
@@ -426,8 +432,17 @@ void QgsMarkerLineSymbolLayerV2Widget::updateMarker()
void QgsMarkerLineSymbolLayerV2Widget::setPlacement()
{
bool interval = radInterval->isChecked();
mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
spinInterval->setEnabled( interval );
//mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
if ( radInterval->isChecked() )
mLayer->setPlacement( QgsMarkerLineSymbolLayerV2::Interval );
else if ( radVertex->isChecked() )
mLayer->setPlacement( QgsMarkerLineSymbolLayerV2::Vertex );
else if ( radVertexLast->isChecked() )
mLayer->setPlacement( QgsMarkerLineSymbolLayerV2::LastVertex );
else
mLayer->setPlacement( QgsMarkerLineSymbolLayerV2::FirstVertex );

emit changed();
}

@@ -7,112 +7,122 @@
<x>0</x>
<y>0</y>
<width>352</width>
<height>232</height>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Marker</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="btnChangeMarker">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marker placement</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radInterval">
<property name="text">
<string>with interval</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spinInterval">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="radVertex">
<property name="text">
<string>on every vertex</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="chkRotateMarker">
<property name="text">
<string>Rotate marker</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line offset</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="spinOffset">
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="6">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>110</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Marker</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="btnChangeMarker">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>109</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marker placement</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radInterval">
<property name="text">
<string>with interval</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spinInterval">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="radVertex">
<property name="text">
<string>on every vertex</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QRadioButton" name="radVertexLast">
<property name="text">
<string>on last vertex only</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QRadioButton" name="radVertexFirst">
<property name="text">
<string>on first vertex only</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkRotateMarker">
<property name="text">
<string>Rotate marker</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line offset</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="spinOffset">
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<item row="8" column="0" colspan="3">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>

0 comments on commit f99179e

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