Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add updateFields() signal, so adding of joined fields is communicated
attributeAdded and attributeDeleted signals are only emitted for "real" fields
and not for "virtual fields" as in joined fields. Therefore this signal should
be used instead to keep track of these
  • Loading branch information
m-kuhn committed Apr 15, 2013
1 parent a51fd5f commit 7c69ec1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
25 changes: 25 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -836,9 +836,34 @@ class QgsVectorLayer : QgsMapLayer

void editingStarted();
void editingStopped();

/**
* Will be emitted, when a new attribute has been added to this vector layer.
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
*
* @param The index of the new attribute
*
* @see updatedFields()
*/
void attributeAdded( int idx );

/**
* Will be emitted, when an attribute has been deleted from this vector layer.
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
*
* @param The index of the deleted attribute
*
* @see updatedFields()
*/
void attributeDeleted( int idx );
void featureAdded( QgsFeatureId fid ); // added in 1.7

/**
* Is emitted, whenever the fields available from this layer have been changed.
* This can be due to manually adding attributes or due to a join.
*/
void updatedFields();

void featureDeleted( QgsFeatureId fid );
void layerDeleted();

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -3114,6 +3114,8 @@ void QgsVectorLayer::updateFields()
// joined fields
if ( mJoinBuffer && mJoinBuffer->containsJoins() )
mJoinBuffer->updateFields( mUpdatedFields );

emit updatedFields();
}


Expand Down
21 changes: 21 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1244,10 +1244,31 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

void editingStarted();
void editingStopped();
/**
* Will be emitted, when a new attribute has been added to this vector layer.
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
*
* @param The index of the new attribute
*
* @see updatedFields()
*/
void attributeAdded( int idx );
/**
* Will be emitted, when an attribute has been deleted from this vector layer.
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
*
* @param The index of the deleted attribute
*
* @see updatedFields()
*/
void attributeDeleted( int idx );
void featureAdded( QgsFeatureId fid ); // added in 1.7
void featureDeleted( QgsFeatureId fid );
/**
* Is emitted, whenever the fields available from this layer have been changed.
* This can be due to manually adding attributes or due to a join.
*/
void updatedFields();
void layerDeleted();

void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayercache.cpp
Expand Up @@ -34,6 +34,7 @@ QgsVectorLayerCache::QgsVectorLayerCache( QgsVectorLayer* layer, int cacheSize,
setCacheAddedAttributes( true );

connect( mLayer, SIGNAL( attributeDeleted( int ) ), SLOT( attributeDeleted( int ) ) );
connect( mLayer, SIGNAL( updatedFields() ), SLOT( updatedFields() ) );
connect( mLayer, SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ), SLOT( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ) );
}

Expand Down Expand Up @@ -236,6 +237,11 @@ void QgsVectorLayerCache::layerDeleted()
mLayer = NULL;
}

void QgsVectorLayerCache::updatedFields()
{
mCache.clear();
}

QgsFeatureIterator QgsVectorLayerCache::getFeatures( const QgsFeatureRequest &featureRequest )
{
QgsFeatureIterator it;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayercache.h
Expand Up @@ -216,14 +216,15 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
*/
void cachedLayerDeleted();

public slots:
private slots:
void attributeValueChanged( QgsFeatureId fid, int field, const QVariant& value );
void featureDeleted( QgsFeatureId fid );
void featureAdded( QgsFeatureId fid );
void attributeAdded( int field );
void attributeDeleted( int field );
void geometryChanged( QgsFeatureId fid, QgsGeometry& geom );
void layerDeleted();
void updatedFields();

private:

Expand Down
15 changes: 2 additions & 13 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -51,8 +51,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
connect( layer(), SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ) );
connect( layer(), SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( featureAdded( QgsFeatureId ) ) );
connect( layer(), SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
connect( layer(), SIGNAL( attributeAdded( int ) ), this, SLOT( attributeAdded( int ) ) );
connect( layer(), SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
connect( layer(), SIGNAL( updatedFields() ), this, SLOT( updatedFields() ) );
connect( mLayerCache, SIGNAL( cachedLayerDeleted() ), this, SLOT( layerDeleted() ) );
}

Expand Down Expand Up @@ -151,18 +150,8 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool newOperation )
reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
}

void QgsAttributeTableModel::attributeAdded( int idx )
void QgsAttributeTableModel::updatedFields()
{
Q_UNUSED( idx );
QgsDebugMsg( "entered." );
loadAttributes();
loadLayer();
emit modelChanged();
}

void QgsAttributeTableModel::attributeDeleted( int idx )
{
Q_UNUSED( idx );
QgsDebugMsg( "entered." );
loadAttributes();
emit modelChanged();
Expand Down
10 changes: 2 additions & 8 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -188,15 +188,9 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel

private slots:
/**
* Launched when attribute has been added
* @param idx attribute index
*/
virtual void attributeAdded( int idx );
/**
* Launched when attribute has been deleted
* @param idx attribute index
* Launched whenever the number of fields has changed
*/
virtual void attributeDeleted( int idx );
virtual void updatedFields();

protected slots:
/**
Expand Down

0 comments on commit 7c69ec1

Please sign in to comment.