Skip to content
Permalink
Browse files

Added vectorfield widgets

  • Loading branch information
mhugent committed Oct 28, 2011
1 parent dde10de commit 3a403cce72ef33422b20dcadc594a0a864c5ad5c
@@ -0,0 +1,200 @@
#include "qgsvectorfieldsymbollayerwidget.h"
#include "qgssymbolv2propertiesdialog.h"
#include "qgsvectorfieldsymbollayer.h"
#include "qgsvectorlayer.h"

QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
{
setupUi( this );
if( mVectorLayer )
{
const QgsFieldMap& fm = mVectorLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fm.constBegin();
mXAttributeComboBox->addItem( "", -1 );
mYAttributeComboBox->addItem( "", -1 );
for ( ; fieldIt != fm.constEnd(); ++fieldIt )
{
QString fieldName = fieldIt.value().name();
int index = fieldIt.key();
mXAttributeComboBox->addItem( fieldName, index );
mYAttributeComboBox->addItem( fieldName, index );
}
}
}

QgsVectorFieldSymbolLayerWidget::~QgsVectorFieldSymbolLayerWidget()
{
}

void QgsVectorFieldSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
if( layer->layerType() != "VectorField" )
{
return;
}
mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
if( !mLayer )
{
return;
}

mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findData( mLayer->xAttribute() ) );
mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findData( mLayer->yAttribute() ) );
mScaleSpinBox->setValue( mLayer->scale() );

QgsVectorFieldSymbolLayer::VectorFieldType type = mLayer->vectorFieldType();
if( type == QgsVectorFieldSymbolLayer::Cartesian )
{
mCartesianRadioButton->setChecked( true );
}
else if( type == QgsVectorFieldSymbolLayer::Polar )
{
mPolarRadioButton->setChecked( true );
}
else if( type == QgsVectorFieldSymbolLayer::Height )
{
mHeightRadioButton->setChecked( true );
}

QgsVectorFieldSymbolLayer::AngleOrientation orientation = mLayer->angleOrientation();
if( orientation == QgsVectorFieldSymbolLayer::ClockwiseFromNorth )
{
mClockwiseFromNorthRadioButton->setChecked( true );
}
else if( orientation == QgsVectorFieldSymbolLayer::CounterclockwiseFromEast )
{
mCounterclockwiseFromEastRadioButton->setChecked( true );
}

QgsVectorFieldSymbolLayer::AngleUnits angleUnits = mLayer->angleUnits();
if( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
{
mDegreesRadioButton->setChecked( true );
}
else if( angleUnits == QgsVectorFieldSymbolLayer::Radians )
{
mRadiansRadioButton->setChecked( true );
}
updateMarkerIcon();
}

QgsSymbolLayerV2* QgsVectorFieldSymbolLayerWidget::symbolLayer()
{
return mLayer;
}

void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setScale( d );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
{
if( mLayer )
{
mLayer->setXAttribute( mXAttributeComboBox->itemData( index ).toInt() );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
{
if( mLayer )
{
mLayer->setYAttribute( mYAttributeComboBox->itemData( index ).toInt() );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mLineStylePushButton_clicked()
{
if ( !mLayer )
{
return;
}

QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this );
if ( dlg.exec() == QDialog::Rejected )
{
return;
}

updateMarkerIcon();
emit changed();
}

void QgsVectorFieldSymbolLayerWidget::updateMarkerIcon()
{
if ( mLayer )
{
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLayer->subSymbol(), mLineStylePushButton->iconSize() );
mLineStylePushButton->setIcon( icon );
}
}

void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Cartesian );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Polar );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Height );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Degrees );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Radians );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::ClockwiseFromNorth );
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
{
if( mLayer && checked )
{
mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::CounterclockwiseFromEast );
emit changed();
}
}
@@ -0,0 +1,40 @@
#ifndef QGSVECTORFIELDSYMBOLLAYERWIDGET_H
#define QGSVECTORFIELDSYMBOLLAYERWIDGET_H

#include "qgssymbollayerv2widget.h"
#include "ui_widget_vectorfield.h"

class QgsVectorFieldSymbolLayer;

class QgsVectorFieldSymbolLayerWidget: public QgsSymbolLayerV2Widget, private Ui::WidgetVectorFieldBase
{
Q_OBJECT
public:
QgsVectorFieldSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent = 0 );
~QgsVectorFieldSymbolLayerWidget();

static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsVectorFieldSymbolLayerWidget( vl ); }

// from base class
virtual void setSymbolLayer( QgsSymbolLayerV2* layer );
virtual QgsSymbolLayerV2* symbolLayer();

protected:
QgsVectorFieldSymbolLayer* mLayer;
void updateMarkerIcon();

private slots:
void on_mScaleSpinBox_valueChanged( double d );
void on_mXAttributeComboBox_currentIndexChanged( int index );
void on_mYAttributeComboBox_currentIndexChanged( int index );
void on_mLineStylePushButton_clicked();
void on_mCartesianRadioButton_toggled( bool checked );
void on_mPolarRadioButton_toggled( bool checked );
void on_mHeightRadioButton_toggled( bool checked );
void on_mDegreesRadioButton_toggled( bool checked );
void on_mRadiansRadioButton_toggled( bool checked );
void on_mClockwiseFromNorthRadioButton_toggled( bool checked );
void on_mCounterclockwiseFromEastRadioButton_toggled( bool checked );
};

#endif // QGSVECTORFIELDSYMBOLLAYERWIDGET_H
@@ -0,0 +1,4 @@
#ifndef QGSVECTORFIELDWIDGET_H
#define QGSVECTORFIELDWIDGET_H

#endif // QGSVECTORFIELDWIDGET_H

0 comments on commit 3a403cc

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