Skip to content
Permalink
Browse files
identify results: fix value map updates (fixes #8818)
dual view: avoid empty undo commands
  • Loading branch information
jef-n committed Feb 8, 2014
1 parent eb769f7 commit 48427e1877cdb762af14f31be85b984a490828e2
Showing with 39 additions and 9 deletions.
  1. +26 −4 src/app/qgsidentifyresultsdialog.cpp
  2. +13 −5 src/gui/attributetable/qgsdualview.cpp
@@ -1183,14 +1183,21 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,
if ( !layItem )
return;

if ( idx >= vlayer->pendingFields().size() )
return;

const QgsField &fld = vlayer->pendingFields().at( idx );

for ( int i = 0; i < layItem->childCount(); i++ )
{
QTreeWidgetItem *featItem = layItem->child( i );

if ( featItem && STRING_TO_FID( featItem->data( 0, Qt::UserRole ) ) == fid )
{
if ( featItem->data( 0, Qt::DisplayRole ).toString() == vlayer->displayField() )
featItem->setData( 1, Qt::DisplayRole, val );
QString value( fld.displayString( val ) );

if ( fld.name() == vlayer->displayField() )
featItem->setData( 1, Qt::DisplayRole, value );

for ( int j = 0; j < featItem->childCount(); j++ )
{
@@ -1200,7 +1207,22 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,

if ( item->data( 0, Qt::UserRole + 1 ).toInt() == idx )
{
item->setData( 1, Qt::DisplayRole, val );
switch ( vlayer->editType( idx ) )
{
case QgsVectorLayer::ValueMap:
value = vlayer->valueMap( idx ).key( val, QString( "(%1)" ).arg( value ) );
break;

case QgsVectorLayer::Calendar:
if ( val.canConvert( QVariant::Date ) )
value = val.toDate().toString( vlayer->dateFormat( idx ) );
break;

default:
break;
}

item->setData( 1, Qt::DisplayRole, value );
return;
}
}
@@ -1305,7 +1327,7 @@ void QgsIdentifyResultsDialog::featureForm()
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( f ) )
return;

QgsFeatureAction action( tr( "Attribute changes" ), f, vlayer, idx, -1, this );
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, idx, -1, this );
if ( vlayer->isEditable() )
{
if ( action.editFeature() )
@@ -335,14 +335,22 @@ bool QgsDualView::saveEditChanges()
return false;
}

// avoid empty command
int i = 0;
for ( ; i < dst.count() && dst[i] == src[i]; ++i )
;

if ( i == dst.count() )
return true;

mLayerCache->layer()->beginEditCommand( tr( "Attributes changed" ) );

for ( int i = 0; i < dst.count(); ++i )
for ( ; i < dst.count(); ++i )
{
if ( dst[i] != src[i] )
{
mLayerCache->layer()->changeAttributeValue( fid, i, dst[i] );
}
if ( dst[i] == src[i] )
continue;

mLayerCache->layer()->changeAttributeValue( fid, i, dst[i] );
}

mLayerCache->layer()->endEditCommand();

0 comments on commit 48427e1

Please sign in to comment.