[QGIS Commit] r11573 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 5 15:50:05 EDT 2009


Author: jef
Date: 2009-09-05 15:50:05 -0400 (Sat, 05 Sep 2009)
New Revision: 11573

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
Log:
[FEATURE] recenter map canvas to an entered coordinate

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-09-05 19:49:47 UTC (rev 11572)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-09-05 19:50:05 UTC (rev 11573)
@@ -1473,17 +1473,38 @@
   mToggleExtentsViewButton->setCheckable( true );
   connect( mToggleExtentsViewButton, SIGNAL( toggled( bool ) ), this, SLOT( extentsViewToggled( bool ) ) );
   statusBar()->addPermanentWidget( mToggleExtentsViewButton, 0 );
-  //coords status bar widget
+
+  // add a label to show current scale
   mCoordsLabel = new QLabel( QString(), statusBar() );
+  mCoordsLabel->setFont( myFont );
   mCoordsLabel->setMinimumWidth( 10 );
   mCoordsLabel->setMaximumHeight( 20 );
-  mCoordsLabel->setFont( myFont );
   mCoordsLabel->setMargin( 3 );
   mCoordsLabel->setAlignment( Qt::AlignCenter );
-  mCoordsLabel->setWhatsThis( tr( "Shows the map coordinates at the "
-                                  "current cursor position. The display is continuously updated "
-                                  "as the mouse is moved." ) );
+  mCoordsLabel->setFrameStyle( QFrame::NoFrame );
+  mCoordsLabel->setText( tr( "Coordinate:" ) );
+  mCoordsLabel->setToolTip( tr( "Current map coordinate" ) );
   statusBar()->addPermanentWidget( mCoordsLabel, 0 );
+
+  //coords status bar widget
+  mCoordsEdit = new QLineEdit( QString(), statusBar() );
+  mCoordsEdit->setFont( myFont );
+  mCoordsEdit->setMinimumWidth( 10 );
+  mCoordsEdit->setMaximumWidth( 200 );
+  mCoordsEdit->setMaximumHeight( 20 );
+  mCoordsEdit->setContentsMargins( 0, 0, 0, 0 );
+  mCoordsEdit->setAlignment( Qt::AlignCenter );
+  mCoordsEdit->setAlignment( Qt::AlignCenter );
+  QRegExp coordValidator( "[+-]?\\d+\\.?\\d*\\s*,\\s*[+-]?\\d+\\.?\\d*" );
+  mCoordsEditValidator = new QRegExpValidator( coordValidator, mCoordsEdit );
+  mCoordsEdit->setWhatsThis( tr( "Shows the map coordinates at the "
+                                 "current cursor position. The display is continuously updated "
+                                 "as the mouse is moved. It also allows editing to set the canvas "
+                                 "center to a given position." ) );
+  mCoordsEdit->setToolTip( tr( "Current map coordinate (formatted as x,y)" ) );
+  statusBar()->addPermanentWidget( mCoordsEdit, 0 );
+  connect( mCoordsEdit, SIGNAL( editingFinished() ), this, SLOT( userCenter() ) );
+
   // add a label to show current scale
   mScaleLabel = new QLabel( QString(), statusBar() );
   mScaleLabel->setFont( myFont );
@@ -4666,11 +4687,10 @@
   }
   else
   {
-    mCoordsLabel->setText( p.toString( mMousePrecisionDecimalPlaces ) );
-    // Set minimum necessary width
-    if ( mCoordsLabel->width() > mCoordsLabel->minimumWidth() )
+    mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
+    if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
     {
-      mCoordsLabel->setMinimumWidth( mCoordsLabel->width() );
+      mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
     }
   }
 }
@@ -4710,7 +4730,34 @@
   }
 }
 
