Skip to content

Commit 706b6f1

Browse files
committed
Update usage of QgsSearchString to QgsExpression
1 parent c343140 commit 706b6f1

2 files changed

Lines changed: 16 additions & 23 deletions

File tree

src/app/qgslabelinggui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
#include "qgspallabeling.h"
2626
#include "qgslabelengineconfigdialog.h"
27-
#include "qgssearchstring.h"
2827
#include "qgsexpressionbuilder.h"
28+
#include "qgsexpression.h"
2929

3030
#include <QColorDialog>
3131
#include <QFontDialog>
@@ -504,12 +504,12 @@ void QgsLabelingGui::showExpressionDialog()
504504
{
505505
QString expression = builder->getExpressionString();
506506
//Do validation here first before applying
507-
QgsSearchString searchString;
508-
if ( !searchString.setString( expression ) )
507+
QgsExpression exp( expression );
508+
if ( exp.hasParserError() )
509509
{
510510
//expression not valid
511511
QMessageBox::critical( 0, "Syntax error",
512-
"Invalid expression syntax. The error message of the parser is: '" + searchString.parserErrorMsg() + "'" );
512+
"Invalid expression syntax. The error message of the parser is: '" + exp.parserErrorString() + "'" );
513513
return;
514514
}
515515

src/core/qgspallabeling.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
#include "qgsdiagram.h"
4242
#include "qgsdiagramrendererv2.h"
4343
#include "qgslabelsearchtree.h"
44-
#include "qgssearchtreenode.h"
45-
#include "qgssearchstring.h"
44+
#include "qgsexpression.h"
4645

4746
#include <qgslogger.h>
4847
#include <qgsvectorlayer.h>
@@ -459,25 +458,20 @@ void QgsPalLayerSettings::registerFeature(QgsVectorLayer* layer, QgsFeature& f,
459458
// Check to see if we are a expression string.
460459
if (isExpression)
461460
{
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() )
468463
{
464+
QgsDebugMsg("PASER HAS ERROR:" + exp.parserErrorString());
469465
return;
470466
}
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())
476470
{
477-
QgsDebugMsg("Expression Label Error = " + outValue.string());
471+
QgsDebugMsg("Expression Label Error = " + exp.evalErrorString());
478472
return;
479473
}
480-
labelText = outValue.string();
474+
labelText = result.toString();
481475
}
482476
else if ( formatNumbers == true && ( f.attributeMap()[fieldIndex].type() == QVariant::Int ||
483477
f.attributeMap()[fieldIndex].type() == QVariant::Double ) )
@@ -778,11 +772,10 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
778772
{
779773
if (lyrTmp.fieldName.isEmpty())
780774
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() )
785777
{
778+
QgsDebugMsg("REFERENCED COLUMN = " + name );
786779
fldIndex = layer->fieldNameIndex( name );
787780
attrIndices.insert(fldIndex);
788781
}

0 commit comments

Comments
 (0)