Skip to content
Permalink
Browse files

Merge branch 'master' of https://github.com/qgis/Quantum-GIS

  • Loading branch information
Werner Macho
Werner Macho committed Aug 27, 2011
2 parents a0b8e3c + 96f7736 commit 30f1153e80b31cf26e538fd63c4ab1ce44dddb2c
@@ -35,6 +35,7 @@
%Include qgsdataprovider.sip
%Include qgsdatasourceuri.sip
%Include qgsdistancearea.sip
%Include qgsexpression.sip
%Include qgsfeature.sip
%Include qgsfield.sip
%Include qgsgeometry.sip
@@ -0,0 +1,64 @@

class QgsExpression
{
%TypeHeaderCode
#include "qgsexpression.h"
%End

public:
QgsExpression( const QString& expr );
~QgsExpression();

//! Returns true if an error occurred when parsing the input expression
bool hasParserError() const;
//! Returns parser error
QString parserErrorString() const;

//! Get the expression ready for evaluation - find out column indexes.
bool prepare( const QgsFieldMap& fields );

//! Get list of columns referenced by the expression
QStringList referencedColumns();
//! Returns true if the expression uses feature geometry for some computation
bool needsGeometry();

// evaluation

//! Evaluate the feature and return the result
//! @note prepare() should be called before calling this method
QVariant evaluate( QgsFeature* f = NULL );

//! Evaluate the feature and return the result
//! @note this method does not expect that prepare() has been called on this instance
QVariant evaluate( QgsFeature* f, const QgsFieldMap& fields );

//! Returns true if an error occurred when evaluating last input
bool hasEvalError() const;
//! Returns evaluation error
QString evalErrorString() const;
//! Set evaluation error (used internally by evaluation functions)
void setEvalErrorString( QString str );

//! Set the number for $rownum special column
void setCurrentRowNumber( int rowNumber );
//! Return the number used for $rownum special column
int currentRowNumber();

//! Return the parsed expression as a string - useful for debugging
QString dump() const;

//! Return calculator used for distance and area calculations
//! (used by internal functions)
QgsDistanceArea* geomCalculator();

//

// tells whether the identifier is a name of existing function
static bool isFunctionName( QString name );

// return index of the function in BuiltinFunctions array
static int functionIndex( QString name );

//! return quoted column reference (in double quotes)
static QString quotedColumnRef( QString name );
};
@@ -407,14 +407,15 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
~Rule();
QString dump() const;
QStringList needsFields() const;
bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const;
bool isFilterOK( QgsFeature& f ) const;
bool isScaleOK( double scale ) const;

QgsSymbolV2* symbol();
bool dependsOnScale() const;
int scaleMinDenom() const;
int scaleMaxDenom() const;
QString filterExpression() const;
QgsExpression* filter() const;

void setScaleMinDenom( int scaleMinDenom );
void setScaleMaxDenom( int scaleMaxDenom );
@@ -511,7 +511,7 @@ def removeRepository(self, repo):


# ----------------------------------------- #
def getInstalledPlugin(self, key, readOnly):
def getInstalledPlugin(self, key, readOnly, testLoad=False):
""" get the metadata of an installed plugin """
if readOnly:
path = QgsApplication.pkgDataPath()
@@ -557,10 +557,11 @@ def getInstalledPlugin(self, key, readOnly):
errorDetails = qgisMinimumVersion
except:
pass
try:
exec ("%s.classFactory(iface)" % key)
except Exception, error:
error = unicode(error.args[0])
if testLoad:
try:
exec ("%s.classFactory(iface)" % key)
except Exception, error:
error = unicode(error.args[0])
except Exception, error:
error = unicode(error.args[0])

@@ -596,7 +597,7 @@ def getInstalledPlugin(self, key, readOnly):


# ----------------------------------------- #
def getAllInstalled(self):
def getAllInstalled(self, testLoad=False):
""" Build the localCache """
self.localCache = {}
# first, try to add the read-only plugins...
@@ -625,7 +626,7 @@ def getAllInstalled(self):
for key in pluginDir.entryList():
key = unicode(key)
if not key in [".",".."]:
plugin = self.getInstalledPlugin(key, False)
plugin = self.getInstalledPlugin(key, False, testLoad)
if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_inst"],plugin["version_inst"]) == 1:
# An obsolete plugin in the "user" location is masking a newer one in the "system" location!
self.obsoletePlugins += [key]
@@ -528,6 +528,9 @@ def addItem(p):
n +=1
self.setWindowTitle(self.tr("QGIS Python Plugin Installer") + self.tr(" - %d plugins available" % len(plugins.all())))
self.buttonUpgradeAll.setEnabled( len(self.upgradeablePlugins) )

# initially, keep insert order
self.treePlugins.sortItems(100,Qt.AscendingOrder)

# resize the columns
for i in [0,1,2,3,4,5]:
@@ -537,8 +540,6 @@ def addItem(p):
self.treePlugins.setColumnWidth(i, 260)
if self.treePlugins.columnWidth(3) > 560:
self.treePlugins.setColumnWidth(3, 560)
# initially, keep order of inserting
self.treePlugins.sortItems(100,Qt.AscendingOrder)


