fix false boolean not shown as so in attribute table

This commit is contained in:
Denis Rouzaud 2019-09-23 17:00:10 +02:00
parent 0e994fda02
commit e31e9a32b8
9 changed files with 145 additions and 6 deletions

View File

@ -0,0 +1,43 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/fieldformatter/qgscheckboxfieldformatter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsCheckBoxFieldFormatter : QgsFieldFormatter
{
%Docstring
Field formatter for a check box field.
.. versionadded:: 3.10
%End
%TypeHeaderCode
#include "qgscheckboxfieldformatter.h"
%End
public:
QgsCheckBoxFieldFormatter();
%Docstring
Constructor for QgsCheckBoxFieldFormatter.
%End
virtual QString id() const;
virtual QString representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const;
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/fieldformatter/qgscheckboxfieldformatter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -321,6 +321,7 @@
%Include auto_generated/geometry/qgswkbptr.sip
%Include auto_generated/./3d/qgs3drendererregistry.sip
%Include auto_generated/./3d/qgsabstract3drenderer.sip
%Include auto_generated/fieldformatter/qgscheckboxfieldformatter.sip
%Include auto_generated/fieldformatter/qgsrangefieldformatter.sip
%Include auto_generated/fieldformatter/qgsdatetimefieldformatter.sip
%Include auto_generated/fieldformatter/qgsfallbackfieldformatter.sip

View File

@ -569,6 +569,7 @@ SET(QGIS_CORE_SRCS
3d/qgs3drendererregistry.cpp
3d/qgsabstract3drenderer.cpp
fieldformatter/qgscheckboxfieldformatter.cpp
fieldformatter/qgsrangefieldformatter.cpp
fieldformatter/qgsdatetimefieldformatter.cpp
fieldformatter/qgsfallbackfieldformatter.cpp
@ -1290,6 +1291,7 @@ SET(QGIS_CORE_HDRS
3d/qgs3drendererregistry.h
3d/qgsabstract3drenderer.h
fieldformatter/qgscheckboxfieldformatter.h
fieldformatter/qgsrangefieldformatter.h
fieldformatter/qgsdatetimefieldformatter.h
fieldformatter/qgsfallbackfieldformatter.h

View File

@ -0,0 +1,47 @@
/***************************************************************************
qgscheckboxfieldformatter.cpp - QgsCheckBoxFieldFormatter
---------------------
begin : 23.09.2019
copyright : (C) 2019 by Denis Rouzaud
email : denis@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QObject>
#include "qgscheckboxfieldformatter.h"
#include "qgsapplication.h"
QString QgsCheckBoxFieldFormatter::id() const
{
return QStringLiteral( "CheckBox" );
}
QString QgsCheckBoxFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
{
Q_UNUSED( layer )
Q_UNUSED( fieldIndex )
Q_UNUSED( cache )
Q_UNUSED( config )
if ( value.isNull() || !value.canConvert<bool>() )
{
return QgsApplication::nullRepresentation();
}
const bool boolValue = value.toBool();
if ( boolValue )
return QObject::tr( "true" );
else
return QObject::tr( "false" );
}

View File

@ -0,0 +1,44 @@
/***************************************************************************
qgscheckboxfieldformatter.h - QgsCheckBoxFieldFormatter
---------------------
begin : 23.09.2019
copyright : (C) 2019 by Denis Rouzaud
email : denis@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSCHECKBOXFIELDFORMATTER_H
#define QGSCHECKBOXFIELDFORMATTER_H
#include "qgis_core.h"
#include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a check box field.
*
* \since QGIS 3.10
*/
class CORE_EXPORT QgsCheckBoxFieldFormatter : public QgsFieldFormatter
{
public:
/**
* Constructor for QgsCheckBoxFieldFormatter.
*/
QgsCheckBoxFieldFormatter() = default;
QString id() const override;
QString representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
};
#endif // QGSCHECKBOXFIELDFORMATTER_H

View File

@ -20,9 +20,6 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
QgsFieldFormatter::QgsFieldFormatter() //NOLINT
{
}
QString QgsFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
{

View File

@ -40,7 +40,7 @@ class QgsVectorLayer;
class CORE_EXPORT QgsFieldFormatter
{
public:
QgsFieldFormatter();
QgsFieldFormatter() = default;
virtual ~QgsFieldFormatter() = default;

View File

@ -23,6 +23,7 @@
#include "qgskeyvaluefieldformatter.h"
#include "qgslistfieldformatter.h"
#include "qgsrangefieldformatter.h"
#include "qgscheckboxfieldformatter.h"
#include "qgsfallbackfieldformatter.h"
@ -36,6 +37,7 @@ QgsFieldFormatterRegistry::QgsFieldFormatterRegistry( QObject *parent )
addFieldFormatter( new QgsListFieldFormatter() );
addFieldFormatter( new QgsDateTimeFieldFormatter() );
addFieldFormatter( new QgsRangeFieldFormatter() );
addFieldFormatter( new QgsCheckBoxFieldFormatter() );
mFallbackFieldFormatter = new QgsFallbackFieldFormatter();
}

View File

@ -689,8 +689,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
return mFieldFormatters.at( index.column() )->representValue( layer(), fieldId, mWidgetConfigs.at( index.column() ),
mAttributeWidgetCaches.at( index.column() ), val );
return mFieldFormatters.at( index.column() )->representValue( layer(),
fieldId,
mWidgetConfigs.at( index.column() ),
mAttributeWidgetCaches.at( index.column() ),
val );
case Qt::EditRole:
return val;