[QGIS Commit] r14247 - in trunk/qgis: python/core src/app
src/app/attributetable src/core src/core/symbology-ng
src/gui/symbology-ng tests/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Sep 18 11:31:31 EDT 2010
Author: jef
Date: 2010-09-18 15:31:31 +0000 (Sat, 18 Sep 2010)
New Revision: 14247
Modified:
trunk/qgis/python/core/qgssearchtreenode.sip
trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
trunk/qgis/src/app/qgsfieldcalculator.cpp
trunk/qgis/src/app/qgssearchquerybuilder.cpp
trunk/qgis/src/core/qgssearchstringlexer.ll
trunk/qgis/src/core/qgssearchstringparser.yy
trunk/qgis/src/core/qgssearchtreenode.cpp
trunk/qgis/src/core/qgssearchtreenode.h
trunk/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp
trunk/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
trunk/qgis/tests/src/core/testqgssearchstring.cpp
Log:
[FEATURE] add search string support for feature ids ($id)
Modified: trunk/qgis/python/core/qgssearchtreenode.sip
===================================================================
--- trunk/qgis/python/core/qgssearchtreenode.sip 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/python/core/qgssearchtreenode.sip 2010-09-18 15:31:31 UTC (rev 14247)
@@ -46,6 +46,9 @@
opLENGTH,
opAREA,
+ // feature id
+ opID,
+
// comparison
opEQ, // =
opNE, // != resp. <>
@@ -98,7 +101,10 @@
QString makeSearchString();
//! checks whether the node tree is valid against supplied attributes
- //! @note optional geom parameter added in 1.5
+ //! @note attributes and optional geom parameter replace with feature in 1.6
+ bool checkAgainst( const QMap<int,QgsField>& fields, QgsFeature &f );
+
+ //! @note deprecated
bool checkAgainst( const QMap<int,QgsField>& fields, const QMap<int, QVariant>& attributes, QgsGeometry* geom = 0 );
//! checks if there were errors during evaluation
@@ -109,7 +115,12 @@
//! wrapper around valueAgainst()
//! @note added in 1.4
+ //! @note attribute/geom replaced by feature in 1.6
bool getValue( QgsSearchTreeValue& value /Out/, QgsSearchTreeNode* node,
+ const QMap<int,QgsField>& fields, QgsFeature &f );
+
+ //! @note deprecated
+ bool getValue( QgsSearchTreeValue& value /Out/, QgsSearchTreeNode* node,
const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
//! return a list of referenced columns in the tree
@@ -134,14 +145,15 @@
void setCurrentRowNumber( int rownum );
protected:
+ //! returns scalar value of node
+ //! @note attribute/geom replaced by feature in 1.6
+ QgsSearchTreeValue valueAgainst( const QMap<int,QgsField>& fields, QgsFeature &f );
-
- //! returns scalar value of node
+ //! @note deprecated
QgsSearchTreeValue valueAgainst( const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
//! strips mText when node is of string type
void stripText();
-
};
Modified: trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledialog.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -568,7 +568,7 @@
QgsFeatureList selectedFeatures = mLayer->selectedFeatures();
for ( QgsFeatureList::Iterator it = selectedFeatures.begin(); it != selectedFeatures.end(); ++it )
{
- if ( searchTree->checkAgainst( mLayer->pendingFields(), it->attributeMap(), it->geometry() ) )
+ if ( searchTree->checkAgainst( mLayer->pendingFields(), *it ) )
mSelectedFeatures << it->id();
// check if there were errors during evaluating
@@ -583,7 +583,7 @@
while ( mLayer->nextFeature( f ) )
{
- if ( searchTree->checkAgainst( mLayer->pendingFields(), f.attributeMap(), f.geometry() ) )
+ if ( searchTree->checkAgainst( mLayer->pendingFields(), f ) )
mSelectedFeatures << f.id();
// check if there were errors during evaluating
Modified: trunk/qgis/src/app/qgsfieldcalculator.cpp
===================================================================
--- trunk/qgis/src/app/qgsfieldcalculator.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/app/qgsfieldcalculator.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -170,14 +170,7 @@
searchTree->setCurrentRowNumber( rownum );
QgsSearchTreeValue value;
- if ( useGeometry )
- {
- searchTree->getValue( value, searchTree, mVectorLayer->pendingFields(), feature.attributeMap(), feature.geometry() );
- }
- else
- {
- searchTree->getValue( value, searchTree, mVectorLayer->pendingFields(), feature.attributeMap() );
- }
+ searchTree->getValue( value, searchTree, mVectorLayer->pendingFields(), feature );
if ( value.isError() )
{
calculationSuccess = false;
Modified: trunk/qgis/src/app/qgssearchquerybuilder.cpp
===================================================================
--- trunk/qgis/src/app/qgssearchquerybuilder.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/app/qgssearchquerybuilder.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -216,7 +216,7 @@
while ( provider->nextFeature( feat ) )
{
- if ( searchTree->checkAgainst( fields, feat.attributeMap(), feat.geometry() ) )
+ if ( searchTree->checkAgainst( fields, feat ) )
{
count++;
}
Modified: trunk/qgis/src/core/qgssearchstringlexer.ll
===================================================================
--- trunk/qgis/src/core/qgssearchstringlexer.ll 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/core/qgssearchstringlexer.ll 2010-09-18 15:31:31 UTC (rev 14247)
@@ -110,6 +110,7 @@
"$area" { return AREA; }
"$length" { return LENGTH; }
+"$id" { return ID; }
{column_ref} { return COLUMN_REF; }
{column_ref_quoted} { return COLUMN_REF; }
Modified: trunk/qgis/src/core/qgssearchstringparser.yy
===================================================================
--- trunk/qgis/src/core/qgssearchstringparser.yy 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/core/qgssearchstringparser.yy 2010-09-18 15:31:31 UTC (rev 14247)
@@ -68,6 +68,7 @@
%token ROWNUM
%token AREA
%token LENGTH
+%token ID
%token NULLVALUE
%token STRING
@@ -151,6 +152,7 @@
| ROWNUM { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opROWNUM, 0, 0); addToTmpNodes($$); }
| AREA { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opAREA, 0, 0); addToTmpNodes($$); }
| LENGTH { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opLENGTH, 0, 0); addToTmpNodes($$); }
+ | ID { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opID, 0, 0); addToTmpNodes($$); }
| NUMBER { $$ = new QgsSearchTreeNode($1); addToTmpNodes($$); }
| STRING { $$ = new QgsSearchTreeNode(QString::fromUtf8(yytext), 0); addToTmpNodes($$); }
| COLUMN_REF { $$ = new QgsSearchTreeNode(QString::fromUtf8(yytext), 1); addToTmpNodes($$); }
Modified: trunk/qgis/src/core/qgssearchtreenode.cpp
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/core/qgssearchtreenode.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -231,7 +231,7 @@
// currently all functions take one parameter
str += QString( "(%1)" ).arg( mLeft->makeSearchString() );
}
- else if ( mOp == opLENGTH || mOp == opAREA || mOp == opROWNUM )
+ else if ( mOp == opLENGTH || mOp == opAREA || mOp == opROWNUM || mOp == opID )
{
// special nullary opeators
switch ( mOp )
@@ -239,6 +239,7 @@
case opLENGTH: str += "$length"; break;
case opAREA: str += "$area"; break;
case opROWNUM: str += "$rownum"; break;
+ case opID: str += "$id"; break;
default: str += "?";
}
}
@@ -374,8 +375,16 @@
}
}
+bool QgsSearchTreeNode::checkAgainst( const QMap<int,QgsField>& fields, const QMap<int, QVariant>& attributes, QgsGeometry* geom )
+{
+ QgsFeature f;
+ f.setAttributeMap( attributes );
+ if ( geom )
+ f.setGeometry( *geom );
+ return checkAgainst( fields, f );
+}
-bool QgsSearchTreeNode::checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom )
+bool QgsSearchTreeNode::checkAgainst( const QgsFieldMap& fields, QgsFeature &f )
{
QgsDebugMsgLevel( "checkAgainst: " + makeSearchString(), 2 );
@@ -394,31 +403,24 @@
switch ( mOp )
{
case opNOT:
- return !mLeft->checkAgainst( fields, attributes, geom );
+ return !mLeft->checkAgainst( fields, f );
case opAND:
- if ( !mLeft->checkAgainst( fields, attributes, geom ) )
+ if ( !mLeft->checkAgainst( fields, f ) )
return false;
- return mRight->checkAgainst( fields, attributes, geom );
+ return mRight->checkAgainst( fields, f );
case opOR:
- if ( mLeft->checkAgainst( fields, attributes, geom ) )
+ if ( mLeft->checkAgainst( fields, f ) )
return true;
- return mRight->checkAgainst( fields, attributes, geom );
+ return mRight->checkAgainst( fields, f );
case opISNULL:
case opISNOTNULL:
- if ( !getValue( value1, mLeft, fields, attributes, geom ) )
+ if ( !getValue( value1, mLeft, fields, f ) )
return false;
- if ( mOp == opISNULL )
- {
- return value1.isNull();
- }
- else if ( mOp == opISNOTNULL )
- {
- return !value1.isNull();
- }
+ return ( mOp == opISNULL ) == value1.isNull();
case opEQ:
case opNE:
@@ -426,8 +428,7 @@
case opLT:
case opGE:
case opLE:
-
- if ( !getValue( value1, mLeft, fields, attributes, geom ) || !getValue( value2, mRight, fields, attributes, geom ) )
+ if ( !getValue( value1, mLeft, fields, f ) || !getValue( value2, mRight, fields, f ) )
return false;
if ( value1.isNull() || value2.isNull() )
@@ -440,12 +441,12 @@
switch ( mOp )
{
- case opEQ: return ( res == 0 );
- case opNE: return ( res != 0 );
- case opGT: return ( res > 0 );
- case opLT: return ( res < 0 );
- case opGE: return ( res >= 0 );
- case opLE: return ( res <= 0 );
+ case opEQ: return res == 0;
+ case opNE: return res != 0;
+ case opGT: return res > 0;
+ case opLT: return res < 0;
+ case opGE: return res >= 0;
+ case opLE: return res <= 0;
default:
mError = QObject::tr( "Unexpected state when evaluating operator!" );
return false;
@@ -454,7 +455,7 @@
case opIN:
case opNOTIN:
{
- if ( !getValue( value1, mLeft, fields, attributes, geom ) ||
+ if ( !getValue( value1, mLeft, fields, f ) ||
!mRight || mRight->type() != tNodeList )
{
return false;
@@ -462,7 +463,7 @@
foreach( QgsSearchTreeNode *node, mRight->mNodeList )
{
- if ( !getValue( value2, node, fields, attributes, geom ) )
+ if ( !getValue( value2, node, fields, f ) )
{
mError = QObject::tr( "Could not retrieve value of list value" );
return false;
@@ -485,8 +486,8 @@
case opLike:
case opILike:
{
- if ( !getValue( value1, mLeft, fields, attributes, geom ) ||
- !getValue( value2, mRight, fields, attributes, geom ) )
+ if ( !getValue( value1, mLeft, fields, f ) ||
+ !getValue( value2, mRight, fields, f ) )
return false;
// value1 is string to be matched
@@ -512,20 +513,29 @@
}
else
{
- return ( QRegExp( str ).indexIn( value1.string() ) != -1 );
+ return QRegExp( str ).indexIn( value1.string() ) != -1;
}
-
}
default:
mError = QObject::tr( "Unknown operator: %1" ).arg( mOp );
- return false;
}
+
+ return false;
}
-bool QgsSearchTreeNode::getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node, const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom )
+bool QgsSearchTreeNode::getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node, const QgsFieldMap& fields, const QMap<int, QVariant>& attributes, QgsGeometry* geom )
{
- value = node->valueAgainst( fields, attributes, geom );
+ QgsFeature f;
+ f.setAttributeMap( attributes );
+ if ( geom )
+ f.setGeometry( *geom );
+ return getValue( value, node, fields, f );
+}
+
+bool QgsSearchTreeNode::getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node, const QgsFieldMap& fields, QgsFeature &f )
+{
+ value = node->valueAgainst( fields, f );
if ( value.isError() )
{
switch (( int )value.number() )
@@ -553,8 +563,17 @@
return true;
}
-QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom )
+QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, const QMap<int, QVariant>& attributes, QgsGeometry* geom )
{
+ QgsFeature f;
+ f.setAttributeMap( attributes );
+ if ( geom )
+ f.setGeometry( *geom );
+ return valueAgainst( fields, f );
+}
+
+QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, QgsFeature &f )
+{
QgsDebugMsgLevel( "valueAgainst: " + makeSearchString(), 2 );
switch ( mType )
@@ -587,7 +606,7 @@
}
// get the value
- QVariant val = attributes[it.key()];
+ QVariant val = f.attributeMap()[it.key()];
if ( val.isNull() )
{
QgsDebugMsgLevel( " NULL", 2 );
@@ -612,32 +631,37 @@
QgsSearchTreeValue value1, value2;
if ( mLeft )
{
- if ( !getValue( value1, mLeft, fields, attributes, geom ) ) return value1;
+ if ( !getValue( value1, mLeft, fields, f ) ) return value1;
}
if ( mRight )
{
- if ( !getValue( value2, mRight, fields, attributes, geom ) ) return value2;
+ if ( !getValue( value2, mRight, fields, f ) ) return value2;
}
if ( mOp == opLENGTH || mOp == opAREA )
{
- if ( !geom )
+ if ( !f.geometry() )
{
return QgsSearchTreeValue( 2, "Geometry is 0" );
}
//check that we don't use area for lines or length for polygons
- if ( mOp == opLENGTH && geom->type() != QGis::Line )
+ if ( mOp == opLENGTH && f.geometry()->type() != QGis::Line )
{
return QgsSearchTreeValue( 0 );
}
- if ( mOp == opAREA && geom->type() != QGis::Polygon )
+ if ( mOp == opAREA && f.geometry()->type() != QGis::Polygon )
{
return QgsSearchTreeValue( 0 );
}
- return QgsSearchTreeValue( mCalc->measure( geom ) );
+ return QgsSearchTreeValue( mCalc->measure( f.geometry() ) );
}
+ if ( mOp == opID )
+ {
+ return QgsSearchTreeValue( f.id() );
+ }
+
if ( mOp == opROWNUM )
{
// the row number has to be previously set by the caller using setCurrentRowNumber
Modified: trunk/qgis/src/core/qgssearchtreenode.h
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.h 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/core/qgssearchtreenode.h 2010-09-18 15:31:31 UTC (rev 14247)
@@ -84,6 +84,9 @@
opLENGTH,
opAREA,
+ // feature id
+ opID,
+
// comparison
opISNULL, // IS NULL
opISNOTNULL, // IS NOT NULL
@@ -144,9 +147,12 @@
QString makeSearchString();
//! checks whether the node tree is valid against supplied attributes
- //! @note optional geom parameter added in 1.5
- bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
+ //! @note attribute and optional geom parameter replaced with feature in 1.6
+ bool checkAgainst( const QgsFieldMap& fields, QgsFeature &f );
+ //! @note deprecated
+ bool checkAgainst( const QMap<int,QgsField>& fields, const QMap<int, QVariant>& attributes, QgsGeometry* geom = 0 );
+
//! checks if there were errors during evaluation
bool hasError() { return ( !mError.isEmpty() ); }
@@ -156,8 +162,12 @@
//! wrapper around valueAgainst()
//! @note added in 1.4
bool getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node,
- const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
+ const QgsFieldMap& fields, QgsFeature &f );
+ //! @note deprecated
+ bool getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node,
+ const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
+
//! return a list of referenced columns in the tree
//! @note added in 1.5
QStringList referencedColumns();
@@ -188,11 +198,12 @@
void append( QList<QgsSearchTreeNode*> );
protected:
+ //! returns scalar value of node
+ QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, QgsFeature &f );
+ //! @note deprecated
+ QgsSearchTreeValue valueAgainst( const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
- //! returns scalar value of node
- QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
-
//! strips mText when node is of string type
void stripText();
Modified: trunk/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -81,7 +81,7 @@
if ( ! mFilterTree )
return true;
- bool res = mFilterTree->checkAgainst( fields, f.attributeMap() );
+ bool res = mFilterTree->checkAgainst( fields, f );
//print "is_ok", res, feature.id(), feature.attributeMap()
return res;
}
Modified: trunk/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -343,7 +343,7 @@
QgsFeature f;
while ( mLayer->nextFeature( f ) )
{
- if ( tree->checkAgainst( fields, f.attributeMap() ) )
+ if ( tree->checkAgainst( fields, f ) )
count++;
if ( tree->hasError() )
break;
Modified: trunk/qgis/tests/src/core/testqgssearchstring.cpp
===================================================================
--- trunk/qgis/tests/src/core/testqgssearchstring.cpp 2010-09-18 10:03:56 UTC (rev 14246)
+++ trunk/qgis/tests/src/core/testqgssearchstring.cpp 2010-09-18 15:31:31 UTC (rev 14247)
@@ -17,6 +17,7 @@
#include <qgssearchstring.h>
#include <qgssearchtreenode.h>
+#include <qgsfeature.h>
class TestQgsSearchString : public QObject
{
@@ -36,9 +37,10 @@
static bool evalString( QString str )
{
+ QgsFeature f;
QgsSearchString ss;
ss.setString( str );
- return ss.tree()->checkAgainst( QgsFieldMap(), QgsAttributeMap() );
+ return ss.tree()->checkAgainst( QgsFieldMap(), f );
}
void TestQgsSearchString::testLike()
More information about the QGIS-commit
mailing list