Navigation Menu

Skip to content

Commit

Permalink
Update usage of QgsSearchString to QgsExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Aug 21, 2011
1 parent c343140 commit 706b6f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -24,8 +24,8 @@

#include "qgspallabeling.h"
#include "qgslabelengineconfigdialog.h"
#include "qgssearchstring.h"
#include "qgsexpressionbuilder.h"
#include "qgsexpression.h"

#include <QColorDialog>
#include <QFontDialog>
Expand Down Expand Up @@ -504,12 +504,12 @@ void QgsLabelingGui::showExpressionDialog()
{
QString expression = builder->getExpressionString();
//Do validation here first before applying
QgsSearchString searchString;
if ( !searchString.setString( expression ) )
QgsExpression exp( expression );
if ( exp.hasParserError() )
{
//expression not valid
QMessageBox::critical( 0, "Syntax error",
"Invalid expression syntax. The error message of the parser is: '" + searchString.parserErrorMsg() + "'" );
"Invalid expression syntax. The error message of the parser is: '" + exp.parserErrorString() + "'" );
return;
}

Expand Down
31 changes: 12 additions & 19 deletions src/core/qgspallabeling.cpp
Expand Up @@ -41,8 +41,7 @@
#include "qgsdiagram.h"
#include "qgsdiagramrendererv2.h"
#include "qgslabelsearchtree.h"
#include "qgssearchtreenode.h"
#include "qgssearchstring.h"
#include "qgsexpression.h"

#include <qgslogger.h>
#include <qgsvectorlayer.h>
Expand Down Expand Up @@ -459,25 +458,20 @@ void QgsPalLayerSettings::registerFeature(QgsVectorLayer* layer, QgsFeature& f,
// Check to see if we are a expression string.
if (isExpression)
{
QgsSearchString searchString;
// We don't do any validating here as we should only have a vaild expression at this point.
searchString.setString( fieldName );

QgsSearchTreeNode* searchTree = searchString.tree();
if ( !searchTree )
QgsExpression exp( fieldName );
if ( exp.hasParserError() )
{
QgsDebugMsg("PASER HAS ERROR:" + exp.parserErrorString());
return;
}

QgsSearchTreeValue outValue;
searchTree->getValue( outValue, searchTree, layer->dataProvider()->fields() , f );

if (outValue.isError())
QVariant result = exp.evaluate(&f,layer->dataProvider()->fields());
QgsDebugMsg("VALUE = " + result.toString());
if (exp.hasEvalError())
{
QgsDebugMsg("Expression Label Error = " + outValue.string());
QgsDebugMsg("Expression Label Error = " + exp.evalErrorString());
return;
}
labelText = outValue.string();
labelText = result.toString();
}
else if ( formatNumbers == true && ( f.attributeMap()[fieldIndex].type() == QVariant::Int ||
f.attributeMap()[fieldIndex].type() == QVariant::Double ) )
Expand Down Expand Up @@ -778,11 +772,10 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
{
if (lyrTmp.fieldName.isEmpty())
return 0;
QgsSearchString searchString;
searchString.setString( lyrTmp.fieldName );
searchString.tree()->referencedColumns();
foreach(QString name, searchString.tree()->referencedColumns() )
QgsExpression exp( lyrTmp.fieldName );
foreach(QString name, exp.referencedColumns() )
{
QgsDebugMsg("REFERENCED COLUMN = " + name );
fldIndex = layer->fieldNameIndex( name );
attrIndices.insert(fldIndex);
}
Expand Down

0 comments on commit 706b6f1

Please sign in to comment.