@@ -1473,17 +1473,38 @@ void QgisApp::createStatusBar()
1473
1473
mToggleExtentsViewButton ->setCheckable ( true );
1474
1474
connect ( mToggleExtentsViewButton , SIGNAL ( toggled ( bool ) ), this , SLOT ( extentsViewToggled ( bool ) ) );
1475
1475
statusBar ()->addPermanentWidget ( mToggleExtentsViewButton , 0 );
1476
- // coords status bar widget
1476
+
1477
+ // add a label to show current scale
1477
1478
mCoordsLabel = new QLabel ( QString (), statusBar () );
1479
+ mCoordsLabel ->setFont ( myFont );
1478
1480
mCoordsLabel ->setMinimumWidth ( 10 );
1479
1481
mCoordsLabel ->setMaximumHeight ( 20 );
1480
- mCoordsLabel ->setFont ( myFont );
1481
1482
mCoordsLabel ->setMargin ( 3 );
1482
1483
mCoordsLabel ->setAlignment ( Qt::AlignCenter );
1483
- mCoordsLabel ->setWhatsThis ( tr ( " Shows the map coordinates at the "
1484
- " current cursor position. The display is continuously updated "
1485
- " as the mouse is moved. " ) );
1484
+ mCoordsLabel ->setFrameStyle ( QFrame::NoFrame );
1485
+ mCoordsLabel -> setText ( tr ( " Coordinate: " ) );
1486
+ mCoordsLabel -> setToolTip ( tr ( " Current map coordinate " ) );
1486
1487
statusBar ()->addPermanentWidget ( mCoordsLabel , 0 );
1488
+
1489
+ // coords status bar widget
1490
+ mCoordsEdit = new QLineEdit ( QString (), statusBar () );
1491
+ mCoordsEdit ->setFont ( myFont );
1492
+ mCoordsEdit ->setMinimumWidth ( 10 );
1493
+ mCoordsEdit ->setMaximumWidth ( 200 );
1494
+ mCoordsEdit ->setMaximumHeight ( 20 );
1495
+ mCoordsEdit ->setContentsMargins ( 0 , 0 , 0 , 0 );
1496
+ mCoordsEdit ->setAlignment ( Qt::AlignCenter );
1497
+ mCoordsEdit ->setAlignment ( Qt::AlignCenter );
1498
+ QRegExp coordValidator ( " [+-]?\\ d+\\ .?\\ d*\\ s*,\\ s*[+-]?\\ d+\\ .?\\ d*" );
1499
+ mCoordsEditValidator = new QRegExpValidator ( coordValidator, mCoordsEdit );
1500
+ mCoordsEdit ->setWhatsThis ( tr ( " Shows the map coordinates at the "
1501
+ " current cursor position. The display is continuously updated "
1502
+ " as the mouse is moved. It also allows editing to set the canvas "
1503
+ " center to a given position." ) );
1504
+ mCoordsEdit ->setToolTip ( tr ( " Current map coordinate (formatted as x,y)" ) );
1505
+ statusBar ()->addPermanentWidget ( mCoordsEdit , 0 );
1506
+ connect ( mCoordsEdit , SIGNAL ( editingFinished () ), this , SLOT ( userCenter () ) );
1507
+
1487
1508
// add a label to show current scale
1488
1509
mScaleLabel = new QLabel ( QString (), statusBar () );
1489
1510
mScaleLabel ->setFont ( myFont );
@@ -4666,11 +4687,10 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
4666
4687
}
4667
4688
else
4668
4689
{
4669
- mCoordsLabel ->setText ( p.toString ( mMousePrecisionDecimalPlaces ) );
4670
- // Set minimum necessary width
4671
- if ( mCoordsLabel ->width () > mCoordsLabel ->minimumWidth () )
4690
+ mCoordsEdit ->setText ( p.toString ( mMousePrecisionDecimalPlaces ) );
4691
+ if ( mCoordsEdit ->width () > mCoordsEdit ->minimumWidth () )
4672
4692
{
4673
- mCoordsLabel ->setMinimumWidth ( mCoordsLabel ->width () );
4693
+ mCoordsEdit ->setMinimumWidth ( mCoordsEdit ->width () );
4674
4694
}
4675
4695
}
4676
4696
}
@@ -4710,6 +4730,33 @@ void QgisApp::userScale()
4710
4730
}
4711
4731
}
4712
4732
4733
+ void QgisApp::userCenter ()
4734
+ {
4735
+ QStringList parts = mCoordsEdit ->text ().split ( ' ,' );
4736
+ if ( parts.size () != 2 )
4737
+ return ;
4738
+
4739
+ bool xOk;
4740
+ double x = parts.at ( 0 ).toDouble ( &xOk );
4741
+ if ( !xOk )
4742
+ return ;
4743
+
4744
+ bool yOk;
4745
+ double y = parts.at ( 1 ).toDouble ( &yOk );
4746
+ if ( !yOk )
4747
+ return ;
4748
+
4749
+ QgsRectangle r = mMapCanvas ->extent ();
4750
+
4751
+ mMapCanvas ->setExtent (
4752
+ QgsRectangle (
4753
+ x - r.width () / 2.0 , y - r.height () / 2.0 ,
4754
+ x + r.width () / 2.0 , y + r.height () / 2.0
4755
+ )
4756
+ );
4757
+ mMapCanvas ->refresh ();
4758
+ }
4759
+
4713
4760
4714
4761
// toggle overview status
4715
4762
void QgisApp::isInOverview ()
@@ -5366,31 +5413,35 @@ void QgisApp::extentsViewToggled( bool theFlag )
5366
5413
{
5367
5414
// extents view mode!
5368
5415
mToggleExtentsViewButton ->setIcon ( getThemeIcon ( " extents.png" ) );
5369
- mCoordsLabel ->setToolTip ( tr ( " Map coordinates for the current view extents" ) );
5416
+ mCoordsEdit ->setToolTip ( tr ( " Map coordinates for the current view extents" ) );
5417
+ mCoordsEdit ->setEnabled ( false );
5370
5418
showExtents ();
5371
5419
}
5372
5420
else
5373
5421
{
5374
5422
// mouse cursor pos view mode!
5375
5423
mToggleExtentsViewButton ->setIcon ( getThemeIcon ( " tracking.png" ) );
5376
- mCoordsLabel ->setToolTip ( tr ( " Map coordinates at mouse cursor position" ) );
5424
+ mCoordsEdit ->setToolTip ( tr ( " Map coordinates at mouse cursor position" ) );
5425
+ mCoordsEdit ->setEnabled ( true );
5426
+ mCoordsLabel ->setText ( tr ( " Coordinate:" ) );
5377
5427
}
5378
5428
}
5379
5429
5380
5430
void QgisApp::showExtents ()
5381
5431
{
5382
5432
if ( !mToggleExtentsViewButton ->isChecked () )
5383
5433
{
5384
- // we are in show coords mode so no need to do anything
5385
5434
return ;
5386
5435
}
5436
+
5387
5437
// update the statusbar with the current extents.
5388
5438
QgsRectangle myExtents = mMapCanvas ->extent ();
5389
- mCoordsLabel ->setText ( tr ( " Extents: %1" ).arg ( myExtents.toString ( true ) ) );
5439
+ mCoordsLabel ->setText ( tr ( " Extents:" ) );
5440
+ mCoordsEdit ->setText ( myExtents.toString ( true ) );
5390
5441
// ensure the label is big enough
5391
- if ( mCoordsLabel ->width () > mCoordsLabel ->minimumWidth () )
5442
+ if ( mCoordsEdit ->width () > mCoordsEdit ->minimumWidth () )
5392
5443
{
5393
- mCoordsLabel ->setMinimumWidth ( mCoordsLabel ->width () );
5444
+ mCoordsEdit ->setMinimumWidth ( mCoordsEdit ->width () );
5394
5445
}
5395
5446
} // QgisApp::showExtents
5396
5447
@@ -6288,7 +6339,7 @@ QPixmap QgisApp::getThemePixmap( const QString theName )
6288
6339
void QgisApp::updateUndoActions ()
6289
6340
{
6290
6341
bool canUndo = false , canRedo = false ;
6291
- QgsMapLayer* layer = this -> activeLayer ();
6342
+ QgsMapLayer* layer = activeLayer ();
6292
6343
if ( layer )
6293
6344
{
6294
6345
QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>( layer );
0 commit comments