Skip to content

Commit

Permalink
[FEATURE] use combobox to display scale. Also add predefined values for
Browse files Browse the repository at this point in the history
quick scale select
  • Loading branch information
alexbruy committed Dec 19, 2011
1 parent 08293fd commit 53e5de7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
30 changes: 22 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -1274,22 +1274,37 @@ void QgisApp::createStatusBar()
mScaleLabel->setToolTip( tr( "Current map scale" ) );
statusBar()->addPermanentWidget( mScaleLabel, 0 );

mScaleEdit = new QLineEdit( QString(), statusBar() );
mScaleEdit = new QComboBox( statusBar() );
mScaleEdit->setObjectName( "mScaleEdit" );
mScaleEdit->setFont( myFont );
mScaleEdit->setMinimumWidth( 10 );
mScaleEdit->setMaximumWidth( 100 );
mScaleEdit->setMaximumHeight( 20 );
mScaleEdit->setContentsMargins( 0, 0, 0, 0 );
mScaleEdit->setAlignment( Qt::AlignLeft );
// QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*" );
QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*|\\d+\\.?\\d*" );
mScaleEditValidator = new QRegExpValidator( validator, mScaleEdit );
mScaleEdit->setValidator( mScaleEditValidator );
mScaleEdit->setWhatsThis( tr( "Displays the current map scale" ) );
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

// make editable and populate with predefined scales
mScaleEdit->setEditable( true );
mScaleEdit->addItem( "1:1000000" );
mScaleEdit->addItem( "1:500000" );
mScaleEdit->addItem( "1:250000" );
mScaleEdit->addItem( "1:100000" );
mScaleEdit->addItem( "1:50000" );
mScaleEdit->addItem( "1:25000" );
mScaleEdit->addItem( "1:10000" );
mScaleEdit->addItem( "1:5000" );
mScaleEdit->addItem( "1:2500" );
mScaleEdit->addItem( "1:1000" );
mScaleEdit->addItem( "1:500" );

statusBar()->addPermanentWidget( mScaleEdit, 0 );
connect( mScaleEdit, SIGNAL( editingFinished() ), this, SLOT( userScale() ) );
connect( mScaleEdit, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( userScale() ) );
connect( mScaleEdit->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( userScale() ) );

//stop rendering status bar widget
mStopRenderButton = new QToolButton( statusBar() );
Expand Down Expand Up @@ -4347,13 +4362,12 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
void QgisApp::showScale( double theScale )
{
if ( theScale >= 1.0 )
mScaleEdit->setText( "1:" + QString::number( theScale, 'f', 0 ) );
mScaleEdit->setEditText( "1:" + QString::number( theScale, 'f', 0 ) );
else if ( theScale > 0.0 )
mScaleEdit->setText( QString::number( 1.0 / theScale, 'f', 0 ) + ":1" );
mScaleEdit->setEditText( QString::number( 1.0 / theScale, 'f', 0 ) + ":1" );
else
mScaleEdit->setText( tr( "Invalid scale" ) );
mScaleEdit->setEditText( tr( "Invalid scale" ) );

// Set minimum necessary width
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
{
mScaleEdit->setMinimumWidth( mScaleEdit->width() );
Expand All @@ -4362,7 +4376,7 @@ void QgisApp::showScale( double theScale )

void QgisApp::userScale()
{
QStringList parts = mScaleEdit->text().split( ':' );
QStringList parts = mScaleEdit->currentText().split( ':' );
if ( parts.size() == 2 )
{
bool leftOk, rightOk;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -24,7 +24,7 @@ class QCursor;
class QFileInfo;
class QKeyEvent;
class QLabel;
class QLineEdit;
class QComboBox;
class QMenu;
class QPixmap;
class QProgressBar;
Expand Down Expand Up @@ -960,7 +960,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! 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;
QComboBox * mScaleEdit;
//! The validator for the mScaleEdit
QValidator * mScaleEditValidator;
//! Widget that will live on the statusbar to display "Coordinate / Extent"
Expand Down

0 comments on commit 53e5de7

Please sign in to comment.