Skip to content
Permalink
Browse files

Put field kit into use

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 9a53b7d commit 82d1871f8cba831f23454ed4482d88de9f80ff08
Showing with 434 additions and 363 deletions.
  1. +1 −0 python/CMakeLists.txt
  2. +0 −36 python/gui/editorwidgets/core/qgseditorwidgetfactory.sip
  3. +0 −8 python/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.sip
  4. +4 −6 src/app/qgisapp.cpp
  5. +4 −6 src/app/qgsattributetypedialog.cpp
  6. +5 −2 src/app/qgsidentifyresultsdialog.cpp
  7. +4 −1 src/core/CMakeLists.txt
  8. +7 −6 src/core/fieldkit/qgsdatetimefieldkit.cpp
  9. +13 −9 src/core/fieldkit/qgsdatetimefieldkit.h
  10. +26 −0 src/core/fieldkit/qgsfallbackfieldkit.cpp
  11. +29 −0 src/core/fieldkit/qgsfallbackfieldkit.h
  12. +5 −0 src/core/fieldkit/qgskeyvaluefieldkit.cpp
  13. +2 −1 src/core/fieldkit/qgskeyvaluefieldkit.h
  14. +5 −0 src/core/fieldkit/qgslistfieldkit.cpp
  15. +3 −1 src/core/fieldkit/qgslistfieldkit.h
  16. +5 −0 src/core/fieldkit/qgsrelationreferencefieldkit.cpp
  17. +3 −1 src/core/fieldkit/qgsrelationreferencefieldkit.h
  18. +5 −0 src/core/fieldkit/qgsvaluemapfieldkit.cpp
  19. +3 −1 src/core/fieldkit/qgsvaluemapfieldkit.h
  20. +66 −0 src/core/fieldkit/qgsvaluerelationfieldkit.cpp
  21. +27 −1 src/core/fieldkit/qgsvaluerelationfieldkit.h
  22. +8 −0 src/core/qgsapplication.cpp
  23. +7 −0 src/core/qgsapplication.h
  24. +38 −11 src/core/qgsfieldkit.cpp
  25. +19 −7 src/core/qgsfieldkit.h
  26. +31 −4 src/core/qgsfieldkitregistry.cpp
  27. +32 −4 src/core/qgsfieldkitregistry.h
  28. +16 −10 src/gui/attributetable/qgsattributetablemodel.cpp
  29. +2 −0 src/gui/attributetable/qgsattributetablemodel.h
  30. +0 −32 src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp
  31. +0 −36 src/gui/editorwidgets/core/qgseditorwidgetfactory.h
  32. +9 −8 src/gui/editorwidgets/qgsdatetimeeditconfig.cpp
  33. +0 −26 src/gui/editorwidgets/qgsdatetimeeditfactory.cpp
  34. +0 −3 src/gui/editorwidgets/qgsdatetimeeditfactory.h
  35. +5 −4 src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp
  36. +3 −2 src/gui/editorwidgets/qgsdatetimesearchwidgetwrapper.cpp
  37. +0 −1 src/gui/editorwidgets/qgskeyvaluewidgetfactory.h
  38. +0 −1 src/gui/editorwidgets/qgslistwidgetfactory.h
  39. +2 −2 src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
  40. +2 −1 src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
  41. +0 −9 src/gui/editorwidgets/qgsvaluemapwidgetfactory.cpp
  42. +3 −2 src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
  43. +11 −11 src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp
  44. +3 −10 src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.h
  45. +0 −9 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp
  46. +0 −1 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.h
  47. +15 −68 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
  48. +3 −13 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h
  49. +8 −9 src/server/qgswmsserver.cpp
@@ -101,6 +101,7 @@ INCLUDE_DIRECTORIES(
../src/core/composer
../src/core/diagram
../src/core/effects
../src/core/fieldkit
../src/core/dxf
../src/core/geometry
../src/core/gps
@@ -110,42 +110,6 @@ class QgsEditorWidgetFactory
*/
//virtual QHash<const char*, int> supportedWidgetTypes();

/**
* If the default sort order should be overwritten for this widget, you can transform the value in here.
*
* @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 value is returned unmodified.
*
* @note Added in 2.16
*/
virtual QVariant sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;

/**
* Return the alignment for a particular field. By default this will consider the field type but can be overwritten if mapped
* values are represented.
* @param vl The vector layer.
* @param fieldIdx The index of the field.
* @param config The editor widget config.
* @return The alignment flag, normally Qt::AlignRight or Qt::AlignLeft
*/
virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const;

/**
* Create a cache for a given field.
*
* @param vl The vector layer.
* @param fieldIdx The index of the field.
* @param config The editor widget config.
*
* @return The default implementation returns an invalid QVariant
*/
virtual QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config );

