Skip to content

Commit

Permalink
Fix for ticket #323 (diacritics in column name).
Browse files Browse the repository at this point in the history
Use QgsLogger in QgsSearchTreeNode instead of std::cout.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5939 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Oct 12, 2006
1 parent 909af2f commit 98497bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
6 changes: 4 additions & 2 deletions src/core/qgssearchstringlexer.ll
Expand Up @@ -34,8 +34,10 @@

white [ \t\r\n]+

col_first [A-Za-z_]
col_next [A-Za-z0-9_]
non_ascii [\x80-\xFF]

col_first [A-Za-z_]|{non_ascii}
col_next [A-Za-z0-9_]|{non_ascii}
column_ref {col_first}{col_next}*

dig [0-9]
Expand Down
38 changes: 13 additions & 25 deletions src/core/qgssearchtreenode.cpp
Expand Up @@ -16,27 +16,15 @@
* *
***************************************************************************/
/* $Id$ */


#include "qgslogger.h"
#include "qgssearchtreenode.h"
#include <qregexp.h>
#include <qobject.h>
#include <iostream>

// turn on/off debugging of search tree evaulation
#undef DEBUG_TREE_EVAL

#ifdef DEBUG_TREE_EVAL
#define TREE_EVAL(x) std::cout << x;
#define TREE_EVAL2(x,y) std::cout << x << y << std::endl;
#define TREE_EVAL3(x,y,z) std::cout << x << y << z << std::endl;
#define TREE_EVAL4(x,y,z,zz) std::cout << x << y << z << zz << std::endl;
#define EVAL_STR(x) (x.length() ? x : "(empty)")
#else
#define TREE_EVAL(x)
#define TREE_EVAL2(x,y)
#define TREE_EVAL3(x,y,z)
#define TREE_EVAL4(x,y,z,zz)
#endif

QgsSearchTreeNode::QgsSearchTreeNode(double number)
{
Expand Down Expand Up @@ -194,7 +182,7 @@ QString QgsSearchTreeNode::makeSearchString()

bool QgsSearchTreeNode::checkAgainst(const std::vector<QgsFeatureAttribute>& attributes)
{
TREE_EVAL2("checkAgainst: ", makeSearchString());
QgsDebugMsgLevel("checkAgainst: " + makeSearchString(), 2);

mError = "";

Expand Down Expand Up @@ -275,8 +263,8 @@ bool QgsSearchTreeNode::checkAgainst(const std::vector<QgsFeatureAttribute>& att

QRegExp re(str);
res = re.search(value1.string());
TREE_EVAL4("REGEXP: ", str, " ~ ", value2.string());
TREE_EVAL2(" res: ", res);
QgsDebugMsgLevel("REGEXP: " + str + " ~ " + value2.string(), 2);
QgsDebugMsgLevel(" res: " + res, 2);
return (res != -1);
}

Expand Down Expand Up @@ -324,22 +312,22 @@ bool QgsSearchTreeNode::getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* n

QgsSearchTreeValue QgsSearchTreeNode::valueAgainst(const std::vector<QgsFeatureAttribute>& attributes)
{
TREE_EVAL2("valueAgainst: ", makeSearchString());
QgsDebugMsgLevel("valueAgainst: " + makeSearchString(), 2);

switch (mType)
{

case tNumber:
TREE_EVAL2("number: ", mNumber);
QgsDebugMsgLevel("number: " + QString::number(mNumber), 2);
return QgsSearchTreeValue(mNumber);

case tString:
TREE_EVAL2("text: ", EVAL_STR(mText));
QgsDebugMsgLevel("text: " + EVAL_STR(mText), 2);
return QgsSearchTreeValue(mText);

case tColumnRef:
{
TREE_EVAL3("column (", mText, "): ");;
QgsDebugMsgLevel("column (" + mText.lower() + "): ", 2);
// find value for the column
std::vector<QgsFeatureAttribute>::const_iterator it;
for (it = attributes.begin(); it != attributes.end(); it++)
Expand All @@ -349,19 +337,19 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst(const std::vector<QgsFeatureA
QString value = (*it).fieldValue();
if ((*it).isNumeric())
{
TREE_EVAL2(" number: ", value.toDouble());
QgsDebugMsgLevel(" number: " + QString::number(value.toDouble()), 2);
return QgsSearchTreeValue(value.toDouble());
}
else
{
TREE_EVAL2(" text: ", EVAL_STR(value));
QgsDebugMsgLevel(" text: " + EVAL_STR(value), 2);
return QgsSearchTreeValue(value);
}
}
}

// else report missing column
TREE_EVAL("ERROR");
QgsDebugMsgLevel("ERROR!", 2);
return QgsSearchTreeValue(1, mText);
}

Expand Down Expand Up @@ -424,7 +412,7 @@ int QgsSearchTreeValue::compare(QgsSearchTreeValue& value1, QgsSearchTreeValue&
else
val2 = value2.string().toDouble();

TREE_EVAL4("NUM_COMP: ", val1, " ~ ", val2);
QgsDebugMsgLevel("NUM_COMP: " + QString::number(val1) + " ~ " + QString::number(val2), 2);

if (val1 < val2)
return -1;
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -715,7 +715,7 @@ void QgsOgrProvider::getFeatureAttribute(OGRFeature * ogrFet, QgsFeature * f, in
return;
}

QString fld = fldDef->GetNameRef();
QString fld = mEncoding->toUnicode(fldDef->GetNameRef());
QByteArray cstr(ogrFet->GetFieldAsString(attindex));
bool numeric = attributeFields[attindex].isNumeric();

Expand All @@ -730,7 +730,7 @@ void QgsOgrProvider::getFeatureAttributes(OGRFeature *ogrFet, QgsFeature *f){
getFeatureAttribute(ogrFet,f,i);
// add the feature attributes to the tree
/*OGRFieldDefn *fldDef = ogrFet->GetFieldDefnRef(i);
QString fld = fldDef->GetNameRef();
QString fld = mEncoding->toUnicode(fldDef->GetNameRef());
// OGRFieldType fldType = fldDef->GetType();
QString val;
Expand Down Expand Up @@ -1149,7 +1149,7 @@ bool QgsOgrProvider::changeAttributeValues(std::map<int,std::map<QString,QString
for ( int f = 0; f < fc; f++ ) {
OGRFieldDefn *fd = of->GetFieldDefnRef ( f );

if ( name.compare( fd->GetNameRef() ) == 0 ) {
if ( name.compare( mEncoding->toUnicode(fd->GetNameRef()) ) == 0 ) {
OGRFieldType type = fd->GetType();
switch ( type ) {
case OFTInteger:
Expand Down

0 comments on commit 98497bd

Please sign in to comment.