Add field kits for a lot of common field types

This commit is contained in:
Matthias Kuhn 2016-12-03 15:33:43 +01:00
parent 570fc4ef96
commit 9a53b7df06
39 changed files with 800 additions and 353 deletions

View File

@ -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.
*

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -0,0 +1,94 @@
/***************************************************************************
qgsrelationreferencefieldkit.cpp - QgsRelationReferenceFieldKit
---------------------
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 "qgsrelationreferencefieldkit.h"
#include "qgsmessagelog.h"
#include "qgsrelation.h"
#include "qgsexpressioncontext.h"
#include "qgsproject.h"
#include "qgsrelationmanager.h"
#include "qgsvectorlayer.h"
QgsRelationReferenceFieldKit::QgsRelationReferenceFieldKit()
{
}
QString QgsRelationReferenceFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache );
// Some sanity checks
if ( !config.contains( QStringLiteral( "Relation" ) ) )
{
QgsMessageLog::logMessage( "Missing Relation in configuration" );
return value.toString();
}
QgsRelation relation = QgsProject::instance()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() );
if ( !relation.isValid() )
{
QgsMessageLog::logMessage( "Invalid relation" );
return value.toString();
}
QgsVectorLayer* referencingLayer = relation.referencingLayer();
if ( vl != referencingLayer )
{
QgsMessageLog::logMessage( "representValue() with inconsistent vl parameter w.r.t relation referencingLayer" );
return value.toString();
}
int referencingFieldIdx = referencingLayer->fields().lookupField( relation.fieldPairs().at( 0 ).first );
if ( referencingFieldIdx != fieldIdx )
{
QgsMessageLog::logMessage( "representValue() with inconsistent fieldIdx parameter w.r.t relation referencingFieldIdx" );
return value.toString();
}
QgsVectorLayer* referencedLayer = relation.referencedLayer();
if ( !referencedLayer )
{
QgsMessageLog::logMessage( "Cannot find referenced layer" );
return value.toString();
}
// Attributes from the referencing layer
QgsAttributes attrs = QgsAttributes( vl->fields().count() );
// Set the value on the foreign key field of the referencing record
attrs[ referencingFieldIdx ] = value;
QgsFeatureRequest request = relation.getReferencedFeatureRequest( attrs );
QgsFeature feature;
referencedLayer->getFeatures( request ).nextFeature( feature );
if ( !feature.isValid() )
return value.toString();
QgsExpression expr( referencedLayer->displayExpression() );
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( referencedLayer );
context.setFeature( feature );
QString title = expr.evaluate( &context ).toString();
if ( expr.hasEvalError() )
{
int referencedFieldIdx = referencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );
title = feature.attribute( referencedFieldIdx ).toString();
}
return title;
}
QVariant QgsRelationReferenceFieldKit::sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
qgsrelationreferencefieldkit.h - QgsRelationReferenceFieldKit
---------------------
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 QGSRELATIONREFERENCEFIELDKIT_H
#define QGSRELATIONREFERENCEFIELDKIT_H
#include "qgsfieldkit.h"
class QgsRelationReferenceFieldKit : public QgsFieldKit
{
public:
QgsRelationReferenceFieldKit();
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;
};
#endif // QGSRELATIONREFERENCEFIELDKIT_H

View File

@ -0,0 +1,41 @@
/***************************************************************************
qgsvaluemapfieldkit.cpp - QgsValueMapFieldKit
---------------------
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 "qgsvaluemapfieldkit.h"
#include "qgsvectorlayer.h"
QgsValueMapFieldKit::QgsValueMapFieldKit()
{
}
QString QgsValueMapFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache )
QString valueInternalText;
if ( value.isNull() )
valueInternalText = VALUEMAP_NULL_TEXT;
else
valueInternalText = value.toString();
return config.key( valueInternalText, QVariant( QStringLiteral( "(%1)" ).arg( vl->fields().at( fieldIdx ).displayString( value ) ) ).toString() );
}
QVariant QgsValueMapFieldKit::sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}

View File

@ -0,0 +1,33 @@
/***************************************************************************
qgsvaluemapfieldkit.h - QgsValueMapFieldKit
---------------------
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 QGSVALUEMAPFIELDKIT_H
#define QGSVALUEMAPFIELDKIT_H
#include "qgsfieldkit.h"
#define VALUEMAP_NULL_TEXT QStringLiteral( "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}" )
class QgsValueMapFieldKit : public QgsFieldKit
{
public:
QgsValueMapFieldKit();
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
QVariant sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const;
};
#endif // QGSVALUEMAPFIELDKIT_H

View File

@ -0,0 +1,78 @@
/***************************************************************************
qgsvaluerelationfieldkit.cpp - QgsValueRelationFieldKit
---------------------
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 "qgsvaluerelationfieldkit.h"
#include "qgis.h"
#include <QSettings>
QgsValueRelationFieldKit::QgsValueRelationFieldKit()
{
}
QString QgsValueRelationFieldKit::representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( layer )
Q_UNUSED( fieldIdx )
QHash<QString, QString> vrCache;
if ( cache.isValid() )
{
vrCache = cache.value<QHash<QString, QString>>();
}
else
{
vrCache = createCache( layer, fieldIdx, config ).value<QHash<QString, QString>>();
}
if ( config.value( QStringLiteral( "AllowMulti" ) ).toBool() )
{
QStringList keyList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );
QStringList valueList;
Q_FOREACH ( const QString& key, keyList )
{
auto val = vrCache.constFind( key );
if ( val != vrCache.constEnd() )
valueList << val.value();
else
valueList << QStringLiteral( "(%1)" ).arg( key );
}
return valueList.join( QStringLiteral( ", " ) ).prepend( '{' ).append( '}' );
}
else
{
if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}
auto val = vrCache.constFind( value.toString() );
if ( val != vrCache.constEnd() )
return val.value();
}
return QStringLiteral( "(%1)" ).arg( value.toString() );
}
QVariant QgsValueRelationFieldKit::sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
qgsvaluerelationfieldkit.h - QgsValueRelationFieldKit
---------------------
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 QGSVALUERELATIONFIELDKIT_H
#define QGSVALUERELATIONFIELDKIT_H
#include "qgsfieldkit.h"
class QgsValueRelationFieldKit : public QgsFieldKit
{
public:
QgsValueRelationFieldKit();
QString representValue( QgsVectorLayer *layer, int fieldIdx, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
};
#endif // QGSVALUERELATIONFIELDKIT_H

View File

@ -267,6 +267,9 @@ class CORE_EXPORT QgsField
/**
* Get the editor widget setup for the field.
*
* Defaults may be set by the provider and can be overridden
* by manual field configuration.
*
* @return the value
*/
QgsEditorWidgetSetup editorWidgetSetup() const;

