mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
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
This commit is contained in:
parent
e89ff94e28
commit
41e63a928f
@ -63,7 +63,8 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QWhatsThis>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegExpValidator>
|
||||
//
|
||||
// Mac OS X Includes
|
||||
// Must include before GEOS 3 due to unqualified use of 'Point'
|
||||
@ -1021,17 +1022,21 @@ void QgisApp::createStatusBar()
|
||||
mScaleLabel->setMinimumWidth(10);
|
||||
mScaleLabel->setMargin(3);
|
||||
mScaleLabel->setAlignment(Qt::AlignCenter);
|
||||
// QWhatsThis::add(mScaleLabel, tr("Displays the current map scale"));
|
||||
// QToolTip::add (mScaleLabel, tr("Current map scale"));
|
||||
mScaleLabel->setFrameStyle(QFrame::NoFrame);
|
||||
mScaleLabel->setText(tr("Scale "));
|
||||
statusBar()->addWidget(mScaleLabel, 0,true);
|
||||
|
||||
mScaleEdit = new QLineEdit(QString(),statusBar());
|
||||
mScaleEdit->setFont(myFont);
|
||||
mScaleEdit->setMinimumWidth(10);
|
||||
mScaleEdit->setMaximumWidth(100);
|
||||
mScaleEdit->setMargin(0);
|
||||
mScaleEdit->setAlignment(Qt::AlignLeft);
|
||||
QRegExp validator("\\d+\\.?\\d*:\\d+\\.?\\d*");
|
||||
mScaleEditValidator = new QRegExpValidator(validator, mScaleEdit);
|
||||
mScaleEdit->setValidator(mScaleEditValidator);
|
||||
QWhatsThis::add(mScaleEdit, tr("Displays the current map scale"));
|
||||
QToolTip::add (mScaleEdit, tr("Current map scale"));
|
||||
QToolTip::add (mScaleEdit, tr("Current map scale (formatted as x:y)"));
|
||||
statusBar()->addWidget(mScaleEdit, 0,true);
|
||||
connect(mScaleEdit, SIGNAL(editingFinished()), this, SLOT(userScale()));
|
||||
|
||||
@ -3544,13 +3549,14 @@ void QgisApp::showMouseCoordinate(QgsPoint & p)
|
||||
|
||||
void QgisApp::showScale(double theScale)
|
||||
{
|
||||
mScaleLabel->setText(tr("Scale 1: "));
|
||||
|
||||
if (theScale >= 1.0)
|
||||
mScaleEdit->setText(QString::number(theScale, 'f', 0));
|
||||
mScaleEdit->setText("1:" + QString::number(theScale, 'f', 0));
|
||||
else if (theScale > 0.0)
|
||||
mScaleEdit->setText(QString::number(1.0/theScale, 'f', 0) + ":1");
|
||||
else
|
||||
mScaleEdit->setText(QString::number(theScale));
|
||||
// Set minimum necessary width
|
||||
mScaleEdit->setText(tr("Invalid scale"));
|
||||
|
||||
// Set minimum necessary width
|
||||
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
|
||||
{
|
||||
mScaleEdit->setMinimumWidth(mScaleEdit->width());
|
||||
@ -3559,13 +3565,20 @@ void QgisApp::showScale(double theScale)
|
||||
|
||||
void QgisApp::userScale()
|
||||
{
|
||||
bool ok;
|
||||
double currentScale = mMapCanvas->getScale();
|
||||
double wantedScale = mScaleEdit->text().toDouble(&ok);
|
||||
|
||||
if (ok)
|
||||
mMapCanvas->zoom(wantedScale/currentScale);
|
||||
|
||||
QStringList parts = mScaleEdit->text().split(':');
|
||||
if (parts.size() == 2)
|
||||
{
|
||||
bool leftOk, rightOk;
|
||||
double leftSide = parts.at(0).toDouble(&leftOk);
|
||||
double rightSide = parts.at(1).toDouble(&rightOk);
|
||||
if (leftSide > 0.0 && leftOk && rightOk)
|
||||
{
|
||||
double wantedScale = rightSide / leftSide;
|
||||
mMapCanvas->zoom(wantedScale/currentScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
void QgisApp::testButton()
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ class QKeyEvent;
|
||||
class QMenu;
|
||||
class QPixmap;
|
||||
class QSplashScreen;
|
||||
class QValidator;
|
||||
|
||||
class QgisAppInterface;
|
||||
class QgsClipboard;
|
||||
@ -547,6 +548,8 @@ private:
|
||||
QLabel * mScaleLabel;
|
||||
//! Widget that will live on the statusbar to display scale value
|
||||
QLineEdit * mScaleEdit;
|
||||
//! The validator for the mScaleEdit
|
||||
QValidator * mScaleEditValidator;
|
||||
//! Widget that will live in the statusbar to display coords
|
||||
QLabel * mCoordsLabel;
|
||||
//! Widget that will live in the statusbar to show progress of operations
|
||||
|
Loading…
x
Reference in New Issue
Block a user