Add doxymentation for field formatters

This commit is contained in:
Matthias Kuhn 2017-01-08 00:46:21 +01:00
parent f7ae653f88
commit 552e1b2e9d
10 changed files with 82 additions and 9 deletions

View File

@ -60,7 +60,7 @@ QString QgsDateTimeFieldFormatter::representValue( QgsVectorLayer* layer, int fi
return result; return result;
} }
QString QgsDateTimeFieldFormatter::defaultFormat( const QVariant::Type type ) QString QgsDateTimeFieldFormatter::defaultFormat( QVariant::Type type )
{ {
switch ( type ) switch ( type )
{ {

View File

@ -19,6 +19,14 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a date time field.
* This represents a date, time or datetime value based on
* the field configuration.
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsDateTimeFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsDateTimeFieldFormatter : public QgsFieldFormatter
{ {
public: public:
@ -38,7 +46,7 @@ class CORE_EXPORT QgsDateTimeFieldFormatter : public QgsFieldFormatter
* - QVariant::Date * - QVariant::Date
* - QVariant::Time * - QVariant::Time
*/ */
static QString defaultFormat( const QVariant::Type type ); static QString defaultFormat( QVariant::Type type );
}; };
#endif // QGSDATETIMEFIELDKIT_H #endif // QGSDATETIMEFIELDKIT_H

View File

@ -19,6 +19,13 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* A default fallback field formatter in case no specialized field formatter is defined.
* The values will be returned unmodified.
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsFallbackFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsFallbackFieldFormatter : public QgsFieldFormatter
{ {
public: public:

View File

@ -32,7 +32,6 @@ QString QgsKeyValueFieldFormatter::representValue( QgsVectorLayer* layer, int fi
if ( value.isNull() ) if ( value.isNull() )
{ {
QSettings settings;
return QgsApplication::nullRepresentation(); return QgsApplication::nullRepresentation();
} }
@ -40,7 +39,8 @@ QString QgsKeyValueFieldFormatter::representValue( QgsVectorLayer* layer, int fi
const QVariantMap map = value.toMap(); const QVariantMap map = value.toMap();
for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i ) for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i )
{ {
if ( !result.isEmpty() ) result.append( ", " ); if ( !result.isEmpty() )
result.append( ", " );
result.append( i.key() ).append( ": " ).append( i.value().toString() ); result.append( i.key() ).append( ": " ).append( i.value().toString() );
} }
return result; return result;

View File

@ -19,6 +19,17 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a key value field.
* This represents a list type value.
* Values will be represented as a colon-delimited and
* comma-separated list.
*
* E.g. "color: yellow, amount: 5"
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsKeyValueFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsKeyValueFieldFormatter : public QgsFieldFormatter
{ {
public: public:

View File

@ -31,16 +31,15 @@ QString QgsListFieldFormatter::representValue( QgsVectorLayer* layer, int fieldI
if ( value.isNull() ) if ( value.isNull() )
{ {
QSettings settings;
return QgsApplication::nullRepresentation(); return QgsApplication::nullRepresentation();
} }
QString result; QString result;
const QVariantList list = value.toList(); Q_FOREACH ( const QVariant& val, value.toList() )
for ( QVariantList::const_iterator i = list.constBegin(); i != list.constEnd(); ++i )
{ {
if ( !result.isEmpty() ) result.append( ", " ); if ( !result.isEmpty() )
result.append( i->toString() ); result.append( ", " );
result.append( val.toString() );
} }
return result; return result;
} }

View File

@ -19,6 +19,14 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a list field.
* This represents a list type value.
* Values will be represented as a comma-separated list.
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsListFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsListFieldFormatter : public QgsFieldFormatter
{ {
public: public:

View File

@ -19,6 +19,14 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a relation reference field.
* A value relation field formatter looks up the values from
* features on another layer.
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsRelationReferenceFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsRelationReferenceFieldFormatter : public QgsFieldFormatter
{ {
public: public:

View File

@ -19,6 +19,23 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgsfieldformatter.h" #include "qgsfieldformatter.h"
/**
* \ingroup core
* Field formatter for a ValueMap field.
* A value relation field formatter looks up the values a map.
*
* The map is defined in the configuration as dictionary under the key "map".
*
* { "map": { 1: "one", 2: "two", 3: "three" } }
*
* Values that are not on the map will be wrapped in parantheses. So with the above
* configuration:
*
* - 3 => "three"
* - 5 => "(5)"
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter
{ {
public: public:

View File

@ -22,6 +22,14 @@
#include <QVector> #include <QVector>
#include <QVariant> #include <QVariant>
/**
* \ingroup core
* Field formatter for a value relation field.
* A value relation field formatter looks up the values from
* features on another layer.
*
* \note Added in QGIS 3.0
*/
class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter
{ {
public: public:
@ -50,6 +58,13 @@ class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter
QVariant createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const override; QVariant createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const override;
/**
* Create a cache for a value relation field.
* This can be used to keep the value map in the local memory
* if doing multiple lookups in a loop.
*
* \note Added in QGIS 3.0
*/
static ValueRelationCache createCache( const QVariantMap& config ); static ValueRelationCache createCache( const QVariantMap& config );
}; };