Skip to content
Permalink
Browse files

QgsFeatureListComboBox nullRepresentation instead of hardcoded "NULL"

Fixes #19901 - Relation Reference Widget: Representation for NULL values is not respected
  • Loading branch information
elpaso committed Sep 20, 2018
1 parent f208191 commit 5378e37cf904c941e5f2ae425c3e5ce1cff35da1
@@ -43,13 +43,13 @@ The layer from which features should be listed.
QString displayExpression() const;
%Docstring
The display expression will be used to display features as well as
the the value to match the typed text against.
the value to match the typed text against.
%End

void setDisplayExpression( const QString &displayExpression );
%Docstring
The display expression will be used to display features as well as
the the value to match the typed text against.
the value to match the typed text against.
%End

QString filterExpression() const;
@@ -223,7 +223,7 @@ void QgsFeatureFilterModel::updateCompleter()
std::sort( entries.begin(), entries.end(), []( const Entry & a, const Entry & b ) { return a.value.localeAwareCompare( b.value ) < 0; } );

if ( mAllowNull )
entries.prepend( Entry( QVariant( QVariant::Int ), tr( "NULL" ), QgsFeature() ) );
entries.prepend( Entry( QVariant( QVariant::Int ), QgsApplication::nullRepresentation(), QgsFeature() ) );

const int newEntriesSize = entries.size();

@@ -433,7 +433,7 @@ void QgsFeatureFilterModel::setExtraIdentifierValueUnguarded( const QVariant &ex
{
beginInsertRows( QModelIndex(), 0, 0 );
if ( extraIdentifierValue.isNull() )
mEntries.prepend( Entry( QVariant( QVariant::Int ), QStringLiteral( "%1" ).arg( tr( "NULL" ) ), QgsFeature() ) );
mEntries.prepend( Entry( QVariant( QVariant::Int ), QgsApplication::nullRepresentation( ), QgsFeature() ) );
else
mEntries.prepend( Entry( extraIdentifierValue, QStringLiteral( "(%1)" ).arg( extraIdentifierValue.toString() ), QgsFeature() ) );
endInsertRows();
@@ -143,7 +143,7 @@ int QgsFeatureListComboBox::nullIndex() const

if ( allowNull() )
{
index = findText( tr( "NULL" ) );
index = findText( QgsApplication::nullRepresentation( ) );
}

return index;
@@ -66,13 +66,13 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox

/**
* The display expression will be used to display features as well as
* the the value to match the typed text against.
* the value to match the typed text against.
*/
QString displayExpression() const;

/**
* The display expression will be used to display features as well as
* the the value to match the typed text against.
* the value to match the typed text against.
*/
void setDisplayExpression( const QString &displayExpression );

@@ -146,3 +146,4 @@ ADD_QGIS_TEST(layoutview testqgslayoutview.cpp)
ADD_QGIS_TEST(valuemapwidgetwrapper testqgsvaluemapwidgetwrapper.cpp)
ADD_QGIS_TEST(valuerelationwidgetwrapper testqgsvaluerelationwidgetwrapper.cpp)
ADD_QGIS_TEST(relationreferencewidget testqgsrelationreferencewidget.cpp)
ADD_QGIS_TEST(featurelistcombobox testqgsfeaturelistcombobox.cpp)
@@ -41,6 +41,7 @@ class TestQgsFeatureListComboBox : public QObject
void testSetGetLayer();
void testSetGetForeignKey();
void testAllowNull();
void nullRepresentation();

private:
void waitForLoaded( QgsFeatureListComboBox *cb );
@@ -52,6 +53,12 @@ void TestQgsFeatureListComboBox::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();

// Set up the QgsSettings environment
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST-FEATURELIST-COMBOBOX" ) );

}

void TestQgsFeatureListComboBox::cleanupTestCase()
@@ -106,8 +113,7 @@ void TestQgsFeatureListComboBox::testSetGetLayer()

void TestQgsFeatureListComboBox::testSetGetForeignKey()
{
QgsFeatureListComboBox *cb = new QgsFeatureListComboBox();
// std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );
std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );

QVERIFY( cb->identifierValue().isNull() );

@@ -117,7 +123,7 @@ void TestQgsFeatureListComboBox::testSetGetForeignKey()
emit cb->lineEdit()->textChanged( "ro" );
QVERIFY( cb->identifierValue().isNull() );

waitForLoaded( cb );
waitForLoaded( cb.get() );

QVERIFY( cb->identifierValue().isNull() );

@@ -127,10 +133,22 @@ void TestQgsFeatureListComboBox::testSetGetForeignKey()

void TestQgsFeatureListComboBox::testAllowNull()
{
QVERIFY( false );
//QVERIFY( false );
// Note to self: implement this!
}

void TestQgsFeatureListComboBox::nullRepresentation()
{

QgsApplication::setNullRepresentation( QStringLiteral( "nope" ) );
std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );
cb->setAllowNull( true );

QCOMPARE( cb->lineEdit()->text(), QStringLiteral( "nope" ) );
QCOMPARE( cb->nullIndex(), 0 );

}

void TestQgsFeatureListComboBox::waitForLoaded( QgsFeatureListComboBox *cb )
{
QgsFeatureFilterModel *model = qobject_cast<QgsFeatureFilterModel *>( cb->model() );

0 comments on commit 5378e37

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