|
Quantum GIS API Documentation
master-693a1fe
|
00001 /*************************************************************************** 00002 qgsvectorfieldsymbollayerwidget.cpp 00003 --------------------- 00004 begin : October 2011 00005 copyright : (C) 2011 by Marco Hugentobler 00006 email : marco dot hugentobler at sourcepole dot ch 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 #include "qgsvectorfieldsymbollayerwidget.h" 00016 #include "qgsvectorfieldsymbollayer.h" 00017 #include "qgsvectorlayer.h" 00018 00019 QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 ) 00020 { 00021 setupUi( this ); 00022 if ( mVectorLayer ) 00023 { 00024 const QgsFields& fm = mVectorLayer->pendingFields(); 00025 mXAttributeComboBox->addItem( "" ); 00026 mYAttributeComboBox->addItem( "" ); 00027 for ( int idx = 0; idx < fm.count(); ++idx ) 00028 { 00029 QString fieldName = fm[idx].name(); 00030 mXAttributeComboBox->addItem( fieldName ); 00031 mYAttributeComboBox->addItem( fieldName ); 00032 } 00033 } 00034 } 00035 00036 QgsVectorFieldSymbolLayerWidget::~QgsVectorFieldSymbolLayerWidget() 00037 { 00038 } 00039 00040 void QgsVectorFieldSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer ) 00041 { 00042 if ( layer->layerType() != "VectorField" ) 00043 { 00044 return; 00045 } 00046 mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer ); 00047 if ( !mLayer ) 00048 { 00049 return; 00050 } 00051 00052 mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) ); 00053 mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) ); 00054 mScaleSpinBox->setValue( mLayer->scale() ); 00055 00056 QgsVectorFieldSymbolLayer::VectorFieldType type = mLayer->vectorFieldType(); 00057 if ( type == QgsVectorFieldSymbolLayer::Cartesian ) 00058 { 00059 mCartesianRadioButton->setChecked( true ); 00060 } 00061 else if ( type == QgsVectorFieldSymbolLayer::Polar ) 00062 { 00063 mPolarRadioButton->setChecked( true ); 00064 } 00065 else if ( type == QgsVectorFieldSymbolLayer::Height ) 00066 { 00067 mHeightRadioButton->setChecked( true ); 00068 } 00069 00070 QgsVectorFieldSymbolLayer::AngleOrientation orientation = mLayer->angleOrientation(); 00071 if ( orientation == QgsVectorFieldSymbolLayer::ClockwiseFromNorth ) 00072 { 00073 mClockwiseFromNorthRadioButton->setChecked( true ); 00074 } 00075 else if ( orientation == QgsVectorFieldSymbolLayer::CounterclockwiseFromEast ) 00076 { 00077 mCounterclockwiseFromEastRadioButton->setChecked( true ); 00078 } 00079 00080 QgsVectorFieldSymbolLayer::AngleUnits angleUnits = mLayer->angleUnits(); 00081 if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees ) 00082 { 00083 mDegreesRadioButton->setChecked( true ); 00084 } 00085 else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians ) 00086 { 00087 mRadiansRadioButton->setChecked( true ); 00088 } 00089 00090 mDistanceUnitComboBox->blockSignals( true ); 00091 mDistanceUnitComboBox->setCurrentIndex( mLayer->distanceUnit() ); 00092 mDistanceUnitComboBox->blockSignals( false ); 00093 00094 emit changed(); 00095 } 00096 00097 QgsSymbolLayerV2* QgsVectorFieldSymbolLayerWidget::symbolLayer() 00098 { 00099 return mLayer; 00100 } 00101 00102 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d ) 00103 { 00104 if ( mLayer ) 00105 { 00106 mLayer->setScale( d ); 00107 emit changed(); 00108 } 00109 } 00110 00111 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index ) 00112 { 00113 if ( mLayer ) 00114 { 00115 mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) ); 00116 emit changed(); 00117 } 00118 } 00119 00120 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index ) 00121 { 00122 if ( mLayer ) 00123 { 00124 mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) ); 00125 emit changed(); 00126 } 00127 } 00128 00129 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked ) 00130 { 00131 if ( mLayer && checked ) 00132 { 00133 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Cartesian ); 00134 mXAttributeComboBox->setEnabled( true ); 00135 mYAttributeComboBox->setEnabled( true ); 00136 mXAttributeLabel->setText( tr( "X attribute" ) ); 00137 mYAttributeLabel->setText( tr( "Y attribute" ) ); 00138 emit changed(); 00139 } 00140 } 00141 00142 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked ) 00143 { 00144 if ( mLayer && checked ) 00145 { 00146 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Polar ); 00147 mXAttributeComboBox->setEnabled( true ); 00148 mYAttributeComboBox->setEnabled( true ); 00149 mXAttributeLabel->setText( tr( "Length attribute" ) ); 00150 mYAttributeLabel->setText( tr( "Angle attribute" ) ); 00151 emit changed(); 00152 } 00153 } 00154 00155 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked ) 00156 { 00157 if ( mLayer && checked ) 00158 { 00159 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Height ); 00160 mXAttributeLabel->setText( "" ); 00161 mXAttributeComboBox->setEnabled( false ); 00162 mYAttributeLabel->setText( tr( "Height attribute" ) ); 00163 emit changed(); 00164 } 00165 } 00166 00167 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked ) 00168 { 00169 if ( mLayer && checked ) 00170 { 00171 mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Degrees ); 00172 emit changed(); 00173 } 00174 } 00175 00176 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked ) 00177 { 00178 if ( mLayer && checked ) 00179 { 00180 mLayer->setAngleUnits( QgsVectorFieldSymbolLayer::Radians ); 00181 emit changed(); 00182 } 00183 } 00184 00185 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked ) 00186 { 00187 if ( mLayer && checked ) 00188 { 00189 mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::ClockwiseFromNorth ); 00190 emit changed(); 00191 } 00192 } 00193 00194 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked ) 00195 { 00196 if ( mLayer && checked ) 00197 { 00198 mLayer->setAngleOrientation( QgsVectorFieldSymbolLayer::CounterclockwiseFromEast ); 00199 emit changed(); 00200 } 00201 } 00202 00203 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitComboBox_currentIndexChanged( int index ) 00204 { 00205 if ( mLayer ) 00206 { 00207 mLayer->setDistanceUnit(( QgsSymbolV2::OutputUnit ) index ); 00208 emit changed(); 00209 } 00210 }