Skip to content
Permalink
Browse files

Document QgsValueMapFieldFormatter::NullValue

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 928f360 commit c6dc31a552ee8388b53f5f45595b06329a915087
@@ -17,6 +17,8 @@

#include "qgsvectorlayer.h"

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

QString QgsValueMapFieldFormatter::id() const
{
return QStringLiteral( "ValueMap" );
@@ -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();

@@ -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;
@@ -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() )
{
@@ -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;
}

@@ -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 );
@@ -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()
@@ -248,7 +248,7 @@ void QgsValueMapConfigDlg::loadFromCSVButtonPushed()
}

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

map[ key ] = val;
}
@@ -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;
}
@@ -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;
@@ -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();

0 comments on commit c6dc31a

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