Skip to content
Permalink
Browse files

[GRASS] create new cat on attribute change if it does not exist

  • Loading branch information
blazek committed Oct 15, 2015
1 parent afdf4e1 commit c358aea04df7a26ed2acc03671c5685bb83453b6
Showing with 42 additions and 12 deletions.
  1. +40 −12 src/providers/grass/qgsgrassprovider.cpp
  2. +2 −0 src/providers/grass/qgsgrassprovider.h
@@ -1254,16 +1254,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
}
if ( newCat == 0 )
{
QgsDebugMsg( QString( "get new cat for cidxFieldIndex() = %1" ).arg( mLayer->cidxFieldIndex() ) );
if ( mLayer->cidxFieldIndex() == -1 )
{
// No features with this field yet in map
newCat = 1;
}
else
{
newCat = cidxGetMaxCat( mLayer->cidxFieldIndex() ) + 1;
}
newCat = getNewCat();
}
QgsDebugMsg( QString( "newCat = %1" ).arg( newCat ) );
Vect_cat_set( mCats, mLayerField, newCat );
@@ -1714,8 +1705,31 @@ void QgsGrassProvider::onAttributeValueChanged( QgsFeatureId fid, int idx, const
}
else
{
QgsDebugMsg( "no cat -> add new cat to line" );
// TODO
int newCat = getNewCat();
QgsDebugMsg( QString( "no cat -> add new cat %1 to line" ).arg( newCat ) );
int type = readLine( mPoints, mCats, realLine );
if ( type <= 0 )
{
QgsDebugMsg( "cannot read line" );
}
else
{
Vect_cat_set( mCats, mLayerField, newCat );
mLayer->map()->lockReadWrite();
int newLid = rewriteLine( realLine, type, mPoints, mCats );
Q_UNUSED( newLid )

// TODO: - store the new cat somewhere for cats mapping
QString error;
// it does insert new record if it doesn't exist
mLayer->changeAttributeValue( newCat, field, value, error );
if ( !error.isEmpty() )
{
QgsGrass::warning( error );
}

mLayer->map()->unlockReadWrite();
}
}
}
}
@@ -1877,6 +1891,20 @@ int QgsGrassProvider::cidxGetMaxCat( int idx )
return cat;
}

int QgsGrassProvider::getNewCat()
{
QgsDebugMsg( QString( "get new cat for cidxFieldIndex() = %1" ).arg( mLayer->cidxFieldIndex() ) );
if ( mLayer->cidxFieldIndex() == -1 )
{
// No features with this field yet in map
return 1;
}
else
{
return cidxGetMaxCat( mLayer->cidxFieldIndex() ) + 1;
}
}

QgsGrassVectorMapLayer * QgsGrassProvider::openLayer() const
{
return mLayer->map()->openLayer( mLayerField );
@@ -410,6 +410,8 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
bool openLayer();
// update topo symbol of new features
void setAddedFeaturesSymbol();
// get new, not yet used cat
int getNewCat();

QgsGrassObject mGrassObject;
// field part of layer or -1 if no field specified

0 comments on commit c358aea

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