Skip to content

Commit

Permalink
[GRASS] update fields on field add/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 13, 2015
1 parent c3839b3 commit 0c0293e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ void QgsGrassPlugin::onEditingStarted()
vectorLayer->updateFields();

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

resetEditActions();
}
Expand All @@ -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" );
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrassplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
void onEditingStopped();
void onCurrentLayerChanged( QgsMapLayer* layer );

void onFieldsChanged();

// Start editing tools
void addFeature();

Expand Down
2 changes: 2 additions & 0 deletions src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,7 @@ void QgsGrassProvider::onAttributeAdded( int idx )
else
{
mEditLayerFields = mEditLayer->fields();
emit fieldsChanged();
}
}

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

Expand Down
6 changes: 6 additions & 0 deletions src/providers/grass/qgsgrassprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0c0293e

Please sign in to comment.