Skip to content

Commit dde10de

Browse files
committedOct 26, 2011
Added vector field symbol layer and widget
1 parent fecb0de commit dde10de

File tree

7 files changed

+343
-0
lines changed

7 files changed

+343
-0
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SET(QGIS_CORE_SRCS
3939
symbology-ng/qgssymbologyv2conversion.cpp
4040
symbology-ng/qgssvgcache.cpp
4141
symbology-ng/qgsellipsesymbollayerv2.cpp
42+
symbology-ng/qgsvectorfieldsymbollayer.cpp
4243

4344
qgis.cpp
4445
qgsapplication.cpp

‎src/core/symbology-ng/qgssymbollayerv2registry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "qgsmarkersymbollayerv2.h"
66
#include "qgslinesymbollayerv2.h"
77
#include "qgsfillsymbollayerv2.h"
8+
#include "qgsvectorfieldsymbollayer.h"
89

910
QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::mInstance = NULL;
1011

@@ -26,6 +27,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
2627
QgsFontMarkerSymbolLayerV2::create ) );
2728
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr( "Ellipse marker" ), QgsSymbolV2::Marker,
2829
QgsEllipseSymbolLayerV2::create ) );
30+
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "VectorField", QObject::tr( "Vector Field marker" ), QgsSymbolV2::Marker,
31+
QgsVectorFieldSymbolLayer::create ) );
2932