49
src/core/qgsfieldkit.cpp Normal file
View File

@ -0,0 +1,49 @@
/***************************************************************************
qgsfieldkit.cpp - QgsFieldKit
---------------------
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 "qgsfieldkit.h"
QgsFieldKit::QgsFieldKit()
{
}
QgsFieldKit::~QgsFieldKit()
{
}
bool QgsFieldKit::supportsField( QgsVectorLayer* layer, int fieldIdx )
{
return true;
}
QString QgsFieldKit::representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
return "1";
}
QVariant QgsFieldKit::sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
{
return 1;
}
Qt::AlignmentFlag QgsFieldKit::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config ) const
{
return Qt::AlignLeft;
}
QVariant QgsFieldKit::createCache( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config ) const
{
return QVariant();
}

61
src/core/qgsfieldkit.h Normal file
View File

@ -0,0 +1,61 @@
/***************************************************************************
qgsfieldkit.h - QgsFieldKit
---------------------
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 QGSFIELDKIT_H
#define QGSFIELDKIT_H
#include <QString>
#include <QVariant>
class QgsVectorLayer;
class QgsFieldKit
{
public:
QgsFieldKit();
virtual ~QgsFieldKit();
virtual bool supportsField( QgsVectorLayer* layer, int fieldIdx );
/**
* Create a pretty String representation of the value.
*
* @return By default the string representation of the provided value as implied by the field definition is returned.
*/
virtual QString representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& 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.
*
* @return By default the value is returned unmodified.
*
* @note Added in 2.16
*/
virtual QVariant sortValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& 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.
*/
virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config ) const;
/**
* Create a cache for a given field.
*/
virtual QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config ) const;
};
#endif // QGSFIELDKIT_H

View File

