From c5f26f41db379332faf4642159e6e55d2bf79cc9 Mon Sep 17 00:00:00 2001 From: uclaros Date: Thu, 4 Jul 2024 12:26:47 +0300 Subject: [PATCH 1/4] fix newly added points preview when zooming/panning --- src/app/georeferencer/qgsgcpcanvasitem.cpp | 6 ++++- src/app/georeferencer/qgsgeorefdatapoint.cpp | 5 ++++ src/app/georeferencer/qgsgeorefmainwindow.cpp | 27 ++++++++++--------- src/app/georeferencer/qgsgeorefmainwindow.h | 3 +-- src/app/georeferencer/qgsmapcoordsdialog.cpp | 25 ++++++++--------- src/app/georeferencer/qgsmapcoordsdialog.h | 15 ++++++----- 6 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/app/georeferencer/qgsgcpcanvasitem.cpp b/src/app/georeferencer/qgsgcpcanvasitem.cpp index 2175d0f97454..c8d541cb4b8f 100644 --- a/src/app/georeferencer/qgsgcpcanvasitem.cpp +++ b/src/app/georeferencer/qgsgcpcanvasitem.cpp @@ -25,7 +25,7 @@ QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas *mapCanvas, QgsGeorefDataPoint *dataPoint, bool isGCPSource ) : QgsMapCanvasItem( mapCanvas ) , mDataPoint( dataPoint ) - , mPointBrush( Qt::red ) + , mPointBrush( mDataPoint && mDataPoint->id() < 0 ? QColor( 0, 200, 0 ) : Qt::red ) , mLabelBrush( Qt::yellow ) , mIsGCPSource( isGCPSource ) { @@ -64,6 +64,10 @@ void QgsGCPCanvasItem::paint( QPainter *p ) p->setBrush( mPointBrush ); p->drawEllipse( -2, -2, 5, 5 ); + // Don't draw point tip for temporary points + if ( id < 0 ) + return; + const QgsSettings s; const bool showIDs = s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/ShowId" ) ).toBool(); const bool showCoords = s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/ShowCoords" ) ).toBool(); diff --git a/src/app/georeferencer/qgsgeorefdatapoint.cpp b/src/app/georeferencer/qgsgeorefdatapoint.cpp index b417bed5d579..b42b013885d2 100644 --- a/src/app/georeferencer/qgsgeorefdatapoint.cpp +++ b/src/app/georeferencer/qgsgeorefdatapoint.cpp @@ -92,13 +92,18 @@ void QgsGeorefDataPoint::setEnabled( bool enabled ) void QgsGeorefDataPoint::setId( int id ) { + const bool noLongerTemporary = mId < 0 && id >= 0; mId = id; if ( mGCPSourceItem ) { + if ( noLongerTemporary ) + mGCPSourceItem->setPointColor( Qt::red ); mGCPSourceItem->update(); } if ( mGCPDestinationItem ) { + if ( noLongerTemporary ) + mGCPDestinationItem->setPointColor( Qt::red ); mGCPDestinationItem->update(); } } diff --git a/src/app/georeferencer/qgsgeorefmainwindow.cpp b/src/app/georeferencer/qgsgeorefmainwindow.cpp index 0f425e13eb30..cc2176cff46c 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.cpp +++ b/src/app/georeferencer/qgsgeorefmainwindow.cpp @@ -764,29 +764,32 @@ void QgsGeoreferencerMainWindow::releasePoint( QPoint p ) void QgsGeoreferencerMainWindow::showCoordDialog( const QgsPointXY &sourceCoordinates ) { - delete mNewlyAddedPointItem; - mNewlyAddedPointItem = nullptr; + if ( !mLayer ) + return; // 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( sourceCoordinates ) ); + QgsCoordinateReferenceSystem lastProjection = mLastGCPProjection.isValid() ? mLastGCPProjection : mTargetCrs; - if ( mLayer && !mMapCoordsDialog ) + if ( !mMapCoordsDialog ) { - mMapCoordsDialog = new QgsMapCoordsDialog( QgisApp::instance()->mapCanvas(), sourceCoordinates, lastProjection, this ); + mNewlyAddedPoint = new QgsGeorefDataPoint( mCanvas, QgisApp::instance()->mapCanvas(), sourceCoordinates, QgsPointXY(), QgsCoordinateReferenceSystem(), true ); + mMapCoordsDialog = new QgsMapCoordsDialog( QgisApp::instance()->mapCanvas(), mNewlyAddedPoint, lastProjection, this ); connect( mMapCoordsDialog, &QgsMapCoordsDialog::pointAdded, this, [ = ]( const QgsPointXY & sourceLayerCoordinate, const QgsPointXY & destinationCoordinate, const QgsCoordinateReferenceSystem & destinationCrs ) { addPoint( sourceLayerCoordinate, destinationCoordinate, destinationCrs ); } ); connect( mMapCoordsDialog, &QObject::destroyed, this, [ = ] { - delete mNewlyAddedPointItem; - mNewlyAddedPointItem = nullptr; + delete mNewlyAddedPoint; + mNewlyAddedPoint = nullptr; } ); - mMapCoordsDialog->show(); } + else + { + mMapCoordsDialog->updateSourceCoordinates( sourceCoordinates ); + } + mMapCoordsDialog->show(); } void QgsGeoreferencerMainWindow::loadGCPsDialog() @@ -2483,8 +2486,8 @@ void QgsGeoreferencerMainWindow::clearGCPData() mPoints.clear(); mGCPListWidget->setGCPList( &mPoints ); - delete mNewlyAddedPointItem; - mNewlyAddedPointItem = nullptr; + delete mNewlyAddedPoint; + mNewlyAddedPoint = nullptr; QgisApp::instance()->mapCanvas()->refresh(); } diff --git a/src/app/georeferencer/qgsgeorefmainwindow.h b/src/app/georeferencer/qgsgeorefmainwindow.h index 99d31d78715a..56298c23033e 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.h +++ b/src/app/georeferencer/qgsgeorefmainwindow.h @@ -285,10 +285,9 @@ class APP_EXPORT QgsGeoreferencerMainWindow : public QMainWindow, private Ui::Qg QgsGeorefToolMovePoint *mToolMovePoint = nullptr; QgsGeorefToolMovePoint *mToolMovePointQgis = nullptr; - QgsGCPCanvasItem *mNewlyAddedPointItem = nullptr; - QgsGeorefDataPoint *mMovingPoint = nullptr; QgsGeorefDataPoint *mMovingPointQgis = nullptr; + QgsGeorefDataPoint *mNewlyAddedPoint = nullptr; QPointer mMapCoordsDialog; bool mUseZeroForTrans = false; diff --git a/src/app/georeferencer/qgsmapcoordsdialog.cpp b/src/app/georeferencer/qgsmapcoordsdialog.cpp index cc522b569160..96478be70085 100644 --- a/src/app/georeferencer/qgsmapcoordsdialog.cpp +++ b/src/app/georeferencer/qgsmapcoordsdialog.cpp @@ -24,13 +24,13 @@ #include "qgsapplication.h" #include "qgsprojectionselectionwidget.h" #include "qgsproject.h" -#include "qgsgcpcanvasitem.h" +#include "qgsgeorefdatapoint.h"" -QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &sourceLayerCoordinates, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent ) +QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, QgsGeorefDataPoint *georefDataPoint, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent ) : QDialog( parent, Qt::Dialog ) , mQgisCanvas( qgisCanvas ) , mRasterCrs( rasterCrs ) - , mSourceLayerCoordinates( sourceLayerCoordinates ) + , mNewlyAddedPoint( georefDataPoint ) { setupUi( this ); QgsGui::enableAutoGeometryRestore( this ); @@ -73,9 +73,6 @@ QgsMapCoordsDialog::~QgsMapCoordsDialog() { delete mToolEmitPoint; - delete mNewlyAddedPointItem; - mNewlyAddedPointItem = nullptr; - QgsSettings settings; settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/Config/Minimize" ), mMinimizeWindowCheckBox->isChecked() ); } @@ -103,7 +100,7 @@ void QgsMapCoordsDialog::buttonBox_accepted() if ( !ok ) y = dmsToDD( leYCoord->text() ); - emit pointAdded( mSourceLayerCoordinates, QgsPointXY( x, y ), mProjectionSelector->crs().isValid() ? mProjectionSelector->crs() : mRasterCrs ); + emit pointAdded( mNewlyAddedPoint->sourcePoint(), QgsPointXY( x, y ), mProjectionSelector->crs().isValid() ? mProjectionSelector->crs() : mRasterCrs ); close(); } @@ -119,13 +116,7 @@ void QgsMapCoordsDialog::maybeSetXY( const QgsPointXY &xy, Qt::MouseButton butto leXCoord->setText( qgsDoubleToString( mapCoordPoint.x() ) ); leYCoord->setText( qgsDoubleToString( mapCoordPoint.y() ) ); - delete mNewlyAddedPointItem; - mNewlyAddedPointItem = nullptr; - - // show a temporary marker at the clicked source point - mNewlyAddedPointItem = new QgsGCPCanvasItem( mQgisCanvas, nullptr, true ); - mNewlyAddedPointItem->setPointColor( QColor( 0, 200, 0 ) ); - mNewlyAddedPointItem->setPos( mNewlyAddedPointItem->toCanvasCoordinates( mapCoordPoint ) ); + mNewlyAddedPoint->setDestinationPoint( mapCoordPoint ); } // only restore window if it was minimized @@ -185,6 +176,12 @@ double QgsMapCoordsDialog::dmsToDD( const QString &dms ) return res; } +void QgsMapCoordsDialog::updateSourceCoordinates( const QgsPointXY &sourceCoordinates ) +{ + mNewlyAddedPoint->setSourcePoint( sourceCoordinates ); +} + + QgsGeorefMapToolEmitPoint::QgsGeorefMapToolEmitPoint( QgsMapCanvas *canvas ) : QgsMapTool( canvas ) { diff --git a/src/app/georeferencer/qgsmapcoordsdialog.h b/src/app/georeferencer/qgsmapcoordsdialog.h index e72ba08ade36..dd9ff0c47e87 100644 --- a/src/app/georeferencer/qgsmapcoordsdialog.h +++ b/src/app/georeferencer/qgsmapcoordsdialog.h @@ -25,7 +25,7 @@ #include "ui_qgsmapcoordsdialogbase.h" -class QgsGCPCanvasItem; +class QgsGeorefDataPoint; class QPushButton; @@ -64,13 +64,16 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase /** * Constructor for QgsMapCoordsDialog. * \param qgisCanvas - * \param sourceCoordinates must be in source layer coordinates, NOT pixels (unless source image is completely non-referenced)! + * \param georefDataPoint Temporary data point used for preview on source and destination canvases while dialog is visible * \param rasterCrs * \param parent */ - QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &sourceCoordinates, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent = nullptr ); + QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, QgsGeorefDataPoint *georefDataPoint, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent = nullptr ); ~QgsMapCoordsDialog() override; + //! Update the source coordinates of the newly added + void updateSourceCoordinates( const QgsPointXY &sourceCoordinates ); + private slots: void buttonBox_accepted(); @@ -101,12 +104,10 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase QgsMapTool *mPrevMapTool = nullptr; QgsMapCanvas *mQgisCanvas = nullptr; - QgsGCPCanvasItem *mNewlyAddedPointItem = nullptr; - QgsCoordinateReferenceSystem mRasterCrs; - //! Source layer coordinates -- must be in source layer coordinates, not pixels (unless source image is completely non-referenced) - QgsPointXY mSourceLayerCoordinates; + //! Used for point preview. Holds the source layer coordinates -- must be in source layer coordinates, not pixels (unless source image is completely non-referenced) + QgsGeorefDataPoint *mNewlyAddedPoint = nullptr; }; #endif From c8b26244831bc9f29a12159b19ecd263e476ee5c Mon Sep 17 00:00:00 2001 From: uclaros Date: Thu, 4 Jul 2024 12:45:51 +0300 Subject: [PATCH 2/4] preview residuals while moving points --- src/app/georeferencer/qgsgeorefmainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/georeferencer/qgsgeorefmainwindow.cpp b/src/app/georeferencer/qgsgeorefmainwindow.cpp index cc2176cff46c..29fd57c6afbf 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.cpp +++ b/src/app/georeferencer/qgsgeorefmainwindow.cpp @@ -744,6 +744,7 @@ void QgsGeoreferencerMainWindow::movePoint( QPoint canvasPixels ) if ( mvPoint ) { mvPoint->moveTo( canvasPixels, pointType ); + mGCPListWidget->updateResiduals(); } } From 7a2295ea90e1929e67aa30f54ec3d4e23cef61cf Mon Sep 17 00:00:00 2001 From: uclaros Date: Thu, 4 Jul 2024 16:39:55 +0300 Subject: [PATCH 3/4] tidy up includes --- src/app/georeferencer/qgsgcpcanvasitem.cpp | 1 + src/app/georeferencer/qgsgcpcanvasitem.h | 5 ++++- src/app/georeferencer/qgsgeorefmainwindow.cpp | 1 - src/app/georeferencer/qgsgeorefmainwindow.h | 1 - src/app/georeferencer/qgsmapcoordsdialog.cpp | 3 +-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/georeferencer/qgsgcpcanvasitem.cpp b/src/app/georeferencer/qgsgcpcanvasitem.cpp index c8d541cb4b8f..24d9f9c294c3 100644 --- a/src/app/georeferencer/qgsgcpcanvasitem.cpp +++ b/src/app/georeferencer/qgsgcpcanvasitem.cpp @@ -14,6 +14,7 @@ ***************************************************************************/ #include "qgsgcpcanvasitem.h" +#include "qgsmapcanvas.h" #include "qgsgeorefdatapoint.h" #include "qgsproject.h" #include "qgsrasterlayer.h" diff --git a/src/app/georeferencer/qgsgcpcanvasitem.h b/src/app/georeferencer/qgsgcpcanvasitem.h index e814938ad6fd..e8f6473882b6 100644 --- a/src/app/georeferencer/qgsgcpcanvasitem.h +++ b/src/app/georeferencer/qgsgcpcanvasitem.h @@ -16,9 +16,12 @@ #ifndef QGSGCPCANVASITEM_H #define QGSGCPCANVASITEM_H -#include "qgsmapcanvas.h" +#include +#include + #include "qgsmapcanvasitem.h" +class QgsMapCanvas; class QgsGeorefDataPoint; class QgsGCPCanvasItem : public QgsMapCanvasItem diff --git a/src/app/georeferencer/qgsgeorefmainwindow.cpp b/src/app/georeferencer/qgsgeorefmainwindow.cpp index 29fd57c6afbf..837781b2dae7 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.cpp +++ b/src/app/georeferencer/qgsgeorefmainwindow.cpp @@ -55,7 +55,6 @@ #include "qgsgeoreftooladdpoint.h" #include "qgsgeoreftooldeletepoint.h" #include "qgsgeoreftoolmovepoint.h" -#include "qgsgcpcanvasitem.h" #include "qgscoordinateutils.h" #include "qgsgcplistwidget.h" diff --git a/src/app/georeferencer/qgsgeorefmainwindow.h b/src/app/georeferencer/qgsgeorefmainwindow.h index 56298c23033e..eea426053e92 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.h +++ b/src/app/georeferencer/qgsgeorefmainwindow.h @@ -45,7 +45,6 @@ class QgsGeorefToolAddPoint; class QgsGeorefToolDeletePoint; class QgsGeorefToolMovePoint; class QgsGeorefToolMovePoint; -class QgsGCPCanvasItem; class QgsGcpPoint; class QgsMapLayer; class QgsScreenHelper; diff --git a/src/app/georeferencer/qgsmapcoordsdialog.cpp b/src/app/georeferencer/qgsmapcoordsdialog.cpp index 96478be70085..0fcdf35186fe 100644 --- a/src/app/georeferencer/qgsmapcoordsdialog.cpp +++ b/src/app/georeferencer/qgsmapcoordsdialog.cpp @@ -23,8 +23,7 @@ #include "qgsgui.h" #include "qgsapplication.h" #include "qgsprojectionselectionwidget.h" -#include "qgsproject.h" -#include "qgsgeorefdatapoint.h"" +#include "qgsgeorefdatapoint.h" QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, QgsGeorefDataPoint *georefDataPoint, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent ) : QDialog( parent, Qt::Dialog ) From 62551be689e89bb76ba2c37664cce37245e665a5 Mon Sep 17 00:00:00 2001 From: uclaros Date: Thu, 4 Jul 2024 20:27:57 +0300 Subject: [PATCH 4/4] clang-tidy --- src/app/georeferencer/qgsgcpcanvasitem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/georeferencer/qgsgcpcanvasitem.h b/src/app/georeferencer/qgsgcpcanvasitem.h index e8f6473882b6..4a7b12ee5393 100644 --- a/src/app/georeferencer/qgsgcpcanvasitem.h +++ b/src/app/georeferencer/qgsgcpcanvasitem.h @@ -24,7 +24,7 @@ class QgsMapCanvas; class QgsGeorefDataPoint; -class QgsGCPCanvasItem : public QgsMapCanvasItem +class QgsGCPCanvasItem final: public QgsMapCanvasItem { public: QgsGCPCanvasItem( QgsMapCanvas *mapCanvas, QgsGeorefDataPoint *dataPoint, bool isGCPSource/* = true*/ );