3033
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
3134
QgsSimpleFillSymbolLayerV2::create ) );
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/***************************************************************************
2+
qgsvectorfieldsymbollayer.cpp
3+
-----------------------------
4+
begin : Octorer 25, 2011
5+
copyright : (C) 2011 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsvectorfieldsymbollayer.h"
19+
20+
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( -1 ), mYAttribute( -1 ), mScale( 1.0 ),
21+
mVectorFieldType( Cartesian ), mAngleOrientation( ClockwiseFromNorth ), mAngleUnits( Degrees )
22+
{
23+
setSubSymbol( new QgsLineSymbolV2() );
24+
}
25+
26+
QgsVectorFieldSymbolLayer::~QgsVectorFieldSymbolLayer()
27+
{
28+
}
29+
30+
QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& properties )
31+
{
32+
QgsVectorFieldSymbolLayer* symbolLayer = new QgsVectorFieldSymbolLayer();
33+
if ( properties.contains( "x_attribute" ) )
34+
{
35+
symbolLayer->setXAttribute( properties["x_attribute"].toInt() );
36+
}
37+
if ( properties.contains( "y_attribute" ) )
38+
{
39+
symbolLayer->setYAttribute( properties["y_attribute"].toInt() );
40+
}
41+
if ( properties.contains( "scale" ) )
42+
{
43+
symbolLayer->setScale( properties["scale"].toDouble() );
44+
}
45+
if ( properties.contains( "vector_field_type" ) )
46+
{
47+
symbolLayer->setVectorFieldType(( VectorFieldType )( properties["vector_field_type"].toInt() ) );
48+
}
49+
if ( properties.contains( "angle_orientation" ) )
50+
{
51+
symbolLayer->setAngleOrientation(( AngleOrientation )( properties["angle_orientation"].toInt() ) );
52+
}
53+
if ( properties.contains( "angle_units" ) )
54+
{
55+
symbolLayer->setAngleUnits(( AngleUnits )( properties["angle_units"].toInt() ) );
56+
}
57+
return symbolLayer;
58+
}
59+
60+
bool QgsVectorFieldSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
61+
{
62+
if ( symbol->type() == QgsSymbolV2::Line )
63+
{
64+
mLineSymbol = static_cast<QgsLineSymbolV2*>( symbol );
65+
return true;
66+
}
67+
return false;
68+
}
69+
70+
void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
71+
{
72+
//soon...
73+
}
74+
75+
void QgsVectorFieldSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
76+
{
77+
if ( mLineSymbol )
78+
{
79+
mLineSymbol->startRender( context.renderContext() );
80+
}
81+
}
82+
83+
void QgsVectorFieldSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
84+
{
85+
if ( mLineSymbol )
86+
{
87+
mLineSymbol->stopRender( context.renderContext() );
88+
}
89+
}
90+
91+
QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::clone() const
92+
{
93+
return QgsVectorFieldSymbolLayer::create( properties() );
94+
}
95+
96+
QgsStringMap QgsVectorFieldSymbolLayer::properties() const
97+
{
98+
QgsStringMap properties;
99+
properties["x_attribute"] = QString::number( mXAttribute );
100+
properties["y_attribute"] = QString::number( mYAttribute );
101+
properties["scale"] = QString::number( mScale );
102+
properties["vector_field_type"] = QString::number( mVectorFieldType );
103+
properties["angle_orientation"] = QString::number( mAngleOrientation );
104+
properties["angle_units"] = QString::number( mAngleUnits );
105+
return properties;
106+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/***************************************************************************
2+
qgsvectorfieldsymbollayer.h
3+
-------------------------
4+
begin : Octorer 25, 2011
5+
copyright : (C) 2011 by Marco Hugentobler
6+
email : marco dot hugentobler at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSVECTORFIELDSYMBOLLAYER_H
19+
#define QGSVECTORFIELDSYMBOLLAYER_H
20+
21+
#include "qgssymbollayerv2.h"
22+
23+
/**A symbol layer class for displaying displacement arrows based on point layer attributes*/
24+
class QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
25+
{
26+
public:
27+
enum VectorFieldType
28+
{
29+
Cartesian = 0,
30+
Polar,
31+
Height
32+
};
33+
34+
enum AngleOrientation
35+
{
36+
ClockwiseFromNorth = 0,
37+
CounterclockwiseFromEast
38+
};
39+
40+
enum AngleUnits
41+
{
42+
Degrees = 0,
43+
Radians
44+
};
45+
46+
QgsVectorFieldSymbolLayer();
47+
~QgsVectorFieldSymbolLayer();
48+
49+
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
50+
51+
QString layerType() const { return "VectorField"; }
52+
53+
bool setSubSymbol( QgsSymbolV2* symbol );
54+
QgsSymbolV2* subSymbol() { return mLineSymbol; }
55+
56+
void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
57+
void startRender( QgsSymbolV2RenderContext& context );
58+
void stopRender( QgsSymbolV2RenderContext& context );
59+
60+
QgsSymbolLayerV2* clone() const;
61+
QgsStringMap properties() const;
62+
63+
//setters and getters
64+
void setXAttribute( int attribute ) { mXAttribute = attribute; }
65+
int xAttribute() const { return mXAttribute; }
66+
void setYAttribute( int attribute ) { mYAttribute = attribute; }
67+
int yAttribute() const { return mYAttribute; }
68+
void setScale( double s ) { mScale = s; }
69+
double scale() const { return mScale; }
70+
void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; }
71+
VectorFieldType vectorFieldType() const { return mVectorFieldType; }
72+
void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; }
73+
AngleOrientation angleOrientation() const { return mAngleOrientation; }
74+
void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
75+
AngleUnits angleUnits() const { return mAngleUnits; }
76+
77+
private:
78+
int mXAttribute;
79+
int mYAttribute;
80+
double mScale;
81+
VectorFieldType mVectorFieldType;
82+
AngleOrientation mAngleOrientation;
83+
AngleUnits mAngleUnits;
84+
85+
QgsLineSymbolV2* mLineSymbol;
86+
};
87+
88+
#endif // QGSVECTORFIELDSYMBOLLAYER_H

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ symbology-ng/qgsvectorcolorbrewercolorrampv2dialog.cpp
2222
symbology-ng/characterwidget.cpp
2323
symbology-ng/qgsstylev2exportimportdialog.cpp
2424
symbology-ng/qgsellipsesymbollayerv2widget.cpp
25+
symbology-ng/qgsvectorfieldsymbollayerwidget.cpp
2526

2627
attributetable/qgsattributetablemodel.cpp
2728
attributetable/qgsattributetablememorymodel.cpp
@@ -98,6 +99,7 @@ symbology-ng/qgspenstylecombobox.h
9899
symbology-ng/qgsbrushstylecombobox.h
99100
symbology-ng/qgsstylev2exportimportdialog.h
100101
symbology-ng/qgsellipsesymbollayerv2widget.h
102+
symbology-ng/qgsvectorfieldsymbollayerwidget.h
101103

102104
attributetable/qgsattributetableview.h
103105
attributetable/qgsattributetablemodel.h

‎src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "qgssymbollayerv2widget.h"
1515
#include "qgsellipsesymbollayerv2widget.h"
16+
#include "qgsvectorfieldsymbollayerwidget.h"
1617
#include "qgssymbolv2.h" //for the unit
1718

1819

@@ -92,6 +93,7 @@ static void _initWidgetFunctions()
9293
_initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create );
9394
_initWidgetFunction( "FontMarker", QgsFontMarkerSymbolLayerV2Widget::create );
9495
_initWidgetFunction( "EllipseMarker", QgsEllipseSymbolLayerV2Widget::create );
96+
_initWidgetFunction( "VectorField", QgsVectorFieldSymbolLayerWidget::create );
9597

