Skip to content
Permalink
Browse files

Update tests

(cherry picked from commit 77804eb)
  • Loading branch information
nyalldawson committed Dec 18, 2019
1 parent bd6aa03 commit 6b7c05651ab36107eb0411e7a507b018dee53f05
@@ -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();
}
@@ -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 )
@@ -263,6 +264,7 @@ void QgsProjectionSelectionWidget::setCrs( const QgsCoordinateReferenceSystem &c
mCrs = crs;
emit crsChanged( crs );
}
updateTooltip();
}

void QgsProjectionSelectionWidget::setLayerCrs( const QgsCoordinateReferenceSystem &crs )
@@ -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() );
}
@@ -153,6 +153,7 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
bool crsIsShown( long srsid ) const;

int firstRecentCrsIndex() const;
void updateTooltip();

private slots:

@@ -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,
@@ -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,
@@ -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 ) ) );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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() );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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() );
@@ -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" ) );
@@ -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() );

@@ -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" ) );
@@ -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() );

@@ -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" ) );
@@ -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" ) );
@@ -91,6 +91,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void noProj();
void customProjString();
void recentProjections();
void displayIdentifier();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
@@ -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.
You can’t perform that action at this time.