/**
* Read the config from an XML file and map it to a proper {@link QgsEditorWidgetConfig}.
*
@@ -28,12 +28,4 @@ class QgsValueRelationSearchWidgetWrapper : QgsSearchWidgetWrapper
QWidget* createWidget( QWidget* parent );
void initWidget( QWidget* editor );

public slots:

//! Called when current value of search widget changes
void onValueChanged();

protected slots:
void setExpression( QString exp );

};
@@ -149,6 +149,8 @@
#include "qgsfeature.h"
#include "qgsformannotationitem.h"
#include "qgsfieldcalculator.h"
#include "qgsfieldkit.h"
#include "qgsfieldkitregistry.h"
#include "qgshtmlannotationitem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsgpsinformationwidget.h"
@@ -6397,12 +6399,8 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant& value )
return value;
}
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() );
QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
if ( factory )
{
return QVariant( factory->representValue( mLayer, idx, setup.config(), QVariant(), value ) );
}
return value;
QgsFieldKit* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
return fieldKit->representValue( mLayer, idx, setup.config(), QVariant(), value );
}

///@endcond
@@ -23,6 +23,8 @@
#include "qgisapp.h"
#include "qgsproject.h"
#include "qgslogger.h"
#include "qgsfieldkitregistry.h"
#include "qgsfieldkit.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"

@@ -348,13 +350,9 @@ void QgsAttributeTypeDialog::defaultExpressionChanged()
return;
}

QString previewText = val.toString();
QgsFieldKit* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( editorWidgetType() );

QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( editorWidgetType() );
if ( factory )
{
previewText = factory->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );
}
QString previewText = fieldKit->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );

mDefaultPreviewLabel->setText( "<i>" + previewText + "</i>" );
}
@@ -43,6 +43,8 @@
#include "qgsstringutils.h"
#include "qgstreewidgetitem.h"
#include "qgsfiledownloader.h"
#include "qgsfieldkitregistry.h"
#include "qgsfieldkit.h"

#include <QCloseEvent>
#include <QLabel>
@@ -732,6 +734,7 @@ QString QgsIdentifyResultsDialog::representValue( QgsVectorLayer* vlayer, const
QMap<QString, QVariant>& layerCaches = mWidgetCaches[vlayer->id()];

QgsEditorWidgetFactory* factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
QgsFieldKit* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );

int idx = vlayer->fields().lookupField( fieldName );

@@ -744,11 +747,11 @@ QString QgsIdentifyResultsDialog::representValue( QgsVectorLayer* vlayer, const
}
else
{
cache = factory->createCache( vlayer, idx, setup.config() );
cache = fieldKit->createCache( vlayer, idx, setup.config() );
layerCaches.insert( fieldName, cache );
}

return factory->representValue( vlayer, idx, setup.config(), cache, value );
return fieldKit->representValue( vlayer, idx, setup.config(), cache, value );
}

void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
@@ -371,6 +371,7 @@ SET(QGIS_CORE_SRCS


fieldkit/qgsdatetimefieldkit.cpp
fieldkit/qgsfallbackfieldkit.cpp
fieldkit/qgskeyvaluefieldkit.cpp
fieldkit/qgslistfieldkit.cpp
fieldkit/qgsrelationreferencefieldkit.cpp
@@ -477,6 +478,7 @@ SET(QGIS_CORE_MOC_HDRS
qgsfeedback.h
qgsfield.h
qgsfieldconstraints.h
qgsfieldkitregistry.h
qgsgeometryvalidator.h
qgsgml.h
qgsgmlschema.h
@@ -670,7 +672,6 @@ SET(QGIS_CORE_HDRS
qgsfeaturerequest.h
qgsfeaturestore.h
qgsfieldkit.h
qgsfieldkitregistry.h
qgsfields.h
qgsfontutils.h
qgsgeometrycache.h
@@ -889,6 +890,7 @@ SET(QGIS_CORE_HDRS
geometry/qgswkbtypes.h

fieldkit/qgsdatetimefieldkit.h
fieldkit/qgsfallbackfieldkit.h
fieldkit/qgskeyvaluefieldkit.h
fieldkit/qgslistfieldkit.h
fieldkit/qgsrelationreferencefieldkit.h
@@ -909,6 +911,7 @@ INCLUDE_DIRECTORIES(
composer
dxf
effects
fieldkit
geometry
layertree
pal
@@ -25,11 +25,12 @@ QgsDateTimeFieldKit::QgsDateTimeFieldKit()

}

bool QgsDateTimeFieldKit::supportsField( QgsVectorLayer* layer, int fieldIdx )
QString QgsDateTimeFieldKit::id() const
{
return QStringLiteral( "DateTime" );
}

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

@@ -41,7 +42,7 @@ QString QgsDateTimeFieldKit::representValue( QgsVectorLayer* layer, int fieldIdx
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}

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

@@ -64,12 +65,12 @@ QString QgsDateTimeFieldKit::defaultFormat( const QVariant::Type type )
switch ( type )
{
case QVariant::DateTime:
return QGSDATETIMEEDIT_DATETIMEFORMAT;
return QGSDATETIMEFIELDKIT_DATETIMEFORMAT;
break;
case QVariant::Time:
return QGSDATETIMEEDIT_TIMEFORMAT;
return QGSDATETIMEFIELDKIT_TIMEFORMAT;
break;
default:
return QGSDATETIMEEDIT_DATEFORMAT;
return QGSDATETIMEFIELDKIT_DATEFORMAT;
}
}
@@ -18,22 +18,26 @@

#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" )
#define QGSDATETIMEFIELDKIT_DATEFORMAT QStringLiteral( "yyyy-MM-dd" )
#define QGSDATETIMEFIELDKIT_TIMEFORMAT QStringLiteral( "HH:mm:ss" )
#define QGSDATETIMEFIELDKIT_DATETIMEFORMAT QStringLiteral( "yyyy-MM-dd HH:mm:ss" )

class QgsDateTimeFieldKit : public QgsFieldKit
class CORE_EXPORT 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;
QString id() const override;

virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, 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
* Get the default format in function of the type.
* The type is expected to be one of
*
* - QVariant::DateTime
* - QVariant::Date
* - QVariant::Time
*/
static QString defaultFormat( const QVariant::Type type );
};
@@ -0,0 +1,26 @@
/***************************************************************************
qgsfallbackfieldkit.cpp - QgsFallbackFieldKit
---------------------
begin : 4.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 "qgsfallbackfieldkit.h"

QgsFallbackFieldKit::QgsFallbackFieldKit()
{

}

QString QgsFallbackFieldKit::id() const
{
return QString();
}
@@ -0,0 +1,29 @@
/***************************************************************************
qgsfallbackfieldkit.h - QgsFallbackFieldKit
---------------------
begin : 4.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 QGSFALLBACKFIELDKIT_H
#define QGSFALLBACKFIELDKIT_H

#include "qgsfieldkit.h"

class CORE_EXPORT QgsFallbackFieldKit : public QgsFieldKit
{
public:
QgsFallbackFieldKit();

QString id() const override;
};

#endif // QGSFALLBACKFIELDKIT_H
@@ -22,6 +22,11 @@ QgsKeyValueFieldKit::QgsKeyValueFieldKit()

}

QString QgsKeyValueFieldKit::id() const
{
return QStringLiteral( "KeyValue" );
}

QString QgsKeyValueFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl );
@@ -18,11 +18,12 @@

#include "qgsfieldkit.h"

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

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

@@ -22,6 +22,11 @@ QgsListFieldKit::QgsListFieldKit()

}

QString QgsListFieldKit::id() const
{
return QStringLiteral( "List" );
}

QString QgsListFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl );
@@ -18,11 +18,13 @@

#include "qgsfieldkit.h"

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

QString id() const override;

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

@@ -27,6 +27,11 @@ QgsRelationReferenceFieldKit::QgsRelationReferenceFieldKit()

}

QString QgsRelationReferenceFieldKit::id() const
{
return QStringLiteral( "RelationReference" );
}

QString QgsRelationReferenceFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache );
@@ -18,11 +18,13 @@

#include "qgsfieldkit.h"

class QgsRelationReferenceFieldKit : public QgsFieldKit
class CORE_EXPORT QgsRelationReferenceFieldKit : public QgsFieldKit
{
public:
QgsRelationReferenceFieldKit();

QString id() const override;

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

virtual QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QVariantMap&config, const QVariant& cache, const QVariant& value ) const override;

0 comments on commit 82d1871

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