QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgskeyvaluefieldformatter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgskeyvaluefieldformatter.cpp - QgsKeyValueFieldFormatter
3 
4  ---------------------
5  begin : 3.12.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
17 #include "qgsapplication.h"
18 
19 #include <QSettings>
20 
22 {
23  return QStringLiteral( "KeyValue" );
24 }
25 
26 QString QgsKeyValueFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
27 {
28  Q_UNUSED( layer )
29  Q_UNUSED( fieldIndex )
30  Q_UNUSED( config )
31  Q_UNUSED( cache )
32 
33  if ( value.isNull() )
34  {
36  }
37 
38  QString result;
39  const QVariantMap map = value.toMap();
40  for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i )
41  {
42  if ( !result.isEmpty() )
43  result.append( ", " );
44  result.append( i.key() ).append( ": " ).append( i.value().toString() );
45  }
46  return result;
47 }
qgskeyvaluefieldformatter.h
qgsapplication.h
QgsKeyValueFieldFormatter::id
QString id() const override
Returns a unique id for this field formatter.
Definition: qgskeyvaluefieldformatter.cpp:21
QgsApplication::nullRepresentation
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
Definition: qgsapplication.cpp:1851
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsKeyValueFieldFormatter::representValue
QString representValue(QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const override
Create a pretty String representation of the value.
Definition: qgskeyvaluefieldformatter.cpp:26