[QGIS Commit] r13962 - trunk/qgis/src/plugins/georeferencer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Jul 25 11:20:16 EDT 2010


Author: mmassing
Date: 2010-07-25 15:20:16 +0000 (Sun, 25 Jul 2010)
New Revision: 13962

Modified:
   trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.h
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
   trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.h
Log:
Patch by Luiz Motta: adds the ability to move GCPs in the qgis canvas (partial commit of #2890). Thanks.

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.cpp	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.cpp	2010-07-25 15:20:16 UTC (rev 13962)
@@ -122,15 +122,33 @@
   }
 }
 
-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();
 }

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.h	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefdatapoint.h	2010-07-25 15:20:16 UTC (rev 13962)
@@ -46,7 +46,7 @@
     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 @@
     void setResidual( const QPointF& r );
 
   public slots:
-    void moveTo( const QPoint & );
+    void moveTo( const QPoint &, bool isMapPlugin );
     void updateCoords();
 
   private:

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-07-25 15:20:16 UTC (rev 13962)
@@ -86,6 +86,7 @@
     , mLayer( 0 )
     , mAgainAddRaster ( false )
     , mMovingPoint( 0 )
+    , mMovingPointQgis ( 0 )
     , mMapCoordsDialog( 0 )
     , mUseZeroForTrans( false )
     , mLoadInQgis( false )
@@ -153,6 +154,7 @@
   delete mToolAddPoint;
   delete mToolDeletePoint;
   delete mToolMovePoint;
+  delete mToolMovePointQgis;
 
 }
 
@@ -382,6 +384,7 @@
 void QgsGeorefPluginGui::setMovePointTool()
 {
   mCanvas->setMapTool( mToolMovePoint );
+  mIface->mapCanvas()->setMapTool( mToolMovePointQgis );
 }
 
 // View slots
@@ -478,7 +481,7 @@
   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::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)
   {
-    mMovingPoint->moveTo( p );
+    return;
+  }
+  bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
+  QgsGeorefDataPoint *mvPoint = (isMapPlugin ? mMovingPoint : mMovingPointQgis);
+
+  if ( mvPoint )
+  {
+    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 @@
   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();

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-07-25 15:20:16 UTC (rev 13962)
@@ -222,8 +222,10 @@
     QgsMapTool *mToolAddPoint;
     QgsMapTool *mToolDeletePoint;
     QgsMapTool *mToolMovePoint;
+    QgsMapTool *mToolMovePointQgis;
 
     QgsGeorefDataPoint *mMovingPoint;
+    QgsGeorefDataPoint *mMovingPointQgis;
     QPointer<QgsMapCoordsDialog> mMapCoordsDialog;
 
     bool mUseZeroForTrans;

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.cpp	2010-07-25 15:20:16 UTC (rev 13962)
@@ -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 @@
   }
 }
 
+bool QgsGeorefToolMovePoint::isCanvas(QgsMapCanvas *canvas)
+{
+  return (mCanvas == canvas);
+}
+
 void QgsGeorefToolMovePoint::canvasMoveEvent( QMouseEvent *e )
 {
   emit pointMoved( e->pos() );

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.h	2010-07-25 15:20:10 UTC (rev 13961)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeoreftoolmovepoint.h	2010-07-25 15:20:16 UTC (rev 13962)
@@ -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 @@
     void canvasMoveEvent( QMouseEvent *e );
     void canvasReleaseEvent( QMouseEvent *e );
 
+    bool isCanvas(QgsMapCanvas *);
+
   signals:
     void pointPressed( const QPoint &p );
     void pointMoved( const QPoint &p );



More information about the QGIS-commit mailing list