Skip to content

Commit 7c69ec1

Browse files
committedApr 15, 2013
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
1 parent a51fd5f commit 7c69ec1

File tree

7 files changed

+60
-22
lines changed

7 files changed

+60
-22
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,34 @@ class QgsVectorLayer : QgsMapLayer
836836

837837
void editingStarted();
838838
void editingStopped();
839+
840+
/**
841+
* Will be emitted, when a new attribute has been added to this vector layer.
842+
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
843+
*
844+
* @param The index of the new attribute
845+
*
846+
* @see updatedFields()
847+
*/
839848
void attributeAdded( int idx );
849+
850+
/**
851+
* Will be emitted, when an attribute has been deleted from this vector layer.
852+
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
853+
*
854+
* @param The index of the deleted attribute
855+
*
856+
* @see updatedFields()
857+
*/
840858
void attributeDeleted( int idx );
841859
void featureAdded( QgsFeatureId fid ); // added in 1.7
860+
861+
/**
862+
* Is emitted, whenever the fields available from this layer have been changed.
863+
* This can be due to manually adding attributes or due to a join.
864+
*/
865+
void updatedFields();
866+
842867
void featureDeleted( QgsFeatureId fid );
843868
void layerDeleted();
844869

‎src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,8 @@ void QgsVectorLayer::updateFields()
31143114
// joined fields
31153115
if ( mJoinBuffer && mJoinBuffer->containsJoins() )
31163116
mJoinBuffer->updateFields( mUpdatedFields );
3117+
3118+
emit updatedFields();
31173119
}
31183120

31193121

‎src/core/qgsvectorlayer.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,10 +1244,31 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
12441244

12451245
void editingStarted();
12461246
void editingStopped();
1247+
/**
1248+
* Will be emitted, when a new attribute has been added to this vector layer.
1249+
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
1250+
*
1251+
* @param The index of the new attribute
1252+
*
1253+
* @see updatedFields()
1254+
*/
12471255
void attributeAdded( int idx );
1256+
/**
1257+
* Will be emitted, when an attribute has been deleted from this vector layer.
1258+
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
1259+
*
1260+
* @param The index of the deleted attribute
1261+
*
1262+
* @see updatedFields()
1263+
*/
12481264
void attributeDeleted( int idx );
12491265
void featureAdded( QgsFeatureId fid ); // added in 1.7
12501266
void featureDeleted( QgsFeatureId fid );
1267+
/**
1268+
* Is emitted, whenever the fields available from this layer have been changed.
1269+
* This can be due to manually adding attributes or due to a join.
1270+
*/
1271+
void updatedFields();
12511272
void layerDeleted();
12521273

12531274
void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );

‎src/core/qgsvectorlayercache.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ QgsVectorLayerCache::QgsVectorLayerCache( QgsVectorLayer* layer, int cacheSize,
3434
setCacheAddedAttributes( true );
3535

3636
connect( mLayer, SIGNAL( attributeDeleted( int ) ), SLOT( attributeDeleted( int ) ) );
37+
connect( mLayer, SIGNAL( updatedFields() ), SLOT( updatedFields() ) );
3738
connect( mLayer, SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ), SLOT( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ) );
3839
}
3940

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

240+
void QgsVectorLayerCache::updatedFields()
241+
{
242+
mCache.clear();
243+
}
244+
239245
QgsFeatureIterator QgsVectorLayerCache::getFeatures( const QgsFeatureRequest &featureRequest )
240246
{
241247
QgsFeatureIterator it;

‎src/core/qgsvectorlayercache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,15 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
216216
*/
217217
void cachedLayerDeleted();
218218

219-
public slots:
219+
private slots:
220220
void attributeValueChanged( QgsFeatureId fid, int field, const QVariant& value );
221221
void featureDeleted( QgsFeatureId fid );
222222
void featureAdded( QgsFeatureId fid );
223223
void attributeAdded( int field );
224224
void attributeDeleted( int field );
225225
void geometryChanged( QgsFeatureId fid, QgsGeometry& geom );
226226
void layerDeleted();
227+
void updatedFields();
227228

228229
private:
229230

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
5151
connect( layer(), SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ) );
5252
connect( layer(), SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( featureAdded( QgsFeatureId ) ) );
5353
connect( layer(), SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
54-
connect( layer(), SIGNAL( attributeAdded( int ) ), this, SLOT( attributeAdded( int ) ) );
55-
connect( layer(), SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
54+
connect( layer(), SIGNAL( updatedFields() ), this, SLOT( updatedFields() ) );
5655
connect( mLayerCache, SIGNAL( cachedLayerDeleted() ), this, SLOT( layerDeleted() ) );
5756
}
5857

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

154-
void QgsAttributeTableModel::attributeAdded( int idx )
153+
void QgsAttributeTableModel::updatedFields()
155154
{
156-
Q_UNUSED( idx );
157-
QgsDebugMsg( "entered." );
158-
loadAttributes();
159-
loadLayer();
160-
emit modelChanged();
161-
}
162-
163-
void QgsAttributeTableModel::attributeDeleted( int idx )
164-
{
165-
Q_UNUSED( idx );
166155
QgsDebugMsg( "entered." );
167156
loadAttributes();
168157
emit modelChanged();

‎src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,9 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
188188

189189
private slots:
190190
/**
191-
* Launched when attribute has been added
192-
* @param idx attribute index
193-
*/
194-
virtual void attributeAdded( int idx );
195-
/**
196-
* Launched when attribute has been deleted
197-
* @param idx attribute index
191+
* Launched whenever the number of fields has changed
198192
*/
199-
virtual void attributeDeleted( int idx );
193+
virtual void updatedFields();
200194

201195
protected slots:
202196
/**

0 commit comments

Comments
 (0)
Please sign in to comment.