Added the possibility to use $area, $length when searching in attribute table.

git-svn-id: http://svn.osgeo.org/qgis/trunk@13434 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2010-05-07 09:15:08 +00:00
parent b3e9ed7afd
commit 55eeb953e3
5 changed files with 41 additions and 9 deletions

View File

@ -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();
@ -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:

View File

@ -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
@ -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

View File

@ -190,6 +190,8 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
return mLayer->featureCount();
}
bool fetchGeom = searchTree->needsGeometry();
QApplication::setOverrideCursor( Qt::WaitCursor );
int count = 0;
@ -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++;
}

View File

@ -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 )
{

View File

@ -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; }
@ -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: