Skip to content

Commit 41e63a9

Browse files
author
g_j_m
committedMar 8, 2007
Tweak the scale display/entry so that users can enter scales in the form
x:y git-svn-id: http://svn.osgeo.org/qgis/trunk@6775 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e89ff94 commit 41e63a9

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
#include <QVBoxLayout>
6464
#include <QWhatsThis>
6565
#include <QtGlobal>
66-
66+
#include <QRegExp>
67+
#include <QRegExpValidator>
6768
//
6869
// Mac OS X Includes
6970
// Must include before GEOS 3 due to unqualified use of 'Point'
@@ -1021,17 +1022,21 @@ void QgisApp::createStatusBar()
10211022
mScaleLabel->setMinimumWidth(10);
10221023
mScaleLabel->setMargin(3);
10231024
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 "));
10261027
statusBar()->addWidget(mScaleLabel, 0,true);
1028+
10271029
mScaleEdit = new QLineEdit(QString(),statusBar());
10281030
mScaleEdit->setFont(myFont);
10291031
mScaleEdit->setMinimumWidth(10);
10301032
mScaleEdit->setMaximumWidth(100);
10311033
mScaleEdit->setMargin(0);
10321034
mScaleEdit->setAlignment(Qt::AlignLeft);
1035+
QRegExp validator("\\d+\\.?\\d*:\\d+\\.?\\d*");
1036+
mScaleEditValidator = new QRegExpValidator(validator, mScaleEdit);
1037+
mScaleEdit->setValidator(mScaleEditValidator);
10331038
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)"));
10351040
statusBar()->addWidget(mScaleEdit, 0,true);
10361041
connect(mScaleEdit, SIGNAL(editingFinished()), this, SLOT(userScale()));
10371042

@@ -3544,13 +3549,14 @@ void QgisApp::showMouseCoordinate(QgsPoint & p)
35443549

35453550
void QgisApp::showScale(double theScale)
35463551
{
3547-
mScaleLabel->setText(tr("Scale 1: "));
3548-
35493552
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");
35513556
else
3552-
mScaleEdit->setText(QString::number(theScale));
3553-
// Set minimum necessary width
3557+
mScaleEdit->setText(tr("Invalid scale"));
3558+
3559+
// Set minimum necessary width
35543560
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
35553561
{
35563562
mScaleEdit->setMinimumWidth(mScaleEdit->width());
@@ -3559,13 +3565,20 @@ void QgisApp::showScale(double theScale)
35593565

35603566
void QgisApp::userScale()
35613567
{
3562-
bool ok;
35633568
double currentScale = mMapCanvas->getScale();
3564-
double wantedScale = mScaleEdit->text().toDouble(&ok);
3565-
3566-
if (ok)
3567-
mMapCanvas->zoom(wantedScale/currentScale);
35683569

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+
}
35693582
}
35703583
void QgisApp::testButton()
35713584
{

‎src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class QKeyEvent;
3434
class QMenu;
3535
class QPixmap;
3636
class QSplashScreen;
37+
class QValidator;
3738

3839
class QgisAppInterface;
3940
class QgsClipboard;
@@ -547,6 +548,8 @@ public slots:
547548
QLabel * mScaleLabel;
548549
//! Widget that will live on the statusbar to display scale value
549550
QLineEdit * mScaleEdit;
551+
//! The validator for the mScaleEdit
552+
QValidator * mScaleEditValidator;
550553
//! Widget that will live in the statusbar to display coords
551554
QLabel * mCoordsLabel;
552555
//! Widget that will live in the statusbar to show progress of operations

0 commit comments

Comments
 (0)