Skip to content

Commit 1da2474

Browse files
authoredSep 20, 2016
Rename QgsEditFormConfig::expression to constraintExpression (#3509)
And QgsEditFormConfig::expressionDescription to constraintDescription. Because only a verbose API is a good API.
1 parent ce23238 commit 1da2474

File tree

9 files changed

+78
-46
lines changed

9 files changed

+78
-46
lines changed
 

‎doc/api_break.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ place of a null pointer.</li>
681681
<li>widgetType() and widgetConfig() now reflect only the user configured values.
682682
QgsEditorWidgetRegistry::instance()->findBest() must be used instead.</li>
683683
<li>widgetType(), widgetConfig(), setWidgetType(), setWidgetConfig() and removeWidgetConfig() now only take a string as first parameter. Access by index has been removed.</li>
684+
<li>expression() has been renamed to constraintExpression()</li>
685+
<li>setExpression() has been renamed to setConstraintExpression()</li>
686+
<li>expressionDescription() has been renamed to constraintDescription()</li>
687+
<li>setExpressionDesctiption() has been renamed to setConstraintDescription()</li>
684688
</ul>
685689

686690
\subsection qgis_api_break_3_0_QgsExpression QgsExpression

‎python/core/qgseditformconfig.sip

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,49 @@ class QgsEditFormConfig
199199

200200
/**
201201
* Returns the constraint expression of a specific field
202+
*
202203
* @param idx The index of the field
203204
* @return the expression
205+
*
204206
* @note added in QGIS 2.16
207+
* @note renamed in QGIS 3.0
205208
*/
206-
QString expression( int idx ) const;
209+
QString constraintExpression( int idx ) const;
207210

208211
/**
209212
* Set the constraint expression for a specific field
213+
*
210214
* @param idx the field index
211-
* @param str the constraint expression
215+
* @param expression the constraint expression
216+
*
212217
* @note added in QGIS 2.16
218+
* @note renamed in QGIS 3.0
213219
*/
214-
void setExpression( int idx, const QString& str );
220+
void setConstraintExpression( int idx, const QString& expression );
215221

216222
/**
217-
* Returns the constraint expression description of a specific filed.
223+
* Returns the constraint expression description of a specific field.
224+
*
218225
* @param idx The index of the field
219-
* @return the expression description
226+
* @return The expression description. Will be presented
227+
* to the user in case the constraint fails.
228+
*
220229
* @note added in QGIS 2.16
230+
* @note renamed in QGIS 3.0
221231
*/
222-
QString expressionDescription( int idx ) const;
232+
QString constraintDescription( int idx ) const;
223233

224234
/**
225235
* Set the constraint expression description for a specific field.
236+
*
226237
* @param idx The index of the field
227-
* @param descr The description of the expression
238+
* @param description The description of the expression. Will be presented
239+
* to the user in case the constraint fails.
240+
*
228241
* @note added in QGIS 2.16
242+
* @note renamed in QGIS 3.0
229243
*/
230-
void setExpressionDescription( int idx, const QString &descr );
244+
void setContraintDescription( int idx, const QString& description );
231245

232246
/**
233247
* Returns if the field at fieldidx should be treated as NOT NULL value

‎src/app/qgsfieldsproperties.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ void QgsFieldsProperties::apply()
949949
editFormConfig.setReadOnly( i, !cfg.mEditable );
950950
editFormConfig.setLabelOnTop( i, cfg.mLabelOnTop );
951951
editFormConfig.setNotNull( i, cfg.mNotNull );
952-
editFormConfig.setExpressionDescription( i, cfg.mConstraintDescription );
953-
editFormConfig.setExpression( i, cfg.mConstraint );
952+
editFormConfig.setContraintDescription( i, cfg.mConstraintDescription );
953+
editFormConfig.setConstraintExpression( i, cfg.mConstraint );
954954

955955
editFormConfig.setWidgetType( name, cfg.mEditorWidgetType );
956956
editFormConfig.setWidgetConfig( name, cfg.mEditorWidgetConfig );
@@ -1032,8 +1032,8 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
10321032
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;
10331033
mLabelOnTop = layer->editFormConfig().labelOnTop( idx );
10341034
mNotNull = layer->editFormConfig().notNull( idx );
1035-
mConstraint = layer->editFormConfig().expression( idx );
1036-
mConstraintDescription = layer->editFormConfig().expressionDescription( idx );
1035+
mConstraint = layer->editFormConfig().constraintExpression( idx );
1036+
mConstraintDescription = layer->editFormConfig().constraintDescription( idx );
10371037
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer, layer->fields().field( idx ).name() );
10381038
mEditorWidgetType = setup.type();
10391039
mEditorWidgetConfig = setup.config();

‎src/core/qgseditformconfig.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ bool QgsEditFormConfig::labelOnTop( int idx ) const
182182
return false;
183183
}
184184

185-
QString QgsEditFormConfig::expression( int idx ) const
185+
QString QgsEditFormConfig::constraintExpression( int idx ) const
186186
{
187187
QString expr;
188188

@@ -192,16 +192,16 @@ QString QgsEditFormConfig::expression( int idx ) const
192192
return expr;
193193
}
194194

195-
void QgsEditFormConfig::setExpression( int idx, const QString& str )
195+
void QgsEditFormConfig::setConstraintExpression( int idx, const QString& expression )
196196
{
197197
if ( idx >= 0 && idx < d->mFields.count() )
198198
{
199199
d.detach();
200-
d->mConstraints[ d->mFields.at( idx ).name()] = str;
200+
d->mConstraints[ d->mFields.at( idx ).name()] = expression;
201201
}
202202
}
203203

204-
QString QgsEditFormConfig::expressionDescription( int idx ) const
204+
QString QgsEditFormConfig::constraintDescription( int idx ) const
205205
{
206206
QString description;
207207

@@ -211,7 +211,7 @@ QString QgsEditFormConfig::expressionDescription( int idx ) const
211211
return description;
212212
}
213213

214-
void QgsEditFormConfig::setExpressionDescription( int idx, const QString &descr )
214+
void QgsEditFormConfig::setContraintDescription( int idx, const QString &descr )
215215
{
216216
if ( idx >= 0 && idx < d->mFields.count() )
217217
{

‎src/core/qgseditformconfig.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,35 +234,49 @@ class CORE_EXPORT QgsEditFormConfig
234234

235235
/**
236236
* Returns the constraint expression of a specific field
237+
*
237238
* @param idx The index of the field
238239
* @return the expression
240+
*
239241
* @note added in QGIS 2.16
242+
* @note renamed in QGIS 3.0
240243
*/
241-
QString expression( int idx ) const;
244+
QString constraintExpression( int idx ) const;
242245

243246
/**
244247
* Set the constraint expression for a specific field
248+
*
245249
* @param idx the field index
246-
* @param str the constraint expression
250+
* @param expression the constraint expression
251+
*
247252
* @note added in QGIS 2.16
253+
* @note renamed in QGIS 3.0
248254
*/
249-
void setExpression( int idx, const QString& str );
255+
void setConstraintExpression( int idx, const QString& expression );
250256

251257
/**
252-
* Returns the constraint expression description of a specific filed.
258+
* Returns the constraint expression description of a specific field.
259+
*
253260
* @param idx The index of the field
254-
* @return the expression description
261+
* @return The expression description. Will be presented
262+
* to the user in case the constraint fails.
263+
*
255264
* @note added in QGIS 2.16
265+
* @note renamed in QGIS 3.0
256266
*/
257-
QString expressionDescription( int idx ) const;
267+
QString constraintDescription( int idx ) const;
258268

259269
/**
260270
* Set the constraint expression description for a specific field.
271+
*
261272
* @param idx The index of the field
262-
* @param descr The description of the expression
273+
* @param description The description of the expression. Will be presented
274+
* to the user in case the constraint fails.
275+
*
263276
* @note added in QGIS 2.16
277+
* @note renamed in QGIS 3.0
264278
*/
265-
void setExpressionDescription( int idx, const QString &descr );
279+
void setContraintDescription( int idx, const QString& description );
266280

267281
/**
268282
* Returns if the field at fieldidx should be treated as NOT NULL value

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle
264264
formConfig.setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
265265
formConfig.setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
266266
formConfig.setNotNull( idx, ewv2CfgElem.attribute( "notNull", "0" ) == "1" );
267-
formConfig.setExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
268-
formConfig.setExpressionDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );
267+
formConfig.setConstraintExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
268+
formConfig.setContraintDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );
269269

270270
formConfig.setWidgetConfig( name, cfg );
271271
}
@@ -320,8 +320,8 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
320320
ewv2CfgElem.setAttribute( "fieldEditable", !vectorLayer->editFormConfig().readOnly( idx ) );
321321
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->editFormConfig().labelOnTop( idx ) );
322322
ewv2CfgElem.setAttribute( "notNull", vectorLayer->editFormConfig().notNull( idx ) );
323-
ewv2CfgElem.setAttribute( "constraint", vectorLayer->editFormConfig().expression( idx ) );
324-
ewv2CfgElem.setAttribute( "constraintDescription", vectorLayer->editFormConfig().expressionDescription( idx ) );
323+
ewv2CfgElem.setAttribute( "constraint", vectorLayer->editFormConfig().constraintExpression( idx ) );
324+
ewv2CfgElem.setAttribute( "constraintDescription", vectorLayer->editFormConfig().constraintDescription( idx ) );
325325

326326
mWidgetFactories[widgetType]->writeConfig( vectorLayer->editFormConfig().widgetConfig( field.name() ), ewv2CfgElem, doc, vectorLayer, idx );
327327

‎src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft )
109109
{
110110
bool toEmit( false );
111111
QString errStr( tr( "predicate is True" ) );
112-
QString expression = layer()->editFormConfig().expression( mFieldIdx );
112+
QString expression = layer()->editFormConfig().constraintExpression( mFieldIdx );
113113
QString description;
114114
QVariant value = ft.attribute( mFieldIdx );
115115

116116
if ( ! expression.isEmpty() )
117117
{
118-
description = layer()->editFormConfig().expressionDescription( mFieldIdx );
118+
description = layer()->editFormConfig().constraintDescription( mFieldIdx );
119119

120120
QgsExpressionContext context = layer()->createExpressionContext();
121121
context.setFeature( ft );

‎src/gui/qgsattributeform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ bool QgsAttributeForm::currentFormValidConstraints( QStringList &invalidFields,
835835
{
836836
invalidFields.append( eww->field().name() );
837837

838-
QString desc = eww->layer()->editFormConfig().expressionDescription( eww->fieldIdx() );
838+
QString desc = eww->layer()->editFormConfig().constraintDescription( eww->fieldIdx() );
839839
descriptions.append( desc );
840840

841841
valid = false; // continue to get all invalif fields
@@ -952,7 +952,7 @@ QList<QgsEditorWidgetWrapper*> QgsAttributeForm::constraintDependencies( QgsEdit
952952
if ( name != ewwName )
953953
{
954954
// get expression and referencedColumns
955-
QgsExpression expr = eww->layer()->editFormConfig().expression( eww->fieldIdx() );
955+
QgsExpression expr = eww->layer()->editFormConfig().constraintExpression( eww->fieldIdx() );
956956

957957
Q_FOREACH ( const QString& colName, expr.referencedColumns() )
958958
{

‎tests/src/gui/testqgsattributeform.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void TestQgsAttributeForm::testFieldConstraint()
8484

8585
// set constraint
8686
QgsEditFormConfig config = layer->editFormConfig();
87-
config.setExpression( 0, QString() );
87+
config.setConstraintExpression( 0, QString() );
8888
layer->setEditFormConfig( config );
8989

9090
// get wrapper
@@ -96,7 +96,7 @@ void TestQgsAttributeForm::testFieldConstraint()
9696
QCOMPARE( label->text(), QString( "col0" ) );
9797

9898
// set a not null constraint
99-
config.setExpression( 0, "col0 is not null" );
99+
config.setConstraintExpression( 0, "col0 is not null" );
100100
layer->setEditFormConfig( config );
101101

102102
// set value to 1
@@ -132,10 +132,10 @@ void TestQgsAttributeForm::testFieldMultiConstraints()
132132

133133
// set constraints for each field
134134
QgsEditFormConfig config = layer->editFormConfig();
135-
config.setExpression( 0, QString() );
136-
config.setExpression( 1, QString() );
137-
config.setExpression( 2, QString() );
138-
config.setExpression( 3, QString() );
135+
config.setConstraintExpression( 0, QString() );
136+
config.setConstraintExpression( 1, QString() );
137+
config.setConstraintExpression( 2, QString() );
138+
config.setConstraintExpression( 3, QString() );
139139
layer->setEditFormConfig( config );
140140

141141
// build a form for this feature
@@ -167,10 +167,10 @@ void TestQgsAttributeForm::testFieldMultiConstraints()
167167
QCOMPARE( label3->text(), QString( "col3" ) );
168168

169169
// update constraint
170-
config.setExpression( 0, "col0 < (col1 * col2)" );
171-
config.setExpression( 1, QString() );
172-
config.setExpression( 2, QString() );
173-
config.setExpression( 3, "col0 = 2" );
170+
config.setConstraintExpression( 0, "col0 < (col1 * col2)" );
171+
config.setConstraintExpression( 1, QString() );
172+
config.setConstraintExpression( 2, QString() );
173+
config.setConstraintExpression( 3, "col0 = 2" );
174174
layer->setEditFormConfig( config );
175175

176176
// change value
@@ -206,7 +206,7 @@ void TestQgsAttributeForm::testOKButtonStatus()
206206

207207
// set constraint
208208
QgsEditFormConfig config = layer->editFormConfig();
209-
config.setExpression( 0, QString() );
209+
config.setConstraintExpression( 0, QString() );
210210
layer->setEditFormConfig( config );
211211

212212
// build a form for this feature
@@ -235,13 +235,13 @@ void TestQgsAttributeForm::testOKButtonStatus()
235235
QCOMPARE( okButton->isEnabled(), true );
236236

237237
// invalid constraint and editable layer : OK button disabled
238-
config.setExpression( 0, "col0 = 0" );
238+
config.setConstraintExpression( 0, "col0 = 0" );
239239
layer->setEditFormConfig( config );
240240
ww->setValue( 1 );
241241
QCOMPARE( okButton->isEnabled(), false );
242242

243243
// valid constraint and editable layer : OK button enabled
244-
config.setExpression( 0, "col0 = 2" );
244+
config.setConstraintExpression( 0, "col0 = 2" );
245245
layer->setEditFormConfig( config );
246246
ww->setValue( 2 );
247247
QCOMPARE( okButton->isEnabled(), true );

0 commit comments

Comments
 (0)
Please sign in to comment.