Skip to content

Commit 10df998

Browse files
committedApr 4, 2023
Fix coords widget locale issues (plus other unreported)
1. fix #52446 2. fix unreported coords not swapped when needed before centering the canvas 3. fix unreported coords not transformed when needed before centering the canvas
1 parent 389f18d commit 10df998

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed
 

‎src/app/qgsstatusbarcoordinateswidget.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
6060
mLineEdit->setAlignment( Qt::AlignCenter );
6161
connect( mLineEdit, &QLineEdit::returnPressed, this, &QgsStatusBarCoordinatesWidget::validateCoordinates );
6262

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)" ) );
6664

6765
//toggle to switch between mouse pos and extents display in status bar widget
6866
mToggleExtentsViewButton = new QToolButton( this );
@@ -173,6 +171,7 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
173171
QString coordText = mLineEdit->text();
174172
const thread_local QRegularExpression sMultipleWhitespaceRx( QStringLiteral( " {2,}" ) );
175173
coordText.replace( sMultipleWhitespaceRx, QStringLiteral( " " ) );
174+
coordText.remove( QStringLiteral( "°" ) );
176175

177176
QStringList parts = coordText.split( ',' );
178177
if ( parts.size() == 2 )
@@ -191,6 +190,17 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
191190
}
192191
}
193192

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+
194204
if ( !xOk || !yOk )
195205
return;
196206

@@ -202,13 +212,32 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates()
202212
{
203213
case Qgis::CoordinateOrder::Default:
204214
case Qgis::CoordinateOrder::XY:
205-
mMapCanvas->setCenter( QgsPointXY( first, second ) );
206215
break;
207216
case Qgis::CoordinateOrder::YX:
208-
mMapCanvas->setCenter( QgsPointXY( second, first ) );
217+
std::swap( first, second );
209218
break;
210219
}
211220

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+
212241
mMapCanvas->refresh();
213242
}
214243

‎src/app/qgsstatusbarcoordinateswidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
7878
//! Widget that will live on the statusbar to display "Coordinate / Extent"
7979
QLabel *mLabel = nullptr;
8080

81-
QValidator *mCoordsEditValidator = nullptr;
8281
QTimer *mDizzyTimer = nullptr;
8382
QgsMapCanvas *mMapCanvas = nullptr;
8483
int mTwoCharSize = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.