@@ -60,9 +60,7 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
60
60
mLineEdit ->setAlignment ( Qt::AlignCenter );
61
61
connect ( mLineEdit , &QLineEdit::returnPressed, this , &QgsStatusBarCoordinatesWidget::validateCoordinates );
62
62
63
- const QRegularExpression coordValidator ( " [+-]?\\ d+\\ .?\\ d*\\ s*,\\ s*[+-]?\\ d+\\ .?\\ d*" );
64
- mCoordsEditValidator = new QRegularExpressionValidator ( coordValidator, this );
65
- mLineEdit ->setToolTip ( tr ( " Current map coordinate (longitude,latitude or east,north)" ) );
63
+ mLineEdit ->setToolTip ( tr ( " Current map coordinate (longitude latitude or east north)" ) );
66
64
67
65
// toggle to switch between mouse pos and extents display in status bar widget
68
66
mToggleExtentsViewButton = new QToolButton ( this );
@@ -173,6 +171,7 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
173
171
QString coordText = mLineEdit ->text ();
174
172
const thread_local QRegularExpression sMultipleWhitespaceRx ( QStringLiteral ( " {2,}" ) );
175
173
coordText.replace ( sMultipleWhitespaceRx , QStringLiteral ( " " ) );
174
+ coordText.remove ( QStringLiteral ( " °" ) );
176
175
177
176
QStringList parts = coordText.split ( ' ,' );
178
177
if ( parts.size () == 2 )
@@ -191,6 +190,17 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
191
190
}
192
191
}
193
192
193
+ // Use locale
194
+ if ( !xOk || !yOk )
195
+ {
196
+ parts = coordText.split ( ' ' );
197
+ if ( parts.size () == 2 )
198
+ {
199
+ first = QLocale ().toDouble ( parts.at ( 0 ), &xOk );
200
+ second = QLocale ().toDouble ( parts.at ( 1 ), &yOk );
201
+ }
202
+ }
203
+
194
204
if ( !xOk || !yOk )
195
205
return ;
196
206
@@ -202,13 +212,32 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
202
212
{
203
213
case Qgis::CoordinateOrder::Default:
204
214
case Qgis::CoordinateOrder::XY:
205
- mMapCanvas ->setCenter ( QgsPointXY ( first, second ) );
206
215
break ;
207
216
case Qgis::CoordinateOrder::YX:
208
- mMapCanvas -> setCenter ( QgsPointXY ( second, first ) );
217
+ std::swap ( first, second );
209
218
break ;
210
219
}
211
220
221
+ QgsPointXY centerPoint { first, second };
222
+
223
+ const QgsCoordinateReferenceSystem displayCrs = QgsProject::instance ()->displaySettings ()->coordinateCrs ();
224
+ const QgsCoordinateReferenceSystem canvasCrs = mMapCanvas ->mapSettings ().destinationCrs ();
225
+ if ( displayCrs.isValid () && canvasCrs.isValid () && displayCrs != canvasCrs )
226
+ {
227
+ const QgsCoordinateTransform ct { displayCrs, canvasCrs, QgsProject::instance ()->transformContext () };
228
+ try
229
+ {
230
+
231
+ centerPoint = ct.transform ( centerPoint );
232
+ }
233
+ catch ( const QgsCsException & )
234
+ {
235
+ return ;
236
+ }
237
+ }
238
+
239
+ mMapCanvas ->setCenter ( centerPoint );
240
+
212
241
mMapCanvas ->refresh ();
213
242
}
214
243
0 commit comments