Skip to content

Commit

Permalink
Merge pull request #7969 from elpaso/bugfix-19901-relation-reference-…
Browse files Browse the repository at this point in the history
…NULL

QgsFeatureListComboBox nullRepresentation instead of hardcoded "NULL"
  • Loading branch information
elpaso authored Sep 21, 2018
2 parents 30b757b + 5378e37 commit 0ee119f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions python/gui/auto_generated/qgsfeaturelistcombobox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsfeaturefiltermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfeaturelistcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int QgsFeatureListComboBox::nullIndex() const

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

return index;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsfeaturelistcombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions tests/src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 22 additions & 4 deletions tests/src/gui/testqgsfeaturelistcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TestQgsFeatureListComboBox : public QObject
void testSetGetLayer();
void testSetGetForeignKey();
void testAllowNull();
void nullRepresentation();

private:
void waitForLoaded( QgsFeatureListComboBox *cb );
Expand All @@ -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()
Expand Down Expand Up @@ -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() );

Expand All @@ -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() );

Expand All @@ -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() );
Expand Down

0 comments on commit 0ee119f

Please sign in to comment.