Skip to content

Commit 1b09393

Browse files
committedSep 21, 2012
Test of signals
1 parent 08d28df commit 1b09393

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
 

‎src/gui/qgsscalecombobox.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
3232
setCompleter( 0 );
3333
connect( this, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( fixupScale() ) );
3434
connect( lineEdit(), SIGNAL( editingFinished() ), this, SLOT( fixupScale() ) );
35+
fixupScale();
3536
}
3637

3738
QgsScaleComboBox::~QgsScaleComboBox()
@@ -124,8 +125,14 @@ void QgsScaleComboBox::fixupScale()
124125
{
125126
mScale = newScale;
126127
}
127-
// We set to the new string representation.
128+
// We set to the new string representation
129+
// or reset to the old
128130
setEditText( toString( mScale ) );
131+
132+
if ( ok )
133+
{
134+
emit scaleChanged();
135+
}
129136
}
130137

131138
QString QgsScaleComboBox::toString( double scale )

‎tests/src/gui/testqgsscalecombobox.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
***************************************************************************/
1717

1818
#include "qgsapplication.h"
19+
#include "qgslogger.h"
1920
#include "qgsscalecombobox.h"
2021
#include <QObject>
2122
#include <QLineEdit>
2223
#include <QComboBox>
24+
#include <QSignalSpy>
2325
#include <QtTest>
2426

2527
class TestQgsScaleComboBox: public QObject
@@ -43,6 +45,7 @@ void TestQgsScaleComboBox::initTestCase()
4345

4446
// Create a combobox, and init with predefined scales.
4547
s = new QgsScaleComboBox();
48+
QgsDebugMsg( QString( "Initial scale is %1" ).arg( s->scaleString() ) );
4649
};
4750

4851
void TestQgsScaleComboBox::cleanupTestCase()
@@ -90,7 +93,18 @@ void TestQgsScaleComboBox::basic()
9093

9194
void TestQgsScaleComboBox::slot_test()
9295
{
96+
QLineEdit *l = s->lineEdit();
97+
l->setText( "" );
98+
99+
QSignalSpy spyScaleChanged( s, SIGNAL( scaleChanged() ) );
100+
QSignalSpy spyFixup( l, SIGNAL( editingFinished() ) );
101+
102+
QTest::keyClicks( l, QLocale::system().toString( 0.02 ) );
103+
QTest::keyClick( l, Qt::Key_Return );
104+
QCOMPARE( spyFixup.count(), 2 ); // Qt emits twice!?
105+
QCOMPARE( spyScaleChanged.count(), 2 ); // Qt emits twice!?
93106
}
107+
94108
void TestQgsScaleComboBox::cleanup()
95109
{
96110
};

0 commit comments

Comments
 (0)
Please sign in to comment.