Skip to content

Commit d1c8884

Browse files
committed
Added SIP, fixed qgisapp to use new setter and optimized a bit
1 parent 01c4ac7 commit d1c8884

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

python/gui/qgsscalecombobox.sip

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ class QgsScaleComboBox : QComboBox
1212
QgsScaleComboBox(QWidget * parent = 0);
1313
~QgsScaleComboBox();
1414

15+
//! Function to read the selected scale as text
16+
// @note added in 2.0
17+
QString scaleString();
18+
//! Function to set the selected scale from text
19+
// @note added in 2.0
20+
bool setScaleString( QString scaleTxt );
21+
//! Function to read the selected scale as double
22+
// @note added in 2.0
23+
double scale();
24+
//! Function to set the selected scale from double
25+
// @note added in 2.0
26+
void setScale( double scale );
27+
28+
//! Helper function to convert a double to scale string
29+
// Performs rounding, so an exact representation is not to
30+
// be expected.
31+
// @note added in 2.0
32+
static QString toString( double scale );
33+
//! Helper function to convert a scale string to double
34+
// @note added in 2.0
35+
static double toDouble( QString scaleString, bool *ok = NULL );
36+
1537
public slots:
1638
void updateScales( const QStringList &scales = QStringList() );
1739
};

src/app/qgisapp.cpp

+4-15
Original file line numberDiff line numberDiff line change
@@ -1467,16 +1467,10 @@ void QgisApp::createStatusBar()
14671467
mScaleEdit->setMaximumWidth( 100 );
14681468
mScaleEdit->setMaximumHeight( 20 );
14691469
mScaleEdit->setContentsMargins( 0, 0, 0, 0 );
1470-
// QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*" );
1471-
// QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*|\\d+\\.?\\d*" );
1472-
// mScaleEditValidator = new QRegExpValidator( validator, mScaleEdit );
1473-
// mScaleEdit->setValidator( mScaleEditValidator );
14741470
mScaleEdit->setWhatsThis( tr( "Displays the current map scale" ) );
14751471
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );
14761472

14771473
statusBar()->addPermanentWidget( mScaleEdit, 0 );
1478-
//connect( mScaleEdit, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( userScale() ) );
1479-
//connect( mScaleEdit->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( userScale() ) );
14801474
connect( mScaleEdit, SIGNAL( scaleChanged() ), this, SLOT( userScale() ) );
14811475

14821476
//stop rendering status bar widget
@@ -5250,15 +5244,10 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
52505244

52515245
void QgisApp::showScale( double theScale )
52525246
{
5253-
if ( theScale >= 1.0 )
5254-
mScaleEdit->setEditText( "1:" + QString::number( theScale, 'f', 0 ) );
5255-
else if ( theScale > 0.0 )
5256-
mScaleEdit->setEditText( QString::number( 1.0 / theScale, 'f', 0 ) + ":1" );
5257-
else
5258-
mScaleEdit->setEditText( tr( "Invalid scale" ) );
5259-
5260-
mOldScale = mScaleEdit->currentText();
5247+
// Why has MapCanvas the scale inverted?
5248+
mScaleEdit->setScale( 1.0 / theScale );
52615249

5250+
// Not sure if the lines below do anything meaningful /Homann
52625251
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
52635252
{
52645253
mScaleEdit->setMinimumWidth( mScaleEdit->width() );
@@ -5267,7 +5256,7 @@ void QgisApp::showScale( double theScale )
52675256

52685257
void QgisApp::userScale()
52695258
{
5270-
// Why has MapCanvas the scale inversed?
5259+
// Why has MapCanvas the scale inverted?
52715260
mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() );
52725261
}
52735262

src/app/qgisapp.h

-2
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
12361236

12371237
bool cmpByText( QAction* a, QAction* b );
12381238

1239-
QString mOldScale;
1240-
12411239
//! the user has trusted the project macros
12421240
bool mTrustedMacros;
12431241

src/gui/qgsscalecombobox.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgis.h"
19+
#include "qgslogger.h"
1920
#include "qgsscalecombobox.h"
2021

2122
#include <QAbstractItemView>
@@ -30,7 +31,7 @@ QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
3031
setEditable( true );
3132
setInsertPolicy( QComboBox::NoInsert );
3233
setCompleter( 0 );
33-
connect( this, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( fixupScale() ) );
34+
connect( this, SIGNAL( activated( const QString & ) ), this, SLOT( fixupScale() ) );
3435
connect( lineEdit(), SIGNAL( editingFinished() ), this, SLOT( fixupScale() ) );
3536
fixupScale();
3637
}
@@ -65,7 +66,7 @@ void QgsScaleComboBox::updateScales( const QStringList &scales )
6566
blockSignals( true );
6667
clear();
6768
addItems( myScalesList );
68-
setEditText( oldScale );
69+
setScaleString( oldScale );
6970
blockSignals( false );
7071
}
7172

@@ -148,18 +149,25 @@ void QgsScaleComboBox::fixupScale()
148149
bool ok;
149150
QStringList txtList;
150151

152+
// QgsDebugMsg( QString( "entered with oldScale: %1" ).arg( oldScale ) );
151153
newScale = toDouble( currentText(), &ok );
152154
if ( ok )
153155
{
154-
mScale = newScale;
156+
// Valid string representation
157+
if ( newScale != oldScale )
158+
{
159+
// Scale has change, update.
160+
// QgsDebugMsg( QString( "New scale OK!: %1" ).arg( newScale ) );
161+
mScale = newScale;
162+
setScale( mScale );
163+
emit scaleChanged();
164+
}
155165
}
156-
// We set to the new string representation
157-
// or reset to the old
158-
setScale( mScale );
159-
160-
if ( oldScale != mScale )
166+
else
161167
{
162-
emit scaleChanged();
168+
// Invalid string representation
169+
// Reset to the old
170+
setScale( mScale );
163171
}
164172
}
165173

0 commit comments

Comments
 (0)