Skip to content

Commit 621698f

Browse files
author
mmassing
committed
Patch by Luiz Motta: adds the ability to move GCPs in the qgis canvas (partial commit of #2890). Thanks.
git-svn-id: http://svn.osgeo.org/qgis/trunk@13962 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent cd1cd21 commit 621698f

6 files changed

+82
-16
lines changed

src/plugins/georeferencer/qgsgeorefdatapoint.cpp

+24-6
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,33 @@ void QgsGeorefDataPoint::updateCoords()
122122
}
123123
}
124124

125-
bool QgsGeorefDataPoint::contains( const QPoint &p )
125+
bool QgsGeorefDataPoint::contains( const QPoint &p, bool isMapPlugin )
126126
{
127-
QPointF pnt = mGCPSourceItem->mapFromScene( p );
128-
return mGCPSourceItem->shape().contains( pnt );
127+
if ( isMapPlugin )
128+
{
129+
QPointF pnt = mGCPSourceItem->mapFromScene( p );
130+
return mGCPSourceItem->shape().contains( pnt );
131+
}
132+
else
133+
{
134+
QPointF pnt = mGCPDestinationItem->mapFromScene( p );
135+
return mGCPDestinationItem->shape().contains( pnt );
136+
}
129137
}
130138

131-
void QgsGeorefDataPoint::moveTo( const QPoint &p )
139+
void QgsGeorefDataPoint::moveTo( const QPoint &p, bool isMapPlugin )
132140
{
133-
QgsPoint pnt = mGCPSourceItem->toMapCoordinates( p );
134-
setPixelCoords( pnt );
141+
if ( isMapPlugin )
142+
{
143+
QgsPoint pnt = mGCPSourceItem->toMapCoordinates( p );
144+
mPixelCoords = pnt;
145+
}
146+
else
147+
{
148+
QgsPoint pnt = mGCPDestinationItem->toMapCoordinates( p );
149+
mMapCoords = pnt;
150+
}
151+
mGCPSourceItem->update();
152+
mGCPDestinationItem->update();
135153
updateCoords();
136154
}

src/plugins/georeferencer/qgsgeorefdatapoint.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QgsGeorefDataPoint : public QObject
4646
int id() const { return mId; }
4747
void setId( int id );
4848

49-
bool contains( const QPoint &p );
49+
bool contains( const QPoint &p, bool isMapPlugin );
5050

5151
QgsMapCanvas *srcCanvas() const { return mSrcCanvas; }
5252
QgsMapCanvas *dstCanvas() const { return mDstCanvas; }
@@ -55,7 +55,7 @@ class QgsGeorefDataPoint : public QObject
5555
void setResidual( const QPointF& r );
5656

5757
public slots:
58-
void moveTo( const QPoint & );
58+
void moveTo( const QPoint &, bool isMapPlugin );
5959
void updateCoords();
6060

6161
private:

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+45-6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
8686
, mLayer( 0 )
8787
, mAgainAddRaster ( false )
8888
, mMovingPoint( 0 )
89+
, mMovingPointQgis ( 0 )
8990
, mMapCoordsDialog( 0 )
9091
, mUseZeroForTrans( false )
9192
, mLoadInQgis( false )
@@ -153,6 +154,7 @@ QgsGeorefPluginGui::~QgsGeorefPluginGui()
153154
delete mToolAddPoint;
154155
delete mToolDeletePoint;
155156
delete mToolMovePoint;
157+
delete mToolMovePointQgis;
156158

157159
}
158160

@@ -382,6 +384,7 @@ void QgsGeorefPluginGui::setDeletePointTool()
382384
void QgsGeorefPluginGui::setMovePointTool()
383385
{
384386
mCanvas->setMapTool( mToolMovePoint );
387+
mIface->mapCanvas()->setMapTool( mToolMovePointQgis );
385388
}
386389

