Skip to content

Commit

Permalink
Show CRS details in tooltips for destination X/Y values
Browse files Browse the repository at this point in the history
Helps clarify for users exactly what CRS these destination coordinates
are in
  • Loading branch information
nyalldawson committed Feb 14, 2022
1 parent 93564e0 commit 622c120
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/app/georeferencer/qgsgcplistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ QVariant QgsGCPListModel::data( const QModelIndex &index, int role ) const
switch ( role )
{
case Qt::ToolTipRole:
{
const QString crsString = mTargetCrs.userFriendlyIdentifier();
const double value = column == QgsGCPListModel::Column::DestinationX ? transformedDestinationPoint.x() : transformedDestinationPoint.y();
return QStringLiteral( "<b>%1</b><br>%2" ).arg( value ).arg( crsString );
}

case Qt::EditRole:
case Qt::UserRole:
// use full precision
Expand Down Expand Up @@ -329,6 +335,7 @@ QVariant QgsGCPListModel::headerData( int section, Qt::Orientation orientation,
switch ( role )
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
{
QString residualUnitType;
switch ( residualUnit() )
Expand Down Expand Up @@ -360,9 +367,25 @@ QVariant QgsGCPListModel::headerData( int section, Qt::Orientation orientation,
case QgsGCPListModel::Column::SourceY:
return tr( "Source Y" );
case QgsGCPListModel::Column::DestinationX:
return tr( "Dest. X" );
case QgsGCPListModel::Column::DestinationY:
return tr( "Dest. Y" );
{
const QString heading = static_cast< Column >( section ) == QgsGCPListModel::Column::DestinationX ? tr( "Dest. X" ) : tr( "Dest. Y" );
switch ( role )
{
case Qt::DisplayRole:
return heading;

case Qt::ToolTipRole:
{
const QString crsString = mTargetCrs.userFriendlyIdentifier();
return QStringLiteral( "<b>%1</b><br>%2" ).arg( heading, crsString );
}

default:
break;
}
break;
}
case QgsGCPListModel::Column::ResidualDx:
return tr( "dX (%1)" ).arg( residualUnitType );
case QgsGCPListModel::Column::ResidualDy:
Expand Down
6 changes: 6 additions & 0 deletions tests/src/app/testqgsgeoreferencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ void TestQgsGeoreferencer::testListModel()
QCOMPARE( model.data( model.index( 0, 3 ) ).toString(), QStringLiteral( "3350923.1250" ) );
QCOMPARE( model.data( model.index( 0, 4 ) ).toString(), QStringLiteral( "-30.0000" ) );
QCOMPARE( model.data( model.index( 0, 5 ) ).toString(), QStringLiteral( "40.0000" ) );
QCOMPARE( model.data( model.index( 0, 4 ), Qt::ToolTipRole ).toString(), QStringLiteral( "<b>-30</b><br>EPSG:4326 - WGS 84" ) );
QCOMPARE( model.data( model.index( 0, 5 ), Qt::ToolTipRole ).toString(), QStringLiteral( "<b>40</b><br>EPSG:4326 - WGS 84" ) );

QCOMPARE( model.data( model.index( 0, 6 ) ).toString(), QStringLiteral( "n/a" ) );
QCOMPARE( model.data( model.index( 0, 7 ) ).toString(), QStringLiteral( "n/a" ) );
QCOMPARE( model.data( model.index( 0, 8 ) ).toString(), QStringLiteral( "n/a" ) );
Expand All @@ -651,6 +654,9 @@ void TestQgsGeoreferencer::testListModel()
QCOMPARE( model.data( model.index( 1, 3 ) ).toString(), QStringLiteral( "3350923.1250" ) );
QCOMPARE( model.data( model.index( 1, 4 ) ).toString(), QStringLiteral( "150.0000" ) );
QCOMPARE( model.data( model.index( 1, 5 ) ).toString(), QStringLiteral( "-30.0000" ) );
// tooltip should show target CRS details for user clarification
QCOMPARE( model.data( model.index( 1, 4 ), Qt::ToolTipRole ).toString(), QStringLiteral( "<b>150</b><br>EPSG:4326 - WGS 84" ) );
QCOMPARE( model.data( model.index( 1, 5 ), Qt::ToolTipRole ).toString(), QStringLiteral( "<b>-30</b><br>EPSG:4326 - WGS 84" ) );
QCOMPARE( model.data( model.index( 1, 6 ) ).toString(), QStringLiteral( "n/a" ) );
QCOMPARE( model.data( model.index( 1, 7 ) ).toString(), QStringLiteral( "n/a" ) );
QCOMPARE( model.data( model.index( 1, 8 ) ).toString(), QStringLiteral( "n/a" ) );
Expand Down

0 comments on commit 622c120

Please sign in to comment.