Skip to content

Commit

Permalink
Document QgsValueMapFieldFormatter::NullValue
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 928f360 commit c6dc31a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/core/fieldformatter/qgsvaluemapfieldformatter.cpp
Expand Up @@ -17,6 +17,8 @@

#include "qgsvectorlayer.h"

const QString QgsValueMapFieldFormatter::NullValue = QStringLiteral( "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}" );

QString QgsValueMapFieldFormatter::id() const
{
return QStringLiteral( "ValueMap" );
Expand All @@ -28,7 +30,7 @@ QString QgsValueMapFieldFormatter::representValue( QgsVectorLayer* layer, int fi

QString valueInternalText;
if ( value.isNull() )
valueInternalText = VALUEMAP_NULL_TEXT;
valueInternalText = NullValue;
else
valueInternalText = value.toString();

Expand Down
9 changes: 7 additions & 2 deletions src/core/fieldformatter/qgsvaluemapfieldformatter.h
Expand Up @@ -18,11 +18,16 @@

#include "qgsfieldformatter.h"

#define VALUEMAP_NULL_TEXT QStringLiteral( "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}" )

class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter
{
public:

/**
* Will be saved in the configuration when a value is NULL.
* It's the magic UUID {2839923C-8B7D-419E-B84B-CA2FE9B80EC7}
*/
static const QString NullValue;

virtual QString id() const override;

virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
Expand Down
10 changes: 5 additions & 5 deletions src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
Expand Up @@ -54,7 +54,7 @@ QVariantMap QgsValueMapConfigDlg::config()

QString ks = ki->text();
if (( ks == QgsApplication::nullRepresentation() ) && !( ki->flags() & Qt::ItemIsEditable ) )
ks = VALUEMAP_NULL_TEXT;
ks = QgsValueMapFieldFormatter::NullValue;

if ( !vi || vi->text().isNull() )
{
Expand Down Expand Up @@ -137,7 +137,7 @@ void QgsValueMapConfigDlg::updateMap( const QMap<QString, QVariant> &map, bool i

if ( insertNull )
{
setRow( row, VALUEMAP_NULL_TEXT, QStringLiteral( "<NULL>" ) );
setRow( row, QgsValueMapFieldFormatter::NullValue, QStringLiteral( "<NULL>" ) );
++row;
}

Expand All @@ -156,7 +156,7 @@ void QgsValueMapConfigDlg::setRow( int row, const QString& value, const QString&
QTableWidgetItem* valueCell;
QTableWidgetItem* descriptionCell = new QTableWidgetItem( description );
tableWidget->insertRow( row );
if ( value == VALUEMAP_NULL_TEXT )
if ( value == QgsValueMapFieldFormatter::NullValue )
{
QFont cellFont;
cellFont.setItalic( true );
Expand All @@ -175,7 +175,7 @@ void QgsValueMapConfigDlg::setRow( int row, const QString& value, const QString&

void QgsValueMapConfigDlg::addNullButtonPushed()
{
setRow( tableWidget->rowCount() - 1, VALUEMAP_NULL_TEXT, QStringLiteral( "<NULL>" ) );
setRow( tableWidget->rowCount() - 1, QgsValueMapFieldFormatter::NullValue, QStringLiteral( "<NULL>" ) );
}

void QgsValueMapConfigDlg::loadFromLayerButtonPushed()
Expand Down Expand Up @@ -248,7 +248,7 @@ void QgsValueMapConfigDlg::loadFromCSVButtonPushed()
}

if ( key == QgsApplication::nullRepresentation() )
key = VALUEMAP_NULL_TEXT;
key = QgsValueMapFieldFormatter::NullValue;

map[ key ] = val;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
Expand Up @@ -147,7 +147,7 @@ void QgsValueMapSearchWidgetWrapper::initWidget( QWidget* editor )

while ( it != cfg.constEnd() )
{
if ( it.value() != VALUEMAP_NULL_TEXT )
if ( it.value() != QgsValueMapFieldFormatter::NullValue )
mComboBox->addItem( it.key(), it.value() );
++it;
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
Expand Up @@ -33,7 +33,7 @@ QVariant QgsValueMapWidgetWrapper::value() const
if ( mComboBox )
v = mComboBox->currentData();

if ( v == VALUEMAP_NULL_TEXT )
if ( v == QgsValueMapFieldFormatter::NullValue )
v = QVariant( field().type() );

return v;
Expand Down Expand Up @@ -79,7 +79,7 @@ void QgsValueMapWidgetWrapper::setValue( const QVariant& value )
{
QString v;
if ( value.isNull() )
v = VALUEMAP_NULL_TEXT;
v = QgsValueMapFieldFormatter::NullValue;
else
v = value.toString();

Expand Down

0 comments on commit c6dc31a

Please sign in to comment.