@@ -48,32 +48,73 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
4848 item->setTextAlignment ( 0 , Qt::AlignRight );
4949 mTable ->addTopLevelItem ( item );
5050
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+ }
5282
83+ void QgsMeasureDialog::updateSettings ()
84+ {
5385 QSettings settings;
86+
5487 int s = settings.value ( " /qgis/measure/projectionEnabled" , " 2" ).toInt ();
5588 if ( s == 2 )
56- mcbProjectionEnabled->setCheckState ( Qt::Checked );
89+ {
90+ mEllipsoidal = true ;
91+ }
5792 else
58- mcbProjectionEnabled->setCheckState ( Qt::Unchecked );
93+ {
94+ mEllipsoidal = false ;
95+ }
5996
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 ();
73108
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 ;
74115 updateUi ();
75- }
76116
117+ }
77118
78119void QgsMeasureDialog::restart ()
79120{
@@ -86,7 +127,6 @@ void QgsMeasureDialog::restart()
86127 item->setTextAlignment ( 0 , Qt::AlignRight );
87128 mTable ->addTopLevelItem ( item );
88129 mTotal = 0 .;
89-
90130 updateUi ();
91131}
92132
@@ -105,9 +145,6 @@ void QgsMeasureDialog::mousePress( QgsPoint &point )
105145
106146void QgsMeasureDialog::mouseMove ( QgsPoint &point )
107147{
108- QSettings settings;
109- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
110-
111148 // show current distance/area while moving the point
112149 // by creating a temporary copy of point array
113150 // and adding moving point at the end
@@ -116,19 +153,19 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
116153 QList<QgsPoint> tmpPoints = mTool ->points ();
117154 tmpPoints.append ( point );
118155 double area = mDa .measurePolygon ( tmpPoints );
119- editTotal->setText ( formatArea ( area, decimalPlaces ) );
156+ editTotal->setText ( formatArea ( area ) );
120157 }
121158 else if ( !mMeasureArea && mTool ->points ().size () > 0 )
122159 {
123160 QgsPoint p1 ( mTool ->points ().last () ), p2 ( point );
124161
125162 double d = mDa .measureLine ( p1, p2 );
126- editTotal->setText ( formatDistance ( mTotal + d, decimalPlaces ) );
163+ editTotal->setText ( formatDistance ( mTotal + d ) );
127164 QGis::UnitType myDisplayUnits;
128165 // Ignore units
129166 convertMeasurement ( d, myDisplayUnits, false );
130167 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 ) );
132169 QgsDebugMsg ( QString ( " Final result is %1" ).arg ( item->text ( 0 ) ) );
133170 }
134171}
@@ -137,14 +174,11 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
137174{
138175 Q_UNUSED ( p );
139176
140- QSettings settings;
141- int decimalPlaces = settings.value ( " /qgis/measure/decimalplaces" , " 3" ).toInt ();
142-
143177 int numPoints = mTool ->points ().size ();
144178 if ( mMeasureArea && numPoints > 2 )
145179 {
146180 double area = mDa .measurePolygon ( mTool ->points () );
147- editTotal->setText ( formatArea ( area, decimalPlaces ) );
181+ editTotal->setText ( formatArea ( area ) );
148182 }
149183 else if ( !mMeasureArea && numPoints > 1 )
150184 {
@@ -155,16 +189,16 @@ void QgsMeasureDialog::addPoint( QgsPoint &p )
155189 double d = mDa .measureLine ( p1, p2 );
156190
157191 mTotal += d;
158- editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
192+ editTotal->setText ( formatDistance ( mTotal ) );
159193
160194 QGis::UnitType myDisplayUnits;
161195 // Ignore units
162196 convertMeasurement ( d, myDisplayUnits, false );
163197
164198 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' ) );
166200
167- item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' , decimalPlaces ) ) );
201+ item = new QTreeWidgetItem ( QStringList ( QLocale::system ().toString ( 0.0 , ' f' ) ) );
168202 item->setTextAlignment ( 0 , Qt::AlignRight );
169203 mTable ->addTopLevelItem ( item );
170204 mTable ->scrollToItem ( item );
@@ -204,44 +238,38 @@ void QgsMeasureDialog::saveWindowLocation()
204238 settings.setValue ( key, height () );
205239}
206240
207- QString QgsMeasureDialog::formatDistance ( double distance, int decimalPlaces )
241+ QString QgsMeasureDialog::formatDistance ( double distance )
208242{
209243 QSettings settings;
210244 bool baseUnit = settings.value ( " /qgis/measure/keepbaseunit" , false ).toBool ();
211245
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 );
215249}
216250
217- QString QgsMeasureDialog::formatArea ( double area, int decimalPlaces )
251+ QString QgsMeasureDialog::formatArea ( double area )
218252{
219253 QSettings settings;
220254 bool baseUnit = settings.value ( " /qgis/measure/keepbaseunit" , false ).toBool ();
221255
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 );
225259}
226260
227261void QgsMeasureDialog::updateUi ()
228262{
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.
230265 mcbProjectionEnabled->setEnabled ( mTool ->canvas ()->hasCrsTransformEnabled () );
231266
232- configureDistanceArea ();
233-
234- QSettings settings;
235-
236267 // 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-
240268 QString toolTip = tr ( " The calculations are based on:" );
241269 if ( ! mTool ->canvas ()->hasCrsTransformEnabled () )
242270 {
243271 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 ) );
245273 toolTip += " <br> * " + tr ( " Ellipsoidal calculation is not possible, as project CRS is undefined." );
246274 }
247275 else
@@ -254,74 +282,19 @@ void QgsMeasureDialog::updateUi()
254282 else
255283 {
256284 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 ) );
258286 }
259287 }
260288
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 ) )
262290 {
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 ) );
264292 }
265293
266294 editTotal->setToolTip ( toolTip );
267295 mTable ->setToolTip ( toolTip );
268296
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 ) ) ) );
325298
326299 if ( mMeasureArea )
327300 {
@@ -330,7 +303,7 @@ void QgsMeasureDialog::changeProjectionEnabledState()
330303 {
331304 area = mDa .measurePolygon ( mTool ->points () );
332305 }
333- editTotal->setText ( formatArea ( area, decimalPlaces ) );
306+ editTotal->setText ( formatArea ( area ) );
334307 }
335308 else
336309 {
@@ -346,14 +319,14 @@ void QgsMeasureDialog::changeProjectionEnabledState()
346319 {
347320 double d = mDa .measureLine ( p1, p2 );
348321 mTotal += d;
349- editTotal->setText ( formatDistance ( mTotal , decimalPlaces ) );
322+ editTotal->setText ( formatDistance ( mTotal ) );
350323 QGis::UnitType myDisplayUnits;
351324
352325 convertMeasurement ( d, myDisplayUnits, false );
353326
354327 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 ) ) );
357330 item->setTextAlignment ( 0 , Qt::AlignRight );
358331 mTable ->addTopLevelItem ( item );
359332 mTable ->scrollToItem ( item );
@@ -364,12 +337,26 @@ void QgsMeasureDialog::changeProjectionEnabledState()
364337 }
365338}
366339
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+
367354void QgsMeasureDialog::configureDistanceArea ()
368355{
369356 QSettings settings;
370357 QString ellipsoidId = settings.value ( " /qgis/measure/ellipsoid" , " WGS84" ).toString ();
371358 mDa .setSourceCrs ( mTool ->canvas ()->mapRenderer ()->destinationCrs ().srsid () );
372359 mDa .setEllipsoid ( ellipsoidId );
373360 // 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 () );
375362}
0 commit comments