label_number_formatting_expression.diff

patch to format result of expressions in labeling - Leyan Ouyang, 2012-06-03 03:50 AM

Download (1.83 KB)

View differences:

src/core/qgspallabeling.cpp
462 462
void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer,  QgsFeature& f, const QgsRenderContext& context )
463 463
{
464 464
  QString labelText;
465
  QVariant result; 
465 466
  // Check to see if we are a expression string.
466 467
  if ( isExpression )
467 468
  {
......
471 472
      QgsDebugMsg( "Expression parser error:" + exp->parserErrorString() );
472 473
      return;
473 474
    }
474
    QVariant result = exp->evaluate( &f, layer->pendingFields() );
475
    result = exp->evaluate( &f, layer->pendingFields() );
475 476
    if ( exp->hasEvalError() )
476 477
    {
477 478
      QgsDebugMsg( "Expression parser eval error:" + exp->evalErrorString() );
478 479
      return;
479 480
    }
480
    labelText  = result.toString();
481

  
482
  }
483
  else
484
  {
485
    result=f.attributeMap()[fieldIndex];
481 486
  }
482
  else if ( formatNumbers == true && ( f.attributeMap()[fieldIndex].type() == QVariant::Int ||
483
                                       f.attributeMap()[fieldIndex].type() == QVariant::Double ) )
487
      
488
  if ( formatNumbers == true && ( result.type() == QVariant::Int || result.type() == QVariant::Double ) )
484 489
  {
485 490
    QString numberFormat;
486
    double d = f.attributeMap()[fieldIndex].toDouble();
491
    double d = result.toDouble();
487 492
    if ( d > 0 && plusSign == true )
488 493
    {
489 494
      numberFormat.append( "+" );
......
493 498
  }
494 499
  else
495 500
  {
496
    labelText = f.attributeMap()[fieldIndex].toString();
501
    labelText = result.toString();
497 502
  }
498 503

  
499 504
  double labelX, labelY; // will receive label size