Skip to content

Commit

Permalink
Test of signals
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Sep 21, 2012
1 parent 08d28df commit 1b09393
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/gui/qgsscalecombobox.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down
14 changes: 14 additions & 0 deletions tests/src/gui/testqgsscalecombobox.cpp
Expand Up @@ -16,10 +16,12 @@
***************************************************************************/

#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsscalecombobox.h"
#include <QObject>
#include <QLineEdit>
#include <QComboBox>
#include <QSignalSpy>
#include <QtTest>

class TestQgsScaleComboBox: public QObject
Expand All @@ -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()
Expand Down Expand Up @@ -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()
{
};
Expand Down

0 comments on commit 1b09393

Please sign in to comment.