diff --git a/src/gui/qgsscalecombobox.cpp b/src/gui/qgsscalecombobox.cpp index dac0b898ac9..e2f3474f573 100644 --- a/src/gui/qgsscalecombobox.cpp +++ b/src/gui/qgsscalecombobox.cpp @@ -32,6 +32,7 @@ QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ) setCompleter( 0 ); connect( this, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( fixupScale() ) ); connect( lineEdit(), SIGNAL( editingFinished() ), this, SLOT( fixupScale() ) ); + fixupScale(); } QgsScaleComboBox::~QgsScaleComboBox() @@ -124,8 +125,14 @@ void QgsScaleComboBox::fixupScale() { mScale = newScale; } - // We set to the new string representation. + // We set to the new string representation + // or reset to the old setEditText( toString( mScale ) ); + + if ( ok ) + { + emit scaleChanged(); + } } QString QgsScaleComboBox::toString( double scale ) diff --git a/tests/src/gui/testqgsscalecombobox.cpp b/tests/src/gui/testqgsscalecombobox.cpp index 4ad15d133df..a4e1837000e 100644 --- a/tests/src/gui/testqgsscalecombobox.cpp +++ b/tests/src/gui/testqgsscalecombobox.cpp @@ -16,10 +16,12 @@ ***************************************************************************/ #include "qgsapplication.h" +#include "qgslogger.h" #include "qgsscalecombobox.h" #include #include #include +#include #include class TestQgsScaleComboBox: public QObject @@ -43,6 +45,7 @@ void TestQgsScaleComboBox::initTestCase() // Create a combobox, and init with predefined scales. s = new QgsScaleComboBox(); + QgsDebugMsg( QString( "Initial scale is %1" ).arg( s->scaleString() ) ); }; void TestQgsScaleComboBox::cleanupTestCase() @@ -90,7 +93,18 @@ void TestQgsScaleComboBox::basic() void TestQgsScaleComboBox::slot_test() { + QLineEdit *l = s->lineEdit(); + l->setText( "" ); + + QSignalSpy spyScaleChanged( s, SIGNAL( scaleChanged() ) ); + QSignalSpy spyFixup( l, SIGNAL( editingFinished() ) ); + + QTest::keyClicks( l, QLocale::system().toString( 0.02 ) ); + QTest::keyClick( l, Qt::Key_Return ); + QCOMPARE( spyFixup.count(), 2 ); // Qt emits twice!? + QCOMPARE( spyScaleChanged.count(), 2 ); // Qt emits twice!? } + void TestQgsScaleComboBox::cleanup() { };