mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #8442 from signedav/textfield_null
Range widget: Remove null representator during editing
This commit is contained in:
commit
438a1daf6a
@ -107,6 +107,8 @@ void QgsDoubleSpinBox::changed( double value )
|
||||
void QgsDoubleSpinBox::clear()
|
||||
{
|
||||
setValue( clearValue() );
|
||||
if ( mLineEdit->isNull() )
|
||||
mLineEdit->clear();
|
||||
}
|
||||
|
||||
void QgsDoubleSpinBox::setClearValue( double customValue, const QString &specialValueText )
|
||||
@ -155,9 +157,15 @@ void QgsDoubleSpinBox::setLineEditAlignment( Qt::Alignment alignment )
|
||||
void QgsDoubleSpinBox::setSpecialValueText( const QString &txt )
|
||||
{
|
||||
if ( txt.isEmpty() )
|
||||
{
|
||||
QDoubleSpinBox::setSpecialValueText( SPECIAL_TEXT_WHEN_EMPTY );
|
||||
mLineEdit->setNullValue( SPECIAL_TEXT_WHEN_EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
QDoubleSpinBox::setSpecialValueText( txt );
|
||||
mLineEdit->setNullValue( SPECIAL_TEXT_WHEN_EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsDoubleSpinBox::stripped( const QString &originalText ) const
|
||||
|
@ -104,6 +104,8 @@ void QgsSpinBox::changed( int value )
|
||||
void QgsSpinBox::clear()
|
||||
{
|
||||
setValue( clearValue() );
|
||||
if ( mLineEdit->isNull() )
|
||||
mLineEdit->clear();
|
||||
}
|
||||
|
||||
void QgsSpinBox::setClearValue( int customValue, const QString &specialValueText )
|
||||
@ -152,9 +154,15 @@ void QgsSpinBox::setLineEditAlignment( Qt::Alignment alignment )
|
||||
void QgsSpinBox::setSpecialValueText( const QString &txt )
|
||||
{
|
||||
if ( txt.isEmpty() )
|
||||
{
|
||||
QSpinBox::setSpecialValueText( SPECIAL_TEXT_WHEN_EMPTY );
|
||||
mLineEdit->setNullValue( SPECIAL_TEXT_WHEN_EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
QSpinBox::setSpecialValueText( txt );
|
||||
mLineEdit->setNullValue( txt );
|
||||
}
|
||||
}
|
||||
|
||||
int QgsSpinBox::valueFromText( const QString &text ) const
|
||||
|
@ -89,7 +89,6 @@ void QgsFilterLineEdit::focusInEvent( QFocusEvent *e )
|
||||
QLineEdit::focusInEvent( e );
|
||||
if ( e->reason() == Qt::MouseFocusReason && ( isNull() || mSelectOnFocus ) )
|
||||
{
|
||||
mFocusInEvent = true;
|
||||
mWaitingForMouseRelease = true;
|
||||
}
|
||||
}
|
||||
@ -213,3 +212,14 @@ bool QgsFilterLineEdit::event( QEvent *event )
|
||||
|
||||
return QLineEdit::event( event );;
|
||||
}
|
||||
|
||||
/// @cond PRIVATE
|
||||
void QgsSpinBoxLineEdit::focusInEvent( QFocusEvent *e )
|
||||
{
|
||||
QLineEdit::focusInEvent( e );
|
||||
if ( isNull() )
|
||||
{
|
||||
clear();
|
||||
}
|
||||
}
|
||||
/// @endcond
|
||||
|
@ -286,7 +286,6 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
|
||||
QString mNullValue;
|
||||
QString mDefaultValue;
|
||||
QString mStyleSheet;
|
||||
bool mFocusInEvent = false;
|
||||
bool mWaitingForMouseRelease = false;
|
||||
bool mSelectOnFocus = false;
|
||||
|
||||
@ -325,6 +324,9 @@ class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
|
||||
setModified( true );
|
||||
emit cleared();
|
||||
}
|
||||
|
||||
protected:
|
||||
void focusInEvent( QFocusEvent *e ) override;
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
|
@ -51,6 +51,7 @@ class TestQgsRangeWidgetWrapper : public QObject
|
||||
void test_setDoubleSmallerRange();
|
||||
void test_setDoubleLimits();
|
||||
void test_nulls();
|
||||
void test_focus();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QgsRangeWidgetWrapper> widget0; // For field 0
|
||||
@ -328,7 +329,64 @@ void TestQgsRangeWidgetWrapper::test_nulls()
|
||||
|
||||
}
|
||||
|
||||
void TestQgsRangeWidgetWrapper::test_focus()
|
||||
{
|
||||
QgsApplication::setNullRepresentation( QString( "nope" ) );
|
||||
|
||||
QWidget *w = new QWidget(); //required for focus events
|
||||
QApplication::setActiveWindow( w );
|
||||
|
||||
QVariantMap cfg;
|
||||
cfg.insert( QStringLiteral( "AllowNull" ), true );
|
||||
|
||||
widget1->setConfig( cfg );
|
||||
QgsDoubleSpinBox *editor1 = qobject_cast<QgsDoubleSpinBox *>( widget1->createWidget( w ) );
|
||||
QVERIFY( editor1 );
|
||||
widget1->initWidget( editor1 );
|
||||
|
||||
widget2->setConfig( cfg );
|
||||
QgsDoubleSpinBox *editor2 = qobject_cast<QgsDoubleSpinBox *>( widget2->createWidget( w ) );
|
||||
QVERIFY( editor2 );
|
||||
widget2->initWidget( editor2 );
|
||||
|
||||
editor1->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );
|
||||
editor2->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );
|
||||
|
||||
QVERIFY( editor1->mLineEdit->isNull() );
|
||||
QVERIFY( editor2->mLineEdit->isNull() );
|
||||
QVERIFY( !editor1->mLineEdit->hasFocus() );
|
||||
QVERIFY( !editor2->mLineEdit->hasFocus() );
|
||||
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
|
||||
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
|
||||
|
||||
editor1->mLineEdit->setFocus();
|
||||
QVERIFY( editor1->mLineEdit->hasFocus() );
|
||||
QVERIFY( !editor2->mLineEdit->hasFocus() );
|
||||
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "" ) );
|
||||
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
|
||||
|
||||
editor2->mLineEdit->setFocus();
|
||||
QVERIFY( !editor1->mLineEdit->hasFocus() );
|
||||
QVERIFY( editor2->mLineEdit->hasFocus() );
|
||||
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
|
||||
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );
|
||||
|
||||
editor1->mLineEdit->setFocus();
|
||||
editor1->mLineEdit->setText( QString( "151.000000000" ) );
|
||||
QVERIFY( !editor1->mLineEdit->isNull() );
|
||||
QVERIFY( editor2->mLineEdit->isNull() );
|
||||
QVERIFY( editor1->mLineEdit->hasFocus() );
|
||||
QVERIFY( !editor2->mLineEdit->hasFocus() );
|
||||
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
|
||||
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
|
||||
|
||||
editor2->mLineEdit->setFocus();
|
||||
QVERIFY( !editor1->mLineEdit->hasFocus() );
|
||||
QVERIFY( editor2->mLineEdit->hasFocus() );
|
||||
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
|
||||
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );
|
||||
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsRangeWidgetWrapper )
|
||||
#include "testqgsrangewidgetwrapper.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user