Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 77804eb)
  • Loading branch information
nyalldawson committed Dec 20, 2019
1 parent bd6aa03 commit 6b7c056
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1174,10 +1174,12 @@ QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( bool shortString )
}
else if ( !description().isEmpty() )
return description();
else if ( shortString )
return QObject::tr( "Unknown CRS" );
else if ( !toWkt().isEmpty() )
return toWkt().left( 30 ) + QChar( 0x2026 );
return QObject::tr( "Unknown CRS: %1" ).arg( toWkt().left( 50 ) + QString( QChar( 0x2026 ) ) );
else if ( !toProj().isEmpty() )
return toProj().left( 30 ) + QChar( 0x2026 );
return QObject::tr( "Unknown CRS: %1" ).arg( toProj().left( 50 ) + QString( QChar( 0x2026 ) ) );
else
return QString();
}
Expand Down
23 changes: 17 additions & 6 deletions src/gui/qgsprojectionselectionwidget.cpp
Expand Up @@ -207,28 +207,29 @@ void QgsProjectionSelectionWidget::comboIndexChanged( int idx )
{
case QgsProjectionSelectionWidget::LayerCrs:
emit crsChanged( mLayerCrs );
return;
break;
case QgsProjectionSelectionWidget::ProjectCrs:
emit crsChanged( mProjectCrs );
return;
break;
case QgsProjectionSelectionWidget::CurrentCrs:
emit crsChanged( mCrs );
return;
break;
case QgsProjectionSelectionWidget::DefaultCrs:
emit crsChanged( mDefaultCrs );
return;
break;
case QgsProjectionSelectionWidget::RecentCrs:
{
long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( srsid );
emit crsChanged( crs );
return;
break;
}
case QgsProjectionSelectionWidget::CrsNotSet:
emit cleared();
emit crsChanged( QgsCoordinateReferenceSystem() );
return;
break;
}
updateTooltip();
}

void QgsProjectionSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &crs )
Expand Down Expand Up @@ -263,6 +264,7 @@ void QgsProjectionSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &c
mCrs = crs;
emit crsChanged( crs );
}
updateTooltip();
}

void QgsProjectionSelectionWidget::setLayerCrs( const QgsCoordinateReferenceSystem &crs )
Expand Down Expand Up @@ -354,3 +356,12 @@ int QgsProjectionSelectionWidget::firstRecentCrsIndex() const
}
return -1;
}

void QgsProjectionSelectionWidget::updateTooltip()
{
QgsCoordinateReferenceSystem c = crs();
if ( c.isValid() )
setToolTip( c.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, true ) );
else
setToolTip( QString() );
}
1 change: 1 addition & 0 deletions src/gui/qgsprojectionselectionwidget.h
Expand Up @@ -153,6 +153,7 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
bool crsIsShown( long srsid ) const;

int firstRecentCrsIndex() const;
void updateTooltip();

private slots:

Expand Down
2 changes: 1 addition & 1 deletion tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -1008,7 +1008,7 @@ void TestQgsProcessingAlgs::rasterLogicOp()

QgsRectangle extent = QgsRectangle( 0, 0, nRows, nCols );
QgsRectangle badExtent = QgsRectangle( -100, -100, 90, 90 );
QgsCoordinateReferenceSystem crs( 3857 );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:3857" ) );
double tform[] =
{
extent.xMinimum(), extent.width() / nCols, 0.0,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/analysis/testqgsreclassifyutils.cpp
Expand Up @@ -182,7 +182,7 @@ void TestQgsReclassifyUtils::testReclassify()
QFETCH( QVector< double >, expected );

QgsRectangle extent = QgsRectangle( 0, 0, nRows, nCols );
QgsCoordinateReferenceSystem crs( 3857 );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:3857" ) );
double tform[] =
{
extent.xMinimum(), extent.width() / nCols, 0.0,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/testqgisappclipboard.cpp
Expand Up @@ -167,7 +167,7 @@ void TestQgisAppClipboard::copyToText()

// test CRS is transformed correctly for GeoJSON

QgsCoordinateReferenceSystem crs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:3111" ) );
feats = QgsFeatureStore();
feats.setCrs( crs );
feat.setGeometry( QgsGeometry( new QgsPoint( 2502577, 2403869 ) ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgsattributetable.cpp
Expand Up @@ -98,7 +98,7 @@ void TestQgsAttributeTable::testFieldCalculation()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceMeters );
Expand Down Expand Up @@ -148,7 +148,7 @@ void TestQgsAttributeTable::testFieldCalculationArea()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMeters );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgsfieldcalculator.cpp
Expand Up @@ -82,7 +82,7 @@ void TestQgsFieldCalculator::testLengthCalculations()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceMeters );
Expand Down Expand Up @@ -143,7 +143,7 @@ void TestQgsFieldCalculator::testAreaCalculations()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMeters );
Expand Down
10 changes: 5 additions & 5 deletions tests/src/app/testqgsmaptoolidentifyaction.cpp
Expand Up @@ -185,7 +185,7 @@ void TestQgsMapToolIdentifyAction::clickxy()
QList<QgsMapLayer *> layers;
layers.append( tempLayer.get() );

QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
canvas->setDestinationCrs( srs );
canvas->setLayers( layers );
canvas->setCurrentLayer( tempLayer.get() );
Expand Down Expand Up @@ -231,7 +231,7 @@ void TestQgsMapToolIdentifyAction::closestPoint()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
canvas->setDestinationCrs( srs );
canvas->setExtent( f1.geometry().boundingBox() );
QgsProject::instance()->setCrs( srs );
Expand Down Expand Up @@ -289,7 +289,7 @@ void TestQgsMapToolIdentifyAction::lengthCalculation()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
canvas->setDestinationCrs( srs );
canvas->setExtent( f1.geometry().boundingBox() );
QgsProject::instance()->setCrs( srs );
Expand Down Expand Up @@ -380,7 +380,7 @@ void TestQgsMapToolIdentifyAction::perimeterCalculation()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
canvas->setDestinationCrs( srs );
canvas->setExtent( f1.geometry().boundingBox() );
QgsProject::instance()->setCrs( srs );
Expand Down Expand Up @@ -455,7 +455,7 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
canvas->setDestinationCrs( srs );
canvas->setExtent( f1.geometry().boundingBox() );
QgsProject::instance()->setCrs( srs );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/testqgsmaptoolreshape.cpp
Expand Up @@ -273,7 +273,7 @@ void TestQgsMapToolReshape::reshapeWithBindingLine()
QList<QgsMapLayer *> layers;
layers.append( vl.get() );

QgsCoordinateReferenceSystem srs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:4326" ) );
mQgisApp->mapCanvas()->setDestinationCrs( srs );
mQgisApp->mapCanvas()->setLayers( layers );
mQgisApp->mapCanvas()->setCurrentLayer( vl.get() );
Expand Down
12 changes: 6 additions & 6 deletions tests/src/app/testqgsmeasuretool.cpp
Expand Up @@ -89,7 +89,7 @@ void TestQgsMeasureTool::testLengthCalculationCartesian()
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), true );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
mCanvas->setDestinationCrs( srs );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
Expand Down Expand Up @@ -132,7 +132,7 @@ void TestQgsMeasureTool::testLengthCalculationCartesian()
QGSCOMPARENEAR( measured, expected, 0.001 );

// check new CoordinateReferenceSystem, points must be reprojected to paint them successfully (issue #15182)
QgsCoordinateReferenceSystem srs2( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs2( QStringLiteral( "EPSG:4326" ) );

QgsCoordinateTransform ct( srs, srs2, QgsProject::instance() );

Expand All @@ -157,7 +157,7 @@ void TestQgsMeasureTool::testLengthCalculationProjected()
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), true );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
mCanvas->setDestinationCrs( srs );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
Expand Down Expand Up @@ -199,7 +199,7 @@ void TestQgsMeasureTool::testLengthCalculationProjected()
QGSCOMPARENEAR( measured, expected, 0.001 );

// check new CoordinateReferenceSystem, points must be reprojected to paint them successfully (issue #15182)
QgsCoordinateReferenceSystem srs2( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs2( QStringLiteral( "EPSG:4326" ) );

QgsCoordinateTransform ct( srs, srs2, QgsProject::instance() );

Expand Down Expand Up @@ -252,7 +252,7 @@ void TestQgsMeasureTool::testAreaCalculationCartesian()
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), true );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
mCanvas->setDestinationCrs( srs );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
Expand Down Expand Up @@ -306,7 +306,7 @@ void TestQgsMeasureTool::testAreaCalculationProjected()
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), true );

// set project CRS and ellipsoid
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3111" ) );
mCanvas->setDestinationCrs( srs );
QgsProject::instance()->setCrs( srs );
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
Expand Down
20 changes: 20 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -91,6 +91,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void noProj();
void customProjString();
void recentProjections();
void displayIdentifier();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
Expand Down Expand Up @@ -1436,5 +1437,24 @@ void TestQgsCoordinateReferenceSystem::recentProjections()
QCOMPARE( recent.at( 9 ).authid(), QStringLiteral( "EPSG:32540" ) );
}

void TestQgsCoordinateReferenceSystem::displayIdentifier()
{
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem();
QCOMPARE( crs.userFriendlyIdentifier(), QString() );
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "EPSG:4326 - WGS 84" ) );
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) );
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "EPSG:3111 - GDA94 / Vicgrid" ) );
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.userFriendlyIdentifier( true ), QStringLiteral( "EPSG:4326" ) );

// non registered custom CRS
crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "Unknown CRS: COMPD_CS[\"unknown\",PROJCS[\"unknown\",GEOGCS[\"unknow%1" ).arg( QString( QChar( 0x2026 ) ) ) );
QCOMPARE( crs.userFriendlyIdentifier( true ), QStringLiteral( "Unknown CRS" ) );
crs.saveAsUserCrs( QStringLiteral( "my test" ) );
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "USER:100010 - my test" ) );
}

QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "testqgscoordinatereferencesystem.moc"

0 comments on commit 6b7c056

Please sign in to comment.