Skip to content

Commit ea91b6f

Browse files
committed
[FEATURE] Port editor widgets to new API
Create a new widget for for attribute form fix #10281 fix #7319 fix #7013 fix #9335 fix #4417
1 parent 373ec56 commit ea91b6f

File tree

147 files changed

+8066
-4923
lines changed

Some content is hidden

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

147 files changed

+8066
-4923
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,6 @@ class QgsVectorLayer : QgsMapLayer
860860
/** set string representing 'true' for a checkbox (added in 1.4) */
861861
void setCheckedState( int idx, QString checked, QString notChecked );
862862

863-
/** return string representing 'true' for a checkbox (added in 1.4)
864-
* @note not available in python bindings
865-
* FIXME: need SIP binding for QPair<QString, QString>
866-
*/
867-
// QPair<QString, QString> checkedState( int idx );
868-
869863
/** get edit form (added in 1.4) */
870864
QString editForm();
871865

@@ -893,15 +887,15 @@ class QgsVectorLayer : QgsMapLayer
893887
void setEditFormInit( QString function );
894888

895889
/**access value map*/
896-
QMap<QString, QVariant> &valueMap( int idx );
890+
QMap<QString, QVariant> valueMap( int idx );
897891

898892
/**access range */
899-
RangeData &range( int idx );
893+
RangeData range( int idx ) /Deprecated/;
900894

901895
/**access relations
902896
* @note added in 1.8
903897
**/
904-
ValueRelationData &valueRelation( int idx );
898+
ValueRelationData valueRelation( int idx ) /Deprecated/;
905899

906900
/**
907901
* Get relations, where the foreign key is on this layer
@@ -914,12 +908,12 @@ class QgsVectorLayer : QgsMapLayer
914908
/**access date format
915909
* @note added in 1.9
916910
*/
917-
QString &dateFormat( int idx );
911+
QString dateFormat( int idx ) /Deprecated/;
918912

919913
/**access widget size for photo and webview widget
920914
* @note added in 1.9
921915
*/
922-
QSize &widgetSize( int idx );
916+
QSize widgetSize( int idx ) /Deprecated/;
923917

924918
/**is edit widget editable
925919
* @note added in 1.9

python/gui/attributetable/qgsdualview.sip

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ class QgsDualView : QStackedWidget
124124
*/
125125
bool saveEditChanges();
126126

127-
/**
128-
* Update the shown feature if an attribute changed
129-
*/
130-
void reloadAttribute( const int& attribute );
131-
132127

