Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m-kuhn committed Jan 7, 2014
1 parent 9c5bbb7 commit 5c38775
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 24 deletions.
20 changes: 18 additions & 2 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -694,8 +694,24 @@ class QgsVectorLayer : QgsMapLayer
@note added in version 1.2 */
bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );

/** changed an attribute value (but does not commit it) */
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal = true );
/**
* Changes an attribute value (but does not commit it)
*
* @deprecated The emitSignal parameter is obsolete and not considered at the moment. It will
* be removed in future releases. Remove it to be prepared for the future. (Since 2.1)
*/
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal ) /Deprecated/;

/**
* Changes an attribute value (but does not commit it)
*
* @param fid The feature id of the feature to be changed
* @param field The index of the field to be updated
* @param value The value which will be assigned to the field
*
* @return true in case of success
*/
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );

/** add an attribute field (but does not commit it)
returns true if the field was added
Expand Down
5 changes: 1 addition & 4 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -188,10 +188,7 @@ void QgsFieldCalculator::accept()
}
else
{
// FIXME workaround while QgsVectorLayer::changeAttributeValue's emitSignal is ignored (see #7071)
mVectorLayer->blockSignals( true );
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, false );
mVectorLayer->blockSignals( false );
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value );
}

rownum++;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolchangelabelproperties.cpp
Expand Up @@ -72,7 +72,7 @@ void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), true );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
}

vlayer->endEditCommand();
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsmaptoolmovelabel.cpp
Expand Up @@ -150,8 +150,8 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
}

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

// set rotation to that of label, if data-defined and no rotation set yet
// honor whether to preserve preexisting data on pin
Expand All @@ -167,7 +167,7 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, defRot, rSuccess ) )
{
double labelRot = mCurrentLabelPos.rotation * 180 / M_PI;
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot, true );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot );
}
}
vlayer->endEditCommand();
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgsmaptoolpinlabels.cpp
Expand Up @@ -418,25 +418,25 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
}

vlayer->beginEditCommand( tr( "Pinned label" ) + QString( " '%1'" ).arg( labelText ) );
writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX, true );
if ( !vlayer->changeAttributeValue( fid, yCol, labelY, true ) )
writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX );
if ( !vlayer->changeAttributeValue( fid, yCol, labelY ) )
writeFailed = true;
if ( hasRCol && !preserveRot )
{
if ( !vlayer->changeAttributeValue( fid, rCol, labelR, true ) )
if ( !vlayer->changeAttributeValue( fid, rCol, labelR ) )
writeFailed = true;
}
vlayer->endEditCommand();
}
else
{
vlayer->beginEditCommand( tr( "Unpinned label" ) + QString( " '%1'" ).arg( labelText ) );
writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ), true );
if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ), true ) )
writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ) );
if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ) ) )
writeFailed = true;
if ( hasRCol && !preserveRot )
{
if ( !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ), true ) )
if ( !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ) ) )
writeFailed = true;
}
vlayer->endEditCommand();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolrotatelabel.cpp
Expand Up @@ -172,7 +172,7 @@ void QgsMapToolRotateLabel::canvasReleaseEvent( QMouseEvent *e )
}

vlayer->beginEditCommand( tr( "Rotated label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation, true );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation );
vlayer->endEditCommand();
mCanvas->refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolrotatepointsymbols.cpp
Expand Up @@ -207,7 +207,7 @@ void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent *e )
QList<int>::const_iterator it = mCurrentRotationAttributes.constBegin();
for ( ; it != mCurrentRotationAttributes.constEnd(); ++it )
{
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, rotation, true ) )
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, rotation ) )
{
rotateSuccess = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -305,7 +305,7 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
}

// different attribute value, edit table
if ( !vlayer->changeAttributeValue( fid, showCol, curVal, false ) )
if ( !vlayer->changeAttributeValue( fid, showCol, curVal ) )
{
QgsDebugMsg( "Failed write to attribute table" );
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsofflineediting.cpp
Expand Up @@ -689,7 +689,7 @@ void QgsOfflineEditing::applyAttributeValueChanges( QgsVectorLayer* offlineLayer
{
QgsFeatureId fid = remoteFid( db, layerId, values.at( i ).fid );

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

emit progressUpdated( i + 1 );
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -2516,7 +2516,12 @@ bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )

bool QgsVectorLayer::changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal )
{
Q_UNUSED( emitSignal ); // TODO[MD] - see also QgsFieldCalculator and #7071
Q_UNUSED( emitSignal );
return changeAttributeValue ( fid, field, value );
}

bool QgsVectorLayer::changeAttributeValue( QgsFeatureId fid, int field, QVariant value )
{
if ( !mEditBuffer || !mDataProvider )
return false;

Expand Down
20 changes: 18 additions & 2 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1067,8 +1067,24 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@note added in version 1.2 */
bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );

/** changed an attribute value (but does not commit it) */
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal = true );
/**
* Changes an attribute value (but does not commit it)
*
* @deprecated The emitSignal parameter is obsolete and not considered at the moment. It will
* be removed in future releases. Remove it to be prepared for the future. (Since 2.1)
*/
Q_DECL_DEPRECATED bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value, bool emitSignal );

/**
* Changes an attribute value (but does not commit it)
*
* @param fid The feature id of the feature to be changed
* @param field The index of the field to be updated
* @param value The value which will be assigned to the field
*
* @return true in case of success
*/
bool changeAttributeValue( QgsFeatureId fid, int field, QVariant value );

/** add an attribute field (but does not commit it)
returns true if the field was added
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -93,7 +93,7 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode
return;

vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, value, true );
vl->changeAttributeValue( fid, fieldIdx, value );
vl->endEditCommand();
}

Expand Down

0 comments on commit 5c38775

Please sign in to comment.