Skip to content

Commit

Permalink
Added the possibility to use $area, $length when searching in attribu…
Browse files Browse the repository at this point in the history
…te table.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13434 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 7, 2010
1 parent 9ff72e1 commit 5241516
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
7 changes: 5 additions & 2 deletions python/core/qgssearchtreenode.sip
Expand Up @@ -68,8 +68,7 @@ class QgsSearchTreeNode
Type type();

//! node value getters
// TODO: for some reason this function is not found by dynamic linker
//Operator op();
Operator op();
double number();
QString columnRef();
QString string();
Expand Down Expand Up @@ -108,6 +107,10 @@ class QgsSearchTreeNode
//! @note added in 1.5
QStringList referencedColumns();

//! check whether there are any operators that need geometry (for area, length)
//! @note added in 1.5
bool needsGeometry();

protected:


Expand Down
12 changes: 8 additions & 4 deletions src/app/attributetable/qgsattributetabledialog.cpp
Expand Up @@ -533,15 +533,19 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
return;
}

// TODO: fetch only necessary columns
// QStringList columns = searchTree->referencedColumns();
bool fetchGeom = searchTree->needsGeometry();

QApplication::setOverrideCursor( Qt::WaitCursor );
mSelectedFeatures.clear();

if ( cbxSearchSelectedOnly->isChecked() )
{
QgsFeatureList selectedFeatures = mLayer->selectedFeatures();
for ( QgsFeatureList::ConstIterator it = selectedFeatures.begin(); it != selectedFeatures.end(); ++it )
for ( QgsFeatureList::Iterator it = selectedFeatures.begin(); it != selectedFeatures.end(); ++it )
{
if ( searchTree->checkAgainst( mLayer->pendingFields(), it->attributeMap() ) )
if ( searchTree->checkAgainst( mLayer->pendingFields(), it->attributeMap(), it->geometry() ) )
mSelectedFeatures << it->id();

// check if there were errors during evaluating
Expand All @@ -551,12 +555,12 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
}
else
{
mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), false );
mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), fetchGeom );
QgsFeature f;

while ( mLayer->nextFeature( f ) )
{
if ( searchTree->checkAgainst( mLayer->pendingFields(), f.attributeMap() ) )
if ( searchTree->checkAgainst( mLayer->pendingFields(), f.attributeMap(), f.geometry() ) )
mSelectedFeatures << f.id();

// check if there were errors during evaluating
Expand Down
6 changes: 4 additions & 2 deletions src/app/qgssearchquerybuilder.cpp
Expand Up @@ -190,6 +190,8 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
return mLayer->featureCount();
}

bool fetchGeom = searchTree->needsGeometry();

QApplication::setOverrideCursor( Qt::WaitCursor );

int count = 0;
Expand All @@ -198,11 +200,11 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
const QgsFieldMap& fields = provider->fields();
QgsAttributeList allAttributes = provider->attributeIndexes();

provider->select( allAttributes, QgsRectangle(), false );
provider->select( allAttributes, QgsRectangle(), fetchGeom );

while ( provider->nextFeature( feat ) )
{
if ( searchTree->checkAgainst( fields, feat.attributeMap() ) )
if ( searchTree->checkAgainst( fields, feat.attributeMap(), feat.geometry() ) )
{
count++;
}
Expand Down
19 changes: 19 additions & 0 deletions src/core/qgssearchtreenode.cpp
Expand Up @@ -249,6 +249,25 @@ QStringList QgsSearchTreeNode::referencedColumns()

}

bool QgsSearchTreeNode::needsGeometry()
{
if ( mType == tOperator )
{
if ( mOp == opLENGTH || mOp == opAREA )
return true;

if ( mLeft && mLeft->needsGeometry() )
return true;
if ( mRight && mRight->needsGeometry() )
return true;
return false;
}
else
{
return false;
}
}


bool QgsSearchTreeNode::checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom )
{
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgssearchtreenode.h
Expand Up @@ -106,7 +106,7 @@ class CORE_EXPORT QgsSearchTreeNode
Type type() { return mType; }

//! node value getters
Operator op();
Operator op() { return mOp; }
double number() { return mNumber; }
QString columnRef() { return mText; }
QString string() { return mText; }
Expand Down Expand Up @@ -145,6 +145,10 @@ class CORE_EXPORT QgsSearchTreeNode
//! @note added in 1.5
QStringList referencedColumns();

//! check whether there are any operators that need geometry (for area, length)
//! @note added in 1.5
bool needsGeometry();

protected:


Expand Down

0 comments on commit 5241516

Please sign in to comment.