Skip to content
Permalink
Browse files

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 5c38775be47e683798b587f0382ca9cd81442565
@@ -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
@@ -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++;
@@ -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();
@@ -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
@@ -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();
@@ -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();
@@ -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();
}
@@ -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;
}
@@ -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;
@@ -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 );
}
@@ -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;

@@ -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
@@ -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();
}

0 comments on commit 5c38775

Please sign in to comment.
You can’t perform that action at this time.