Skip to content
Permalink
Browse files

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

@@ -3114,6 +3114,8 @@ void QgsVectorLayer::updateFields()
// joined fields
if ( mJoinBuffer && mJoinBuffer->containsJoins() )
mJoinBuffer->updateFields( mUpdatedFields );

emit updatedFields();
}


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

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

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

QgsFeatureIterator QgsVectorLayerCache::getFeatures( const QgsFeatureRequest &featureRequest )
{
QgsFeatureIterator it;
@@ -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:

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

@@ -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();
@@ -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:
/**

0 comments on commit 7c69ec1

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