Skip to content
Permalink
Browse files

Add field kits for a lot of common field types

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 570fc4e commit 9a53b7df063fe1d6d281c0066493364d169ac46e
Showing with 800 additions and 353 deletions.
  1. +0 −13 python/gui/editorwidgets/core/qgseditorwidgetfactory.sip
  2. +19 −0 src/core/CMakeLists.txt
  3. +75 −0 src/core/fieldkit/qgsdatetimefieldkit.cpp
  4. +41 −0 src/core/fieldkit/qgsdatetimefieldkit.h
  5. +46 −0 src/core/fieldkit/qgskeyvaluefieldkit.cpp
  6. +29 −0 src/core/fieldkit/qgskeyvaluefieldkit.h
  7. +46 −0 src/core/fieldkit/qgslistfieldkit.cpp
  8. +29 −0 src/core/fieldkit/qgslistfieldkit.h
  9. +94 −0 src/core/fieldkit/qgsrelationreferencefieldkit.cpp
  10. +31 −0 src/core/fieldkit/qgsrelationreferencefieldkit.h
  11. +41 −0 src/core/fieldkit/qgsvaluemapfieldkit.cpp
  12. +33 −0 src/core/fieldkit/qgsvaluemapfieldkit.h
  13. +78 −0 src/core/fieldkit/qgsvaluerelationfieldkit.cpp
  14. +31 −0 src/core/fieldkit/qgsvaluerelationfieldkit.h
  15. +3 −0 src/core/qgsfield.h
  16. +49 −0 src/core/qgsfieldkit.cpp
  17. +61 −0 src/core/qgsfieldkit.h
  18. +38 −0 src/core/qgsfieldkitregistry.cpp
  19. +48 −0 src/core/qgsfieldkitregistry.h
  20. +1 −0 src/gui/CMakeLists.txt
  21. +1 −16 src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp
  22. +0 −13 src/gui/editorwidgets/core/qgseditorwidgetfactory.h
  23. +0 −17 src/gui/editorwidgets/qgsdatetimeeditconfig.cpp
  24. +2 −12 src/gui/editorwidgets/qgsdatetimeeditconfig.h
  25. +0 −41 src/gui/editorwidgets/qgsdatetimeeditfactory.cpp
  26. +0 −7 src/gui/editorwidgets/qgsdatetimeeditfactory.h
  27. +1 −33 src/gui/editorwidgets/qgskeyvaluewidgetfactory.cpp
  28. +0 −1 src/gui/editorwidgets/qgskeyvaluewidgetfactory.h
  29. +1 −33 src/gui/editorwidgets/qgslistwidgetfactory.cpp
  30. +0 −1 src/gui/editorwidgets/qgslistwidgetfactory.h
  31. +1 −67 src/gui/editorwidgets/qgsrelationreferencefactory.cpp
  32. +0 −4 src/gui/editorwidgets/qgsrelationreferencefactory.h
  33. +1 −0 src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
  34. +0 −2 src/gui/editorwidgets/qgsvaluemapconfigdlg.h
  35. +0 −18 src/gui/editorwidgets/qgsvaluemapwidgetfactory.cpp
  36. +0 −3 src/gui/editorwidgets/qgsvaluemapwidgetfactory.h
  37. +0 −65 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp
  38. +0 −3 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.h
  39. +0 −4 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h
@@ -110,19 +110,6 @@ class QgsEditorWidgetFactory
*/
//virtual QHash<const char*, int> supportedWidgetTypes();

/**
* Create a pretty String representation of the value.
*
* @param vl The vector layer.
* @param fieldIdx The index of the field.
* @param config The editor widget config.
* @param cache The editor widget cache.
* @param value The value to represent.
*
* @return By default the string representation of the provided value as implied by the field definition is returned.
*/
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;

