Skip to content

Commit f4bc536

Browse files
committedDec 20, 2016
Manage null representation value in QgsApplication::nullRepresentation()
1 parent 35a2be6 commit f4bc536

28 files changed

+99
-54
lines changed
 

‎src/app/qgsclipboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ QString QgsClipboard::generateClipboardText() const
123123
textFields += it->geometry().exportToWkt();
124124
else
125125
{
126-
textFields += settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
126+
textFields += QgsApplication::nullRepresentation();
127127
}
128128
}
129129

‎src/app/qgsoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
640640
else
641641
mComboCopyFeatureFormat->setCurrentIndex( mComboCopyFeatureFormat->findData( mSettings->value( QStringLiteral( "/qgis/copyGeometryAsWKT" ), true ).toBool() ?
642642
QgsClipboard::AttributesWithWKT : QgsClipboard::AttributesOnly ) );
643-
leNullValue->setText( mSettings->value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
643+
leNullValue->setText( QgsApplication::nullRepresentation() );
644644
cbxIgnoreShapeEncoding->setChecked( mSettings->value( QStringLiteral( "/qgis/ignoreShapeEncoding" ), true ).toBool() );
645645

646646
cmbLegendDoubleClickAction->setCurrentIndex( mSettings->value( QStringLiteral( "/qgis/legendDoubleClickAction" ), 0 ).toInt() );
@@ -1254,7 +1254,7 @@ void QgsOptions::saveOptions()
12541254
}
12551255
mSettings->setValue( QStringLiteral( "/qgis/enableMacros" ), cmbEnableMacros->currentIndex() );
12561256

1257-
mSettings->setValue( QStringLiteral( "/qgis/nullValue" ), leNullValue->text() );
1257+
QgsApplication::setNullRepresentation( leNullValue->text() );
12581258
mSettings->setValue( QStringLiteral( "/qgis/style" ), cmbStyle->currentText() );
12591259
mSettings->setValue( QStringLiteral( "/IconSize" ), cmbIconSize->currentText() );
12601260