387390
// View slots
@@ -478,7 +481,7 @@ void QgsGeorefPluginGui::deleteDataPoint( const QPoint &coords )
478481
for ( QgsGCPList::iterator it = mPoints.begin(); it != mPoints.end(); ++it )
479482
{
480483
QgsGeorefDataPoint* pt = *it;
481-
if ( /*pt->pixelCoords() == coords ||*/ pt->contains( coords ) ) // first operand for removing from GCP table
484+
if ( /*pt->pixelCoords() == coords ||*/ pt->contains( coords, true ) ) // first operand for removing from GCP table
482485
{
483486
int row = mPoints.indexOf( *it );
484487
mGCPListWidget->model()->removeRow( row );
@@ -507,28 +510,54 @@ void QgsGeorefPluginGui::deleteDataPoint( int index )
507510

508511
void QgsGeorefPluginGui::selectPoint( const QPoint &p )
509512
{
513+
// Get Map Sender
514+
QObject *tool = sender();
515+
if ( tool == 0)
516+
{
517+
return;
518+
}
519+
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
520+
510521
for ( QgsGCPList::iterator it = mPoints.begin(); it != mPoints.end(); ++it )
511522
{
512-
if (( *it )->contains( p ) )
523+
if ( ( *it )->contains( p, isMapPlugin ) )
513524
{
514-
mMovingPoint = *it;
525+
isMapPlugin ? mMovingPoint = *it : mMovingPointQgis = *it;
515526
break;
516527
}
517528
}
529+
518530
}
519531

520532
void QgsGeorefPluginGui::movePoint( const QPoint &p )
521533
{
522-
if ( mMovingPoint )
534+
// Get Map Sender
535+
QObject *tool = sender();
536+
if ( tool == 0)
537+
{
538+
return;
539+
}
540+
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
541+
QgsGeorefDataPoint *mvPoint = (isMapPlugin ? mMovingPoint : mMovingPointQgis);
542+
543+
if ( mvPoint )
523544
{
524-
mMovingPoint->moveTo( p );
545+
mvPoint->moveTo( p, isMapPlugin );
525546
mGCPListWidget->updateGCPList();
526547
}
548+
527549
}
528550

529551
void QgsGeorefPluginGui::releasePoint( const QPoint &p )
530552
{
531-
mMovingPoint = 0;
553+
// Get Map Sender
554+
QObject *tool = sender();
555+
if ( tool == 0)
556+
{
557+
return;
558+
}
559+
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
560+
isMapPlugin ? mMovingPoint = 0 : mMovingPointQgis = 0;
532561
}
533562

534563
void QgsGeorefPluginGui::showCoordDialog( const QgsPoint &pixelCoords )
@@ -894,6 +923,16 @@ void QgsGeorefPluginGui::createMapCanvas()
894923
connect( mToolMovePoint, SIGNAL( pointReleased( const QPoint & ) ),
895924
this, SLOT( releasePoint( const QPoint & ) ) );
896925

926+
// Point in Qgis Map
927+
mToolMovePointQgis = new QgsGeorefToolMovePoint( mIface->mapCanvas() );
928+
mToolMovePointQgis->setAction( mActionMoveGCPPoint );
929+
connect( mToolMovePointQgis, SIGNAL( pointPressed( const QPoint & ) ),
930+
this, SLOT( selectPoint( const QPoint & ) ) );
931+
connect( mToolMovePointQgis, SIGNAL( pointMoved( const QPoint & ) ),
932+
this, SLOT( movePoint( const QPoint & ) ) );
933+
connect( mToolMovePointQgis, SIGNAL( pointReleased( const QPoint & ) ),
934+
this, SLOT( releasePoint( const QPoint & ) ) );
935+
897936
QSettings s;
898937
int action = s.value( "/qgis/wheel_action", 0 ).toInt();
899938
double zoomFactor = s.value( "/qgis/zoom_factor", 2 ).toDouble();

src/plugins/georeferencer/qgsgeorefplugingui.h

+2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
222222
QgsMapTool *mToolAddPoint;
223223
QgsMapTool *mToolDeletePoint;
224224
QgsMapTool *mToolMovePoint;
225+
QgsMapTool *mToolMovePointQgis;
225226

226227
QgsGeorefDataPoint *mMovingPoint;
228+
QgsGeorefDataPoint *mMovingPointQgis;
227229
QPointer<QgsMapCoordsDialog> mMapCoordsDialog;
228230

229231
bool mUseZeroForTrans;

src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15-
/* $Id$ */
15+
/* $Id: qgsgeoreftoolmovepoint.cpp 13187 2010-03-28 22:14:44Z jef $ */
1616

1717
#include "qgsmapcanvas.h"
1818

@@ -33,6 +33,11 @@ void QgsGeorefToolMovePoint::canvasPressEvent( QMouseEvent *e )
3333
}
3434
}
3535

36+
bool QgsGeorefToolMovePoint::isCanvas(QgsMapCanvas *canvas)
37+
{
38+
return (mCanvas == canvas);
39+
}
40+
3641
void QgsGeorefToolMovePoint::canvasMoveEvent( QMouseEvent *e )
3742
{
3843
emit pointMoved( e->pos() );

src/plugins/georeferencer/qgsgeoreftoolmovepoint.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15-
/* $Id$ */
15+
/* $Id: qgsgeoreftoolmovepoint.h 13187 2010-03-28 22:14:44Z jef $ */
1616

1717
#ifndef QGSGEOREFTOOLMOVEPOINT_H
1818
#define QGSGEOREFTOOLMOVEPOINT_H
@@ -34,6 +34,8 @@ class QgsGeorefToolMovePoint : public QgsMapTool
3434
void canvasMoveEvent( QMouseEvent *e );
3535
void canvasReleaseEvent( QMouseEvent *e );
3636

37+
bool isCanvas(QgsMapCanvas *);
38+
3739
signals:
3840
void pointPressed( const QPoint &p );
3941
void pointMoved( const QPoint &p );

0 commit comments

Comments
 (0)