9698
_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create );
9799
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>WidgetVectorFieldBase</class>
4+
<widget class="QWidget" name="WidgetVectorFieldBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>291</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout_4">
17+
<item row="0" column="0">
18+
<widget class="QLabel" name="mXAttributeLabel">
19+
<property name="text">
20+
<string>X attribute</string>
21+
</property>
22+
</widget>
23+
</item>
24+
<item row="0" column="1" colspan="2">
25+
<widget class="QComboBox" name="mXAttributeComboBox"/>
26+
</item>
27+
<item row="1" column="0">
28+
<widget class="QLabel" name="mYAttributeLabel">
29+
<property name="text">
30+
<string>Y Attribute</string>
31+
</property>
32+
</widget>
33+
</item>
34+
<item row="1" column="1" colspan="2">
35+
<widget class="QComboBox" name="mYAttributeComboBox"/>
36+
</item>
37+
<item row="2" column="0">
38+
<widget class="QLabel" name="mScaleLabel">
39+
<property name="text">
40+
<string>Scale</string>
41+
</property>
42+
</widget>
43+
</item>
44+
<item row="2" column="1" colspan="2">
45+
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/>
46+
</item>
47+
<item row="4" column="0" rowspan="2" colspan="2">
48+
<widget class="QGroupBox" name="mFieldTypeGroupBox">
49+
<property name="title">
50+
<string>Vector field type</string>
51+
</property>
52+
<layout class="QGridLayout" name="gridLayout">
53+
<item row="0" column="0">
54+
<widget class="QRadioButton" name="mCartesianRadioButton">
55+
<property name="text">
56+
<string>Cartesian</string>
57+
</property>
58+
</widget>
59+
</item>
60+
<item row="1" column="0">
61+
<widget class="QRadioButton" name="mPolarRadioButton">
62+
<property name="text">
63+
<string>Polar</string>
64+
</property>
65+
</widget>
66+
</item>
67+
<item row="2" column="0">
68+
<widget class="QRadioButton" name="mHeightRadioButton">
69+
<property name="text">
70+
<string>Height only</string>
71+
</property>
72+
</widget>
73+
</item>
74+
</layout>
75+
</widget>
76+
</item>
77+
<item row="4" column="2" colspan="2">
78+
<widget class="QGroupBox" name="mAngleUnitsGroupBox">
79+
<property name="title">
80+
<string>Angle units</string>
81+
</property>
82+
<layout class="QGridLayout" name="gridLayout_3">
83+
<item row="0" column="0">
84+
<widget class="QRadioButton" name="mDegreesRadioButton">
85+
<property name="text">
86+
<string>Degrees</string>
87+
</property>
88+
</widget>
89+
</item>
90+
<item row="1" column="0">
91+
<widget class="QRadioButton" name="mRadiansRadioButton">
92+
<property name="text">
93+
<string>Radians</string>
94+
</property>
95+
</widget>
96+
</item>
97+
</layout>
98+
</widget>
99+
</item>
100+
<item row="5" column="2" colspan="2">
101+
<widget class="QGroupBox" name="mAngleOrientationGroupBox">
102+
<property name="title">
103+
<string>Angle orientation</string>
104+
</property>
105+
<layout class="QGridLayout" name="gridLayout_2">
106+
<item row="1" column="0">
107+
<widget class="QRadioButton" name="mCounterclockwiseFromEastRadioButton">
108+
<property name="text">
109+
<string>Counterclockwise from east</string>
110+
</property>
111+
</widget>
112+
</item>
113+
<item row="0" column="0">
114+
<widget class="QRadioButton" name="mClockwiseFromNorthRadioButton">
115+
<property name="text">
116+
<string>Clockwise from north</string>
117+
</property>
118+
</widget>
119+
</item>
120+
</layout>
121+
</widget>
122+
</item>
123+
<item row="3" column="0">
124+
<widget class="QLabel" name="mLineStyleLabel">
125+
<property name="text">
126+
<string>LineStyle</string>
127+
</property>
128+
</widget>
129+
</item>
130+
<item row="3" column="1" colspan="2">
131+
<widget class="QPushButton" name="mLineStylePushButton">
132+
<property name="text">
133+
<string>change</string>
134+
</property>
135+
</widget>
136+
</item>
137+
</layout>
138+
</widget>
139+
<resources/>
140+
<connections/>
141+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.