Skip to content
Permalink
Browse files

[GRASS] insert record for new feature

  • Loading branch information
blazek committed Sep 27, 2015
1 parent f2a1efe commit a9c8a0164a6fed40d20f0835c1499e7ab1183007
Showing with 31 additions and 8 deletions.
  1. +19 −1 src/providers/grass/qgsgrassprovider.cpp
  2. +12 −7 src/providers/grass/qgsgrassvectormaplayer.cpp
@@ -1116,6 +1116,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
{
struct line_pnts *points = Vect_new_line_struct();
struct line_cats *cats = Vect_new_cats_struct();
int newCat = 0;

setPoints( points, geometry );
// TODO: get also old type if it is feature previously deleted
@@ -1130,7 +1131,6 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
// resetting fid probably is not possible because it is stored in undo commands and used in buffer maps

QgsDebugMsg( QString( "get new cat for mCidxFieldIndex = %1" ).arg( mCidxFieldIndex ) );
int newCat = 0;
if ( mCidxFieldIndex == -1 )
{
// No features with this field yet in map
@@ -1142,6 +1142,12 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
}
QgsDebugMsg( QString( "newCat = %1" ).arg( newCat ) );
Vect_cat_set( cats, mLayerField, newCat );
QString error;
mLayer->insertAttributes( newCat, error );
if ( !error.isEmpty() )
{
QgsGrass::warning( error );
}
}
}
else
@@ -1204,6 +1210,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
}
// TODO: create also centroid and add it to undo
}

if ( newCat > 0 )
{
if ( mLayer->hasTable() )
{
addedFeatures[fid].setAttribute( mLayer->keyColumn(), newCat );
}
else
{
addedFeatures[fid].setAttribute( 0, newCat );
}
}
}
}

@@ -626,6 +626,8 @@ void QgsGrassVectorMapLayer::createTable( const QgsFields &fields, QString &erro
{
QgsDebugMsg( error );
}
mHasTable = true;
mKeyColumn = 0;
}
QgsDebugMsg( "Table successfully created" );
}
@@ -784,16 +786,19 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, QString &error )
{
QgsDebugMsg( QString( "mField = %1 cat = %2" ).arg( mField ).arg( cat ) );

QString query = QString( "INSERT INTO %1 ( %2 ) VALUES ( %3 )" ).arg( mFieldInfo->table ).arg( mFieldInfo->key ).arg( cat );
executeSql( query, error );
if ( error.isEmpty() )
if ( mHasTable )
{
QList<QVariant> values;
for ( int i = 0; i < mAttributeFields.size(); i++ )
QString query = QString( "INSERT INTO %1 ( %2 ) VALUES ( %3 )" ).arg( mFieldInfo->table ).arg( mFieldInfo->key ).arg( cat );
executeSql( query, error );
if ( error.isEmpty() )
{
values << QVariant();
QList<QVariant> values;
for ( int i = 0; i < mAttributeFields.size(); i++ )
{
values << QVariant();
}
mAttributes[cat] = values;
}
mAttributes[cat] = values;
}
}

0 comments on commit a9c8a01

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