Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add field kits for a lot of common field types
- Loading branch information
Showing
39 changed files
with
800 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.