/**
* If the default sort order should be overwritten for this widget, you can transform the value in here.
*
@@ -127,6 +127,8 @@ SET(QGIS_CORE_SRCS
qgsfeaturestore.cpp
qgsfield.cpp
qgsfieldconstraints.cpp
qgsfieldkit.cpp
qgsfieldkitregistry.cpp
qgsfields.cpp
qgsfontutils.cpp
qgsgeometrycache.cpp
@@ -367,6 +369,14 @@ SET(QGIS_CORE_SRCS
geometry/qgswkbptr.cpp
geometry/qgswkbtypes.cpp


fieldkit/qgsdatetimefieldkit.cpp
fieldkit/qgskeyvaluefieldkit.cpp
fieldkit/qgslistfieldkit.cpp
fieldkit/qgsrelationreferencefieldkit.cpp
fieldkit/qgsvaluemapfieldkit.cpp
fieldkit/qgsvaluerelationfieldkit.cpp

${CMAKE_CURRENT_BINARY_DIR}/qgscontexthelp_texts.cpp
${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp
)
@@ -659,6 +669,8 @@ SET(QGIS_CORE_HDRS
qgsfeatureiterator.h
qgsfeaturerequest.h
qgsfeaturestore.h
qgsfieldkit.h
qgsfieldkitregistry.h
qgsfields.h
qgsfontutils.h
qgsgeometrycache.h
@@ -875,6 +887,13 @@ SET(QGIS_CORE_HDRS
geometry/qgssurface.h
geometry/qgswkbptr.h
geometry/qgswkbtypes.h

fieldkit/qgsdatetimefieldkit.h
fieldkit/qgskeyvaluefieldkit.h
fieldkit/qgslistfieldkit.h
fieldkit/qgsrelationreferencefieldkit.h
fieldkit/qgsvaluemapfieldkit.h
fieldkit/qgsvaluerelationfieldkit.h
)

IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
@@ -0,0 +1,75 @@
/***************************************************************************
qgsdatetimefieldkit.cpp - QgsDateTimeFieldKit
---------------------
begin : 2.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 "qgsdatetimefieldkit.h"

#include <QSettings>

#include "qgsfield.h"
#include "qgsvectorlayer.h"

QgsDateTimeFieldKit::QgsDateTimeFieldKit()
{

}

bool QgsDateTimeFieldKit::supportsField( QgsVectorLayer* layer, int fieldIdx )
{
}

QString QgsDateTimeFieldKit::representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache )

QString result;

if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}

const QgsField field = layer->fields().at( fieldIdx );
const QString displayFormat = config.value( QStringLiteral( "display_format" ), defaultFormat( field.type() ) ).toString();
const QString fieldFormat = config.value( QStringLiteral( "field_format" ), defaultFormat( field.type() ) ).toString();

QDateTime date = QDateTime::fromString( value.toString(), fieldFormat );

if ( date.isValid() )
{
result = date.toString( displayFormat );
}
else
{
result = value.toString();
}

return result;
}

QString QgsDateTimeFieldKit::defaultFormat( const QVariant::Type type )
{
switch ( type )
{
case QVariant::DateTime:
return QGSDATETIMEEDIT_DATETIMEFORMAT;
break;
case QVariant::Time:
return QGSDATETIMEEDIT_TIMEFORMAT;
break;
default:
return QGSDATETIMEEDIT_DATEFORMAT;
}
}
@@ -0,0 +1,41 @@
/***************************************************************************
qgsdatetimefieldkit.h - QgsDateTimeFieldKit
---------------------
begin : 2.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 QGSDATETIMEFIELDKIT_H
#define QGSDATETIMEFIELDKIT_H

#include "qgsfieldkit.h"

#define QGSDATETIMEEDIT_DATEFORMAT QStringLiteral( "yyyy-MM-dd" )
#define QGSDATETIMEEDIT_TIMEFORMAT QStringLiteral( "HH:mm:ss" )
#define QGSDATETIMEEDIT_DATETIMEFORMAT QStringLiteral( "yyyy-MM-dd HH:mm:ss" )

class QgsDateTimeFieldKit : public QgsFieldKit
{
public:
QgsDateTimeFieldKit();

virtual bool supportsField( QgsVectorLayer* layer, int fieldIdx ) override;
virtual QString representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;

/**
* Get the default format in function of the type
* @param type the field type
* @return the date/time format
*/
static QString defaultFormat( const QVariant::Type type );
};

#endif // QGSDATETIMEFIELDKIT_H
@@ -0,0 +1,46 @@
/***************************************************************************
qgskeyvaluefieldkit.cpp - QgsKeyValueFieldKit
---------------------
begin : 3.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 "qgskeyvaluefieldkit.h"

#include <QSettings>

QgsKeyValueFieldKit::QgsKeyValueFieldKit()
{

}

QString QgsKeyValueFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
Q_UNUSED( cache );

if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}

QString result;
const QVariantMap map = value.toMap();
for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i )
{
if ( !result.isEmpty() ) result.append( ", " );
result.append( i.key() ).append( ": " ).append( i.value().toString() );
}
return result;
}
@@ -0,0 +1,29 @@
/***************************************************************************
qgskeyvaluefieldkit.h - QgsKeyValueFieldKit
---------------------
begin : 3.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 QGSKEYVALUEFIELDKIT_H
#define QGSKEYVALUEFIELDKIT_H

#include "qgsfieldkit.h"

class QgsKeyValueFieldKit : public QgsFieldKit
{
public:
QgsKeyValueFieldKit();

QString representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
};

#endif // QGSKEYVALUEFIELDKIT_H
@@ -0,0 +1,46 @@
/***************************************************************************
qgslistfieldkit.cpp - QgsListFieldKit
---------------------
begin : 3.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 "qgslistfieldkit.h"

#include <QSettings>

QgsListFieldKit::QgsListFieldKit()
{

}

QString QgsListFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
Q_UNUSED( cache );

if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}

QString result;
const QVariantList list = value.toList();
for ( QVariantList::const_iterator i = list.constBegin(); i != list.constEnd(); ++i )
{
if ( !result.isEmpty() ) result.append( ", " );
result.append( i->toString() );
}
return result;
}
@@ -0,0 +1,29 @@
/***************************************************************************
qgslistfieldkit.h - QgsListFieldKit
---------------------
begin : 3.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@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 QGSLISTFIELDKIT_H
#define QGSLISTFIELDKIT_H

#include "qgsfieldkit.h"

class QgsListFieldKit : public QgsFieldKit
{
public:
QgsListFieldKit();

QString representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
};

#endif // QGSLISTFIELDKIT_H

0 comments on commit 9a53b7d

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