Skip to content

Commit 48427e1

Browse files
committed
identify results: fix value map updates (fixes #8818)
dual view: avoid empty undo commands
1 parent eb769f7 commit 48427e1

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/app/qgsidentifyresultsdialog.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,14 +1183,21 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,
11831183
if ( !layItem )
11841184
return;
11851185

1186+
if ( idx >= vlayer->pendingFields().size() )
1187+
return;
1188+
1189+
const QgsField &fld = vlayer->pendingFields().at( idx );
1190+
11861191
for ( int i = 0; i < layItem->childCount(); i++ )
11871192
{
11881193
QTreeWidgetItem *featItem = layItem->child( i );
11891194

11901195
if ( featItem && STRING_TO_FID( featItem->data( 0, Qt::UserRole ) ) == fid )
11911196
{
1192-
if ( featItem->data( 0, Qt::DisplayRole ).toString() == vlayer->displayField() )
1193-
featItem->setData( 1, Qt::DisplayRole, val );
1197+
QString value( fld.displayString( val ) );
1198+
1199+
if ( fld.name() == vlayer->displayField() )
1200+
featItem->setData( 1, Qt::DisplayRole, value );
11941201

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

12011208
if ( item->data( 0, Qt::UserRole + 1 ).toInt() == idx )
12021209
{
1203-
item->setData( 1, Qt::DisplayRole, val );
1210+
switch ( vlayer->editType( idx ) )
1211+
{
1212+
case QgsVectorLayer::ValueMap:
1213+
value = vlayer->valueMap( idx ).key( val, QString( "(%1)" ).arg( value ) );
1214+
break;
1215+
1216+
case QgsVectorLayer::Calendar:
1217+
if ( val.canConvert( QVariant::Date ) )
1218+
value = val.toDate().toString( vlayer->dateFormat( idx ) );
1219+
break;
1220+
1221+
default:
1222+
break;
1223+
}
1224+
1225+
item->setData( 1, Qt::DisplayRole, value );
12041226
return;
12051227
}
12061228
}
@@ -1305,7 +1327,7 @@ void QgsIdentifyResultsDialog::featureForm()
13051327
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( f ) )
13061328
return;
13071329

1308-
QgsFeatureAction action( tr( "Attribute changes" ), f, vlayer, idx, -1, this );
1330+
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, idx, -1, this );
13091331
if ( vlayer->isEditable() )
13101332
{
13111333
if ( action.editFeature() )

src/gui/attributetable/qgsdualview.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,22 @@ bool QgsDualView::saveEditChanges()
335335
return false;
336336
}
337337

338+
// avoid empty command
339+
int i = 0;
340+
for ( ; i < dst.count() && dst[i] == src[i]; ++i )
341+
;
342+
343+
if ( i == dst.count() )
344+
return true;
345+
338346
mLayerCache->layer()->beginEditCommand( tr( "Attributes changed" ) );
339347

340-
for ( int i = 0; i < dst.count(); ++i )
348+
for ( ; i < dst.count(); ++i )
341349
{
342-
if ( dst[i] != src[i] )
343-
{
344-
mLayerCache->layer()->changeAttributeValue( fid, i, dst[i] );
345-
}
350+
if ( dst[i] == src[i] )
351+
continue;
352+
353+
mLayerCache->layer()->changeAttributeValue( fid, i, dst[i] );
346354
}
347355

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

0 commit comments

Comments
 (0)