Skip to content

Commit 82d1871

Browse files
committed
Put field kit into use
1 parent 9a53b7d commit 82d1871

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+434
-363
lines changed

python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ INCLUDE_DIRECTORIES(
101101
../src/core/composer
102102
../src/core/diagram
103103
../src/core/effects
104+
../src/core/fieldkit
104105
../src/core/dxf
105106
../src/core/geometry
106107
../src/core/gps

python/gui/editorwidgets/core/qgseditorwidgetfactory.sip

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,42 +110,6 @@ class QgsEditorWidgetFactory
110110
*/
111111
//virtual QHash<const char*, int> supportedWidgetTypes();
112112

113-
/**
114-
* If the default sort order should be overwritten for this widget, you can transform the value in here.
115-
*
116-
* @param vl The vector layer.
117-
* @param fieldIdx The index of the field.
118-
* @param config The editor widget config.
119-
* @param cache The editor widget cache.
120-
* @param value The value to represent.
121-
*
122-
* @return By default the value is returned unmodified.
123-
*
124-
* @note Added in 2.16
125-
*/
126-
virtual QVariant sortValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;
127-
128-
/**
129-
* Return the alignment for a particular field. By default this will consider the field type but can be overwritten if mapped
130-
* values are represented.
131-
* @param vl The vector layer.
132-
* @param fieldIdx The index of the field.
133-
* @param config The editor widget config.
134-
* @return The alignment flag, normally Qt::AlignRight or Qt::AlignLeft
135-
*/
136-
virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const;
137-
138-
/**
139-
* Create a cache for a given field.
140-
*
141-
* @param vl The vector layer.
142-
* @param fieldIdx The index of the field.
143-
* @param config The editor widget config.
144-
*
145-
* @return The default implementation returns an invalid QVariant
146-
*/
147-
virtual QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config );
148-
149113
/**
150114
* Read the config from an XML file and map it to a proper {@link QgsEditorWidgetConfig}.
151115
*

python/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.sip

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,4 @@ class QgsValueRelationSearchWidgetWrapper : QgsSearchWidgetWrapper
2828
QWidget* createWidget( QWidget* parent );
2929
void initWidget( QWidget* editor );
3030

31-
public slots:
32-
33-
//! Called when current value of search widget changes
34-
void onValueChanged();
35-
36-
protected slots:
37-
void setExpression( QString exp );
38-
3931
};

src/app/qgisapp.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@
149149
#include "qgsfeature.h"
150150
#include "qgsformannotationitem.h"
151151
#include "qgsfieldcalculator.h"
152+
#include "qgsfieldkit.h"
153+
#include "qgsfieldkitregistry.h"
152154
#include "qgshtmlannotationitem.h"
153155
#include "qgsgenericprojectionselector.h"
154156
#include "qgsgpsinformationwidget.h"
@@ -6397,12 +6399,8 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant& value )
63976399
return value;
63986400
}
63996401
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() );
6400-
QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
6401-
if ( factory )
6402-
{
6403-
return QVariant( factory->representValue( mLayer, idx, setup.config(), QVariant(), value ) );
6404-
}
6405-
return value;
6402+
QgsFieldKit* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
6403+
return fieldKit->representValue( mLayer, idx, setup.config(), QVariant(), value );
64066404
}
64076405

64086406
///@endcond

src/app/qgsattributetypedialog.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "qgisapp.h"
2424
#include "qgsproject.h"
2525
#include "qgslogger.h"
26+
#include "qgsfieldkitregistry.h"
27+
#include "qgsfieldkit.h"
2628
#include "qgseditorwidgetfactory.h"
2729
#include "qgseditorwidgetregistry.h"
2830

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

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

353-
QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( editorWidgetType() );
354-
if ( factory )
355-
{
356-
previewText = factory->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );
357-
}
355+
QString previewText = fieldKit->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );
358356

359357
mDefaultPreviewLabel->setText( "<i>" + previewText + "</i>" );
360358
}

src/app/qgsidentifyresultsdialog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "qgsstringutils.h"
4444
#include "qgstreewidgetitem.h"
4545
#include "qgsfiledownloader.h"
46+
#include "qgsfieldkitregistry.h"
47+
#include "qgsfieldkit.h"
4648

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

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

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

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

751-
return factory->representValue( vlayer, idx, setup.config(), cache, value );
754+
return fieldKit->representValue( vlayer, idx, setup.config(), cache, value );
752755
}
753756

754757
void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,

src/core/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ SET(QGIS_CORE_SRCS
371371

372372

373373
fieldkit/qgsdatetimefieldkit.cpp
374+
fieldkit/qgsfallbackfieldkit.cpp
374375
fieldkit/qgskeyvaluefieldkit.cpp
375376
fieldkit/qgslistfieldkit.cpp
376377
fieldkit/qgsrelationreferencefieldkit.cpp
@@ -477,6 +478,7 @@ SET(QGIS_CORE_MOC_HDRS
477478
qgsfeedback.h
478479
qgsfield.h
479480
qgsfieldconstraints.h
481+
qgsfieldkitregistry.h
480482
qgsgeometryvalidator.h
481483
qgsgml.h
482484
qgsgmlschema.h
@@ -670,7 +672,6 @@ SET(QGIS_CORE_HDRS
670672
qgsfeaturerequest.h
671673
qgsfeaturestore.h
672674
qgsfieldkit.h
673-
qgsfieldkitregistry.h
674675
qgsfields.h
675676
qgsfontutils.h
676677
qgsgeometrycache.h
@@ -889,6 +890,7 @@ SET(QGIS_CORE_HDRS
889890
geometry/qgswkbtypes.h
890891

891892
fieldkit/qgsdatetimefieldkit.h
893+
fieldkit/qgsfallbackfieldkit.h
892894
fieldkit/qgskeyvaluefieldkit.h
893895
fieldkit/qgslistfieldkit.h
894896
fieldkit/qgsrelationreferencefieldkit.h
@@ -909,6 +911,7 @@ INCLUDE_DIRECTORIES(
909911
composer
910912
dxf
911913
effects
914+
fieldkit
912915
geometry
913916
layertree
914917
pal

src/core/fieldkit/qgsdatetimefieldkit.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ QgsDateTimeFieldKit::QgsDateTimeFieldKit()
2525

2626
}
2727

28-
bool QgsDateTimeFieldKit::supportsField( QgsVectorLayer* layer, int fieldIdx )
28+
QString QgsDateTimeFieldKit::id() const
2929
{
30+
return QStringLiteral( "DateTime" );
3031
}
3132

32-
QString QgsDateTimeFieldKit::representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
33+
QString QgsDateTimeFieldKit::representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
3334
{
3435
Q_UNUSED( cache )
3536

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

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

@@ -64,12 +65,12 @@ QString QgsDateTimeFieldKit::defaultFormat( const QVariant::Type type )
6465
switch ( type )
6566
{
6667
case QVariant::DateTime:
67-
return QGSDATETIMEEDIT_DATETIMEFORMAT;
68+
return QGSDATETIMEFIELDKIT_DATETIMEFORMAT;
6869
break;
6970
case QVariant::Time:
70-
return QGSDATETIMEEDIT_TIMEFORMAT;
71+
return QGSDATETIMEFIELDKIT_TIMEFORMAT;
7172
break;
7273
default:
73-
return QGSDATETIMEEDIT_DATEFORMAT;
74+
return QGSDATETIMEFIELDKIT_DATEFORMAT;
7475
}
7576
}

src/core/fieldkit/qgsdatetimefieldkit.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@
1818

1919
#include "qgsfieldkit.h"
2020

21-
#define QGSDATETIMEEDIT_DATEFORMAT QStringLiteral( "yyyy-MM-dd" )
22-
#define QGSDATETIMEEDIT_TIMEFORMAT QStringLiteral( "HH:mm:ss" )
23-
#define QGSDATETIMEEDIT_DATETIMEFORMAT QStringLiteral( "yyyy-MM-dd HH:mm:ss" )
21+
#define QGSDATETIMEFIELDKIT_DATEFORMAT QStringLiteral( "yyyy-MM-dd" )
22+
#define QGSDATETIMEFIELDKIT_TIMEFORMAT QStringLiteral( "HH:mm:ss" )
23+
#define QGSDATETIMEFIELDKIT_DATETIMEFORMAT QStringLiteral( "yyyy-MM-dd HH:mm:ss" )
2424

25-
class QgsDateTimeFieldKit : public QgsFieldKit
25+
class CORE_EXPORT QgsDateTimeFieldKit : public QgsFieldKit
2626
{
2727
public:
2828
QgsDateTimeFieldKit();
2929

30-
virtual bool supportsField( QgsVectorLayer* layer, int fieldIdx ) override;
31-
virtual QString representValue( QgsVectorLayer* layer, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
30+
QString id() const override;
31+
32+
virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
3233

3334
/**
34-
* Get the default format in function of the type
35-
* @param type the field type
36-
* @return the date/time format
35+
* Get the default format in function of the type.
36+
* The type is expected to be one of
37+
*
38+
* - QVariant::DateTime
39+
* - QVariant::Date
40+
* - QVariant::Time
3741
*/
3842
static QString defaultFormat( const QVariant::Type type );
3943
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/***************************************************************************
2+
qgsfallbackfieldkit.cpp - QgsFallbackFieldKit
3+
4+
---------------------
5+
begin : 4.12.2016
6+
copyright : (C) 2016 by Matthias Kuhn
7+
email : matthias@opengis.ch
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+
***************************************************************************/
16+
#include "qgsfallbackfieldkit.h"
17+
18+
QgsFallbackFieldKit::QgsFallbackFieldKit()
19+
{
20+
21+
}
22+
23+
QString QgsFallbackFieldKit::id() const
24+
{
25+
return QString();
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************************
2+
qgsfallbackfieldkit.h - QgsFallbackFieldKit
3+
4+
---------------------
5+
begin : 4.12.2016
6+
copyright : (C) 2016 by Matthias Kuhn
7+
email : matthias@opengis.ch
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+
***************************************************************************/
16+
#ifndef QGSFALLBACKFIELDKIT_H
17+
#define QGSFALLBACKFIELDKIT_H
18+
19+
#include "qgsfieldkit.h"
20+
21+
class CORE_EXPORT QgsFallbackFieldKit : public QgsFieldKit
22+
{
23+
public:
24+
QgsFallbackFieldKit();
25+
26+
QString id() const override;
27+
};
28+
29+
#endif // QGSFALLBACKFIELDKIT_H

src/core/fieldkit/qgskeyvaluefieldkit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ QgsKeyValueFieldKit::QgsKeyValueFieldKit()
2222

2323
}
2424

