mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
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:
parent
b3e9ed7afd
commit
55eeb953e3
@ -68,8 +68,7 @@ class QgsSearchTreeNode
|
|||||||
Type type();
|
Type type();
|
||||||
|
|
||||||
//! node value getters
|
//! node value getters
|
||||||
// TODO: for some reason this function is not found by dynamic linker
|
Operator op();
|
||||||
//Operator op();
|
|
||||||
double number();
|
double number();
|
||||||
QString columnRef();
|
QString columnRef();
|
||||||
QString string();
|
QString string();
|
||||||
@ -108,6 +107,10 @@ class QgsSearchTreeNode
|
|||||||
//! @note added in 1.5
|
//! @note added in 1.5
|
||||||
QStringList referencedColumns();
|
QStringList referencedColumns();
|
||||||
|
|
||||||
|
//! check whether there are any operators that need geometry (for area, length)
|
||||||
|
//! @note added in 1.5
|
||||||
|
bool needsGeometry();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
@ -533,15 +533,19 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fetch only necessary columns
|
||||||
|
// QStringList columns = searchTree->referencedColumns();
|
||||||
|
bool fetchGeom = searchTree->needsGeometry();
|
||||||
|
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
mSelectedFeatures.clear();
|
mSelectedFeatures.clear();
|
||||||
|
|
||||||
if ( cbxSearchSelectedOnly->isChecked() )
|
if ( cbxSearchSelectedOnly->isChecked() )
|
||||||
{
|
{
|
||||||
QgsFeatureList selectedFeatures = mLayer->selectedFeatures();
|
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();
|
mSelectedFeatures << it->id();
|
||||||
|
|
||||||
// check if there were errors during evaluating
|
// check if there were errors during evaluating
|
||||||
@ -551,12 +555,12 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), false );
|
mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), fetchGeom );
|
||||||
QgsFeature f;
|
QgsFeature f;
|
||||||
|
|
||||||
while ( mLayer->nextFeature( f ) )
|
while ( mLayer->nextFeature( f ) )
|
||||||
{
|
{
|
||||||
if ( searchTree->checkAgainst( mLayer->pendingFields(), f.attributeMap() ) )
|
if ( searchTree->checkAgainst( mLayer->pendingFields(), f.attributeMap(), f.geometry() ) )
|
||||||
mSelectedFeatures << f.id();
|
mSelectedFeatures << f.id();
|
||||||
|
|
||||||
// check if there were errors during evaluating
|
// check if there were errors during evaluating
|
||||||
|
@ -190,6 +190,8 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
|
|||||||
return mLayer->featureCount();
|
return mLayer->featureCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fetchGeom = searchTree->needsGeometry();
|
||||||
|
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -198,11 +200,11 @@ long QgsSearchQueryBuilder::countRecords( QString searchString )
|
|||||||
const QgsFieldMap& fields = provider->fields();
|
const QgsFieldMap& fields = provider->fields();
|
||||||
QgsAttributeList allAttributes = provider->attributeIndexes();
|
QgsAttributeList allAttributes = provider->attributeIndexes();
|
||||||
|
|
||||||
provider->select( allAttributes, QgsRectangle(), false );
|
provider->select( allAttributes, QgsRectangle(), fetchGeom );
|
||||||
|
|
||||||
while ( provider->nextFeature( feat ) )
|
while ( provider->nextFeature( feat ) )
|
||||||
{
|
{
|
||||||
if ( searchTree->checkAgainst( fields, feat.attributeMap() ) )
|
if ( searchTree->checkAgainst( fields, feat.attributeMap(), feat.geometry() ) )
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -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 )
|
bool QgsSearchTreeNode::checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom )
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ class CORE_EXPORT QgsSearchTreeNode
|
|||||||
Type type() { return mType; }
|
Type type() { return mType; }
|
||||||
|
|
||||||
//! node value getters
|
//! node value getters
|
||||||
Operator op();
|
Operator op() { return mOp; }
|
||||||
double number() { return mNumber; }
|
double number() { return mNumber; }
|
||||||
QString columnRef() { return mText; }
|
QString columnRef() { return mText; }
|
||||||
QString string() { return mText; }
|
QString string() { return mText; }
|
||||||
@ -145,6 +145,10 @@ class CORE_EXPORT QgsSearchTreeNode
|
|||||||
//! @note added in 1.5
|
//! @note added in 1.5
|
||||||
QStringList referencedColumns();
|
QStringList referencedColumns();
|
||||||
|
|
||||||
|
//! check whether there are any operators that need geometry (for area, length)
|
||||||
|
//! @note added in 1.5
|
||||||
|
bool needsGeometry();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user