‎src/core/fieldformatter/qgsdatetimefieldformatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ QString QgsDateTimeFieldFormatter::representValue( QgsVectorLayer* layer, int fi
3434
if ( value.isNull() )
3535
{
3636
QSettings settings;
37-
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
37+
return QgsApplication::nullRepresentation();
3838
}
3939

4040
const QgsField field = layer->fields().at( fieldIndex );

‎src/core/fieldformatter/qgskeyvaluefieldformatter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* *
1515
***************************************************************************/
1616
#include "qgskeyvaluefieldformatter.h"
17+
#include "qgsapplication.h"
1718

1819
#include <QSettings>
1920

@@ -32,7 +33,7 @@ QString QgsKeyValueFieldFormatter::representValue( QgsVectorLayer* layer, int fi
3233
if ( value.isNull() )
3334
{
3435
QSettings settings;
35-
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
36+
return QgsApplication::nullRepresentation();
3637
}
3738

3839
QString result;

‎src/core/fieldformatter/qgslistfieldformatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* *
1515
***************************************************************************/
1616
#include "qgslistfieldformatter.h"
17-
17+
#include "qgsapplication.h"
1818
#include <QSettings>
1919

2020
QString QgsListFieldFormatter::id() const
@@ -32,7 +32,7 @@ QString QgsListFieldFormatter::representValue( QgsVectorLayer* layer, int fieldI
3232
if ( value.isNull() )
3333
{
3434
QSettings settings;
35-
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
35+
return QgsApplication::nullRepresentation();
3636
}
3737

3838
QString result;

‎src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer* layer, i
4747
Q_UNUSED( layer )
4848
Q_UNUSED( fieldIndex )
4949

50-
QgsValueRelationFieldFormatter::ValueRelationCache vrCache;
50+
ValueRelationCache vrCache;
5151

5252
if ( cache.isValid() )
5353
{
@@ -77,8 +77,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer* layer, i
7777
{
7878
if ( value.isNull() )
7979
{
80-
QSettings settings;
81-
return settings.value( "qgis/nullValue", "NULL" ).toString();
80+
return QgsApplication::nullRepresentation();
8281
}
8382

8483
Q_FOREACH ( const QgsValueRelationFieldFormatter::ValueRelationItem& item, vrCache )

‎src/core/qgsapplication.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,25 @@ void QgsApplication::copyPath( const QString& src, const QString& dst )
12581258
}
12591259
}
12601260

1261+
QString QgsApplication::nullRepresentation()
1262+
{
1263+
QgsApplication* app = instance();
1264+
if ( app->mNullRepresentation.isNull() )
1265+
app->mNullRepresentation = QSettings().value( QStringLiteral( "qgis/nullValue" ), QStringLiteral( "NULL" ) ).toString();
1266+
return app->mNullRepresentation;
1267+
}
1268+
1269+
void QgsApplication::setNullRepresentation( const QString& nullRepresentation )
1270+
{
1271+
QgsApplication* app = instance();
1272+
if ( app->mNullRepresentation == nullRepresentation )
1273+
return;
1274+
1275+
app->mNullRepresentation = nullRepresentation;
1276+
QSettings().setValue( QStringLiteral( "qgis/nullValue" ), nullRepresentation );
1277+
emit app->nullRepresentationChanged();
1278+
}
1279+
12611280
QgsActionScopeRegistry* QgsApplication::actionScopeRegistry()
12621281
{
12631282
return instance()->mActionScopeRegistry;

‎src/core/qgsapplication.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,21 @@ class CORE_EXPORT QgsApplication : public QApplication
402402
*/
403403
static QgsFieldFormatterRegistry* fieldKitRegistry();
404404

405+
/**
406+
* This string is used to represent the value `NULL` throughout QGIS.
407+
*
408+
* In general, when passing values around, prefer to use a null QVariant
409+
* `QVariant( field.type() )` or `QVariant( QVariant::Int )`. This value
410+
* should only be used in the final presentation step when showing values
411+
* in a widget or sending it to a web browser.
412+
*/
413+
static QString nullRepresentation();
414+
415+
/**
416+
* \copydoc nullRepresentation()
417+
*/
418+
static void setNullRepresentation( const QString& nullRepresentation );
419+
405420
public slots:
406421

407422
/** Causes the application instance to emit the settingsChanged() signal. This should
@@ -422,6 +437,11 @@ class CORE_EXPORT QgsApplication : public QApplication
422437
*/
423438
void settingsChanged();
424439

440+
/**
441+
* \copydoc nullRepresentation()
442+
*/
443+
void nullRepresentationChanged();
444+
425445
private:
426446
static void copyPath( const QString& src, const QString& dst );
427447
static QObject* ABISYM( mFileOpenEventReceiver );
@@ -472,6 +492,7 @@ class CORE_EXPORT QgsApplication : public QApplication
472492
QgsRuntimeProfiler* mProfiler;
473493
QgsTaskManager* mTaskManager;
474494
QgsFieldFormatterRegistry* mFieldFormatterRegistry;
495+
QString mNullRepresentation;
475496
};
476497

477498
#endif

‎src/core/qgsfield.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ QString QgsField::displayString( const QVariant& v ) const
211211
if ( v.isNull() )
212212
{
213213
QSettings settings;
214-
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
214+
return QgsApplication::nullRepresentation();
215215
}
216216

217217
if ( d->type == QVariant::Double && d->precision > 0 )

‎src/gui/attributetable/qgsfeaturelistmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const
7373
{
7474
if ( role == Qt::DisplayRole )
7575
{
76-
return QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
76+
return QgsApplication::nullRepresentation();
7777
}
7878
else if ( role == QgsAttributeTableModel::FeatureIdRole )
7979
{

‎src/gui/editorwidgets/qgsdatetimeedit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )
3737
mClearButton->hide();
3838
connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clear() ) );
3939

40-
mNullLabel = new QLineEdit( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(), this );
40+
mNullLabel = new QLineEdit( QgsApplication::nullRepresentation(), this );
4141
mNullLabel->setReadOnly( true );
4242
mNullLabel->setStyleSheet( QStringLiteral( "position: absolute; border: none; font-style: italic; color: grey;" ) );
4343
mNullLabel->hide();

‎src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void QgsDefaultSearchWidgetWrapper::setExpression( QString exp )
5858
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong );
5959

6060
QSettings settings;
61-
QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
61+
QString nullValue = QgsApplication::nullRepresentation();
6262
QString fieldName = layer()->fields().at( mFieldIdx ).name();
6363
QString str;
6464
if ( exp == nullValue )

‎src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const
4141

4242
if ( mLineEdit )
4343
{
44-
if ( mLineEdit->text().isEmpty() || mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
44+
if ( mLineEdit->text().isEmpty() || mLineEdit->text() == QgsApplication::nullRepresentation() )
4545
{
4646
return QVariant( field().type() );
4747
}
@@ -93,7 +93,7 @@ void QgsExternalResourceWidgetWrapper::initWidget( QWidget* editor )
9393
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor );
9494
if ( fle )
9595
{
96-
fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
96+
fle->setNullValue( QgsApplication::nullRepresentation() );
9797
}
9898
}
9999
else
@@ -151,7 +151,7 @@ void QgsExternalResourceWidgetWrapper::setValue( const QVariant& value )
151151
{
152152
if ( value.isNull() )
153153
{
154-
mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
154+
mLineEdit->setText( QgsApplication::nullRepresentation() );
155155
}
156156
else
157157
{
@@ -169,7 +169,7 @@ void QgsExternalResourceWidgetWrapper::setValue( const QVariant& value )
169169
{
170170
if ( value.isNull() )
171171
{
172-
mQgsWidget->setDocumentPath( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
172+
mQgsWidget->setDocumentPath( QgsApplication::nullRepresentation() );
173173
}
174174
else
175175
{

‎src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ QVariant QgsFileNameWidgetWrapper::value() const
3636

3737
if ( mLineEdit )
3838
{
39-
if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
39+
if ( mLineEdit->text() == QgsApplication::nullRepresentation() )
4040
value = QVariant( field().type() );
4141
else
4242
value = mLineEdit->text();
@@ -103,7 +103,7 @@ void QgsFileNameWidgetWrapper::initWidget( QWidget* editor )
103103
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor );
104104
if ( fle )
105105
{
106-
fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
106+
fle->setNullValue( QgsApplication::nullRepresentation() );
107107
}
108108

109109
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
@@ -115,7 +115,7 @@ void QgsFileNameWidgetWrapper::setValue( const QVariant& value )
115115
if ( mLineEdit )
116116
{
117117
if ( value.isNull() )
118-
mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
118+
mLineEdit->setText( QgsApplication::nullRepresentation() );
119119
else
120120
mLineEdit->setText( value.toString() );
121121
}

‎src/gui/editorwidgets/qgsphotowidgetwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ QVariant QgsPhotoWidgetWrapper::value() const
137137

138138
if ( mLineEdit )
139139
{
140-
if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
140+
if ( mLineEdit->text() == QgsApplication::nullRepresentation() )
141141
v = QVariant( QVariant::String );
142142
else
143143
v = mLineEdit->text();
@@ -223,7 +223,7 @@ void QgsPhotoWidgetWrapper::initWidget( QWidget* editor )
223223
QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
224224
if ( fle )
225225
{
226-
fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
226+
fle->setNullValue( QgsApplication::nullRepresentation() );
227227
}
228228

229229
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
@@ -246,7 +246,7 @@ void QgsPhotoWidgetWrapper::setValue( const QVariant& value )
246246
{
247247
if ( value.isNull() )
248248
{
249-
whileBlocking( mLineEdit )->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
249+
whileBlocking( mLineEdit )->setText( QgsApplication::nullRepresentation() );
250250
clearPicture();
251251
}
252252
else

‎src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
116116
minval -= stepval;
117117
}
118118
mDoubleSpinBox->setValue( minval );
119-
mDoubleSpinBox->setSpecialValueText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
119+
mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
120120
}
121121
mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits<double>::min() );
122122
mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits<double>::max() );
@@ -137,7 +137,7 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
137137
int stepval = step.toInt();
138138
minval -= stepval;
139139
mIntSpinBox->setValue( minval );
140-
mIntSpinBox->setSpecialValueText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
140+
mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
141141
}
142142
setupIntEditor( min, max, step, mIntSpinBox, this );
143143
if ( config( QStringLiteral( "Suffix" ) ).isValid() )

‎src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void QgsRelationReferenceSearchWidgetWrapper::onValueChanged( const QVariant& va
137137
else
138138
{
139139
QSettings settings;
140-
setExpression( value.isNull() ? settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() : value.toString() );
140+
setExpression( value.isNull() ? QgsApplication::nullRepresentation() : value.toString() );
141141
emit valueChanged();
142142
}
143143
emit expressionChanged( mExpression );
@@ -146,7 +146,7 @@ void QgsRelationReferenceSearchWidgetWrapper::onValueChanged( const QVariant& va
146146
void QgsRelationReferenceSearchWidgetWrapper::setExpression( QString exp )
147147
{
148148
QSettings settings;
149-
QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
149+
QString nullValue = QgsApplication::nullRepresentation();
150150
QString fieldName = layer()->fields().at( mFieldIdx ).name();
151151

152152
QString str;

‎src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
302302

303303
void QgsRelationReferenceWidget::deleteForeignKey()
304304
{
305-
QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
305+
QVariant nullValue = QgsApplication::nullRepresentation();
306306
if ( mReadOnlySelector )
307307
{
308308
QString nullText = QLatin1String( "" );
@@ -477,7 +477,7 @@ void QgsRelationReferenceWidget::init()
477477
mFilterComboBoxes << cb;
478478
mReferencedLayer->uniqueValues( idx, uniqueValues );
479479
cb->addItem( mReferencedLayer->attributeDisplayName( idx ) );
480-
QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
480+
QVariant nullValue = QgsApplication::nullRepresentation();
481481
cb->addItem( nullValue.toString(), QVariant( mReferencedLayer->fields().at( idx ).type() ) );
482482

483483
qSort( uniqueValues.begin(), uniqueValues.end(), qgsVariantLessThan );
@@ -496,7 +496,7 @@ void QgsRelationReferenceWidget::init()
496496

497497
if ( mChainFilters )
498498
{
499-
QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
499+
QVariant nullValue = QgsApplication::nullRepresentation();
500500

501501
QgsFeature ft;
502502
QgsFeatureIterator fit = layerCache->getFeatures();
@@ -552,7 +552,7 @@ void QgsRelationReferenceWidget::init()
552552
mComboBox->setCompleter( completer );
553553

554554

555-
QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
555+
QVariant nullValue = QgsApplication::nullRepresentation();
556556

557557
if ( mChainFilters && mFeature.isValid() )
558558
{
@@ -797,7 +797,7 @@ void QgsRelationReferenceWidget::mapToolDeactivated()
797797

798798
void QgsRelationReferenceWidget::filterChanged()
799799
{
800-
QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
800+
QVariant nullValue = QgsApplication::nullRepresentation();
801801

802802
QStringList filters;
803803
QgsAttributeList attrs;

‎src/gui/editorwidgets/qgstexteditwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ QVariant QgsTextEditWrapper::value() const
5656
}
5757

5858
if (( v.isEmpty() && ( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) ||
59-
v == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
59+
v == QgsApplication::nullRepresentation() )
6060
return QVariant( field().type() );
6161

6262
if ( !defaultValue().isNull() && v == defaultValue().toString() )
@@ -119,7 +119,7 @@ void QgsTextEditWrapper::initWidget( QWidget* editor )
119119
QVariant defVal = defaultValue();
120120
if ( defVal.isNull() )
121121
{
122-
defVal = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" );
122+
defVal = QgsApplication::nullRepresentation();
123123
}
124124

125125
QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
@@ -215,7 +215,7 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant& val )
215215
if ( val.isNull() )
216216
{
217217
if ( !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
218-
v = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
218+
v = QgsApplication::nullRepresentation();
219219
}
220220
else
221221
v = val.toString();

‎src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QVariant QgsUniqueValuesWidgetWrapper::value() const
3737

3838
if ( mLineEdit )
3939
{
40-
if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
40+
if ( mLineEdit->text() == QgsApplication::nullRepresentation() )
4141
value = QVariant( field().type() );
4242
else
4343
value = mLineEdit->text();
@@ -83,7 +83,7 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor )
8383
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor );
8484
if ( fle && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
8585
{
86-
fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
86+
fle->setNullValue( QgsApplication::nullRepresentation() );
8787
}
8888

8989
QCompleter* c = new QCompleter( sValues );
@@ -127,7 +127,7 @@ void QgsUniqueValuesWidgetWrapper::setValue( const QVariant& value )
127127
if ( mLineEdit )
128128
{
129129
if ( value.isNull() )
130-
mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
130+
mLineEdit->setText( QgsApplication::nullRepresentation() );
131131
else
132132
mLineEdit->setText( value.toString() );
133133
}

‎src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsattributetypeloaddialog.h"
1919
#include "qgsvaluemapfieldformatter.h"
20+
#include "qgsapplication.h"
2021

2122
#include <QSettings>
2223
#include <QFileDialog>
@@ -52,7 +53,7 @@ QVariantMap QgsValueMapConfigDlg::config()
5253
continue;
5354

5455
QString ks = ki->text();
55-
if (( ks == settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) && !( ki->flags() & Qt::ItemIsEditable ) )
56+
if (( ks == QgsApplication::nullRepresentation() ) && !( ki->flags() & Qt::ItemIsEditable ) )
5657
ks = VALUEMAP_NULL_TEXT;
5758

5859
if ( !vi || vi->text().isNull() )
@@ -159,7 +160,7 @@ void QgsValueMapConfigDlg::setRow( int row, const QString& value, const QString&
159160
{
160161
QFont cellFont;
161162
cellFont.setItalic( true );
162-
valueCell = new QTableWidgetItem( settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
163+
valueCell = new QTableWidgetItem( QgsApplication::nullRepresentation() );
163164
valueCell->setFont( cellFont );
164165
valueCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
165166
descriptionCell->setFont( cellFont );
@@ -246,7 +247,7 @@ void QgsValueMapConfigDlg::loadFromCSVButtonPushed()
246247
val = val.mid( 1, val.length() - 2 );
247248
}
248249

249-
if ( key == settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
250+
if ( key == QgsApplication::nullRepresentation() )
250251
key = VALUEMAP_NULL_TEXT;
251252

252253
map[ key ] = val;

‎src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void QgsValueRelationSearchWidgetWrapper::onValueChanged()
190190
else
191191
{
192192
QSettings settings;
193-
setExpression( vl.isNull() ? settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() : vl.toString() );
193+
setExpression( vl.isNull() ? QgsApplication::nullRepresentation() : vl.toString() );
194194
emit valueChanged();
195195
}
196196
emit expressionChanged( mExpression );
@@ -199,7 +199,7 @@ void QgsValueRelationSearchWidgetWrapper::onValueChanged()
199199
void QgsValueRelationSearchWidgetWrapper::setExpression( QString exp )
200200
{
201201
QSettings settings;
202-
QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
202+
QString nullValue = QgsApplication::nullRepresentation();
203203
QString fieldName = layer()->fields().at( mFieldIdx ).name();
204204

205205
QString str;

‎src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QVariant QgsWebViewWidgetWrapper::value() const
4848

4949
if ( mLineEdit )
5050
{
51-
if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() )
51+
if ( mLineEdit->text() == QgsApplication::nullRepresentation() )
5252
v = QVariant( QVariant::String );
5353
else
5454
v = mLineEdit->text();
@@ -101,7 +101,7 @@ void QgsWebViewWidgetWrapper::initWidget( QWidget* editor )
101101
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
102102
if ( fle )
103103
{
104-
fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
104+
fle->setNullValue( QgsApplication::nullRepresentation() );
105105
}
106106

107107
container = qobject_cast<QWidget*>( mLineEdit->parent() );
@@ -151,7 +151,7 @@ void QgsWebViewWidgetWrapper::setValue( const QVariant& value )
151151
if ( mLineEdit )
152152
{
153153
if ( value.isNull() )
154-
mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() );
154+
mLineEdit->setText( QgsApplication::nullRepresentation() );
155155
else
156156
mLineEdit->setText( value.toString() );
157157
}

‎src/gui/qgsfieldvalidator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgslogger.h"
2929
#include "qgslonglongvalidator.h"
3030
#include "qgsfields.h"
31+
#include "qgsapplication.h"
3132

3233
QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, const QString& defaultValue, const QString& dateFormat )
3334
: QValidator( parent )
@@ -84,7 +85,7 @@ QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, co
8485
}
8586

8687
QSettings settings;
87-
mNullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
88+
mNullValue = QgsApplication::nullRepresentation();
8889
}
8990

9091
QgsFieldValidator::~QgsFieldValidator()

‎src/gui/qgsfilewidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgsfilterlineedit.h"
2828
#include "qgslogger.h"
2929
#include "qgsproject.h"
30+
#include "qgsapplication.h"
3031

3132
QgsFileWidget::QgsFileWidget( QWidget *parent )
3233
: QWidget( parent )
@@ -82,7 +83,7 @@ QString QgsFileWidget::filePath()
8283

8384
void QgsFileWidget::setFilePath( QString path )
8485
{
85-
if ( path == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ) )
86+
if ( path == QgsApplication::nullRepresentation() )
8687
{
8788
path = QLatin1String( "" );
8889
}
@@ -286,7 +287,7 @@ QString QgsFileWidget::toUrl( const QString& path ) const
286287
QString rep;
287288
if ( path.isEmpty() )
288289
{
289-
return QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
290+
return QgsApplication::nullRepresentation();
290291
}
291292

292293
QString urlStr = relativePath( path, false );

‎src/gui/qgsquerybuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void QgsQueryBuilder::fillValues( int idx, int limit )
120120
mLayer->uniqueValues( idx, values, limit );
121121

122122
QSettings settings;
123-
QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
123+
QString nullValue = QgsApplication::nullRepresentation();
124124

125125
QgsDebugMsg( QString( "nullValue: %1" ).arg( nullValue ) );
126126

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
1515
${CMAKE_SOURCE_DIR}/src/core/layertree
1616
${CMAKE_SOURCE_DIR}/src/core/raster
1717
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
18+
${CMAKE_SOURCE_DIR}/src/test
1819
)
1920
INCLUDE_DIRECTORIES(SYSTEM
2021
${QT_INCLUDE_DIR}

‎tests/src/core/testqgsfield.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <QSharedPointer>
2121

2222
#include "qgsfield.h"
23+
#include "qgsapplication.h"
24+
#include "qgstest.h"
2325

2426
class TestQgsField: public QObject
2527
{
@@ -299,8 +301,7 @@ void TestQgsField::displayString()
299301
QCOMPARE( stringField.displayString( test ), test );
300302

301303
//test NULL
302-
QSettings s;
303-
s.setValue( QStringLiteral( "qgis/nullValue" ), "TEST NULL" );
304+
QgsApplication::setNullRepresentation( "TEST NULL" );
304305
QVariant nullString = QVariant( QVariant::String );
305306
QCOMPARE( stringField.displayString( nullString ), QString( "TEST NULL" ) );
306307

@@ -513,5 +514,5 @@ void TestQgsField::collection()
513514
QVERIFY( !field.convertCompatible( str ) );
514515
}
515516

516-
QTEST_MAIN( TestQgsField )
517+
QGSTEST_MAIN( TestQgsField )
517518
#include "testqgsfield.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.