@@ -271,35 +271,32 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
271
271
// verify attribute table has proper field setup
272
272
bool showSuccess;
273
273
int showCol;
274
- int show ;
274
+ int showVal ;
275
275
276
- if ( !dataDefinedShowHide ( vlayer, fid, show , showSuccess, showCol ) )
276
+ if ( !dataDefinedShowHide ( vlayer, fid, showVal , showSuccess, showCol ) )
277
277
{
278
278
return false ;
279
279
}
280
280
281
+ int curVal = hide ? 0 : 1 ;
282
+
281
283
// check if attribute value is already the same
282
- QgsFeature f;
283
- if ( !vlayer->getFeatures ( QgsFeatureRequest ().setFilterFid ( fid ).setFlags ( QgsFeatureRequest::NoGeometry ) ).nextFeature ( f ) )
284
+ if ( showSuccess && showVal == curVal )
284
285
{
285
286
return false ;
286
287
}
287
288
288
- int colVal = hide ? 0 : 1 ;
289
- QVariant fQVal = f.attributes ()[showCol];
290
- bool convToInt;
291
- int fVal = fQVal .toInt ( &convToInt );
292
-
293
- if ( !convToInt || fVal == colVal )
289
+ // allow NULL (maybe default) value to stand for show label (i.e. 1)
290
+ // skip NULL attributes if trying to show label
291
+ if ( !showSuccess && curVal == 1 )
294
292
{
295
293
return false ;
296
294
}
297
295
298
296
// different attribute value, edit table
299
- QString labelText = currentLabelText ( 24 );
300
297
QString editTxt = hide ? tr ( " Hid label" ) : tr ( " Showed label" );
301
- vlayer->beginEditCommand ( editTxt + QString ( " '%1' " ). arg ( labelText ) );
302
- if ( !vlayer->changeAttributeValue ( fid, showCol, colVal, true ) )
298
+ vlayer->beginEditCommand ( editTxt );
299
+ if ( !vlayer->changeAttributeValue ( fid, showCol, curVal, false ) )
303
300
{
304
301
QgsDebugMsg ( " Failed write to attribute table" );
305
302
vlayer->endEditCommand ();
0 commit comments