|
41 | 41 | #include "qgsdiagram.h" |
42 | 42 | #include "qgsdiagramrendererv2.h" |
43 | 43 | #include "qgslabelsearchtree.h" |
44 | | -#include "qgssearchtreenode.h" |
45 | | -#include "qgssearchstring.h" |
| 44 | +#include "qgsexpression.h" |
46 | 45 |
|
47 | 46 | #include <qgslogger.h> |
48 | 47 | #include <qgsvectorlayer.h> |
@@ -459,25 +458,20 @@ void QgsPalLayerSettings::registerFeature(QgsVectorLayer* layer, QgsFeature& f, |
459 | 458 | // Check to see if we are a expression string. |
460 | 459 | if (isExpression) |
461 | 460 | { |
462 | | - QgsSearchString searchString; |
463 | | - // We don't do any validating here as we should only have a vaild expression at this point. |
464 | | - searchString.setString( fieldName ); |
465 | | - |
466 | | - QgsSearchTreeNode* searchTree = searchString.tree(); |
467 | | - if ( !searchTree ) |
| 461 | + QgsExpression exp( fieldName ); |
| 462 | + if ( exp.hasParserError() ) |
468 | 463 | { |
| 464 | + QgsDebugMsg("PASER HAS ERROR:" + exp.parserErrorString()); |
469 | 465 | return; |
470 | 466 | } |
471 | | - |
472 | | - QgsSearchTreeValue outValue; |
473 | | - searchTree->getValue( outValue, searchTree, layer->dataProvider()->fields() , f ); |
474 | | - |
475 | | - if (outValue.isError()) |
| 467 | + QVariant result = exp.evaluate(&f,layer->dataProvider()->fields()); |
| 468 | + QgsDebugMsg("VALUE = " + result.toString()); |
| 469 | + if (exp.hasEvalError()) |
476 | 470 | { |
477 | | - QgsDebugMsg("Expression Label Error = " + outValue.string()); |
| 471 | + QgsDebugMsg("Expression Label Error = " + exp.evalErrorString()); |
478 | 472 | return; |
479 | 473 | } |
480 | | - labelText = outValue.string(); |
| 474 | + labelText = result.toString(); |
481 | 475 | } |
482 | 476 | else if ( formatNumbers == true && ( f.attributeMap()[fieldIndex].type() == QVariant::Int || |
483 | 477 | f.attributeMap()[fieldIndex].type() == QVariant::Double ) ) |
@@ -778,11 +772,10 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, |
778 | 772 | { |
779 | 773 | if (lyrTmp.fieldName.isEmpty()) |
780 | 774 | return 0; |
781 | | - QgsSearchString searchString; |
782 | | - searchString.setString( lyrTmp.fieldName ); |
783 | | - searchString.tree()->referencedColumns(); |
784 | | - foreach(QString name, searchString.tree()->referencedColumns() ) |
| 775 | + QgsExpression exp( lyrTmp.fieldName ); |
| 776 | + foreach(QString name, exp.referencedColumns() ) |
785 | 777 | { |
| 778 | + QgsDebugMsg("REFERENCED COLUMN = " + name ); |
786 | 779 | fldIndex = layer->fieldNameIndex( name ); |
787 | 780 | attrIndices.insert(fldIndex); |
788 | 781 | } |
|
0 commit comments