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/qgis@6747 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
homann 2007-03-02 21:04:19 +00:00
parent 9f5cefc0c1
commit 325a312a56
4 changed files with 43 additions and 20 deletions

View File

@ -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");

View File

@ -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 @@ private:
//!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

View File

@ -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));
}

View File

@ -277,7 +277,7 @@ signals:
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();