@@ -48,32 +48,73 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
48
48
item->setTextAlignment ( 0 , Qt::AlignRight );
49
49
mTable ->addTopLevelItem ( item );
50
50
51
- // mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") );
51
+ // Update when the ellipsoidal button has changed state.
52
+ connect ( mcbProjectionEnabled, SIGNAL ( stateChanged ( int ) ),
53
+ this , SLOT ( ellipsoidalButton () ) );
54
+ // Update whenever the canvas has refreshed. Maybe more often than needed,
55
+ // but at least every time any canvas related settings changes
56
+ connect ( mTool ->canvas (), SIGNAL ( mapCanvasRefreshed () ),
57
+ this , SLOT ( updateSettings () ) );
58
+ // // Update when project wide transformation has changed
59
+ // connect( mTool->canvas()->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ),
60
+ // this, SLOT( changeProjectionEnabledState() ) );
61
+ // // Update when project CRS has changed
62
+ // connect( mTool->canvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ),
63
+ // this, SLOT( changeProjectionEnabledState() ) );
64
+
65
+ updateSettings ();
66
+ }
67
+
68
+ void QgsMeasureDialog::ellipsoidalButton ()
69
+ {
70
+ QSettings settings;
71
+
72
+ if ( mcbProjectionEnabled->isChecked () )
73
+ {
74
+ settings.setValue ( " /qgis/measure/projectionEnabled" , 2 );
75
+ }
76
+ else
77
+ {
78
+ settings.setValue ( " /qgis/measure/projectionEnabled" , 0 );
79
+ }
80
+ updateSettings ();
81
+ }
52
82
83
+ void QgsMeasureDialog::updateSettings ()
84
+ {
53
85
QSettings settings;
86
+
54
87
int s = settings.value ( " /qgis/measure/projectionEnabled" , " 2" ).toInt ();
55
88
if ( s == 2 )
56
- mcbProjectionEnabled->setCheckState ( Qt::Checked );
89
+ {
90
+ mEllipsoidal = true ;
91
+ }
57
92
else
58
- mcbProjectionEnabled->setCheckState ( Qt::Unchecked );
93
+ {
94
+ mEllipsoidal = false ;
95
+ }
59
96
60
- // Update when the ellipsoidal button has changed state.
61
- connect ( mcbProjectionEnabled, SIGNAL ( stateChanged ( int ) ),
62
- this , SLOT ( changeProjectionEnabledState () ) );
63
- // Update whenever the canvas has refreshed. Maybe more often than needed,
64
- // but at least every time any settings changes
65
- connect ( mTool ->canvas (), SIGNAL ( mapCanvasRefreshed () ),
66
- this , SLOT ( changeProjectionEnabledState () ) );
67
- // Update when project wide transformation has changed
68
- connect ( mTool ->canvas ()->mapRenderer (), SIGNAL ( hasCrsTransformEnabled ( bool ) ),
69
- this , SLOT ( changeProjectionEnabledState () ) );
70
- // Update when project CRS has changed
71
- connect ( mTool ->canvas ()->mapRenderer (), SIGNAL ( destinationSrsChanged () ),
72
- this , SLOT ( changeProjectionEnabledState () ) );
97
+ mDecimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
98
+ mCanvasUnits = mTool ->canvas ()->mapUnits ();
99
+ mDisplayUnits = QGis::fromLiteral ( settings.value ( " /qgis/measure/displayunits" , QGis::toLiteral ( QGis::Meters ) ).toString () );
100
+
101
+ QgsDebugMsg ( " ****************" );
102
+ QgsDebugMsg ( QString ( " Ellipsoidal: %1" ).arg ( mEllipsoidal ? " true" : " false" ) );
103
+ QgsDebugMsg ( QString ( " Decimalpla.: %1" ).arg ( mDecimalPlaces ) );
104
+ QgsDebugMsg ( QString ( " Display u. : %1" ).arg ( QGis::toLiteral ( mDisplayUnits ) ) );
105
+ QgsDebugMsg ( QString ( " Canvas u. : %1" ).arg ( QGis::toLiteral ( mCanvasUnits ) ) );
106
+
107
+ configureDistanceArea ();
73
108
109
+ // clear interface
110
+ mTable ->clear ();
111
+ QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
112
+ item->setTextAlignment ( 0 , Qt::AlignRight );
113
+ mTable ->addTopLevelItem ( item );
114
+ mTotal = 0 ;
74
115
updateUi ();
75
- }
76
116
117
+ }
77
118
78
119
void QgsMeasureDialog::restart ()
79
120
{
@@ -86,7 +127,6 @@ void QgsMeasureDialog::restart()
86
127
item->setTextAlignment ( 0 , Qt::AlignRight );
87
128
mTable ->addTopLevelItem ( item );
88
129
mTotal = 0 .;
89
-
90
130
updateUi ();
91
131
}
92
132
@@ -105,9 +145,6 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
105
145
106
146
void QgsMeasureDialog::mouseMove ( QgsPoint &point )
107
147
{
108
- QSettings settings;
109
- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
110
-
111
148
// show current distance/area while moving the point
112
149
// by creating a temporary copy of point array
113
150
// and adding moving point at the end
@@ -116,19 +153,19 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
116
153
QList<QgsPoint> tmpPoints = mTool ->points ();
117
154
tmpPoints.append ( point );
118
155
double area = mDa .measurePolygon ( tmpPoints );
119
- editTotal->setText ( formatArea ( area, decimalPlaces ) );
156
+ editTotal->setText ( formatArea ( area ) );
120
157
}
121
158
else if ( !mMeasureArea && mTool ->points ().size () > 0 )
122
159
{
123
160
QgsPoint p1 ( mTool ->points ().last () ), p2 ( point );
124
161
125
162
double d = mDa .measureLine ( p1, p2 );
126
- editTotal->setText ( formatDistance ( mTotal + d, decimalPlaces ) );
163
+ editTotal->setText ( formatDistance ( mTotal + d ) );
127
164
QGis::UnitType myDisplayUnits;
128
165
// Ignore units
129
166
convertMeasurement ( d, myDisplayUnits, false );
130
167
QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
131
- item->setText ( 0 , QLocale::system ().toString ( d, ' f' , decimalPlaces ) );
168
+ item->setText ( 0 , QLocale::system ().toString ( d, ' f' , mDecimalPlaces ) );
132
169
QgsDebugMsg ( QString ( " Final result is %1" ).arg ( item->text ( 0 ) ) );
133
170
}
134
171
}
@@ -137,14 +174,11 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
137
174
{
138
175
Q_UNUSED ( p );
139
176
140
- QSettings settings;
141
- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
142
-
143
177
int numPoints = mTool ->points ().size ();
144
178
if ( mMeasureArea && numPoints > 2 )
145
179
{
146
180
double area = mDa .measurePolygon ( mTool ->points () );
147
- editTotal->setText ( formatArea ( area, decimalPlaces ) );
181
+ editTotal->setText ( formatArea ( area ) );
148
182
}
149
183
else if ( !mMeasureArea && numPoints > 1 )
150
184
{
@@ -155,16 +189,16 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
155
189
double d = mDa .measureLine ( p1, p2 );
156
190
157
191
mTotal += d;
158
- editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
192
+ editTotal->setText ( formatDistance ( mTotal ) );
159
193
160
194
QGis::UnitType myDisplayUnits;
161
195
// Ignore units
162
196
convertMeasurement ( d, myDisplayUnits, false );
163
197
164
198
QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
165
- item->setText ( 0 , QLocale::system ().toString ( d, ' f' , decimalPlaces ) );
199
+ item->setText ( 0 , QLocale::system ().toString ( d, ' f' ) );
166
200
167
- item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , decimalPlaces ) ) );
201
+ item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' ) ) );
168
202
item->setTextAlignment ( 0 , Qt::AlignRight );
169
203
mTable ->addTopLevelItem ( item );
170
204
mTable ->scrollToItem ( item );
@@ -204,44 +238,38 @@ void QgsMeasureDialog::saveWindowLocation()
204
238
settings.setValue ( key, height () );
205
239
}
206
240
207
- QString QgsMeasureDialog::formatDistance ( double distance, int decimalPlaces )
241
+ QString QgsMeasureDialog::formatDistance ( double distance )
208
242
{
209
243
QSettings settings;
210
244
bool baseUnit = settings.value ( " /qgis/measure/keepbaseunit" , false ).toBool ();
211
245
212
- QGis::UnitType myDisplayUnits ;
213
- convertMeasurement ( distance, myDisplayUnits , false );
214
- return QgsDistanceArea::textUnit ( distance, decimalPlaces, myDisplayUnits , false , baseUnit );
246
+ QGis::UnitType newDisplayUnits ;
247
+ convertMeasurement ( distance, newDisplayUnits , false );
248
+ return QgsDistanceArea::textUnit ( distance, mDecimalPlaces , newDisplayUnits , false , baseUnit );
215
249
}
216
250
217
- QString QgsMeasureDialog::formatArea ( double area, int decimalPlaces )
251
+ QString QgsMeasureDialog::formatArea ( double area )
218
252
{
219
253
QSettings settings;
220
254
bool baseUnit = settings.value ( " /qgis/measure/keepbaseunit" , false ).toBool ();
221
255
222
- QGis::UnitType myDisplayUnits ;
223
- convertMeasurement ( area, myDisplayUnits , true );
224
- return QgsDistanceArea::textUnit ( area, decimalPlaces, myDisplayUnits , true , baseUnit );
256
+ QGis::UnitType newDisplayUnits ;
257
+ convertMeasurement ( area, newDisplayUnits , true );
258
+ return QgsDistanceArea::textUnit ( area, mDecimalPlaces , newDisplayUnits , true , baseUnit );
225
259
}
226
260
227
261
void QgsMeasureDialog::updateUi ()
228
262
{
229
- // Only enable checkbox when project wide transformation is on
263
+ // If project wide transformation is off, disbale checkbox and unmark it.
264
+ // When on, enable checbox and mark with saved value.
230
265
mcbProjectionEnabled->setEnabled ( mTool ->canvas ()->hasCrsTransformEnabled () );
231
266
232
- configureDistanceArea ();
233
-
234
- QSettings settings;
235
-
236
267
// Set tooltip to indicate how we calculate measurments
237
- QGis::UnitType mapUnits = mTool ->canvas ()->mapUnits ();
238
- QGis::UnitType displayUnits = QGis::fromLiteral ( settings.value ( " /qgis/measure/displayunits" , QGis::toLiteral ( QGis::Meters ) ).toString () );
239
-
240
268
QString toolTip = tr ( " The calculations are based on:" );
241
269
if ( ! mTool ->canvas ()->hasCrsTransformEnabled () )
242
270
{
243
271
toolTip += " <br> * " + tr ( " Project CRS transformation is turned off." ) + " " ;
244
- toolTip += tr ( " Canvas units setting is taken from project properties setting (%1)." ).arg ( QGis::tr ( mapUnits ) );
272
+ toolTip += tr ( " Canvas units setting is taken from project properties setting (%1)." ).arg ( QGis::tr ( mCanvasUnits ) );
245
273
toolTip += " <br> * " + tr ( " Ellipsoidal calculation is not possible, as project CRS is undefined." );
246
274
}
247
275
else
@@ -254,74 +282,19 @@ void QgsMeasureDialog::updateUi()
254
282
else
255
283
{
256
284
toolTip += " <br> * " + tr ( " Project CRS transformation is turned on but ellipsoidal calculation is not selected." );
257
- toolTip += " <br> * " + tr ( " The canvas units setting is taken from the project CRS (%1)." ).arg ( QGis::tr ( mapUnits ) );
285
+ toolTip += " <br> * " + tr ( " The canvas units setting is taken from the project CRS (%1)." ).arg ( QGis::tr ( mCanvasUnits ) );
258
286
}
259
287
}
260
288
261
- if (( mapUnits == QGis::Meters && displayUnits == QGis::Feet ) || ( mapUnits == QGis::Feet && displayUnits == QGis::Meters ) )
289
+ if (( mCanvasUnits == QGis::Meters && mDisplayUnits == QGis::Feet ) || ( mCanvasUnits == QGis::Feet && mDisplayUnits == QGis::Meters ) )
262
290
{
263
- toolTip += " <br> * " + tr ( " Finally, the value is converted from %2 to %3." ).arg ( QGis::tr ( mapUnits ) ).arg ( QGis::tr ( displayUnits ) );
291
+ toolTip += " <br> * " + tr ( " Finally, the value is converted from %2 to %3." ).arg ( QGis::tr ( mCanvasUnits ) ).arg ( QGis::tr ( mDisplayUnits ) );
264
292
}
265
293
266
294
editTotal->setToolTip ( toolTip );
267
295
mTable ->setToolTip ( toolTip );
268
296
269
- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
270
-
271
- mTable ->setHeaderLabels ( QStringList ( tr ( " Segments [%1]" ).arg ( QGis::tr ( displayUnits ) ) ) );
272
-
273
- if ( mMeasureArea )
274
- {
275
- mTable ->hide ();
276
- editTotal->setText ( formatArea ( 0 , decimalPlaces ) );
277
- }
278
- else
279
- {
280
- mTable ->show ();
281
- editTotal->setText ( formatDistance ( 0 , decimalPlaces ) );
282
- }
283
- }
284
-
285
- void QgsMeasureDialog::convertMeasurement ( double &measure, QGis::UnitType &u, bool isArea )
286
- {
287
- // Helper for converting between meters and feet
288
- // The parameter &u is out only...
289
-
290
- // Get the canvas units
291
- QGis::UnitType myUnits = mTool ->canvas ()->mapUnits ();
292
-
293
- // Get the units for display
294
- QSettings settings;
295
- QGis::UnitType displayUnits = QGis::fromLiteral ( settings.value ( " /qgis/measure/displayunits" , QGis::toLiteral ( QGis::Meters ) ).toString () );
296
-
297
- QgsDebugMsg ( QString ( " Preferred display units are %1" ).arg ( QGis::toLiteral ( displayUnits ) ) );
298
-
299
- mDa .convertMeasurement ( measure, myUnits, displayUnits, isArea );
300
- u = myUnits;
301
- }
302
-
303
- void QgsMeasureDialog::changeProjectionEnabledState ()
304
- {
305
- // store value
306
- QSettings settings;
307
- if ( mcbProjectionEnabled->isChecked () )
308
- {
309
- settings.setValue ( " /qgis/measure/projectionEnabled" , 2 );
310
- }
311
- else
312
- {
313
- settings.setValue ( " /qgis/measure/projectionEnabled" , 0 );
314
- }
315
-
316
- // clear interface
317
- mTable ->clear ();
318
- QTreeWidgetItem* item = new QTreeWidgetItem ( QStringList ( QString::number ( 0 , ' f' , 1 ) ) );
319
- item->setTextAlignment ( 0 , Qt::AlignRight );
320
- mTable ->addTopLevelItem ( item );
321
- mTotal = 0 ;
322
- updateUi ();
323
-
324
- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
297
+ mTable ->setHeaderLabels ( QStringList ( tr ( " Segments [%1]" ).arg ( QGis::tr ( mDisplayUnits ) ) ) );
325
298
326
299
if ( mMeasureArea )
327
300
{
@@ -330,7 +303,7 @@ void QgsMeasureDialog::changeProjectionEnabledState()
330
303
{
331
304
area = mDa .measurePolygon ( mTool ->points () );
332
305
}
333
- editTotal->setText ( formatArea ( area, decimalPlaces ) );
306
+ editTotal->setText ( formatArea ( area ) );
334
307
}
335
308
else
336
309
{
@@ -346,14 +319,14 @@ void QgsMeasureDialog::changeProjectionEnabledState()
346
319
{
347
320
double d = mDa .measureLine ( p1, p2 );
348
321
mTotal += d;
349
- editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
322
+ editTotal->setText ( formatDistance ( mTotal ) );
350
323
QGis::UnitType myDisplayUnits;
351
324
352
325
convertMeasurement ( d, myDisplayUnits, false );
353
326
354
327
QTreeWidgetItem *item = mTable ->topLevelItem ( mTable ->topLevelItemCount () - 1 );
355
- item->setText ( 0 , QLocale::system ().toString ( d, ' f' , decimalPlaces ) );
356
- item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , decimalPlaces ) ) );
328
+ item->setText ( 0 , QLocale::system ().toString ( d, ' f' ) );
329
+ item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , mDecimalPlaces ) ) );
357
330
item->setTextAlignment ( 0 , Qt::AlignRight );
358
331
mTable ->addTopLevelItem ( item );
359
332
mTable ->scrollToItem ( item );
@@ -364,12 +337,26 @@ void QgsMeasureDialog::changeProjectionEnabledState()
364
337
}
365
338
}
366
339
340
+ void QgsMeasureDialog::convertMeasurement ( double &measure, QGis::UnitType &u, bool isArea )
341
+ {
342
+ // Helper for converting between meters and feet
343
+ // The parameter &u is out only...
344
+
345
+ // Get the canvas units
346
+ QGis::UnitType myUnits = mCanvasUnits ;
347
+
348
+ QgsDebugMsg ( QString ( " Preferred display units are %1" ).arg ( QGis::toLiteral ( mDisplayUnits ) ) );
349
+
350
+ mDa .convertMeasurement ( measure, myUnits, mDisplayUnits , isArea );
351
+ u = myUnits;
352
+ }
353
+
367
354
void QgsMeasureDialog::configureDistanceArea ()
368
355
{
369
356
QSettings settings;
370
357
QString ellipsoidId = settings.value ( " /qgis/measure/ellipsoid" , " WGS84" ).toString ();
371
358
mDa .setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationCrs ().srsid () );
372
359
mDa .setEllipsoid ( ellipsoidId );
373
360
// Only use ellipsoidal calculation when project wide transformation is enabled.
374
- mDa .setEllipsoidalMode ( mcbProjectionEnabled-> isChecked () && mTool ->canvas ()->hasCrsTransformEnabled () );
361
+ mDa .setEllipsoidalMode ( mEllipsoidal && mTool ->canvas ()->hasCrsTransformEnabled () );
375
362
}
0 commit comments