25+
QString QgsKeyValueFieldKit::id() const
26+
{
27+
return QStringLiteral( "KeyValue" );
28+
}
29+
2530
QString QgsKeyValueFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
2631
{
2732
Q_UNUSED( vl );

src/core/fieldkit/qgskeyvaluefieldkit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
#include "qgsfieldkit.h"
2020

21-
class QgsKeyValueFieldKit : public QgsFieldKit
21+
class CORE_EXPORT QgsKeyValueFieldKit : public QgsFieldKit
2222
{
2323
public:
2424
QgsKeyValueFieldKit();
2525

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

src/core/fieldkit/qgslistfieldkit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ QgsListFieldKit::QgsListFieldKit()
2222

2323
}
2424

25+
QString QgsListFieldKit::id() const
26+
{
27+
return QStringLiteral( "List" );
28+
}
29+
2530
QString QgsListFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
2631
{
2732
Q_UNUSED( vl );

src/core/fieldkit/qgslistfieldkit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
#include "qgsfieldkit.h"
2020

21-
class QgsListFieldKit : public QgsFieldKit
21+
class CORE_EXPORT QgsListFieldKit : public QgsFieldKit
2222
{
2323
public:
2424
QgsListFieldKit();
2525

26+
QString id() const override;
27+
2628
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
2729
};
2830

src/core/fieldkit/qgsrelationreferencefieldkit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ QgsRelationReferenceFieldKit::QgsRelationReferenceFieldKit()
2727

2828
}
2929

30+
QString QgsRelationReferenceFieldKit::id() const
31+
{
32+
return QStringLiteral( "RelationReference" );
33+
}
34+
3035
QString QgsRelationReferenceFieldKit::representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
3136
{
3237
Q_UNUSED( cache );

src/core/fieldkit/qgsrelationreferencefieldkit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
#include "qgsfieldkit.h"
2020

21-
class QgsRelationReferenceFieldKit : public QgsFieldKit
21+
class CORE_EXPORT QgsRelationReferenceFieldKit : public QgsFieldKit
2222
{
2323
public:
2424
QgsRelationReferenceFieldKit();
2525

26+
QString id() const override;
27+
2628
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
2729

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

0 commit comments

Comments
 (0)