|
| 1 | +#include "qgsvectorfieldsymbollayerwidget.h" |
| 2 | +#include "qgssymbolv2propertiesdialog.h" |
| 3 | +#include "qgsvectorfieldsymbollayer.h" |
| 4 | +#include "qgsvectorlayer.h" |
| 5 | + |
| 6 | +QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 ) |
| 7 | +{ |
| 8 | + setupUi( this ); |
| 9 | + if( mVectorLayer ) |
| 10 | + { |
| 11 | + const QgsFieldMap& fm = mVectorLayer->pendingFields(); |
| 12 | + QgsFieldMap::const_iterator fieldIt = fm.constBegin(); |
| 13 | + mXAttributeComboBox->addItem( "", -1 ); |
| 14 | + mYAttributeComboBox->addItem( "", -1 ); |
| 15 | + for ( ; fieldIt != fm.constEnd(); ++fieldIt ) |
| 16 | + { |
| 17 | + QString fieldName = fieldIt.value().name(); |
| 18 | + int index = fieldIt.key(); |
| 19 | + mXAttributeComboBox->addItem( fieldName, index ); |
| 20 | + mYAttributeComboBox->addItem( fieldName, index ); |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +QgsVectorFieldSymbolLayerWidget::~QgsVectorFieldSymbolLayerWidget() |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +void QgsVectorFieldSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer ) |
| 30 | +{ |
| 31 | + if( layer->layerType() != "VectorField" ) |
| 32 | + { |
| 33 | + return; |
| 34 | + } |
| 35 | + mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer ); |
| 36 | + if( !mLayer ) |
| 37 | + { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findData( mLayer->xAttribute() ) ); |
| 42 | + mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findData( mLayer->yAttribute() ) ); |
| 43 | + mScaleSpinBox->setValue( mLayer->scale() ); |
| 44 | + |
| 45 | + QgsVectorFieldSymbolLayer::VectorFieldType type = mLayer->vectorFieldType(); |
| 46 | + if( type == QgsVectorFieldSymbolLayer::Cartesian ) |
| 47 | + { |
| 48 | + mCartesianRadioButton->setChecked( true ); |
| 49 | + } |
| 50 | + else if( type == QgsVectorFieldSymbolLayer::Polar ) |
| 51 | + { |
| 52 | + mPolarRadioButton->setChecked( true ); |
| 53 | + } |
| 54 | + else if( type == QgsVectorFieldSymbolLayer::Height ) |
| 55 | + { |
| 56 | + mHeightRadioButton->setChecked( true ); |
| 57 | + } |
| 58 | + |
| 59 | + QgsVectorFieldSymbolLayer::AngleOrientation orientation = mLayer->angleOrientation(); |
| 60 | + if( orientation == QgsVectorFieldSymbolLayer::ClockwiseFromNorth ) |
| 61 | + { |
| 62 | + mClockwiseFromNorthRadioButton->setChecked( true ); |
| 63 | + } |
| 64 | + else if( orientation == QgsVectorFieldSymbolLayer::CounterclockwiseFromEast ) |
| 65 | + { |
| 66 | + mCounterclockwiseFromEastRadioButton->setChecked( true ); |
| 67 | + } |
| 68 | + |
| 69 | + QgsVectorFieldSymbolLayer::AngleUnits angleUnits = mLayer->angleUnits(); |
| 70 | + if( angleUnits == QgsVectorFieldSymbolLayer::Degrees ) |
| 71 | + { |
| 72 | + mDegreesRadioButton->setChecked( true ); |
| 73 | + } |
| 74 | + else if( angleUnits == QgsVectorFieldSymbolLayer::Radians ) |
| 75 | + { |
| 76 | + mRadiansRadioButton->setChecked( true ); |
| 77 | + } |
| 78 | + updateMarkerIcon(); |
| 79 | +} |
| 80 | + |
| 81 | +QgsSymbolLayerV2* QgsVectorFieldSymbolLayerWidget::symbolLayer() |
| 82 | +{ |
| 83 | + return mLayer; |
| 84 | +} |
| 85 | + |
| 86 | +void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d ) |
| 87 | +{ |
| 88 | + if( mLayer ) |
| 89 | + { |
| 90 | + mLayer->setScale( d ); |
| 91 | + emit changed(); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index ) |
| 96 | +{ |
| 97 | + if( mLayer ) |
| 98 | + { |
| 99 | + mLayer->setXAttribute( mXAttributeComboBox->itemData( index ).toInt() ); |
| 100 | + emit changed(); |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index ) |
| 105 | +{ |
| 106 | + if( mLayer ) |
| 107 | + { |
| 108 | + mLayer->setYAttribute( mYAttributeComboBox->itemData( index ).toInt() ); |
| 109 | + emit changed(); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +void QgsVectorFieldSymbolLayerWidget::on_mLineStylePushButton_clicked() |
| 114 | +{ |
| 115 | + if ( !mLayer ) |
| 116 | + { |
| 117 | + return; |
| 118 | + } |
| 119 | + |
| 120 | + QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this ); |
| 121 | + if ( dlg.exec() == QDialog::Rejected ) |
| 122 | + { |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + updateMarkerIcon(); |
| 127 | + emit changed(); |
| 128 | +} |
| 129 | + |
| 130 | +void QgsVectorFieldSymbolLayerWidget::updateMarkerIcon() |
| 131 | +{ |
| 132 | + if ( mLayer ) |
| 133 | + { |
| 134 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLayer->subSymbol(), mLineStylePushButton->iconSize() ); |
| 135 | + mLineStylePushButton->setIcon( icon ); |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked ) |
| 140 | +{ |
| 141 | + if( mLayer && checked ) |
| 142 | + { |
| 143 | + mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Cartesian ); |
| 144 | + emit changed(); |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked ) |
| 149 | +{ |
| 150 | + if( mLayer && checked ) |
| 151 | + { |
| 152 | + mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Polar ); |
| 153 | + emit changed(); |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked ) |
| 158 | +{ |
| 159 | + if( mLayer && checked ) |
| 160 | + { |
| 161 | + mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Height ); |
| 162 | + emit changed(); |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked ) |
| 167 | +{ |
| 168 | + if( mLayer && checked ) |
| 169 | + { |
| 170 | + mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Degrees ); |
| 171 | + emit changed(); |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked ) |
| 176 | +{ |
| 177 | + if( mLayer && checked ) |
| 178 | + { |
| 179 | + mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Radians ); |
| 180 | + emit changed(); |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked ) |
| 185 | +{ |
| 186 | + if( mLayer && checked ) |
| 187 | + { |
| 188 | + mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::ClockwiseFromNorth ); |
| 189 | + emit changed(); |
| 190 | + } |
| 191 | +} |
| 192 | + |
| 193 | +void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked ) |
| 194 | +{ |
| 195 | + if( mLayer && checked ) |
| 196 | + { |
| 197 | + mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::CounterclockwiseFromEast ); |
| 198 | + emit changed(); |
| 199 | + } |
| 200 | +} |
0 commit comments