Skip to content

Commit

Permalink
Added input so that user can set specific scale. Set focus in the lin…
Browse files Browse the repository at this point in the history
…edit showing scale, enter your scale and hit return!

git-svn-id: http://svn.osgeo.org/qgis/trunk@6747 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Mar 2, 2007
1 parent cb859a7 commit 559a28a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
38 changes: 30 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -23,6 +23,7 @@ class QRect;
class QStringList;
class QCursor;
class QLabel;
class QLineEdit;
class QProgressBar;
class QFileInfo;
class QSettings;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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));
}


Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -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();
Expand Down

0 comments on commit 559a28a

Please sign in to comment.