Skip to content

Commit

Permalink
move map scale selector to QgsScaleComboBox class. Highlight nearest
Browse files Browse the repository at this point in the history
value to the current scale when open selectors popup
  • Loading branch information
alexbruy committed Jan 10, 2012
1 parent ca352db commit b30f2b6
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 17 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -30,6 +30,7 @@
%Include qgsprojectionselector.sip
%Include qgsquickprint.sip
%Include qgsrubberband.sip
%Include qgsscalecombobox.sip
%Include qgstextannotationitem.sip
%Include qgsvertexmarker.sip
%Include qgssearchquerybuilder.sip
Expand Down
15 changes: 15 additions & 0 deletions python/gui/qgsscalecombobox.sip
@@ -0,0 +1,15 @@

/** A combobox which lets the user select map scale from predefined list
* and highlights nearest to current scale valu
*/
class QgsScaleComboBox : QComboBox
{
%TypeHeaderCode
#include <qgsscalecombobox.h>
%End

public:
QgsScaleComboBox(QWidget * parent = 0);
~QgsScaleComboBox();
};

17 changes: 2 additions & 15 deletions src/app/qgisapp.cpp
Expand Up @@ -160,6 +160,7 @@
#include "qgsrasterlayerproperties.h"
#include "qgsrectangle.h"
#include "qgsrenderer.h"
#include "qgsscalecombobox.h"
#include "qgsshortcutsmanager.h"
#include "qgssnappingdialog.h"
#include "qgssponsors.h"
Expand Down Expand Up @@ -1293,7 +1294,7 @@ void QgisApp::createStatusBar()
mScaleLabel->setToolTip( tr( "Current map scale" ) );
statusBar()->addPermanentWidget( mScaleLabel, 0 );

mScaleEdit = new QComboBox( statusBar() );
mScaleEdit = new QgsScaleComboBox( statusBar() );
mScaleEdit->setObjectName( "mScaleEdit" );
mScaleEdit->setFont( myFont );
mScaleEdit->setMinimumWidth( 10 );
Expand All @@ -1307,20 +1308,6 @@ void QgisApp::createStatusBar()
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( currentIndexChanged( const QString & ) ), this, SLOT( userScale() ) );
connect( mScaleEdit->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( userScale() ) );
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -24,7 +24,6 @@ class QCursor;
class QFileInfo;
class QKeyEvent;
class QLabel;
class QComboBox;
class QMenu;
class QPixmap;
class QProgressBar;
Expand Down Expand Up @@ -76,6 +75,8 @@ class QgsDecorationScaleBar;

class QgsMessageLogViewer;

class QgsScaleComboBox;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
Expand Down Expand Up @@ -1003,7 +1004,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
QComboBox * mScaleEdit;
QgsScaleComboBox * mScaleEdit;
//! The validator for the mScaleEdit
QValidator * mScaleEditValidator;
//! Widget that will live on the statusbar to display "Coordinate / Extent"
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -69,6 +69,7 @@ qgsprojectbadlayerguihandler.cpp
qgsprojectionselector.cpp
qgsquickprint.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgstextannotationitem.cpp
qgsvertexmarker.cpp
qgsludialog.cpp
Expand Down Expand Up @@ -135,6 +136,7 @@ qgsludialog.h
qgsprojectbadlayerguihandler.h
qgslonglongvalidator.h
qgssearchquerybuilder.h
qgsscalecombobox.h
qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsquerybuilder.h
Expand Down Expand Up @@ -167,6 +169,7 @@ qgsprojectionselector.h
qgsrubberband.h
qgsvertexmarker.h
qgsmaptip.h
qgsscalecombobox.h
qgssearchquerybuilder.h
qgsattributeeditor.h
qgsfieldvalidator.h
Expand Down
70 changes: 70 additions & 0 deletions src/gui/qgsscalecombobox.cpp
@@ -0,0 +1,70 @@
/***************************************************************************
qgsscalecombobox.h
------------------------
begin : January 7, 2012
copyright : (C) 2012 by Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsscalecombobox.h"

#include <QAbstractItemView>

QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
{
// make combobox editable and populate with predefined scales
setEditable( true );
addItem( "1:1000000" );
addItem( "1:500000" );
addItem( "1:250000" );
addItem( "1:100000" );
addItem( "1:50000" );
addItem( "1:25000" );
addItem( "1:10000" );
addItem( "1:5000" );
addItem( "1:2500" );
addItem( "1:1000" );
addItem( "1:500" );

setInsertPolicy( QComboBox::NoInsert );
}

QgsScaleComboBox::~QgsScaleComboBox()
{
}

void QgsScaleComboBox::showPopup()
{
QComboBox::showPopup();

QStringList parts = currentText().split( ':' );
bool ok;
int idx = 0;
int min = 999999;
long currScale = parts.at( 1 ).toLong( &ok );
long nextScale, delta;
for ( int i = 0; i < count(); i++ )
{
parts = itemText( i ).split( ':' );
nextScale = parts.at( 1 ).toLong( &ok );
delta = qAbs( currScale - nextScale );
if( delta < min )
{
min = delta;
idx = i;
}
}

blockSignals( true );
view()->setCurrentIndex( model()->index( idx, 0 ) );
blockSignals( false );
}
38 changes: 38 additions & 0 deletions src/gui/qgsscalecombobox.h
@@ -0,0 +1,38 @@
/***************************************************************************
qgsscalecombobox.h
------------------------
begin : January 7, 2012
copyright : (C) 2012 by Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSSCALECOMBOBOX_H
#define QGSSCALECOMBOBOX_H

#include <QComboBox>

/** \ingroup gui
* A combobox which lets the user select map scale from predefined list
* and highlights nearest to current scale valu
**/
class GUI_EXPORT QgsScaleComboBox : public QComboBox
{
Q_OBJECT
public:
QgsScaleComboBox( QWidget* parent = 0 );
virtual ~QgsScaleComboBox();

protected:
void showPopup();
};

#endif // QGSSCALECOMBOBOX_H

0 comments on commit b30f2b6

Please sign in to comment.