Test of signals

This commit is contained in:
Magnus Homann 2012-09-19 23:55:14 +02:00
parent 08d28df9c2
commit 1b09393bd7
2 changed files with 22 additions and 1 deletions

View File

@ -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 )

View File

@ -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()
{
};