@ -0,0 +1,38 @@
/***************************************************************************
qgsfieldkitregistry.cpp - QgsFieldKitRegistry
---------------------
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 "qgsfieldkitregistry.h"
#include "qgsfieldkit.h"
QgsFieldKitRegistry::QgsFieldKitRegistry()
{
}
QgsFieldKitRegistry::~QgsFieldKitRegistry()
{
qDeleteAll( mFieldKits );
}
void QgsFieldKitRegistry::addFieldKit( QgsFieldKit* kit )
{
mFieldKits.prepend( kit );
}
void QgsFieldKitRegistry::removeFieldKit( QgsFieldKit* kit )
{
mFieldKits.removeOne( kit );
delete kit;
}

View File

@ -0,0 +1,48 @@
/***************************************************************************
qgsfieldkitregistry.h - QgsFieldKitRegistry
---------------------
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 QGSFIELDKITREGISTRY_H
#define QGSFIELDKITREGISTRY_H
#include <QVector>
class QgsFieldKit;
class QgsFieldKitRegistry
{
public:
/**
* You should not normally need to create your own field kit registry.
*
* Use the one provided by `QgsApplication::fieldKitRegistry()` instead.
*/
QgsFieldKitRegistry();
~QgsFieldKitRegistry();
/**
* They will take precedence in order of adding them.
* The later they are added, the more weight they have.
*
* Ownership is transferred to the registry.
*/
void addFieldKit( QgsFieldKit* kit );
void removeFieldKit( QgsFieldKit* kit );
private:
QVector<QgsFieldKit*> mFieldKits;
};
#endif // QGSFIELDKITREGISTRY_H

View File

@ -791,6 +791,7 @@ INCLUDE_DIRECTORIES(
../core
../core/auth
../core/composer
../core/fieldkit
../core/geometry
../core/layertree
../core/raster

View File

@ -60,21 +60,6 @@ void QgsEditorWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, Q
Q_UNUSED( fieldIdx );
}
QString QgsEditorWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl )
Q_UNUSED( fieldIdx )
Q_UNUSED( config )
Q_UNUSED( cache )
Q_UNUSED( value )
QString defVal;
if ( vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginProvider && vl->dataProvider() )
defVal = vl->dataProvider()->defaultValueClause( vl->fields().fieldOriginIndex( fieldIdx ) );
return value == defVal ? defVal : vl->fields().at( fieldIdx ).displayString( value );
}
QVariant QgsEditorWidgetFactory::sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl )
@ -146,4 +131,4 @@ void QgsEditorWidgetFactory::xml2config( const QDomElement& configElement, QgsEd
{
config.insert( fieldName, value );
}
}
}

View File

@ -128,19 +128,6 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual QHash<const char*, int> supportedWidgetTypes() { return QHash<const char*, int>(); }
/**
* 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.
*

View File

@ -119,23 +119,6 @@ QgsEditorWidgetConfig QgsDateTimeEditConfig::config()
return myConfig;
}
QString QgsDateTimeEditConfig::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;
}
}
void QgsDateTimeEditConfig::setConfig( const QgsEditorWidgetConfig &config )
{
const QgsField fieldDef = layer()->fields().at( field() );

View File

@ -29,6 +29,8 @@ class GUI_EXPORT QgsDateTimeEditConfig : public QgsEditorConfigWidget, private U
Q_OBJECT
public:
QgsDateTimeEditConfig( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = nullptr );
QgsEditorWidgetConfig config() override;
void setConfig( const QgsEditorWidgetConfig &config ) override;
private slots:
void updateDemoWidget();
@ -36,18 +38,6 @@ class GUI_EXPORT QgsDateTimeEditConfig : public QgsEditorConfigWidget, private U
void updateDisplayFormat( const QString& fieldFormat );
void displayFormatChanged( int idx );
void showHelp( bool buttonChecked );
// QgsEditorConfigWidget interface
public:
QgsEditorWidgetConfig config() override;
void setConfig( const QgsEditorWidgetConfig &config ) override;
/**
* Get the default format in fonction of the type
* @param type the field type
* @return the date/time format
*/
static QString defaultFormat( const QVariant::Type type );
};
#endif // QGSDATETIMEEDITCONFIG_H

View File

