diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp index 89734ce39ee..e2373dc6de5 100644 --- a/src/app/qgsclipboard.cpp +++ b/src/app/qgsclipboard.cpp @@ -123,7 +123,7 @@ QString QgsClipboard::generateClipboardText() const textFields += it->geometry().exportToWkt(); else { - textFields += settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + textFields += QgsApplication::nullRepresentation(); } } diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index 982cd54ae61..b2013838e28 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -640,7 +640,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) else mComboCopyFeatureFormat->setCurrentIndex( mComboCopyFeatureFormat->findData( mSettings->value( QStringLiteral( "/qgis/copyGeometryAsWKT" ), true ).toBool() ? QgsClipboard::AttributesWithWKT : QgsClipboard::AttributesOnly ) ); - leNullValue->setText( mSettings->value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + leNullValue->setText( QgsApplication::nullRepresentation() ); cbxIgnoreShapeEncoding->setChecked( mSettings->value( QStringLiteral( "/qgis/ignoreShapeEncoding" ), true ).toBool() ); cmbLegendDoubleClickAction->setCurrentIndex( mSettings->value( QStringLiteral( "/qgis/legendDoubleClickAction" ), 0 ).toInt() ); @@ -1254,7 +1254,7 @@ void QgsOptions::saveOptions() } mSettings->setValue( QStringLiteral( "/qgis/enableMacros" ), cmbEnableMacros->currentIndex() ); - mSettings->setValue( QStringLiteral( "/qgis/nullValue" ), leNullValue->text() ); + QgsApplication::setNullRepresentation( leNullValue->text() ); mSettings->setValue( QStringLiteral( "/qgis/style" ), cmbStyle->currentText() ); mSettings->setValue( QStringLiteral( "/IconSize" ), cmbIconSize->currentText() ); diff --git a/src/core/fieldformatter/qgsdatetimefieldformatter.cpp b/src/core/fieldformatter/qgsdatetimefieldformatter.cpp index 3c793ca795c..a5333fd90b0 100644 --- a/src/core/fieldformatter/qgsdatetimefieldformatter.cpp +++ b/src/core/fieldformatter/qgsdatetimefieldformatter.cpp @@ -34,7 +34,7 @@ QString QgsDateTimeFieldFormatter::representValue( QgsVectorLayer* layer, int fi if ( value.isNull() ) { QSettings settings; - return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } const QgsField field = layer->fields().at( fieldIndex ); diff --git a/src/core/fieldformatter/qgskeyvaluefieldformatter.cpp b/src/core/fieldformatter/qgskeyvaluefieldformatter.cpp index 06db8930205..3628a3acb95 100644 --- a/src/core/fieldformatter/qgskeyvaluefieldformatter.cpp +++ b/src/core/fieldformatter/qgskeyvaluefieldformatter.cpp @@ -14,6 +14,7 @@ * * ***************************************************************************/ #include "qgskeyvaluefieldformatter.h" +#include "qgsapplication.h" #include @@ -32,7 +33,7 @@ QString QgsKeyValueFieldFormatter::representValue( QgsVectorLayer* layer, int fi if ( value.isNull() ) { QSettings settings; - return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } QString result; diff --git a/src/core/fieldformatter/qgslistfieldformatter.cpp b/src/core/fieldformatter/qgslistfieldformatter.cpp index 2a78be7c5ee..3214eb21464 100644 --- a/src/core/fieldformatter/qgslistfieldformatter.cpp +++ b/src/core/fieldformatter/qgslistfieldformatter.cpp @@ -14,7 +14,7 @@ * * ***************************************************************************/ #include "qgslistfieldformatter.h" - +#include "qgsapplication.h" #include QString QgsListFieldFormatter::id() const @@ -32,7 +32,7 @@ QString QgsListFieldFormatter::representValue( QgsVectorLayer* layer, int fieldI if ( value.isNull() ) { QSettings settings; - return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } QString result; diff --git a/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp b/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp index d4f8ee28b44..4fdee0b3fc9 100644 --- a/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp +++ b/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp @@ -47,7 +47,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer* layer, i Q_UNUSED( layer ) Q_UNUSED( fieldIndex ) - QgsValueRelationFieldFormatter::ValueRelationCache vrCache; + ValueRelationCache vrCache; if ( cache.isValid() ) { @@ -77,8 +77,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer* layer, i { if ( value.isNull() ) { - QSettings settings; - return settings.value( "qgis/nullValue", "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } Q_FOREACH ( const QgsValueRelationFieldFormatter::ValueRelationItem& item, vrCache ) diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index b5d410888bc..8ff33afd6e6 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -1258,6 +1258,25 @@ void QgsApplication::copyPath( const QString& src, const QString& dst ) } } +QString QgsApplication::nullRepresentation() +{ + QgsApplication* app = instance(); + if ( app->mNullRepresentation.isNull() ) + app->mNullRepresentation = QSettings().value( QStringLiteral( "qgis/nullValue" ), QStringLiteral( "NULL" ) ).toString(); + return app->mNullRepresentation; +} + +void QgsApplication::setNullRepresentation( const QString& nullRepresentation ) +{ + QgsApplication* app = instance(); + if ( app->mNullRepresentation == nullRepresentation ) + return; + + app->mNullRepresentation = nullRepresentation; + QSettings().setValue( QStringLiteral( "qgis/nullValue" ), nullRepresentation ); + emit app->nullRepresentationChanged(); +} + QgsActionScopeRegistry* QgsApplication::actionScopeRegistry() { return instance()->mActionScopeRegistry; diff --git a/src/core/qgsapplication.h b/src/core/qgsapplication.h index 168e2df8e1b..c980f962265 100644 --- a/src/core/qgsapplication.h +++ b/src/core/qgsapplication.h @@ -402,6 +402,21 @@ class CORE_EXPORT QgsApplication : public QApplication */ static QgsFieldFormatterRegistry* fieldKitRegistry(); + /** + * This string is used to represent the value `NULL` throughout QGIS. + * + * In general, when passing values around, prefer to use a null QVariant + * `QVariant( field.type() )` or `QVariant( QVariant::Int )`. This value + * should only be used in the final presentation step when showing values + * in a widget or sending it to a web browser. + */ + static QString nullRepresentation(); + + /** + * \copydoc nullRepresentation() + */ + static void setNullRepresentation( const QString& nullRepresentation ); + public slots: /** Causes the application instance to emit the settingsChanged() signal. This should @@ -422,6 +437,11 @@ class CORE_EXPORT QgsApplication : public QApplication */ void settingsChanged(); + /** + * \copydoc nullRepresentation() + */ + void nullRepresentationChanged(); + private: static void copyPath( const QString& src, const QString& dst ); static QObject* ABISYM( mFileOpenEventReceiver ); @@ -472,6 +492,7 @@ class CORE_EXPORT QgsApplication : public QApplication QgsRuntimeProfiler* mProfiler; QgsTaskManager* mTaskManager; QgsFieldFormatterRegistry* mFieldFormatterRegistry; + QString mNullRepresentation; }; #endif diff --git a/src/core/qgsfield.cpp b/src/core/qgsfield.cpp index c60aa9dba24..5cfa7a633a1 100644 --- a/src/core/qgsfield.cpp +++ b/src/core/qgsfield.cpp @@ -211,7 +211,7 @@ QString QgsField::displayString( const QVariant& v ) const if ( v.isNull() ) { QSettings settings; - return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } if ( d->type == QVariant::Double && d->precision > 0 ) diff --git a/src/gui/attributetable/qgsfeaturelistmodel.cpp b/src/gui/attributetable/qgsfeaturelistmodel.cpp index e33c2c5a75c..7ddcb1d9d47 100644 --- a/src/gui/attributetable/qgsfeaturelistmodel.cpp +++ b/src/gui/attributetable/qgsfeaturelistmodel.cpp @@ -73,7 +73,7 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const { if ( role == Qt::DisplayRole ) { - return QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } else if ( role == QgsAttributeTableModel::FeatureIdRole ) { diff --git a/src/gui/editorwidgets/qgsdatetimeedit.cpp b/src/gui/editorwidgets/qgsdatetimeedit.cpp index 264d4e2be6d..bc028cdf4e9 100644 --- a/src/gui/editorwidgets/qgsdatetimeedit.cpp +++ b/src/gui/editorwidgets/qgsdatetimeedit.cpp @@ -37,7 +37,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent ) mClearButton->hide(); connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); - mNullLabel = new QLineEdit( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(), this ); + mNullLabel = new QLineEdit( QgsApplication::nullRepresentation(), this ); mNullLabel->setReadOnly( true ); mNullLabel->setStyleSheet( QStringLiteral( "position: absolute; border: none; font-style: italic; color: grey;" ) ); mNullLabel->hide(); diff --git a/src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp index 6920f89a3b3..8ceb19221e9 100644 --- a/src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp @@ -58,7 +58,7 @@ void QgsDefaultSearchWidgetWrapper::setExpression( QString exp ) bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong ); QSettings settings; - QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + QString nullValue = QgsApplication::nullRepresentation(); QString fieldName = layer()->fields().at( mFieldIdx ).name(); QString str; if ( exp == nullValue ) diff --git a/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp b/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp index ccac4d02b8d..2a8db09ff4f 100644 --- a/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp @@ -41,7 +41,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const if ( mLineEdit ) { - if ( mLineEdit->text().isEmpty() || mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( mLineEdit->text().isEmpty() || mLineEdit->text() == QgsApplication::nullRepresentation() ) { return QVariant( field().type() ); } @@ -93,7 +93,7 @@ void QgsExternalResourceWidgetWrapper::initWidget( QWidget* editor ) QgsFilterLineEdit* fle = qobject_cast( editor ); if ( fle ) { - fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + fle->setNullValue( QgsApplication::nullRepresentation() ); } } else @@ -151,7 +151,7 @@ void QgsExternalResourceWidgetWrapper::setValue( const QVariant& value ) { if ( value.isNull() ) { - mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mLineEdit->setText( QgsApplication::nullRepresentation() ); } else { @@ -169,7 +169,7 @@ void QgsExternalResourceWidgetWrapper::setValue( const QVariant& value ) { if ( value.isNull() ) { - mQgsWidget->setDocumentPath( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mQgsWidget->setDocumentPath( QgsApplication::nullRepresentation() ); } else { diff --git a/src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp b/src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp index 55d8c0db5f3..32bc438d8b8 100644 --- a/src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp @@ -36,7 +36,7 @@ QVariant QgsFileNameWidgetWrapper::value() const if ( mLineEdit ) { - if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( mLineEdit->text() == QgsApplication::nullRepresentation() ) value = QVariant( field().type() ); else value = mLineEdit->text(); @@ -103,7 +103,7 @@ void QgsFileNameWidgetWrapper::initWidget( QWidget* editor ) QgsFilterLineEdit* fle = qobject_cast( editor ); if ( fle ) { - fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + fle->setNullValue( QgsApplication::nullRepresentation() ); } connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) ); @@ -115,7 +115,7 @@ void QgsFileNameWidgetWrapper::setValue( const QVariant& value ) if ( mLineEdit ) { if ( value.isNull() ) - mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mLineEdit->setText( QgsApplication::nullRepresentation() ); else mLineEdit->setText( value.toString() ); } diff --git a/src/gui/editorwidgets/qgsphotowidgetwrapper.cpp b/src/gui/editorwidgets/qgsphotowidgetwrapper.cpp index fe4017ae8c8..5be3e1e3b98 100644 --- a/src/gui/editorwidgets/qgsphotowidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsphotowidgetwrapper.cpp @@ -137,7 +137,7 @@ QVariant QgsPhotoWidgetWrapper::value() const if ( mLineEdit ) { - if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( mLineEdit->text() == QgsApplication::nullRepresentation() ) v = QVariant( QVariant::String ); else v = mLineEdit->text(); @@ -223,7 +223,7 @@ void QgsPhotoWidgetWrapper::initWidget( QWidget* editor ) QgsFilterLineEdit *fle = qobject_cast( mLineEdit ); if ( fle ) { - fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + fle->setNullValue( QgsApplication::nullRepresentation() ); } connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) ); @@ -246,7 +246,7 @@ void QgsPhotoWidgetWrapper::setValue( const QVariant& value ) { if ( value.isNull() ) { - whileBlocking( mLineEdit )->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + whileBlocking( mLineEdit )->setText( QgsApplication::nullRepresentation() ); clearPicture(); } else diff --git a/src/gui/editorwidgets/qgsrangewidgetwrapper.cpp b/src/gui/editorwidgets/qgsrangewidgetwrapper.cpp index 0d584fc7060..b3c3db1a135 100644 --- a/src/gui/editorwidgets/qgsrangewidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsrangewidgetwrapper.cpp @@ -116,7 +116,7 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor ) minval -= stepval; } mDoubleSpinBox->setValue( minval ); - mDoubleSpinBox->setSpecialValueText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits::min() ); mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits::max() ); @@ -137,7 +137,7 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor ) int stepval = step.toInt(); minval -= stepval; mIntSpinBox->setValue( minval ); - mIntSpinBox->setSpecialValueText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } setupIntEditor( min, max, step, mIntSpinBox, this ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) diff --git a/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp index 950baefbad2..a5cdafa84df 100644 --- a/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp @@ -137,7 +137,7 @@ void QgsRelationReferenceSearchWidgetWrapper::onValueChanged( const QVariant& va else { QSettings settings; - setExpression( value.isNull() ? settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() : value.toString() ); + setExpression( value.isNull() ? QgsApplication::nullRepresentation() : value.toString() ); emit valueChanged(); } emit expressionChanged( mExpression ); @@ -146,7 +146,7 @@ void QgsRelationReferenceSearchWidgetWrapper::onValueChanged( const QVariant& va void QgsRelationReferenceSearchWidgetWrapper::setExpression( QString exp ) { QSettings settings; - QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + QString nullValue = QgsApplication::nullRepresentation(); QString fieldName = layer()->fields().at( mFieldIdx ).name(); QString str; diff --git a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp index 432959fa87b..c83c55c1793 100644 --- a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp @@ -302,7 +302,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value ) void QgsRelationReferenceWidget::deleteForeignKey() { - QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + QVariant nullValue = QgsApplication::nullRepresentation(); if ( mReadOnlySelector ) { QString nullText = QLatin1String( "" ); @@ -477,7 +477,7 @@ void QgsRelationReferenceWidget::init() mFilterComboBoxes << cb; mReferencedLayer->uniqueValues( idx, uniqueValues ); cb->addItem( mReferencedLayer->attributeDisplayName( idx ) ); - QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + QVariant nullValue = QgsApplication::nullRepresentation(); cb->addItem( nullValue.toString(), QVariant( mReferencedLayer->fields().at( idx ).type() ) ); qSort( uniqueValues.begin(), uniqueValues.end(), qgsVariantLessThan ); @@ -496,7 +496,7 @@ void QgsRelationReferenceWidget::init() if ( mChainFilters ) { - QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + QVariant nullValue = QgsApplication::nullRepresentation(); QgsFeature ft; QgsFeatureIterator fit = layerCache->getFeatures(); @@ -552,7 +552,7 @@ void QgsRelationReferenceWidget::init() mComboBox->setCompleter( completer ); - QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + QVariant nullValue = QgsApplication::nullRepresentation(); if ( mChainFilters && mFeature.isValid() ) { @@ -797,7 +797,7 @@ void QgsRelationReferenceWidget::mapToolDeactivated() void QgsRelationReferenceWidget::filterChanged() { - QVariant nullValue = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + QVariant nullValue = QgsApplication::nullRepresentation(); QStringList filters; QgsAttributeList attrs; diff --git a/src/gui/editorwidgets/qgstexteditwrapper.cpp b/src/gui/editorwidgets/qgstexteditwrapper.cpp index c5d4d7d8893..dea2534de38 100644 --- a/src/gui/editorwidgets/qgstexteditwrapper.cpp +++ b/src/gui/editorwidgets/qgstexteditwrapper.cpp @@ -56,7 +56,7 @@ QVariant QgsTextEditWrapper::value() const } if (( v.isEmpty() && ( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) || - v == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + v == QgsApplication::nullRepresentation() ) return QVariant( field().type() ); if ( !defaultValue().isNull() && v == defaultValue().toString() ) @@ -119,7 +119,7 @@ void QgsTextEditWrapper::initWidget( QWidget* editor ) QVariant defVal = defaultValue(); if ( defVal.isNull() ) { - defVal = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ); + defVal = QgsApplication::nullRepresentation(); } QgsFilterLineEdit *fle = qobject_cast( mLineEdit ); @@ -215,7 +215,7 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant& val ) if ( val.isNull() ) { if ( !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) - v = QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + v = QgsApplication::nullRepresentation(); } else v = val.toString(); diff --git a/src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp b/src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp index f1e9a55f7c8..88753907811 100644 --- a/src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp @@ -37,7 +37,7 @@ QVariant QgsUniqueValuesWidgetWrapper::value() const if ( mLineEdit ) { - if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( mLineEdit->text() == QgsApplication::nullRepresentation() ) value = QVariant( field().type() ); else value = mLineEdit->text(); @@ -83,7 +83,7 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor ) QgsFilterLineEdit* fle = qobject_cast( editor ); if ( fle && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) { - fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + fle->setNullValue( QgsApplication::nullRepresentation() ); } QCompleter* c = new QCompleter( sValues ); @@ -127,7 +127,7 @@ void QgsUniqueValuesWidgetWrapper::setValue( const QVariant& value ) if ( mLineEdit ) { if ( value.isNull() ) - mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mLineEdit->setText( QgsApplication::nullRepresentation() ); else mLineEdit->setText( value.toString() ); } diff --git a/src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp b/src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp index a9c76c137ab..d7d54c69860 100644 --- a/src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp +++ b/src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp @@ -17,6 +17,7 @@ #include "qgsattributetypeloaddialog.h" #include "qgsvaluemapfieldformatter.h" +#include "qgsapplication.h" #include #include @@ -52,7 +53,7 @@ QVariantMap QgsValueMapConfigDlg::config() continue; QString ks = ki->text(); - if (( ks == settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) && !( ki->flags() & Qt::ItemIsEditable ) ) + if (( ks == QgsApplication::nullRepresentation() ) && !( ki->flags() & Qt::ItemIsEditable ) ) ks = VALUEMAP_NULL_TEXT; if ( !vi || vi->text().isNull() ) @@ -159,7 +160,7 @@ void QgsValueMapConfigDlg::setRow( int row, const QString& value, const QString& { QFont cellFont; cellFont.setItalic( true ); - valueCell = new QTableWidgetItem( settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + valueCell = new QTableWidgetItem( QgsApplication::nullRepresentation() ); valueCell->setFont( cellFont ); valueCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); descriptionCell->setFont( cellFont ); @@ -246,7 +247,7 @@ void QgsValueMapConfigDlg::loadFromCSVButtonPushed() val = val.mid( 1, val.length() - 2 ); } - if ( key == settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( key == QgsApplication::nullRepresentation() ) key = VALUEMAP_NULL_TEXT; map[ key ] = val; diff --git a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp index 89ac128ad37..a9352983d04 100644 --- a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp @@ -190,7 +190,7 @@ void QgsValueRelationSearchWidgetWrapper::onValueChanged() else { QSettings settings; - setExpression( vl.isNull() ? settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() : vl.toString() ); + setExpression( vl.isNull() ? QgsApplication::nullRepresentation() : vl.toString() ); emit valueChanged(); } emit expressionChanged( mExpression ); @@ -199,7 +199,7 @@ void QgsValueRelationSearchWidgetWrapper::onValueChanged() void QgsValueRelationSearchWidgetWrapper::setExpression( QString exp ) { QSettings settings; - QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + QString nullValue = QgsApplication::nullRepresentation(); QString fieldName = layer()->fields().at( mFieldIdx ).name(); QString str; diff --git a/src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp b/src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp index 58bcf3d7465..c0fac4d7d1d 100644 --- a/src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp @@ -48,7 +48,7 @@ QVariant QgsWebViewWidgetWrapper::value() const if ( mLineEdit ) { - if ( mLineEdit->text() == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ) + if ( mLineEdit->text() == QgsApplication::nullRepresentation() ) v = QVariant( QVariant::String ); else v = mLineEdit->text(); @@ -101,7 +101,7 @@ void QgsWebViewWidgetWrapper::initWidget( QWidget* editor ) QgsFilterLineEdit* fle = qobject_cast( mLineEdit ); if ( fle ) { - fle->setNullValue( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + fle->setNullValue( QgsApplication::nullRepresentation() ); } container = qobject_cast( mLineEdit->parent() ); @@ -151,7 +151,7 @@ void QgsWebViewWidgetWrapper::setValue( const QVariant& value ) if ( mLineEdit ) { if ( value.isNull() ) - mLineEdit->setText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); + mLineEdit->setText( QgsApplication::nullRepresentation() ); else mLineEdit->setText( value.toString() ); } diff --git a/src/gui/qgsfieldvalidator.cpp b/src/gui/qgsfieldvalidator.cpp index 8c4eea9da80..a6b03cf914d 100644 --- a/src/gui/qgsfieldvalidator.cpp +++ b/src/gui/qgsfieldvalidator.cpp @@ -28,6 +28,7 @@ #include "qgslogger.h" #include "qgslonglongvalidator.h" #include "qgsfields.h" +#include "qgsapplication.h" QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, const QString& defaultValue, const QString& dateFormat ) : QValidator( parent ) @@ -84,7 +85,7 @@ QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, co } QSettings settings; - mNullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + mNullValue = QgsApplication::nullRepresentation(); } QgsFieldValidator::~QgsFieldValidator() diff --git a/src/gui/qgsfilewidget.cpp b/src/gui/qgsfilewidget.cpp index ad22c4b9782..ad46fb2ae56 100644 --- a/src/gui/qgsfilewidget.cpp +++ b/src/gui/qgsfilewidget.cpp @@ -27,6 +27,7 @@ #include "qgsfilterlineedit.h" #include "qgslogger.h" #include "qgsproject.h" +#include "qgsapplication.h" QgsFileWidget::QgsFileWidget( QWidget *parent ) : QWidget( parent ) @@ -82,7 +83,7 @@ QString QgsFileWidget::filePath() void QgsFileWidget::setFilePath( QString path ) { - if ( path == QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ) ) + if ( path == QgsApplication::nullRepresentation() ) { path = QLatin1String( "" ); } @@ -286,7 +287,7 @@ QString QgsFileWidget::toUrl( const QString& path ) const QString rep; if ( path.isEmpty() ) { - return QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + return QgsApplication::nullRepresentation(); } QString urlStr = relativePath( path, false ); diff --git a/src/gui/qgsquerybuilder.cpp b/src/gui/qgsquerybuilder.cpp index 384b4a3c2cd..2f80d422abd 100644 --- a/src/gui/qgsquerybuilder.cpp +++ b/src/gui/qgsquerybuilder.cpp @@ -120,7 +120,7 @@ void QgsQueryBuilder::fillValues( int idx, int limit ) mLayer->uniqueValues( idx, values, limit ); QSettings settings; - QString nullValue = settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString(); + QString nullValue = QgsApplication::nullRepresentation(); QgsDebugMsg( QString( "nullValue: %1" ).arg( nullValue ) ); diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 68d93bdd22f..d6c310b3242 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -15,6 +15,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core/layertree ${CMAKE_SOURCE_DIR}/src/core/raster ${CMAKE_SOURCE_DIR}/src/core/symbology-ng + ${CMAKE_SOURCE_DIR}/src/test ) INCLUDE_DIRECTORIES(SYSTEM ${QT_INCLUDE_DIR} diff --git a/tests/src/core/testqgsfield.cpp b/tests/src/core/testqgsfield.cpp index 3d01641e18d..60d846e22dd 100644 --- a/tests/src/core/testqgsfield.cpp +++ b/tests/src/core/testqgsfield.cpp @@ -20,6 +20,8 @@ #include #include "qgsfield.h" +#include "qgsapplication.h" +#include "qgstest.h" class TestQgsField: public QObject { @@ -299,8 +301,7 @@ void TestQgsField::displayString() QCOMPARE( stringField.displayString( test ), test ); //test NULL - QSettings s; - s.setValue( QStringLiteral( "qgis/nullValue" ), "TEST NULL" ); + QgsApplication::setNullRepresentation( "TEST NULL" ); QVariant nullString = QVariant( QVariant::String ); QCOMPARE( stringField.displayString( nullString ), QString( "TEST NULL" ) ); @@ -513,5 +514,5 @@ void TestQgsField::collection() QVERIFY( !field.convertCompatible( str ) ); } -QTEST_MAIN( TestQgsField ) +QGSTEST_MAIN( TestQgsField ) #include "testqgsfield.moc"