Skip to content
Permalink
Browse files

[georeferencer] Show a temporary marker at the clicked point after ad…

…ding a point,

while the dialog for entering the map coordinates is open

This allows users to see the raster point they clicked while they search
the map canvas for the corresponding point. Helps for people like me
with goldfish memories who forget where they clicked on the raster
and are trying to locate!
  • Loading branch information
nyalldawson committed Feb 19, 2021
1 parent c67e29a commit a4349acf8b7e1fcfc852bc65279aded877d97632
@@ -223,6 +223,11 @@ void QgsGCPCanvasItem::checkBoundingRectChange()
prepareGeometryChange();
}

void QgsGCPCanvasItem::setPointColor( const QColor &color )
{
mPointBrush.setColor( color );
}

double QgsGCPCanvasItem::fontSizePainterUnits( double points, const QgsRenderContext &c )
{
return points * 0.3527 * c.scaleFactor();
@@ -41,6 +41,8 @@ class QgsGCPCanvasItem : public QgsMapCanvasItem

QgsMapCanvas *canvas() const { return mMapCanvas; }

void setPointColor( const QColor &color );

private:

QgsGeorefDataPoint *mDataPoint = nullptr;
@@ -57,6 +57,7 @@
#include "qgsgeoreftooladdpoint.h"
#include "qgsgeoreftooldeletepoint.h"
#include "qgsgeoreftoolmovepoint.h"
#include "qgsgcpcanvasitem.h"

#include "qgsleastsquares.h"
#include "qgsgcplistwidget.h"
@@ -627,6 +628,13 @@ void QgsGeoreferencerMainWindow::releasePoint( QPoint p )

void QgsGeoreferencerMainWindow::showCoordDialog( const QgsPointXY &pixelCoords )
{
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 ) );

QgsCoordinateReferenceSystem lastProjection = mLastGCPProjection.isValid() ? mLastGCPProjection : mProjection;
if ( mLayer && !mMapCoordsDialog )
@@ -636,6 +644,11 @@ void QgsGeoreferencerMainWindow::showCoordDialog( const QgsPointXY &pixelCoords
{
addPoint( a, b, crs );
} );
connect( mMapCoordsDialog, &QObject::destroyed, this, [ = ]
{
delete mNewlyAddedPointItem;
mNewlyAddedPointItem = nullptr;
} );
mMapCoordsDialog->show();
}
}
@@ -2188,6 +2201,9 @@ void QgsGeoreferencerMainWindow::clearGCPData()
mPoints.clear();
mGCPListWidget->updateGCPList();

delete mNewlyAddedPointItem;
mNewlyAddedPointItem = nullptr;

QgisApp::instance()->mapCanvas()->refresh();
}

@@ -44,6 +44,7 @@ class QgsGeorefToolAddPoint;
class QgsGeorefToolDeletePoint;
class QgsGeorefToolMovePoint;
class QgsGeorefToolMovePoint;
class QgsGCPCanvasItem;

class QgsGeorefDockWidget : public QgsDockWidget
{
@@ -248,6 +249,8 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
QgsGeorefToolMovePoint *mToolMovePoint = nullptr;
QgsGeorefToolMovePoint *mToolMovePointQgis = nullptr;

QgsGCPCanvasItem *mNewlyAddedPointItem = nullptr;

QgsGeorefDataPoint *mMovingPoint = nullptr;
QgsGeorefDataPoint *mMovingPointQgis = nullptr;
QPointer<QgsMapCoordsDialog> mMapCoordsDialog;
@@ -24,6 +24,7 @@
#include "qgsapplication.h"
#include "qgsprojectionselectionwidget.h"
#include "qgsproject.h"
#include "qgsgcpcanvasitem.h"

QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas *qgisCanvas, const QgsPointXY &pixelCoords, QgsCoordinateReferenceSystem &rasterCrs, QWidget *parent )
: QDialog( parent, Qt::Dialog )
@@ -72,6 +73,9 @@ QgsMapCoordsDialog::~QgsMapCoordsDialog()
{
delete mToolEmitPoint;

delete mNewlyAddedPointItem;
mNewlyAddedPointItem = nullptr;

QgsSettings settings;
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/Config/Minimize" ), mMinimizeWindowCheckBox->isChecked() );
}
@@ -114,6 +118,14 @@ void QgsMapCoordsDialog::maybeSetXY( const QgsPointXY &xy, Qt::MouseButton butto
leYCoord->clear();
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 ) );
}

// only restore window if it was minimized
@@ -23,9 +23,10 @@
#include "qgsprojectionselectionwidget.h"
#include "qgscoordinatereferencesystem.h"


#include "ui_qgsmapcoordsdialogbase.h"

class QgsGCPCanvasItem;

class QPushButton;

class QgsGeorefMapToolEmitPoint : public QgsMapTool
@@ -85,6 +86,8 @@ class QgsMapCoordsDialog : public QDialog, private Ui::QgsMapCoordsDialogBase
QgsMapTool *mPrevMapTool = nullptr;
QgsMapCanvas *mQgisCanvas = nullptr;

QgsGCPCanvasItem *mNewlyAddedPointItem = nullptr;

QgsCoordinateReferenceSystem mRasterCrs;

QgsPointXY mPixelCoords;

0 comments on commit a4349ac

Please sign in to comment.