Skip to content

Commit

Permalink
Added vector field symbol layer and widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Oct 26, 2011
1 parent fecb0de commit dde10de
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -39,6 +39,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgssymbologyv2conversion.cpp
symbology-ng/qgssvgcache.cpp
symbology-ng/qgsellipsesymbollayerv2.cpp
symbology-ng/qgsvectorfieldsymbollayer.cpp

qgis.cpp
qgsapplication.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2registry.cpp
Expand Up @@ -5,6 +5,7 @@
#include "qgsmarkersymbollayerv2.h"
#include "qgslinesymbollayerv2.h"
#include "qgsfillsymbollayerv2.h"
#include "qgsvectorfieldsymbollayer.h"

QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::mInstance = NULL;

Expand All @@ -26,6 +27,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
QgsFontMarkerSymbolLayerV2::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr( "Ellipse marker" ), QgsSymbolV2::Marker,
QgsEllipseSymbolLayerV2::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "VectorField", QObject::tr( "Vector Field marker" ), QgsSymbolV2::Marker,
QgsVectorFieldSymbolLayer::create ) );

addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
QgsSimpleFillSymbolLayerV2::create ) );
Expand Down
106 changes: 106 additions & 0 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
@@ -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;
}
88 changes: 88 additions & 0 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.h
@@ -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
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ symbology-ng/qgsvectorcolorbrewercolorrampv2dialog.cpp
symbology-ng/characterwidget.cpp
symbology-ng/qgsstylev2exportimportdialog.cpp
symbology-ng/qgsellipsesymbollayerv2widget.cpp
symbology-ng/qgsvectorfieldsymbollayerwidget.cpp

attributetable/qgsattributetablemodel.cpp
attributetable/qgsattributetablememorymodel.cpp
Expand Down Expand Up @@ -98,6 +99,7 @@ symbology-ng/qgspenstylecombobox.h
symbology-ng/qgsbrushstylecombobox.h
symbology-ng/qgsstylev2exportimportdialog.h
symbology-ng/qgsellipsesymbollayerv2widget.h
symbology-ng/qgsvectorfieldsymbollayerwidget.h

attributetable/qgsattributetableview.h
attributetable/qgsattributetablemodel.h
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
Expand Up @@ -13,6 +13,7 @@

#include "qgssymbollayerv2widget.h"
#include "qgsellipsesymbollayerv2widget.h"
#include "qgsvectorfieldsymbollayerwidget.h"
#include "qgssymbolv2.h" //for the unit


Expand Down Expand Up @@ -92,6 +93,7 @@ static void _initWidgetFunctions()
_initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "FontMarker", QgsFontMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "EllipseMarker", QgsEllipseSymbolLayerV2Widget::create );
_initWidgetFunction( "VectorField", QgsVectorFieldSymbolLayerWidget::create );

_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create );
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
Expand Down
141 changes: 141 additions & 0 deletions src/ui/symbollayer/widget_vectorfield.ui
@@ -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>

0 comments on commit dde10de

Please sign in to comment.