# ----------------------------------------- #
@@ -629,7 +630,7 @@ def installPlugin(self, key, quiet=False):
exec ("reload (%s)" % plugin["localdir"])
except:
pass
plugins.getAllInstalled()
plugins.getAllInstalled(testLoad=True)
plugins.rebuild()
plugin = plugins.all()[key]
if not plugin["error"]:
@@ -24,8 +24,7 @@
#include <qgsapplication.h>
#include <qgsvectordataprovider.h>
#include <qgsvectorlayer.h>
#include <qgssearchstring.h>
#include <qgssearchtreenode.h>
#include <qgsexpression.h>

#include "qgisapp.h"
#include "qgsaddattrdialog.h"
@@ -532,23 +531,21 @@ void QgsAttributeTableDialog::updateSelectionFromLayer()
void QgsAttributeTableDialog::doSearch( QString searchString )
{
// parse search string and build parsed tree
QgsSearchString search;
if ( !search.setString( searchString ) )
QgsExpression search( searchString );
if ( search.hasParserError() )
{
QMessageBox::critical( this, tr( "Search string parsing error" ), search.parserErrorMsg() );
QMessageBox::critical( this, tr( "Parsing error" ), search.parserErrorString() );
return;
}

QgsSearchTreeNode* searchTree = search.tree();
if ( searchTree == NULL )
if ( ! search.prepare( mLayer->pendingFields() ) )
{
QMessageBox::information( this, tr( "Search results" ), tr( "You've supplied an empty search string." ) );
return;
QMessageBox::critical( this, tr( "Evaluation error" ), search.evalErrorString() );
}

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

QApplication::setOverrideCursor( Qt::WaitCursor );
mSelectedFeatures.clear();
@@ -558,11 +555,12 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
QgsFeatureList selectedFeatures = mLayer->selectedFeatures();
for ( QgsFeatureList::Iterator it = selectedFeatures.begin(); it != selectedFeatures.end(); ++it )
{
if ( searchTree->checkAgainst( mLayer->pendingFields(), *it ) )
mSelectedFeatures << it->id();
QgsFeature& feat = *it;
if ( search.evaluate( &feat ).toInt() != 0 )
mSelectedFeatures << feat.id();

// check if there were errors during evaluating
if ( searchTree->hasError() )
if ( search.hasEvalError() )
break;
}
}
@@ -573,20 +571,20 @@ void QgsAttributeTableDialog::doSearch( QString searchString )

while ( mLayer->nextFeature( f ) )
{
if ( searchTree->checkAgainst( mLayer->pendingFields(), f ) )
if ( search.evaluate( &f ).toInt() != 0 )
mSelectedFeatures << f.id();

// check if there were errors during evaluating
if ( searchTree->hasError() )
if ( search.hasEvalError() )
break;
}
}

QApplication::restoreOverrideCursor();

if ( searchTree->hasError() )
if ( search.hasEvalError() )
{
QMessageBox::critical( this, tr( "Error during search" ), searchTree->errorMsg() );
QMessageBox::critical( this, tr( "Error during search" ), search.evalErrorString() );
return;
}

@@ -625,12 +623,12 @@ void QgsAttributeTableDialog::search()
QString str;
if ( mQuery->displayText() == nullValue )
{
str = QString( "%1 IS NULL" ).arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) );
str = QString( "%1 IS NULL" ).arg( QgsExpression::quotedColumnRef( fieldName ) );
}
else
{
str = QString( "%1 %2 '%3'" )
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
.arg( QgsExpression::quotedColumnRef( fieldName ) )
.arg( numeric ? "=" : sensString )
.arg( numeric
? mQuery->displayText().replace( "'", "''" )
@@ -24,8 +24,7 @@
#include "qgssymbol.h"
#include "qgsattributeeditor.h"
#include "qgshighlight.h"
#include "qgssearchstring.h"
#include "qgssearchtreenode.h"
#include "qgsexpression.h"
#include "qgspythonrunner.h"

#include "qgisapp.h"
@@ -208,15 +207,12 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
QString expr = le->text();
le->setText( tr( "Error" ) );

QgsSearchString ss;
if ( !ss.setString( expr ) )
QgsExpression exp( expr );
if ( exp.hasParserError() )
continue;

QgsSearchTreeNode *st = ss.tree();
if ( !st )
continue;

if ( !mFeature->geometry() && st->needsGeometry() )
if ( !mFeature->geometry() && exp.needsGeometry() )
{
QgsFeature f;
if ( vl->featureAtId( mFeature->id(), f, true, false ) && f.geometry() )
@@ -225,19 +221,24 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
}

QgsSearchTreeValue value;
st->getValue( value, st, vl->pendingFields(), *mFeature );
QVariant value = exp.evaluate( mFeature, vl->pendingFields() );

if ( !value.isError() )
if ( !exp.hasEvalError() )
{
if ( value.isNumeric() )
le->setText( QString::number( value.number() ) );
else
le->setText( value.string() );
QString text;
switch ( value.type() )
{
case QVariant::Invalid: text = "NULL"; break;
case QVariant::Int: text = QString::number( value.toInt() ); break;
case QVariant::Double: text = QString::number( value.toDouble() ); break;
case QVariant::String:
default: text = value.toString();
}
le->setText( text );
}
else
{
le->setText( tr( "Error: %1" ).arg( st->errorMsg() ) );
le->setText( tr( "Error: %1" ).arg( exp.evalErrorString() ) );
}
}
}

0 comments on commit 30f1153

Please sign in to comment.
You can’t perform that action at this time.