Skip to content

Commit 5c38775

Browse files
committed
Always emit signal when attribute values change
Fix #9268 * Remove QgsVectorLayer::blockSignals() calls from QgsFieldCalculator * Deprecate emitSignal parameter from QgsVectorLayer::changeAttributeValue( fid, field, value, emitSignal ) * Code cleanup to update calls to the new emitSignal-less method
1 parent 9c5bbb7 commit 5c38775

12 files changed

+58
-24
lines changed

python/core/qgsvectorlayer.sip

+18-2
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,24 @@ class QgsVectorLayer : QgsMapLayer
694694
@note added in version 1.2 */
695695
bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
696696

697-
/** changed an attribute value (but does not commit it) */
698-
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal = true );
697+
/**
698+
* Changes an attribute value (but does not commit it)
699+
*
700+
* @deprecated The emitSignal parameter is obsolete and not considered at the moment. It will
701+
* be removed in future releases. Remove it to be prepared for the future. (Since 2.1)
702+
*/
703+
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal ) /Deprecated/;
704+
705+
/**
706+
* Changes an attribute value (but does not commit it)
707+
*
708+
* @param fid The feature id of the feature to be changed
709+
* @param field The index of the field to be updated
710+
* @param value The value which will be assigned to the field
711+
*
712+
* @return true in case of success
713+
*/
714+
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );
699715

700716
/** add an attribute field (but does not commit it)
701717
returns true if the field was added

src/app/qgsfieldcalculator.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,7 @@ void QgsFieldCalculator::accept()
188188
}
189189
else
190190
{
191-
// FIXME workaround while QgsVectorLayer::changeAttributeValue's emitSignal is ignored (see #7071)
192-
mVectorLayer->blockSignals( true );
193-
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, false );
194-
mVectorLayer->blockSignals( false );
191+
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value );
195192
}
196193

197194
rownum++;

src/app/qgsmaptoolchangelabelproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
7272
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
7373
for ( ; changeIt != changes.constEnd(); ++changeIt )
7474
{
75-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), true );
75+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
7676
}
7777

7878
vlayer->endEditCommand();

src/app/qgsmaptoolmovelabel.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
150150
}
151151

152152
vlayer->beginEditCommand( tr( "Moved label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
153-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew, true );
154-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew, true );
153+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew );
154+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew );
155155

156156
// set rotation to that of label, if data-defined and no rotation set yet
157157
// honor whether to preserve preexisting data on pin
@@ -167,7 +167,7 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
167167
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, defRot, rSuccess ) )
168168
{
169169
double labelRot = mCurrentLabelPos.rotation * 180 / M_PI;
170-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot, true );
170+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot );
171171
}
172172
}
173173
vlayer->endEditCommand();

src/app/qgsmaptoolpinlabels.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,25 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
418418
}
419419

420420
vlayer->beginEditCommand( tr( "Pinned label" ) + QString( " '%1'" ).arg( labelText ) );
421-
writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX, true );
422-
if ( !vlayer->changeAttributeValue( fid, yCol, labelY, true ) )
421+
writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX );
422+
if ( !vlayer->changeAttributeValue( fid, yCol, labelY ) )
423423
writeFailed = true;
424424
if ( hasRCol && !preserveRot )
425425
{
426-
if ( !vlayer->changeAttributeValue( fid, rCol, labelR, true ) )
426+
if ( !vlayer->changeAttributeValue( fid, rCol, labelR ) )
427427
writeFailed = true;
428428
}
429429
vlayer->endEditCommand();
430430
}
431431
else
432432
{
433433
vlayer->beginEditCommand( tr( "Unpinned label" ) + QString( " '%1'" ).arg( labelText ) );
434-
writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ), true );
435-
if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ), true ) )
434+
writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ) );
435+
if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ) ) )
436436
writeFailed = true;
437437
if ( hasRCol && !preserveRot )
438438
{
439-
if ( !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ), true ) )
439+
if ( !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ) ) )
440440
writeFailed = true;
441441
}
442442
vlayer->endEditCommand();

src/app/qgsmaptoolrotatelabel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void QgsMapToolRotateLabel::canvasReleaseEvent( QMouseEvent *e )
172172
}
173173

174174
vlayer->beginEditCommand( tr( "Rotated label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
175-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation, true );
175+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation );
176176
vlayer->endEditCommand();
177177
mCanvas->refresh();
178178
}

src/app/qgsmaptoolrotatepointsymbols.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent *e )
207207
QList<int>::const_iterator it = mCurrentRotationAttributes.constBegin();
208208
for ( ; it != mCurrentRotationAttributes.constEnd(); ++it )
209209
{
210-
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, rotation, true ) )
210+
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, rotation ) )
211211
{
212212
rotateSuccess = false;
213213
}

src/app/qgsmaptoolshowhidelabels.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
305305
}
306306

307307
// different attribute value, edit table
308-
if ( !vlayer->changeAttributeValue( fid, showCol, curVal, false ) )
308+
if ( !vlayer->changeAttributeValue( fid, showCol, curVal ) )
309309
{
310310
QgsDebugMsg( "Failed write to attribute table" );
311311
return false;

src/core/qgsofflineediting.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ void QgsOfflineEditing::applyAttributeValueChanges( QgsVectorLayer* offlineLayer
689689
{
690690
QgsFeatureId fid = remoteFid( db, layerId, values.at( i ).fid );
691691

692-
remoteLayer->changeAttributeValue( fid, attrLookup[ values.at( i ).attr ], values.at( i ).value, false );
692+
remoteLayer->changeAttributeValue( fid, attrLookup[ values.at( i ).attr ], values.at( i ).value );
693693

694694
emit progressUpdated( i + 1 );
695695
}

src/core/qgsvectorlayer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,12 @@ bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )
25162516

25172517
bool QgsVectorLayer::changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal )
25182518
{
2519-
Q_UNUSED( emitSignal ); // TODO[MD] - see also QgsFieldCalculator and #7071
2519+
Q_UNUSED( emitSignal );
2520+
return changeAttributeValue ( fid, field, value );
2521+
}
2522+
2523+
bool QgsVectorLayer::changeAttributeValue( QgsFeatureId fid, int field, QVariant value )
2524+
{
25202525
if ( !mEditBuffer || !mDataProvider )
25212526
return false;
25222527

src/core/qgsvectorlayer.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,24 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
10671067
@note added in version 1.2 */
10681068
bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
10691069

1070-
/** changed an attribute value (but does not commit it) */
1071-
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal = true );
1070+
/**
1071+
* Changes an attribute value (but does not commit it)
1072+
*
1073+
* @deprecated The emitSignal parameter is obsolete and not considered at the moment. It will
1074+
* be removed in future releases. Remove it to be prepared for the future. (Since 2.1)
1075+
*/
1076+
Q_DECL_DEPRECATED bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal );
1077+
1078+
/**
1079+
* Changes an attribute value (but does not commit it)
1080+
*
1081+
* @param fid The feature id of the feature to be changed
1082+
* @param field The index of the field to be updated
1083+
* @param value The value which will be assigned to the field
1084+
*
1085+
* @return true in case of success
1086+
*/
1087+
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );
10721088

10731089
/** add an attribute field (but does not commit it)
10741090
returns true if the field was added

src/gui/attributetable/qgsattributetabledelegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode
9393
return;
9494

9595
vl->beginEditCommand( tr( "Attribute changed" ) );
96-
vl->changeAttributeValue( fid, fieldIdx, value, true );
96+
vl->changeAttributeValue( fid, fieldIdx, value );
9797
vl->endEditCommand();
9898
}
9999

0 commit comments

Comments
 (0)