133128
signals:
134129
/**

python/gui/editorwidgets/core/qgseditorwidgetfactory.sip

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,122 @@ class QgsEditorWidgetFactory
2323
%End
2424

2525
public:
26+
/**
27+
* Constructor
28+
*
29+
* @param name A human readable name for this widget type
30+
*/
2631
QgsEditorWidgetFactory( const QString& name );
32+
2733
virtual ~QgsEditorWidgetFactory();
28-
virtual QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const = 0 /Factory/;
29-
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const = 0 /Factory/;
34+
35+
/**
36+
* Override this in your implementation.
37+
* Create a new editor widget wrapper. Call {@link QgsEditorWidgetRegistry::create()}
38+
* instead of calling this method directly.
39+
*
40+
* @param vl The vector layer on which this widget will act
41+
* @param fieldIdx The field index on which this widget will act
42+
* @param editor An editor widget if already existent. If NULL is provided, a new widget will be created.
43+
* @param parent The parent for the wrapper class and any created widget.
44+
*
45+
* @return A new widget wrapper
46+
*/
47+
virtual QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const = 0;
48+
49+
/**
50+
* Return The human readable identifier name of this widget type
51+
*
52+
* @return a name
53+
*/
54+
QString name();
55+
56+
/**
57+
* Override this in your implementation.
58+
* Create a new configuration widget for this widget type.
59+
*
60+
* @param vl The layer for which the widget will be created
61+
* @param fieldIdx The field index for which the widget will be created
62+
* @param parent The parent widget of the created config widget
63+
*
64+
* @return A configuration widget
65+
*/
66+
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const = 0;
67+
68+
/**
69+
* Read the config from an XML file and map it to a proper {@link QgsEditorWidgetConfig}.
70+
*
71+
* @param configElement The configuration element from the project file
72+
* @param layer The layer for which this configuration applies
73+
* @param fieldIdx The field on the layer for which this configuration applies
74+
*
75+
* @return A configuration object. This will be passed to your widget wrapper later on
76+
*/
77+
QgsEditorWidgetConfig readEditorConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );
78+
79+
/**
80+
* Serialize your configuration and save it in a xml doc.
81+
*
82+
* @param config The configuration to serialize
83+
* @param configElement The element, where you can write your configuration into
84+
* @param doc The document. You can use this to create new nodes
85+
* @param layer The layer for which this configuration applies
86+
* @param fieldIdx The field on the layer for which this configuration applies
87+
*/
88+
virtual void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx );
89+
90+
/**
91+
* Check if this editor widget type supports a certain field.
92+
*
93+
* @param vl The layer
94+
* @param fieldIdx The field index
95+
* @return True if the type is supported for this field
96+
*/
97+
bool supportsField( QgsVectorLayer* vl, int fieldIdx );
98+
99+
/**
100+
* Create a pretty String representation of the value.
101+
*
102+
* @param vl The vector layer.
103+
* @param fieldIdx The index of the field.
104+
* @param config The editor widget config.
105+
* @param value The value to represent.
106+
*
107+
* @return By default the string representation of the provided value.
108+
*/
109+
virtual QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const;
110+
111+
/**
112+
* Create a cache for a given field.
113+
*
114+
* @param vl The vector layer.
115+
* @param fieldIdx The index of the field.
116+
* @param config The editor widget config.
117+
*
118+
* @return The default implementation returns an invalid QVariant
119+
*/
120+
virtual QVariant createCache( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config );
121+
122+
private:
123+
/**
124+
* Read the config from an XML file and map it to a proper {@link QgsEditorWidgetConfig}.
125+
*
126+
* @param configElement The configuration element from the project file
127+
* @param layer The layer for which this configuration applies
128+
* @param fieldIdx The field on the layer for which this configuration applies
129+
*
130+
* @return A configuration object. This will be passed to your widget wrapper later on
131+
*/
30132
virtual QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );
31-
virtual void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, const QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx );
32133

33-
virtual QString name();
134+
/**
135+
* This method allows to disable this editor widget type for a certain field.
136+
* By default, it returns true for all fields.
137+
* Reimplement this if you only support certain fields.
138+
*
139+
* @param vl
140+
* @param fieldIdx
141+
* @return True if the field is supported.
142+
*/
143+
virtual bool isFieldSupported( QgsVectorLayer* vl, int fieldIdx );
34144
};

python/gui/editorwidgets/core/qgseditorwidgetwrapper.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class QgsEditorWidgetWrapper : QObject
2727
QVariant config( QString key );
2828

2929
QgsVectorLayer* layer();
30-
int field();
30+
QgsField field();
31+
int fieldIdx();
3132

3233
protected:
3334
virtual QWidget* createWidget( QWidget* parent ) = 0 /Factory/;

python/gui/gui.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
%Include qgsattributeeditor.sip
1616
%Include qgsattributeeditorcontext.sip
1717
%Include qgsattributedialog.sip
18+
%Include qgsattributeform.sip
19+
%Include qgsattributeforminterface.sip
1820
%Include qgsbusyindicatordialog.sip
1921
%Include qgscollapsiblegroupbox.sip
2022
%Include qgscolorbutton.sip

python/gui/qgsattributedialog.sip

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ class QgsAttributeDialog : QObject
6161
int exec();
6262
void show();
6363

64-
void dialogDestroyed();
6564
};

python/gui/qgsattributeeditor.sip

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,6 @@ class QgsAttributeEditor : QObject
3131
*/
3232
static QWidget* createAttributeEditor( QWidget* parent, QWidget* editor, QgsVectorLayer* vl, int idx, const QVariant& value, QgsAttributeEditorContext& context ) /Factory/;
3333

