Skip to content
Permalink
Browse files

Test of signals

  • Loading branch information
homann committed Sep 21, 2012
1 parent 08d28df commit 1b09393bd72b0a4370d78431108d57ee819e7e6f
Showing with 22 additions and 1 deletion.
  1. +8 −1 src/gui/qgsscalecombobox.cpp
  2. +14 −0 tests/src/gui/testqgsscalecombobox.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 )
@@ -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
@@ -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()
{
};

0 comments on commit 1b09393

Please sign in to comment.
You can’t perform that action at this time.