Skip to content

Commit

Permalink
Patch by Luiz Motta: adds the ability to move GCPs in the qgis canvas…
Browse files Browse the repository at this point in the history
… (partial commit of #2890). Thanks.

git-svn-id: http://svn.osgeo.org/qgis/trunk@13962 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Jul 25, 2010
1 parent cd1cd21 commit 621698f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
30 changes: 24 additions & 6 deletions src/plugins/georeferencer/qgsgeorefdatapoint.cpp
Expand Up @@ -122,15 +122,33 @@ void QgsGeorefDataPoint::updateCoords()
}
}

bool QgsGeorefDataPoint::contains( const QPoint &p )
bool QgsGeorefDataPoint::contains( const QPoint &p, bool isMapPlugin )
{
QPointF pnt = mGCPSourceItem->mapFromScene( p );
return mGCPSourceItem->shape().contains( pnt );
if ( isMapPlugin )
{
QPointF pnt = mGCPSourceItem->mapFromScene( p );
return mGCPSourceItem->shape().contains( pnt );
}
else
{
QPointF pnt = mGCPDestinationItem->mapFromScene( p );
return mGCPDestinationItem->shape().contains( pnt );
}
}

void QgsGeorefDataPoint::moveTo( const QPoint &p )
void QgsGeorefDataPoint::moveTo( const QPoint &p, bool isMapPlugin )
{
QgsPoint pnt = mGCPSourceItem->toMapCoordinates( p );
setPixelCoords( pnt );
if ( isMapPlugin )
{
QgsPoint pnt = mGCPSourceItem->toMapCoordinates( p );
mPixelCoords = pnt;
}
else
{
QgsPoint pnt = mGCPDestinationItem->toMapCoordinates( p );
mMapCoords = pnt;
}
mGCPSourceItem->update();
mGCPDestinationItem->update();
updateCoords();
}
4 changes: 2 additions & 2 deletions src/plugins/georeferencer/qgsgeorefdatapoint.h
Expand Up @@ -46,7 +46,7 @@ class QgsGeorefDataPoint : public QObject
int id() const { return mId; }
void setId( int id );

bool contains( const QPoint &p );
bool contains( const QPoint &p, bool isMapPlugin );

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

public slots:
void moveTo( const QPoint & );
void moveTo( const QPoint &, bool isMapPlugin );
void updateCoords();

private:
Expand Down
51 changes: 45 additions & 6 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -86,6 +86,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
, mLayer( 0 )
, mAgainAddRaster ( false )
, mMovingPoint( 0 )
, mMovingPointQgis ( 0 )
, mMapCoordsDialog( 0 )
, mUseZeroForTrans( false )
, mLoadInQgis( false )
Expand Down Expand Up @@ -153,6 +154,7 @@ QgsGeorefPluginGui::~QgsGeorefPluginGui()
delete mToolAddPoint;
delete mToolDeletePoint;
delete mToolMovePoint;
delete mToolMovePointQgis;

}

Expand Down Expand Up @@ -382,6 +384,7 @@ void QgsGeorefPluginGui::setDeletePointTool()
void QgsGeorefPluginGui::setMovePointTool()
{
mCanvas->setMapTool( mToolMovePoint );
mIface->mapCanvas()->setMapTool( mToolMovePointQgis );
}

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

void QgsGeorefPluginGui::selectPoint( const QPoint &p )
{
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
{
return;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;

for ( QgsGCPList::iterator it = mPoints.begin(); it != mPoints.end(); ++it )
{
if (( *it )->contains( p ) )
if ( ( *it )->contains( p, isMapPlugin ) )
{
mMovingPoint = *it;
isMapPlugin ? mMovingPoint = *it : mMovingPointQgis = *it;
break;
}
}

}

void QgsGeorefPluginGui::movePoint( const QPoint &p )
{
if ( mMovingPoint )
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
{
return;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
QgsGeorefDataPoint *mvPoint = (isMapPlugin ? mMovingPoint : mMovingPointQgis);

if ( mvPoint )
{
mMovingPoint->moveTo( p );
mvPoint->moveTo( p, isMapPlugin );
mGCPListWidget->updateGCPList();
}

}

void QgsGeorefPluginGui::releasePoint( const QPoint &p )
{
mMovingPoint = 0;
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
{
return;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
isMapPlugin ? mMovingPoint = 0 : mMovingPointQgis = 0;
}

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

// Point in Qgis Map
mToolMovePointQgis = new QgsGeorefToolMovePoint( mIface->mapCanvas() );
mToolMovePointQgis->setAction( mActionMoveGCPPoint );
connect( mToolMovePointQgis, SIGNAL( pointPressed( const QPoint & ) ),
this, SLOT( selectPoint( const QPoint & ) ) );
connect( mToolMovePointQgis, SIGNAL( pointMoved( const QPoint & ) ),
this, SLOT( movePoint( const QPoint & ) ) );
connect( mToolMovePointQgis, SIGNAL( pointReleased( const QPoint & ) ),
this, SLOT( releasePoint( const QPoint & ) ) );

QSettings s;
int action = s.value( "/qgis/wheel_action", 0 ).toInt();
double zoomFactor = s.value( "/qgis/zoom_factor", 2 ).toDouble();
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -222,8 +222,10 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
QgsMapTool *mToolAddPoint;
QgsMapTool *mToolDeletePoint;
QgsMapTool *mToolMovePoint;
QgsMapTool *mToolMovePointQgis;

QgsGeorefDataPoint *mMovingPoint;
QgsGeorefDataPoint *mMovingPointQgis;
QPointer<QgsMapCoordsDialog> mMapCoordsDialog;

bool mUseZeroForTrans;
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp
Expand Up @@ -12,7 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsgeoreftoolmovepoint.cpp 13187 2010-03-28 22:14:44Z jef $ */

#include "qgsmapcanvas.h"

Expand All @@ -33,6 +33,11 @@ void QgsGeorefToolMovePoint::canvasPressEvent( QMouseEvent *e )
}
}

bool QgsGeorefToolMovePoint::isCanvas(QgsMapCanvas *canvas)
{
return (mCanvas == canvas);
}

void QgsGeorefToolMovePoint::canvasMoveEvent( QMouseEvent *e )
{
emit pointMoved( e->pos() );
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/georeferencer/qgsgeoreftoolmovepoint.h
Expand Up @@ -12,7 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsgeoreftoolmovepoint.h 13187 2010-03-28 22:14:44Z jef $ */

#ifndef QGSGEOREFTOOLMOVEPOINT_H
#define QGSGEOREFTOOLMOVEPOINT_H
Expand All @@ -34,6 +34,8 @@ class QgsGeorefToolMovePoint : public QgsMapTool
void canvasMoveEvent( QMouseEvent *e );
void canvasReleaseEvent( QMouseEvent *e );

bool isCanvas(QgsMapCanvas *);

signals:
void pointPressed( const QPoint &p );
void pointMoved( const QPoint &p );
Expand Down

0 comments on commit 621698f

Please sign in to comment.