Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added vector field symbol layer and widget
- Loading branch information
Showing
7 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*************************************************************************** | ||
qgsvectorfieldsymbollayer.cpp | ||
----------------------------- | ||
begin : Octorer 25, 2011 | ||
copyright : (C) 2011 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsvectorfieldsymbollayer.h" | ||
|
||
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( -1 ), mYAttribute( -1 ), mScale( 1.0 ), | ||
mVectorFieldType( Cartesian ), mAngleOrientation( ClockwiseFromNorth ), mAngleUnits( Degrees ) | ||
{ | ||
setSubSymbol( new QgsLineSymbolV2() ); | ||
} | ||
|
||
QgsVectorFieldSymbolLayer::~QgsVectorFieldSymbolLayer() | ||
{ | ||
} | ||
|
||
QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& properties ) | ||
{ | ||
QgsVectorFieldSymbolLayer* symbolLayer = new QgsVectorFieldSymbolLayer(); | ||
if ( properties.contains( "x_attribute" ) ) | ||
{ | ||
symbolLayer->setXAttribute( properties["x_attribute"].toInt() ); | ||
} | ||
if ( properties.contains( "y_attribute" ) ) | ||
{ | ||
symbolLayer->setYAttribute( properties["y_attribute"].toInt() ); | ||
} | ||
if ( properties.contains( "scale" ) ) | ||
{ | ||
symbolLayer->setScale( properties["scale"].toDouble() ); | ||
} | ||
if ( properties.contains( "vector_field_type" ) ) | ||
{ | ||
symbolLayer->setVectorFieldType(( VectorFieldType )( properties["vector_field_type"].toInt() ) ); | ||
} | ||
if ( properties.contains( "angle_orientation" ) ) | ||
{ | ||
symbolLayer->setAngleOrientation(( AngleOrientation )( properties["angle_orientation"].toInt() ) ); | ||
} | ||
if ( properties.contains( "angle_units" ) ) | ||
{ | ||
symbolLayer->setAngleUnits(( AngleUnits )( properties["angle_units"].toInt() ) ); | ||
} | ||
return symbolLayer; | ||
} | ||
|
||
bool QgsVectorFieldSymbolLayer::setSubSymbol( QgsSymbolV2* symbol ) | ||
{ | ||
if ( symbol->type() == QgsSymbolV2::Line ) | ||
{ | ||
mLineSymbol = static_cast<QgsLineSymbolV2*>( symbol ); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) | ||
{ | ||
//soon... | ||
} | ||
|
||
void QgsVectorFieldSymbolLayer::startRender( QgsSymbolV2RenderContext& context ) | ||
{ | ||
if ( mLineSymbol ) | ||
{ | ||
mLineSymbol->startRender( context.renderContext() ); | ||
} | ||
} | ||
|
||
void QgsVectorFieldSymbolLayer::stopRender( QgsSymbolV2RenderContext& context ) | ||
{ | ||
if ( mLineSymbol ) | ||
{ | ||
mLineSymbol->stopRender( context.renderContext() ); | ||
} | ||
} | ||
|
||
QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::clone() const | ||
{ | ||
return QgsVectorFieldSymbolLayer::create( properties() ); | ||
} | ||
|
||
QgsStringMap QgsVectorFieldSymbolLayer::properties() const | ||
{ | ||
QgsStringMap properties; | ||
properties["x_attribute"] = QString::number( mXAttribute ); | ||
properties["y_attribute"] = QString::number( mYAttribute ); | ||
properties["scale"] = QString::number( mScale ); | ||
properties["vector_field_type"] = QString::number( mVectorFieldType ); | ||
properties["angle_orientation"] = QString::number( mAngleOrientation ); | ||
properties["angle_units"] = QString::number( mAngleUnits ); | ||
return properties; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*************************************************************************** | ||
qgsvectorfieldsymbollayer.h | ||
------------------------- | ||
begin : Octorer 25, 2011 | ||
copyright : (C) 2011 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSVECTORFIELDSYMBOLLAYER_H | ||
#define QGSVECTORFIELDSYMBOLLAYER_H | ||
|
||
#include "qgssymbollayerv2.h" | ||
|
||
/**A symbol layer class for displaying displacement arrows based on point layer attributes*/ | ||
class QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2 | ||
{ | ||
public: | ||
enum VectorFieldType | ||
{ | ||
Cartesian = 0, | ||
Polar, | ||
Height | ||
}; | ||
|
||
enum AngleOrientation | ||
{ | ||
ClockwiseFromNorth = 0, | ||
CounterclockwiseFromEast | ||
}; | ||
|
||
enum AngleUnits | ||
{ | ||
Degrees = 0, | ||
Radians | ||
}; | ||
|
||
QgsVectorFieldSymbolLayer(); | ||
~QgsVectorFieldSymbolLayer(); | ||
|
||
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); | ||
|
||
QString layerType() const { return "VectorField"; } | ||
|
||
bool setSubSymbol( QgsSymbolV2* symbol ); | ||
QgsSymbolV2* subSymbol() { return mLineSymbol; } | ||
|
||
void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ); | ||
void startRender( QgsSymbolV2RenderContext& context ); | ||
void stopRender( QgsSymbolV2RenderContext& context ); | ||
|
||
QgsSymbolLayerV2* clone() const; | ||
QgsStringMap properties() const; | ||
|
||
//setters and getters | ||
void setXAttribute( int attribute ) { mXAttribute = attribute; } | ||
int xAttribute() const { return mXAttribute; } | ||
void setYAttribute( int attribute ) { mYAttribute = attribute; } | ||
int yAttribute() const { return mYAttribute; } | ||
void setScale( double s ) { mScale = s; } | ||
double scale() const { return mScale; } | ||
void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; } | ||
VectorFieldType vectorFieldType() const { return mVectorFieldType; } | ||
void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; } | ||
AngleOrientation angleOrientation() const { return mAngleOrientation; } | ||
void setAngleUnits( AngleUnits units ) { mAngleUnits = units; } | ||
AngleUnits angleUnits() const { return mAngleUnits; } | ||
|
||
private: | ||
int mXAttribute; | ||
int mYAttribute; | ||
double mScale; | ||
VectorFieldType mVectorFieldType; | ||
AngleOrientation mAngleOrientation; | ||
AngleUnits mAngleUnits; | ||
|
||
QgsLineSymbolV2* mLineSymbol; | ||
}; | ||
|
||
#endif // QGSVECTORFIELDSYMBOLLAYER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>WidgetVectorFieldBase</class> | ||
<widget class="QWidget" name="WidgetVectorFieldBase"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>291</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout_4"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="mXAttributeLabel"> | ||
<property name="text"> | ||
<string>X attribute</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1" colspan="2"> | ||
<widget class="QComboBox" name="mXAttributeComboBox"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="mYAttributeLabel"> | ||
<property name="text"> | ||
<string>Y Attribute</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1" colspan="2"> | ||
<widget class="QComboBox" name="mYAttributeComboBox"/> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="mScaleLabel"> | ||
<property name="text"> | ||
<string>Scale</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1" colspan="2"> | ||
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/> | ||
</item> | ||
<item row="4" column="0" rowspan="2" colspan="2"> | ||
<widget class="QGroupBox" name="mFieldTypeGroupBox"> | ||
<property name="title"> | ||
<string>Vector field type</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QRadioButton" name="mCartesianRadioButton"> | ||
<property name="text"> | ||
<string>Cartesian</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="mPolarRadioButton"> | ||
<property name="text"> | ||
<string>Polar</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QRadioButton" name="mHeightRadioButton"> | ||
<property name="text"> | ||
<string>Height only</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item row="4" column="2" colspan="2"> | ||
<widget class="QGroupBox" name="mAngleUnitsGroupBox"> | ||
<property name="title"> | ||
<string>Angle units</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout_3"> | ||
<item row="0" column="0"> | ||
<widget class="QRadioButton" name="mDegreesRadioButton"> | ||
<property name="text"> | ||
<string>Degrees</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="mRadiansRadioButton"> | ||
<property name="text"> | ||
<string>Radians</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item row="5" column="2" colspan="2"> | ||
<widget class="QGroupBox" name="mAngleOrientationGroupBox"> | ||
<property name="title"> | ||
<string>Angle orientation</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout_2"> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="mCounterclockwiseFromEastRadioButton"> | ||
<property name="text"> | ||
<string>Counterclockwise from east</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0"> | ||
<widget class="QRadioButton" name="mClockwiseFromNorthRadioButton"> | ||
<property name="text"> | ||
<string>Clockwise from north</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QLabel" name="mLineStyleLabel"> | ||
<property name="text"> | ||
<string>LineStyle</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1" colspan="2"> | ||
<widget class="QPushButton" name="mLineStylePushButton"> | ||
<property name="text"> | ||
<string>change</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |