Skip to content

Commit

Permalink
Rename things to clarify that they aren't always pixel values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 14, 2022
1 parent 11314ad commit 10457a9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
11 changes: 10 additions & 1 deletion src/app/georeferencer/qgsgeorefdatapoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class QgsGeorefDataPoint : public QObject
Q_OBJECT

public:
//! constructor

/**
* Constructor for QgsGeorefDataPoint
* \param srcCanvas
* \param dstCanvas
* \param sourceCoordinates must be in source layer coordinates, NOT pixels (unless source image is completely non-referenced)!
* \param destinationMapCoords
* \param destinationCrs
* \param enable
*/
QgsGeorefDataPoint( QgsMapCanvas *srcCanvas, QgsMapCanvas *dstCanvas,
const QgsPointXY &sourceCoordinates, const QgsPointXY &destinationMapCoords,
const QgsCoordinateReferenceSystem &destinationCrs, bool enable );
Expand Down
18 changes: 9 additions & 9 deletions src/app/georeferencer/qgsgeorefmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,23 +628,23 @@ void QgsGeoreferencerMainWindow::releasePoint( QPoint p )
}
}

void QgsGeoreferencerMainWindow::showCoordDialog( const QgsPointXY &pixelCoords )
void QgsGeoreferencerMainWindow::showCoordDialog( const QgsPointXY &sourceCoordinates )
{
delete mNewlyAddedPointItem;
mNewlyAddedPointItem = nullptr;

// show a temporary marker at the clicked source point on the raster while we show the coordinate dialog.
mNewlyAddedPointItem = new QgsGCPCanvasItem( mCanvas, nullptr, true );
mNewlyAddedPointItem->setPointColor( QColor( 0, 200, 0 ) );
mNewlyAddedPointItem->setPos( mNewlyAddedPointItem->toCanvasCoordinates( pixelCoords ) );
mNewlyAddedPointItem->setPos( mNewlyAddedPointItem->toCanvasCoordinates( sourceCoordinates ) );

QgsCoordinateReferenceSystem lastProjection = mLastGCPProjection.isValid() ? mLastGCPProjection : mProjection;
if ( mLayer && !mMapCoordsDialog )
{
mMapCoordsDialog = new QgsMapCoordsDialog( QgisApp::instance()->mapCanvas(), pixelCoords, lastProjection, this );
connect( mMapCoordsDialog, &QgsMapCoordsDialog::pointAdded, this, [ = ]( const QgsPointXY & a, const QgsPointXY & destination, const QgsCoordinateReferenceSystem & destinationCrs )
mMapCoordsDialog = new QgsMapCoordsDialog( QgisApp::instance()->mapCanvas(), sourceCoordinates, lastProjection, this );
connect( mMapCoordsDialog, &QgsMapCoordsDialog::pointAdded, this, [ = ]( const QgsPointXY & sourceLayerCoordinate, const QgsPointXY & destinationCoordinate, const QgsCoordinateReferenceSystem & destinationCrs )
{
addPoint( a, destination, destinationCrs );
addPoint( sourceLayerCoordinate, destinationCoordinate, destinationCrs );
} );
connect( mMapCoordsDialog, &QObject::destroyed, this, [ = ]
{
Expand Down Expand Up @@ -1251,14 +1251,14 @@ bool QgsGeoreferencerMainWindow::loadGCPs( /*bool verbose*/ )
QTextStream points( &pointFile );
QString line = points.readLine();
int i = 0;
QgsCoordinateReferenceSystem proj;
if ( line.contains( "#CRS: " ) )
QgsCoordinateReferenceSystem destinationCrs;
if ( line.contains( QLatin1String( "#CRS: " ) ) )
{
proj = QgsCoordinateReferenceSystem( line.remove( "#CRS: " ) );
destinationCrs = QgsCoordinateReferenceSystem( line.remove( QStringLiteral( "#CRS: " ) ) );
line = points.readLine();
}
else
proj = QgsProject::instance()->crs();
destinationCrs = QgsProject::instance()->crs();

while ( !points.atEnd() )
{
Expand Down
12 changes: 11 additions & 1 deletion src/app/georeferencer/qgsgeorefmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
void linkQGisToGeoref( bool link );

// gcps

/**
* Adds a new reference point.
* \param sourceCoords MUST be in source layer coordinates, e.g. if source is already georeferenced then it is in layer coordinates NOT pixels
* \param destinationMapCoords
* \param destinationCrs
* \param enable
* \param finalize
*/
void addPoint( const QgsPointXY &sourceCoords, const QgsPointXY &destinationMapCoords,
const QgsCoordinateReferenceSystem &destinationCrs, bool enable = true, bool finalize = true );

void deleteDataPoint( QPoint pixelCoords );
void deleteDataPoint( int index );
void showCoordDialog( const QgsPointXY &pixelCoords );
void showCoordDialog( const QgsPointXY &sourceCoordinates );

void selectPoint( QPoint );
void movePoint( QPoint canvasPixels );
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgeoreftooladdpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QgsGeorefToolAddPoint : public QgsMapToolEmitPoint
void canvasPressEvent( QgsMapMouseEvent *e ) override;

signals:
void showCoordDialog( const QgsPointXY & );
void showCoordDialog( const QgsPointXY &sourceCoordinates );
};

#endif // QGSGEOREFTOOLADDPOINT_H
6 changes: 3 additions & 3 deletions src/app/georeferencer/qgsmapcoordsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
#include "qgsproject.h"
#include "qgsgcpcanvasitem.h"

QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &pixelCoords, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent )
QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &sourceLayerCoordinates, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent )
: QDialog( parent, Qt::Dialog )
, mQgisCanvas( qgisCanvas )
, mRasterCrs( rasterCrs )
, mPixelCoords( pixelCoords )
, mSourceLayerCoordinates( sourceLayerCoordinates )
{
setupUi( this );
QgsGui::enableAutoGeometryRestore( this );
Expand Down Expand Up @@ -103,7 +103,7 @@ void QgsMapCoordsDialog::buttonBox_accepted()
if ( !ok )
y = dmsToDD( leYCoord->text() );

emit pointAdded( mPixelCoords, QgsPointXY( x, y ), mProjectionSelector->crs().isValid() ? mProjectionSelector->crs() : mRasterCrs );
emit pointAdded( mSourceLayerCoordinates, QgsPointXY( x, y ), mProjectionSelector->crs().isValid() ? mProjectionSelector->crs() : mRasterCrs );
close();
}

Expand Down
22 changes: 19 additions & 3 deletions src/app/georeferencer/qgsmapcoordsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase
Q_OBJECT

public:
QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &pixelCoords, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent = nullptr );

/**
* Constructor for QgsMapCoordsDialog.
* \param qgisCanvas
* \param sourceCoordinates must be in source layer coordinates, NOT pixels (unless source image is completely non-referenced)!
* \param rasterCrs
* \param parent
*/
QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &sourceCoordinates, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent = nullptr );
~QgsMapCoordsDialog() override;

private slots:
Expand All @@ -73,7 +81,14 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase
void setPrevTool();

signals:
void pointAdded( const QgsPointXY &a, const QgsPointXY &destination, const QgsCoordinateReferenceSystem &destinationCrs );

/**
* Emitted when a point should be added through the dialog.
* \param sourceCoordinate source point, which MUST be in source layer coordinates not pixels
* \param destinationCoordinate
* \param destinationCrs
*/
void pointAdded( const QgsPointXY &sourceCoordinate, const QgsPointXY &destinationCoordinate, const QgsCoordinateReferenceSystem &destinationCrs );

private:
double dmsToDD( const QString &dms );
Expand All @@ -90,7 +105,8 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase

QgsCoordinateReferenceSystem mRasterCrs;

QgsPointXY mPixelCoords;
//! Source layer coordinates -- must be in source layer coordinates, not pixels (unless source image is completely non-referenced)
QgsPointXY mSourceLayerCoordinates;
};

#endif

0 comments on commit 10457a9

Please sign in to comment.