63
63
#include < QVBoxLayout>
64
64
#include < QWhatsThis>
65
65
#include < QtGlobal>
66
-
66
+ #include < QRegExp>
67
+ #include < QRegExpValidator>
67
68
//
68
69
// Mac OS X Includes
69
70
// Must include before GEOS 3 due to unqualified use of 'Point'
@@ -1021,17 +1022,21 @@ void QgisApp::createStatusBar()
1021
1022
mScaleLabel ->setMinimumWidth (10 );
1022
1023
mScaleLabel ->setMargin (3 );
1023
1024
mScaleLabel ->setAlignment (Qt::AlignCenter);
1024
- // QWhatsThis::add( mScaleLabel, tr("Displays the current map scale") );
1025
- // QToolTip::add ( mScaleLabel, tr("Current map scale "));
1025
+ mScaleLabel -> setFrameStyle (QFrame::NoFrame );
1026
+ mScaleLabel -> setText ( tr (" Scale " ));
1026
1027
statusBar ()->addWidget (mScaleLabel , 0 ,true );
1028
+
1027
1029
mScaleEdit = new QLineEdit (QString (),statusBar ());
1028
1030
mScaleEdit ->setFont (myFont);
1029
1031
mScaleEdit ->setMinimumWidth (10 );
1030
1032
mScaleEdit ->setMaximumWidth (100 );
1031
1033
mScaleEdit ->setMargin (0 );
1032
1034
mScaleEdit ->setAlignment (Qt::AlignLeft);
1035
+ QRegExp validator (" \\ d+\\ .?\\ d*:\\ d+\\ .?\\ d*" );
1036
+ mScaleEditValidator = new QRegExpValidator (validator, mScaleEdit );
1037
+ mScaleEdit ->setValidator (mScaleEditValidator );
1033
1038
QWhatsThis::add (mScaleEdit , tr (" Displays the current map scale" ));
1034
- QToolTip::add (mScaleEdit , tr (" Current map scale" ));
1039
+ QToolTip::add (mScaleEdit , tr (" Current map scale (formatted as x:y) " ));
1035
1040
statusBar ()->addWidget (mScaleEdit , 0 ,true );
1036
1041
connect (mScaleEdit , SIGNAL (editingFinished ()), this , SLOT (userScale ()));
1037
1042
@@ -3544,13 +3549,14 @@ void QgisApp::showMouseCoordinate(QgsPoint & p)
3544
3549
3545
3550
void QgisApp::showScale (double theScale)
3546
3551
{
3547
- mScaleLabel ->setText (tr (" Scale 1: " ));
3548
-
3549
3552
if (theScale >= 1.0 )
3550
- mScaleEdit ->setText (QString::number (theScale, ' f' , 0 ));
3553
+ mScaleEdit ->setText (" 1:" + QString::number (theScale, ' f' , 0 ));
3554
+ else if (theScale > 0.0 )
3555
+ mScaleEdit ->setText (QString::number (1.0 /theScale, ' f' , 0 ) + " :1" );
3551
3556
else
3552
- mScaleEdit ->setText (QString::number (theScale));
3553
- // Set minimum necessary width
3557
+ mScaleEdit ->setText (tr (" Invalid scale" ));
3558
+
3559
+ // Set minimum necessary width
3554
3560
if ( mScaleEdit ->width () > mScaleEdit ->minimumWidth () )
3555
3561
{
3556
3562
mScaleEdit ->setMinimumWidth (mScaleEdit ->width ());
@@ -3559,13 +3565,20 @@ void QgisApp::showScale(double theScale)
3559
3565
3560
3566
void QgisApp::userScale ()
3561
3567
{
3562
- bool ok;
3563
3568
double currentScale = mMapCanvas ->getScale ();
3564
- double wantedScale = mScaleEdit ->text ().toDouble (&ok);
3565
-
3566
- if (ok)
3567
- mMapCanvas ->zoom (wantedScale/currentScale);
3568
3569
3570
+ QStringList parts = mScaleEdit ->text ().split (' :' );
3571
+ if (parts.size () == 2 )
3572
+ {
3573
+ bool leftOk, rightOk;
3574
+ double leftSide = parts.at (0 ).toDouble (&leftOk);
3575
+ double rightSide = parts.at (1 ).toDouble (&rightOk);
3576
+ if (leftSide > 0.0 && leftOk && rightOk)
3577
+ {
3578
+ double wantedScale = rightSide / leftSide;
3579
+ mMapCanvas ->zoom (wantedScale/currentScale);
3580
+ }
3581
+ }
3569
3582
}
3570
3583
void QgisApp::testButton ()
3571
3584
{
0 commit comments