Skip to content
Permalink
Browse files

move map scale selector to QgsScaleComboBox class. Highlight nearest

value to the current scale when open selectors popup
  • Loading branch information
alexbruy committed Jan 10, 2012
1 parent ca352db commit b30f2b65b6f803835c44076a87b1317de9498173
@@ -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
@@ -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();
};

@@ -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"
@@ -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 );
@@ -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() ) );
@@ -24,7 +24,6 @@ class QCursor;
class QFileInfo;
class QKeyEvent;
class QLabel;
class QComboBox;
class QMenu;
class QPixmap;
class QProgressBar;
@@ -76,6 +75,8 @@ class QgsDecorationScaleBar;

class QgsMessageLogViewer;

class QgsScaleComboBox;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
@@ -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"
@@ -69,6 +69,7 @@ qgsprojectbadlayerguihandler.cpp
qgsprojectionselector.cpp
qgsquickprint.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgstextannotationitem.cpp
qgsvertexmarker.cpp
qgsludialog.cpp
@@ -135,6 +136,7 @@ qgsludialog.h
qgsprojectbadlayerguihandler.h
qgslonglongvalidator.h
qgssearchquerybuilder.h
qgsscalecombobox.h
qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsquerybuilder.h
@@ -167,6 +169,7 @@ qgsprojectionselector.h
qgsrubberband.h
qgsvertexmarker.h
qgsmaptip.h
qgsscalecombobox.h
qgssearchquerybuilder.h
qgsattributeeditor.h
qgsfieldvalidator.h
@@ -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 );
}
@@ -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.
You can’t perform that action at this time.