Skip to content
Permalink
Browse files
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/qgis@13962 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Jul 25, 2010
1 parent 82d17fe commit 13144193d0667fba9ad18a8d455c7494149f9d47
@@ -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();
}
@@ -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; }
@@ -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:
@@ -86,6 +86,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
, mLayer( 0 )
, mAgainAddRaster ( false )
, mMovingPoint( 0 )
, mMovingPointQgis ( 0 )
, mMapCoordsDialog( 0 )
, mUseZeroForTrans( false )
, mLoadInQgis( false )
@@ -153,6 +154,7 @@ QgsGeorefPluginGui::~QgsGeorefPluginGui()
delete mToolAddPoint;
delete mToolDeletePoint;
delete mToolMovePoint;
delete mToolMovePointQgis;

}

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

// View slots
@@ -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 );
@@ -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 )
@@ -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();
@@ -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;
@@ -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"

@@ -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() );
@@ -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
@@ -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 );

0 comments on commit 1314419

Please sign in to comment.