Skip to content
Permalink
Browse files

[GRASS] update fields on field add/delete

  • Loading branch information
blazek committed Oct 13, 2015
1 parent c3839b3 commit 0c0293e9b851d54b81b8d5be3c35390aceecd14d
@@ -419,6 +419,7 @@ void QgsGrassPlugin::onEditingStarted()
vectorLayer->updateFields();

connect( vectorLayer, SIGNAL( editingStopped() ), SLOT( onEditingStopped() ) );
connect( grassProvider, SIGNAL( fieldsChanged() ), SLOT( onFieldsChanged() ) );

resetEditActions();
}
@@ -439,6 +440,35 @@ void QgsGrassPlugin::onEditingStopped()
resetEditActions();
}

void QgsGrassPlugin::onFieldsChanged()
{
QgsDebugMsg( "entered" );
QgsGrassProvider* grassProvider = dynamic_cast<QgsGrassProvider*>( sender() );
if ( !grassProvider )
{
return;
}
QString uri = grassProvider->dataSourceUri();
uri.remove( QRegExp( "[^_]*$" ) );
QgsDebugMsg( "uri = " + uri );
foreach ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
{
if ( !layer || layer->type() != QgsMapLayer::VectorLayer )
{
continue;
}

QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vectorLayer && vectorLayer->providerType() == "grass" && vectorLayer->dataProvider() )
{
if ( vectorLayer->dataProvider()->dataSourceUri().startsWith( uri ) )
{
vectorLayer->updateFields();
}
}
}
}

void QgsGrassPlugin::addFeature()
{
QgsDebugMsg( "entered" );
@@ -121,6 +121,8 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
void onEditingStopped();
void onCurrentLayerChanged( QgsMapLayer* layer );

void onFieldsChanged();

// Start editing tools
void addFeature();

@@ -1726,6 +1726,7 @@ void QgsGrassProvider::onAttributeAdded( int idx )
else
{
mEditLayerFields = mEditLayer->fields();
emit fieldsChanged();
}
}

@@ -1752,6 +1753,7 @@ void QgsGrassProvider::onAttributeDeleted( int idx )
else
{
mEditLayerFields = mEditLayer->fields();
emit fieldsChanged();
}
}

@@ -396,6 +396,12 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider

void onDataChanged();

signals:
// TODO: move to QGIS core?
// Emited when a fields was added/deleted so that other layers sharing the same layer
// may be updated
void fieldsChanged();

protected:
// used by QgsGrassFeatureSource
QgsGrassVectorMapLayer *openLayer() const;

0 comments on commit 0c0293e

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