+void QgisApp::userCenter()
+{
+  QStringList parts = mCoordsEdit->text().split( ',' );
+  if ( parts.size() != 2 )
+    return;
 
+  bool xOk;
+  double x = parts.at( 0 ).toDouble( &xOk );
+  if ( !xOk )
+    return;
+
+  bool yOk;
+  double y = parts.at( 1 ).toDouble( &yOk );
+  if ( !yOk )
+    return;
+
+  QgsRectangle r = mMapCanvas->extent();
+
+  mMapCanvas->setExtent(
+    QgsRectangle(
+      x - r.width() / 2.0,  y - r.height() / 2.0,
+      x + r.width() / 2.0, y + r.height() / 2.0
+    )
+  );
+  mMapCanvas->refresh();
+}
+
+
 // toggle overview status
 void QgisApp::isInOverview()
 {
@@ -5366,14 +5413,17 @@
   {
     //extents view mode!
     mToggleExtentsViewButton->setIcon( getThemeIcon( "extents.png" ) );
-    mCoordsLabel->setToolTip( tr( "Map coordinates for the current view extents" ) );
+    mCoordsEdit->setToolTip( tr( "Map coordinates for the current view extents" ) );
+    mCoordsEdit->setEnabled( false );
     showExtents();
   }
   else
   {
     //mouse cursor pos view mode!
     mToggleExtentsViewButton->setIcon( getThemeIcon( "tracking.png" ) );
-    mCoordsLabel->setToolTip( tr( "Map coordinates at mouse cursor position" ) );
+    mCoordsEdit->setToolTip( tr( "Map coordinates at mouse cursor position" ) );
+    mCoordsEdit->setEnabled( true );
+    mCoordsLabel->setText( tr( "Coordinate:" ) );
   }
 }
 
@@ -5381,16 +5431,17 @@
 {
   if ( !mToggleExtentsViewButton->isChecked() )
   {
-    //we are in show coords mode so no need to do anything
     return;
   }
+
   // update the statusbar with the current extents.
   QgsRectangle myExtents = mMapCanvas->extent();
-  mCoordsLabel->setText( tr( "Extents: %1" ).arg( myExtents.toString( true ) ) );
+  mCoordsLabel->setText( tr( "Extents:" ) );
+  mCoordsEdit->setText( myExtents.toString( true ) );
   //ensure the label is big enough
-  if ( mCoordsLabel->width() > mCoordsLabel->minimumWidth() )
+  if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
   {
-    mCoordsLabel->setMinimumWidth( mCoordsLabel->width() );
+    mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
   }
 } // QgisApp::showExtents
 
@@ -6288,7 +6339,7 @@
 void QgisApp::updateUndoActions()
 {
   bool canUndo = false, canRedo = false;
-  QgsMapLayer* layer = this->activeLayer();
+  QgsMapLayer* layer = activeLayer();
   if ( layer )
   {
     QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2009-09-05 19:49:47 UTC (rev 11572)
+++ trunk/qgis/src/app/qgisapp.h	2009-09-05 19:50:05 UTC (rev 11573)
@@ -399,6 +399,8 @@
     void showScale( double theScale );
     //! Slot to handle user scale input;
     void userScale();
+    //! Slot to handle user center input;
+    void userCenter();
     //! Remove a layer from the map and legend
     void removeLayer();
     //! zoom to extent of layer
@@ -872,8 +874,12 @@
     QLineEdit * mScaleEdit;
     //! The validator for the mScaleEdit
     QValidator * mScaleEditValidator;
-    //! Widget that will live in the statusbar to display coords
+    //! Widget that will live on the statusbar to display "Coordinate / Extent"
     QLabel * mCoordsLabel;
+    //! Widget that will live in the statusbar to display and edit coords
+    QLineEdit * mCoordsEdit;
+    //! The validator for the mCoordsEdit
+    QValidator * mCoordsEditValidator;
     //! Widget that will live in the statusbar to show progress of operations
     QProgressBar * mProgressBar;
     //! Widget used to suppress rendering



More information about the QGIS-commit mailing list