@ -67,47 +67,6 @@ void QgsDateTimeEditFactory::writeConfig( const QgsEditorWidgetConfig& config, Q
config2xml( config, configElement, QStringLiteral( "allow_null" ) );
}
QString QgsDateTimeEditFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl )
Q_UNUSED( fieldIdx )
Q_UNUSED( cache )
QString result;
if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}
const QgsField field = vl->fields().at( fieldIdx );
const QString displayFormat = config.value( QStringLiteral( "display_format" ), QgsDateTimeEditConfig::defaultFormat( field.type() ) ).toString();
const QString fieldFormat = config.value( QStringLiteral( "field_format" ), QgsDateTimeEditConfig::defaultFormat( field.type() ) ).toString();
QDateTime date = QDateTime::fromString( value.toString(), fieldFormat );
if ( date.isValid() )
{
result = date.toString( displayFormat );
}
else
{
result = value.toString();
}
return result;
}
Qt::AlignmentFlag QgsDateTimeEditFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
return Qt::AlignLeft;
}
QHash<const char*, int> QgsDateTimeEditFactory::supportedWidgetTypes()
{
QHash<const char*, int> map = QHash<const char*, int>();

View File

@ -18,10 +18,6 @@
#include "qgseditorwidgetfactory.h"
#define QGSDATETIMEEDIT_DATEFORMAT "yyyy-MM-dd"
#define QGSDATETIMEEDIT_TIMEFORMAT "HH:mm:ss"
#define QGSDATETIMEEDIT_DATETIMEFORMAT "yyyy-MM-dd HH:mm:ss"
/** \ingroup gui
* \class QgsDateTimeEditFactory
* \note not available in Python bindings
@ -38,9 +34,6 @@ class GUI_EXPORT QgsDateTimeEditFactory : public QgsEditorWidgetFactory
QgsSearchWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
QgsEditorConfigWidget* configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QHash<const char*, int> supportedWidgetTypes() override;
unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;
};

View File

@ -57,40 +57,8 @@ void QgsKeyValueWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config,
Q_UNUSED( fieldIdx );
}
QString QgsKeyValueWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& 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;
}
Qt::AlignmentFlag QgsKeyValueWidgetFactory::alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
return Qt::AlignLeft;
}
unsigned int QgsKeyValueWidgetFactory::fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const
{
const QgsField field = vl->fields().field( fieldIdx );
return field.type() == QVariant::Map && field.subType() != QVariant::Invalid ? 20 : 0;
}
}

View File

@ -39,7 +39,6 @@ class GUI_EXPORT QgsKeyValueWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;
};

View File

@ -58,40 +58,8 @@ void QgsListWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDo
Q_UNUSED( fieldIdx );
}
QString QgsListWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& 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;
}
Qt::AlignmentFlag QgsListWidgetFactory::alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
return Qt::AlignLeft;
}
unsigned int QgsListWidgetFactory::fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const
{
const QgsField field = vl->fields().field( fieldIdx );
return ( field.type() == QVariant::List || field.type() == QVariant::StringList ) && field.subType() != QVariant::Invalid ? 20 : 0;
}
}

View File

@ -39,7 +39,6 @@ class GUI_EXPORT QgsListWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;
};

View File

@ -116,74 +116,8 @@ QHash<const char*, int> QgsRelationReferenceFactory::supportedWidgetTypes()
return map;
}
QString QgsRelationReferenceFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache );
// Some sanity checks
if ( !config.contains( QStringLiteral( "Relation" ) ) )
{
QgsDebugMsg( "Missing Relation in configuration" );
return value.toString();
}
QgsRelation relation = QgsProject::instance()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() );
if ( !relation.isValid() )
{
QgsDebugMsg( "Invalid relation" );
return value.toString();
}
QgsVectorLayer* referencingLayer = relation.referencingLayer();
if ( vl != referencingLayer )
{
QgsDebugMsg( "representValue() with inconsistent vl parameter w.r.t relation referencingLayer" );
return value.toString();
}
int referencingFieldIdx = referencingLayer->fields().lookupField( relation.fieldPairs().at( 0 ).first );
if ( referencingFieldIdx != fieldIdx )
{
QgsDebugMsg( "representValue() with inconsistent fieldIdx parameter w.r.t relation referencingFieldIdx" );
return value.toString();
}
QgsVectorLayer* referencedLayer = relation.referencedLayer();
if ( !referencedLayer )
{
QgsDebugMsg( "Cannot find referenced layer" );
return value.toString();
}
// Attributes from the referencing layer
QgsAttributes attrs = QgsAttributes( vl->fields().count() );
// Set the value on the foreign key field of the referencing record
attrs[ referencingFieldIdx ] = value;
QgsFeatureRequest request = relation.getReferencedFeatureRequest( attrs );
QgsFeature feature;
referencedLayer->getFeatures( request ).nextFeature( feature );
if ( !feature.isValid() )
return value.toString();
QgsExpression expr( referencedLayer->displayExpression() );
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( referencedLayer );
context.setFeature( feature );
QString title = expr.evaluate( &context ).toString();
if ( expr.hasEvalError() )
{
int referencedFieldIdx = referencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );
title = feature.attribute( referencedFieldIdx ).toString();
}
return title;
}
QVariant QgsRelationReferenceFactory::sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}
unsigned int QgsRelationReferenceFactory::fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const
{
const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
return !relations.isEmpty() ? 21 /*A bit stronger than the range widget*/ : 5;
}
}

