Skip to content

Commit 0903684

Browse files
committed
fix edit widget deprecation warnings and sync sip bindings
1 parent d1da612 commit 0903684

File tree

5 files changed

+133
-35
lines changed

5 files changed

+133
-35
lines changed

python/core/qgsvectorlayer.sip

+108-18
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ class QgsVectorLayer : QgsMapLayer
118118
{
119119
GeneratedLayout,
120120
TabLayout,
121-
UiFileLayout,
121+
UiFileLayout
122122
};
123123

124+
/**
125+
* @deprecated Use the editorWidgetV2() system instead
126+
*/
124127
enum EditType
125128
{
126129
LineEdit,
@@ -758,16 +761,38 @@ class QgsVectorLayer : QgsMapLayer
758761
*
759762
* @return The id for the editor widget or a NULL string if not applicable
760763
*/
761-
const QString editorWidgetV2( int fieldIdx );
764+
const QString editorWidgetV2( int fieldIdx ) const;
765+
766+
/**
767+
* Get the id for the editor widget used to represent the field at the given index
768+
*
769+
* @param fieldName The name of the field
770+
*
771+
* @return The id for the editor widget or a NULL string if not applicable
772+
*
773+
* @note python method name editorWidgetV2ByName
774+
*/
775+
const QString editorWidgetV2( const QString& fieldName ) const /PyName=editorWidgetV2ByName/;
762776

763777
/**
764778
* Get the configuration for the editor widget used to represent the field at the given index
765779
*
766780
* @param fieldIdx The index of the field
767781
*
768-
* @return The id for the editor widget or a NULL string if not configured
782+
* @return The configuration for the editor widget or an empty config if the field does not exist
769783
*/
770-
const QgsEditorWidgetConfig editorWidgetV2Config( int fieldIdx );
784+
const QgsEditorWidgetConfig editorWidgetV2Config( int fieldIdx ) const;
785+
786+
/**
787+
* Get the configuration for the editor widget used to represent the field at the given index
788+
*
789+
* @param fieldName The name of the field
790+
*
791+
* @return The configuration for the editor widget or an empty config if the field does not exist
792+
*
793+
* @note python method name is editorWidgetV2ConfigByName
794+
*/
795+
const QgsEditorWidgetConfig editorWidgetV2Config( const QString& fieldName ) const /PyName=editorWidgetV2ConfigByName/;
771796

772797
/**
773798
* Returns a list of tabs holding groups and fields
@@ -841,24 +866,48 @@ class QgsVectorLayer : QgsMapLayer
841866
*/
842867
bool rollBack( bool deleteBuffer = true );
843868

844-
/**get edit type*/
845-
EditType editType( int idx );
869+
/**
870+
* Get edit type
871+
*
872+
* @deprecated Use @see{editorWidgetV2} instead
873+
*/
874+
EditType editType( int idx ) /Deprecated/;
846875

847-
/**set edit type*/
848-
void setEditType( int idx, EditType edit );
876+
/**
877+
* Get edit type
878+
*
879+
* @deprecated Use @see{setEditorWidgetV2} instead
880+
*/
881+
void setEditType( int idx, EditType edit ) /Deprecated/;
849882

850883
/** get the active layout for the attribute editor for this layer (added in 1.9) */
851884
EditorLayout editorLayout();
852885

853886
/** set the active layout for the attribute editor for this layer (added in 1.9) */
854887
void setEditorLayout( EditorLayout editorLayout );
855888

889+
/**
890+
* Set the editor widget type for a field
891+
*
892+
* @param attrIdx Index of the field
893+
* @param widgetType Type id of the editor widget to use
894+
*/
856895
void setEditorWidgetV2( int attrIdx, const QString& widgetType );
857896

897+
/**
898+
* Set the editor widget config for a field
899+
*
900+
* @param attrIdx Index of the field
901+
* @param config The config to set for this field
902+
*/
858903
void setEditorWidgetV2Config( int attrIdx, const QMap<QString, QVariant>& config );
859904

860-
/** set string representing 'true' for a checkbox (added in 1.4) */
861-
void setCheckedState( int idx, QString checked, QString notChecked );
905+
/**
906+
* Set string representing 'true' for a checkbox (added in 1.4)
907+
*
908+
* @deprecated Use @see{setEditorWidgetV2Config} instead
909+
*/
910+
void setCheckedState( int idx, QString checked, QString notChecked ) /Deprecated/;
862911

863912
/** get edit form (added in 1.4) */
864913
QString editForm();
@@ -886,16 +935,25 @@ class QgsVectorLayer : QgsMapLayer
886935
/** set python function for edit form initialization (added in 1.4) */
887936
void setEditFormInit( QString function );
888937

889-
/**access value map*/
890-
QMap<QString, QVariant> valueMap( int idx );
938+
/**
939+
* Access value map
940+
* @deprecated Use @see{editorWidgetV2Config} instead
941+
*/
942+
QMap<QString, QVariant> valueMap( int idx ) /Deprecated/;
891943

892-
/**access range */
944+
/**
945+
* Access range widget config data
946+
*
947+
* @deprecated Use @see{editorWidgetV2Config} instead
948+
*/
893949
RangeData range( int idx ) /Deprecated/;
894950

895-
/**access relations
951+
/**
952+
* Access value relation widget data
953+
*
896954
* @note added in 1.8
897-
**/
898-
ValueRelationData valueRelation( int idx ) /Deprecated/;
955+
*/
956+
ValueRelationData valueRelation( int idx );
899957

900958
/**
901959
* Get relations, where the foreign key is on this layer
@@ -905,13 +963,21 @@ class QgsVectorLayer : QgsMapLayer
905963
*/
906964
QList<QgsRelation> referencingRelations( int idx );
907965

908-
/**access date format
966+
/**
967+
* Access date format
968+
*
909969
* @note added in 1.9
970+
*
971+
* @deprecated Use @see{setEditorWdigetV2Config} instead
910972
*/
911973
QString dateFormat( int idx ) /Deprecated/;
912974

913-
/**access widget size for photo and webview widget
975+
/**
976+
* Access widget size for photo and webview widget
977+
*
914978
* @note added in 1.9
979+
*
980+
* @deprecated Use @see{setEditorWdigetV2Config} instead
915981
*/
916982
QSize widgetSize( int idx ) /Deprecated/;
917983

@@ -1110,6 +1176,9 @@ class QgsVectorLayer : QgsMapLayer
11101176
/** This signal is emitted when modifications has been done on layer */
11111177
void layerModified();
11121178

1179+
/** Is emitted, when layer is checked for modifications. Use for last-minute additions */
1180+
void beforeModifiedCheck() const;
1181+
11131182
/** Is emitted, when editing on this layer has started*/
11141183
void editingStarted();
11151184

@@ -1179,6 +1248,27 @@ class QgsVectorLayer : QgsMapLayer
11791248
/** Signal emitted when setLayerTransparency() is called */
11801249
void layerTransparencyChanged( int layerTransparency );
11811250

1251+
/**
1252+
* Signal emitted when a new edit command has been started
1253+
*
1254+
* @param text Description for this edit command
1255+
*/
1256+
void editCommandStarted( const QString& text );
1257+
1258+
/**
1259+
* Signal emitted, when an edit command successfully ended
1260+
* @note This does not mean it is also committed, only that it is written
1261+
* to the edit buffer. See {@link beforeCommitChanges()}
1262+
*/
1263+
void editCommandEnded();
1264+
1265+
/**
1266+
* Signal emitted, whan an edit command is destroyed
1267+
* @note This is not a rollback, it is only related to the current edit command.
1268+
* See {@link beforeRollBack()}
1269+
*/
1270+
void editCommandDestroyed();
1271+
11821272
protected:
11831273
/** Set the extent */
11841274
void setExtent( const QgsRectangle &rect );

src/app/qgsmergeattributesdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
9090
int col = 0;
9191
for ( int idx = 0; idx < fields.count(); ++idx )
9292
{
93-
if ( mVectorLayer->editType( idx ) == QgsVectorLayer::Hidden ||
94-
mVectorLayer->editType( idx ) == QgsVectorLayer::Immutable )
93+
if ( mVectorLayer->editorWidgetV2( idx ) == "Hidden" ||
94+
mVectorLayer->editorWidgetV2( idx ) == "Immutable" )
9595
continue;
9696

9797
mTableWidget->setColumnCount( col + 1 );

src/core/qgsvectorlayer.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11201120
* @param fieldName The name of the field
11211121
*
11221122
* @return The id for the editor widget or a NULL string if not applicable
1123+
*
1124+
* @note python method name editorWidgetV2ByName
11231125
*/
11241126
const QString editorWidgetV2( const QString& fieldName ) const;
11251127

@@ -1138,6 +1140,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11381140
* @param fieldName The name of the field
11391141
*
11401142
* @return The configuration for the editor widget or an empty config if the field does not exist
1143+
*
1144+
* @note python method name is editorWidgetV2ConfigByName
11411145
*/
11421146
const QgsEditorWidgetConfig editorWidgetV2Config( const QString& fieldName ) const;
11431147

@@ -1252,7 +1256,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
12521256
/**
12531257
* Set string representing 'true' for a checkbox (added in 1.4)
12541258
*
1255-
* @deprecated Use @see{setEditorWdigetV2Config} instead
1259+
* @deprecated Use @see{setEditorWidgetV2Config} instead
12561260
*/
12571261
Q_DECL_DEPRECATED void setCheckedState( int idx, QString checked, QString notChecked );
12581262

@@ -1284,14 +1288,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
12841288

12851289
/**
12861290
* Access value map
1287-
* @deprecated Use @see{editorWdigetV2Config} instead
1291+
* @deprecated Use @see{editorWidgetV2Config} instead
12881292
*/
12891293
Q_DECL_DEPRECATED QMap<QString, QVariant> valueMap( int idx );
12901294

12911295
/**
12921296
* Access range widget config data
12931297
*
1294-
* @deprecated Use @see{editorWdigetV2Config} instead
1298+
* @deprecated Use @see{editorWidgetV2Config} instead
12951299
*/
12961300
Q_DECL_DEPRECATED RangeData range( int idx );
12971301

src/mapserver/qgsserverprojectparser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QD
469469
attributeElem.setAttribute( "typeName", field.typeName() );
470470

471471
//edit type to text
472-
QgsVectorLayer::EditType typeEnum = vLayer->editType( idx );
473-
attributeElem.setAttribute( "editType", editTypeString( typeEnum ) );
472+
attributeElem.setAttribute( "editType", vLayer->editorWidgetV2( idx ) );
474473
attributeElem.setAttribute( "comment", field.comment() );
475474
attributeElem.setAttribute( "length", field.length() );
476475
attributeElem.setAttribute( "precision", field.precision() );

src/mapserver/qgswmsserver.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -2903,30 +2903,30 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
29032903
return attributeVal;
29042904
}
29052905

2906-
QgsVectorLayer::EditType type = vl->editType( idx );
2907-
if ( type == QgsVectorLayer::ValueMap )
2906+
QString type = vl->editorWidgetV2( idx );
2907+
if ( type == "ValueMap" )
29082908
{
2909-
QMap<QString, QVariant> valueMap = vl->valueMap( idx );
2910-
QMap<QString, QVariant>::const_iterator vmapIt = valueMap.constBegin();
2911-
for ( ; vmapIt != valueMap.constEnd(); ++vmapIt )
2909+
QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
2910+
QMap<QString, QVariant>::const_iterator vmapIt = cfg.constBegin();
2911+
for ( ; vmapIt != cfg.constEnd(); ++vmapIt )
29122912
{
29132913
if ( vmapIt.value().toString() == attributeVal )
29142914
{
29152915
return vmapIt.key();
29162916
}
29172917
}
29182918
}
2919-
else if ( type == QgsVectorLayer::ValueRelation )
2919+
else if ( type == "ValueRelation" )
29202920
{
2921-
QgsVectorLayer::ValueRelationData vrdata = vl->valueRelation( idx );
2922-
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( vrdata.mLayer ) );
2921+
QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
2922+
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( cfg.value( "Layer" ).toString() ) );
29232923
if ( !layer )
29242924
{
29252925
return attributeVal;
29262926
}
29272927

29282928
QString outputString;
2929-
if ( vrdata.mAllowMulti )
2929+
if ( cfg.value( "AllowMulti" ).toBool() )
29302930
{
29312931
QString valueString = attributeVal;
29322932
QStringList valueList = valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );
@@ -2936,7 +2936,12 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
29362936
{
29372937
outputString += ";";
29382938
}
2939-
outputString += relationValue( valueList.at( i ), layer, vrdata.mKey, vrdata.mValue );
2939+
outputString += relationValue(
2940+
valueList.at( i ),
2941+
layer,
2942+
cfg.value( "Key" ).toString(),
2943+
cfg.value( "Value" ).toString()
2944+
);
29402945
}
29412946
}
29422947
return outputString;

0 commit comments

Comments
 (0)