Skip to content
Permalink
Browse files

[attrtable] Only update table at the end of an edit command

Fix #9315
  • Loading branch information
m-kuhn committed Jan 30, 2014
1 parent 70c5949 commit 3ba33d73fb739686ae3f7bad4e4d7054384899a0
@@ -3263,17 +3263,20 @@ void QgsVectorLayer::setRendererV2( QgsFeatureRendererV2 *r )
void QgsVectorLayer::beginEditCommand( QString text )
{
undoStack()->beginMacro( text );
emit editCommandStarted( text );
}

void QgsVectorLayer::endEditCommand()
{
undoStack()->endMacro();
emit editCommandEnded();
}

void QgsVectorLayer::destroyEditCommand()
{
undoStack()->endMacro();
undoStack()->undo();
emit editCommandDestroyed();
}


@@ -1539,6 +1539,27 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Signal emitted when setLayerTransparency() is called */
void layerTransparencyChanged( int layerTransparency );

/**
* Signal emitted when a new edit command has been started
*
* @param text Description for this edit command
*/
void editCommandStarted( const QString& text );

/**
* Signal emitted, when an edit command successfully ended
* @note This does not mean it is also committed, only that it is written
* to the edit buffer. See {@link beforeCommitChanges()}
*/
void editCommandEnded();

/**
* Signal emitted, whan an edit command is destroyed
* @note This is not a rollback, it is only related to the current edit command.
* See {@link beforeRollBack()}
*/
void editCommandDestroyed();

private slots:
void onRelationsLoaded();

@@ -55,6 +55,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
connect( layer(), SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
connect( layer(), SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
connect( layer(), SIGNAL( updatedFields() ), this, SLOT( updatedFields() ) );
connect( layer(), SIGNAL( editCommandEnded() ), this, SLOT( editCommandEnded() ) );
connect( mLayerCache, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( featureAdded( QgsFeatureId ) ) );
connect( mLayerCache, SIGNAL( cachedLayerDeleted() ), this, SLOT( layerDeleted() ) );
}
@@ -162,6 +163,14 @@ void QgsAttributeTableModel::updatedFields()
emit modelChanged();
}

void QgsAttributeTableModel::editCommandEnded()
{
reload( createIndex( mChangedCellBounds.top(), mChangedCellBounds.left() ),
createIndex( mChangedCellBounds.bottom(), mChangedCellBounds.right() ) );

mChangedCellBounds = QRect();
}

void QgsAttributeTableModel::attributeDeleted( int idx )
{
if ( idx == mCachedField )
@@ -592,7 +601,29 @@ bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &
if ( !layer()->isModified() )
return false;

emit dataChanged( index, index );
if ( mChangedCellBounds.isNull() )
{
mChangedCellBounds = QRect( index.column(), index.row(), 0, 0 );
}
else
{
if ( index.column() < mChangedCellBounds.left() )
{
mChangedCellBounds.setLeft( index.column() );
}
if ( index.row() < mChangedCellBounds.top() )
{
mChangedCellBounds.setTop( index.row() );
}
if ( index.column() > mChangedCellBounds.right() )
{
mChangedCellBounds.setRight( index.column() );
}
if ( index.row() > mChangedCellBounds.bottom() )
{
mChangedCellBounds.setBottom( index.row() );
}
}

return true;
}
@@ -212,6 +212,13 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
*/
virtual void updatedFields();

/**
* Gets called when an edit command ends
* This will synchronize all fields which have been changed since the last
* edit command in one single go
*/
virtual void editCommandEnded();

/**
* Called whenever a column is removed;
*/
@@ -274,6 +281,15 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
int mCachedField;
/** Allows to cache one specific column (used for sorting) */
QHash<QgsFeatureId, QVariant> mFieldCache;

/**
* Holds the bounds of changed cells while an update operation is running
* top = min row
* left = min column
* bottom = max row
* right = max column
*/
QRect mChangedCellBounds;
};


0 comments on commit 3ba33d7

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