|
14 | 14 | ***************************************************************************/ |
15 | 15 |
|
16 | 16 | #include "qgsdisplayangle.h" |
| 17 | +#include "qgsmapcanvas.h" |
| 18 | +#include "qgslogger.h" |
| 19 | + |
17 | 20 | #include <QSettings> |
18 | 21 | #include <cmath> |
19 | 22 |
|
20 | | -QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ) |
| 23 | +QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f ) |
| 24 | + : QDialog( tool->canvas()->topLevelWidget(), f ), mTool( tool ) |
21 | 25 | { |
22 | 26 | setupUi( this ); |
23 | 27 | QSettings settings; |
24 | | - int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt(); |
25 | | - if ( s == 2 ) |
26 | | - mcbProjectionEnabled->setCheckState( Qt::Checked ); |
27 | | - else |
28 | | - mcbProjectionEnabled->setCheckState( Qt::Unchecked ); |
29 | 28 |
|
30 | | - connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ), |
31 | | - this, SLOT( changeState() ) ); |
32 | | - connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ), |
33 | | - this, SIGNAL( changeProjectionEnabledState() ) ); |
| 29 | + // Update whenever the canvas has refreshed. Maybe more often than needed, |
| 30 | + // but at least every time any canvas related settings changes |
| 31 | + connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ), |
| 32 | + this, SLOT( updateSettings() ) ); |
| 33 | + |
| 34 | + updateSettings(); |
34 | 35 | } |
35 | 36 |
|
36 | 37 | QgsDisplayAngle::~QgsDisplayAngle() |
37 | 38 | { |
38 | 39 |
|
39 | 40 | } |
40 | 41 |
|
41 | | -bool QgsDisplayAngle::projectionEnabled() |
| 42 | + |
| 43 | +void QgsDisplayAngle::setValueInRadians( double value ) |
| 44 | +{ |
| 45 | + mValue = value; |
| 46 | + updateUi(); |
| 47 | +} |
| 48 | + |
| 49 | +void QgsDisplayAngle::updateSettings() |
42 | 50 | { |
43 | | - return mcbProjectionEnabled->isChecked(); |
| 51 | + emit changeProjectionEnabledState(); |
44 | 52 | } |
45 | 53 |
|
46 | | -void QgsDisplayAngle::setValueInRadians( double value ) |
| 54 | +void QgsDisplayAngle::updateUi() |
47 | 55 | { |
| 56 | + |
48 | 57 | QSettings settings; |
49 | 58 | QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString(); |
| 59 | + int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); |
| 60 | + |
50 | 61 | if ( unitString == "degrees" ) |
51 | 62 | { |
52 | | - mAngleLineEdit->setText( tr( "%1 degrees" ).arg( value * 180 / M_PI ) ); |
| 63 | + mAngleLineEdit->setText( tr( "%1 degrees" ).arg( QLocale::system().toString( mValue * 180 / M_PI ), |
| 64 | + 'f', decimals ) ); |
53 | 65 | } |
54 | 66 | else if ( unitString == "radians" ) |
55 | 67 | { |
56 | | - mAngleLineEdit->setText( tr( "%1 radians" ).arg( value ) ); |
| 68 | + mAngleLineEdit->setText( tr( "%1 radians" ).arg( QLocale::system().toString( mValue ), |
| 69 | + 'f', decimals ) ); |
| 70 | + |
57 | 71 | } |
58 | 72 | else if ( unitString == "gon" ) |
59 | 73 | { |
60 | | - mAngleLineEdit->setText( tr( "%1 gon" ).arg( value / M_PI * 200 ) ); |
| 74 | + mAngleLineEdit->setText( tr( "%1 gon" ).arg( QLocale::system().toString( mValue / M_PI * 200 ), |
| 75 | + 'f', decimals ) ); |
61 | 76 | } |
62 | 77 | } |
63 | | - |
64 | | -void QgsDisplayAngle::changeState() |
65 | | -{ |
66 | | - QSettings settings; |
67 | | - if ( mcbProjectionEnabled->isChecked() ) |
68 | | - settings.setValue( "/qgis/measure/projectionEnabled", 2 ); |
69 | | - else |
70 | | - settings.setValue( "/qgis/measure/projectionEnabled", 0 ); |
71 | | -} |
|
0 commit comments