34-
/**
35-
* Creates a widget form a QgsAttributeEditorElement definition. Will recursively generate containers and widgets.
36-
* @param widgetDef The definition for the widget
37-
* @param parent The parent object
38-
* @param vl The vector layer to use as data source
39-
* @param feat The feature to create the widget for
40-
* @param context the context used for the created attribute editor
41-
* @param [out] labelText An optional label text will be written into the referenced QString. It will be set to
42-
* a QString::null value if no label should be shown
43-
* @param [out] labelOnTop Will be set to true if the label should be placed on top of the field.
44-
* If set to false, the label should be shown left or right of the field
45-
*
46-
*/
47-
static QWidget *createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, const QgsFeature &feat, QgsAttributeEditorContext& context, QString& labelText, bool& labelOnTop ) /Factory/;
48-
4934
static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value );
5035
static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value );
51-
52-
public slots:
53-
void selectFileName();
54-
void selectDate();
55-
void loadUrl( const QString & );
56-
void loadPixmap( const QString & );
57-
void updateUrl();
58-
void openUrl();
59-
void updateColor();
60-
};
61-
62-
class QgsStringRelay : QObject
63-
{
64-
%TypeHeaderCode
65-
#include "qgsattributeeditor.h"
66-
%End
67-
public:
68-
QgsStringRelay( QObject* parent = 0 );
69-
70-
void appendProxy( QWidget* proxy );
71-
72-
public slots:
73-
void changeText();
74-
void changeText( QString str );
75-
76-
signals:
77-
void textChanged( QString );
7836
};

python/gui/qgsattributeeditorcontext.sip

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class QgsAttributeEditorContext
1212
public:
1313
QgsAttributeEditorContext();
1414

15-
QWidget* proxyWidget( QgsVectorLayer* vl, int fieldIdx );
16-
//! @note not available in python bindings
17-
// void addProxyWidgets( QgsVectorLayer* vl, QMap<int, QWidget*> proxyWidgets );
18-
void addProxyWidget( QgsVectorLayer* vl, int idx, QWidget* widget );
19-
2015
void setDistanceArea( const QgsDistanceArea& distanceArea );
2116
const QgsDistanceArea& distanceArea();
2217

python/gui/qgsattributeform.sip

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgsattributeform.h
3+
--------------------------------------
4+
Date : 3.5.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
class QgsAttributeForm : QWidget
17+
{
18+
%TypeHeaderCode
19+
#include <qgsattributeform.h>
20+
%End
21+
22+
public:
23+
explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature feature = QgsFeature(), QgsAttributeEditorContext context = QgsAttributeEditorContext(), QWidget *parent = 0 );
24+
~QgsAttributeForm();
25+
26+
const QgsFeature& feature();
27+
28+
void hideButtonBox();
29+
30+
void showButtonBox();
31+
32+
signals:
33+
/**
34+
* Notifies about changes of attributes
35+
*
36+
* @param attribute The name of the attribute that changed.
37+
* @param value The new value of the attribute.
38+
*/
39+
void attributeChanged( QString attribute, const QVariant& value );
40+
41+
public slots:
42+
void changeAttribute( const QString& field, const QVariant& value );
43+
void setFeature( const QgsFeature& feature );
44+
bool save();
45+
void accept();
46+
void resetValues();
47+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/***************************************************************************
2+
qgsattributeforminterface.sip
3+
--------------------------------------
4+
Date : 12.5.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
class QgsAttributeFormInterface
17+
{
18+
%TypeHeaderCode
19+
#include <qgsattributeforminterface.h>
20+
%End
21+
public:
22+
explicit QgsAttributeFormInterface( QgsAttributeForm* form );
23+
24+
virtual bool acceptChanges( const QgsFeature& feat );
25+
26+
virtual void initForm();
27+
28+
virtual void featureChanged();
29+
30+
QgsAttributeForm* form();
31+
32+
const QgsFeature& feature();
33+
};

src/app/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SET(QGIS_APP_SRCS
1111
qgsannotationwidget.cpp
1212
qgsattributeactiondialog.cpp
1313
qgsattributetypedialog.cpp
14-
qgsattributetypeloaddialog.cpp
1514
qgsattributetabledialog.cpp
1615
qgsbookmarks.cpp
1716
qgsbrowserdockwidget.cpp
@@ -164,7 +163,6 @@ SET (QGIS_APP_MOC_HDRS
164163
qgsannotationwidget.h
165164
qgsattributeactiondialog.h
166165
qgsattributetypedialog.h
167-
qgsattributetypeloaddialog.h
168166
qgsattributetabledialog.h
169167
qgsbookmarks.h
170168
qgsbrowserdockwidget.h

0 commit comments

Comments
 (0)