mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[GRASS] create new cat on attribute change if it does not exist
This commit is contained in:
parent
afdf4e1ac4
commit
c358aea04d
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user