From 559a28a6de24b03c7656f9c2db1ff2abba0fe9a1 Mon Sep 17 00:00:00 2001 From: homann Date: Fri, 2 Mar 2007 21:04:19 +0000 Subject: [PATCH] Added input so that user can set specific scale. Set focus in the linedit showing scale, enter your scale and hit return! git-svn-id: http://svn.osgeo.org/qgis/trunk@6747 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/app/qgisapp.cpp | 38 ++++++++++++++++++++++++++++++-------- src/app/qgisapp.h | 9 +++++++-- src/gui/qgsmapcanvas.cpp | 14 +++++--------- src/gui/qgsmapcanvas.h | 2 +- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index c7f603baaa10..4544fbf47c34 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1021,9 +1021,20 @@ 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")); +// QWhatsThis::add(mScaleLabel, tr("Displays the current map scale")); +// QToolTip::add (mScaleLabel, tr("Current map 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); + QWhatsThis::add(mScaleEdit, tr("Displays the current map scale")); + QToolTip::add (mScaleEdit, tr("Current map scale")); + statusBar()->addWidget(mScaleEdit, 0,true); + connect(mScaleEdit, SIGNAL(editingFinished()), this, SLOT(userScale())); + //coords status bar widget mCoordsLabel = new QLabel(QString(), statusBar()); mCoordsLabel->setMinimumWidth(10); @@ -1161,8 +1172,8 @@ void QgisApp::setupConnections() connect(mMapCanvas->mapRender(), SIGNAL(projectionsEnabled(bool)), this, SLOT(projectionsEnabled(bool))); connect(mMapCanvas->mapRender(), SIGNAL(destinationSrsChanged()), this, SLOT(destinationSrsChanged())); connect(mMapCanvas, SIGNAL(extentsChanged()),this,SLOT(showExtents())); - connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(showScale(QString))); - connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(updateMouseCoordinatePrecision())); + connect(mMapCanvas, SIGNAL(scaleChanged(long)), this, SLOT(showScale(long))); + connect(mMapCanvas, SIGNAL(scaleChanged(long)), this, SLOT(updateMouseCoordinatePrecision())); connect(mRenderSuppressionCBox, SIGNAL(toggled(bool )), mMapCanvas, SLOT(setRenderFlag(bool))); } @@ -3524,16 +3535,27 @@ void QgisApp::showMouseCoordinate(QgsPoint & p) } } -void QgisApp::showScale(QString theScale) +void QgisApp::showScale(long theScale) { - mScaleLabel->setText(theScale); + mScaleLabel->setText(tr("Scale 1: ")); + mScaleEdit->setText(QString::number(theScale)); // Set minimum necessary width - if ( mScaleLabel->width() > mScaleLabel->minimumWidth() ) + if ( mScaleEdit->width() > mScaleEdit->minimumWidth() ) { - mScaleLabel->setMinimumWidth(mScaleLabel->width()); + mScaleEdit->setMinimumWidth(mScaleEdit->width()); } } +void QgisApp::userScale() +{ + bool ok; + double currentScale = mMapCanvas->getScale(); + double wantedScale = mScaleEdit->text().toDouble(&ok); + + if (ok) + mMapCanvas->zoom(wantedScale/currentScale); + +} void QgisApp::testButton() { /* QgsShapeFileLayer *sfl = new QgsShapeFileLayer("foo"); diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 6fa33e520e71..2475dfc69b1a 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -23,6 +23,7 @@ class QRect; class QStringList; class QCursor; class QLabel; +class QLineEdit; class QProgressBar; class QFileInfo; class QSettings; @@ -174,7 +175,9 @@ public slots: //copy the click coord to clipboard and let the user know its there void showCapturePointCoordinate(QgsPoint &); //! Slot to show current map scale; - void showScale(QString theScale); + void showScale(long theScale); + //! Slot to handle user scale input; + void userScale(); //! Remove a layer from the map and legend void removeLayer(); //! zoom to extent of layer @@ -540,8 +543,10 @@ public slots: //!The name of the active theme QString mThemeName; - //! Widget that will live on the statusbar to display scale + //! Widget that will live on the statusbar to display "scale 1:" QLabel * mScaleLabel; + //! Widget that will live on the statusbar to display scale value + QLineEdit * mScaleEdit; //! Widget that will live in the statusbar to display coords QLabel * mCoordsLabel; //! Widget that will live in the statusbar to show progress of operations diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 47c703c2bab5..ae1a66f65562 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -431,15 +431,11 @@ void QgsMapCanvas::setExtent(QgsRect const & r) void QgsMapCanvas::updateScale() { double scale = mMapRender->scale(); - QString myScaleString = tr("Scale "); - int thePrecision = 0; - if (scale == 0) - myScaleString = ""; - else if (scale >= 1) - myScaleString += QString("1: ") + QString::number(scale,'f',thePrecision); - else - myScaleString += QString::number(1.0/scale, 'f', thePrecision) + QString(": 1"); - emit scaleChanged(myScaleString); + + if (scale < 1) + emit scaleChanged(lround(-1.0/scale)); + else + emit scaleChanged(lround(scale)); } diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index e9816dde73d4..a24ae0902f0e 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -277,7 +277,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView void xyCoordinates(QgsPoint & p); //! Emitted when the scale of the map changes - void scaleChanged(QString); + void scaleChanged(long); //! Emitted when the extents of the map change void extentsChanged();