View File

@ -82,10 +82,6 @@ class GUI_EXPORT QgsRelationReferenceFactory : public QgsEditorWidgetFactory
*/
virtual void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
virtual QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value ) const override;
virtual QHash<const char *, int> supportedWidgetTypes() override;
virtual unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;

View File

@ -16,6 +16,7 @@
#include "qgsvaluemapconfigdlg.h"
#include "qgsattributetypeloaddialog.h"
#include "qgsvaluemapfieldkit.h"
#include <QSettings>
#include <QFileDialog>

View File

@ -20,8 +20,6 @@
#include "qgseditorconfigwidget.h"
#define VALUEMAP_NULL_TEXT "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"
/** \ingroup gui
* \class QgsValueMapConfigDlg
* \note not available in Python bindings

View File

@ -82,24 +82,6 @@ void QgsValueMapWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config,
}
}
QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( cache )
QString valueInternalText;
if ( value.isNull() )
valueInternalText = QStringLiteral( VALUEMAP_NULL_TEXT );
else
valueInternalText = value.toString();
return config.key( valueInternalText, QVariant( QStringLiteral( "(%1)" ).arg( vl->fields().at( fieldIdx ).displayString( value ) ) ).toString() );
}
QVariant QgsValueMapWidgetFactory::sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}
Qt::AlignmentFlag QgsValueMapWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );

View File

@ -35,9 +35,6 @@ class GUI_EXPORT QgsValueMapWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QHash<const char *, int> supportedWidgetTypes() override;
};

View File

@ -79,71 +79,6 @@ void QgsValueRelationWidgetFactory::writeConfig( const QgsEditorWidgetConfig& co
config2xml( config, configElement, QStringLiteral( "UseCompleter" ) );
}
QString QgsValueRelationWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
Q_UNUSED( vl )
Q_UNUSED( fieldIdx )
QgsValueRelationWidgetWrapper::ValueRelationCache vrCache;
if ( cache.isValid() )
{
vrCache = cache.value<QgsValueRelationWidgetWrapper::ValueRelationCache>();
}
else
{
vrCache = QgsValueRelationWidgetWrapper::createCache( config );
}
if ( config.value( QStringLiteral( "AllowMulti" ) ).toBool() )
{
QStringList keyList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );
QStringList valueList;
Q_FOREACH ( const QgsValueRelationWidgetWrapper::ValueRelationItem& item, vrCache )
{
if ( keyList.contains( item.first.toString() ) )
{
valueList << item.second;
}
}
return valueList.join( QStringLiteral( ", " ) ).prepend( '{' ).append( '}' );
}
else
{
if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
}
Q_FOREACH ( const QgsValueRelationWidgetWrapper::ValueRelationItem& item, vrCache )
{
if ( item.first == value )
{
return item.second;
}
}
}
return QStringLiteral( "(%1)" ).arg( value.toString() );
}
QVariant QgsValueRelationWidgetFactory::sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
{
return representValue( vl, fieldIdx, config, cache, value );
}
Qt::AlignmentFlag QgsValueRelationWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
{
Q_UNUSED( vl );
Q_UNUSED( fieldIdx );
Q_UNUSED( config );
return Qt::AlignLeft;
}
QVariant QgsValueRelationWidgetFactory::createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config )
{
Q_UNUSED( vl )

View File

@ -37,9 +37,6 @@ class GUI_EXPORT QgsValueRelationWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) override;
};

View File

@ -48,10 +48,6 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
{
Q_OBJECT
public:
typedef QPair < QVariant, QString > ValueRelationItem;
typedef QVector < ValueRelationItem > ValueRelationCache;
public:
explicit QgsValueRelationWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = nullptr, QWidget* parent = nullptr );
static bool orderByKeyLessThan( const QgsValueRelationWidgetWrapper::ValueRelationItem& p1 ,