8 changes: 5 additions & 3 deletions src/core/qgsexpressionlexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "qgsexpression.h"
#include "qgsexpressionparser.hpp"
#include <QRegExp>

#include <QLocale>

// if not defined, searches for isatty()
// which doesn't in MSVC compiler
Expand Down Expand Up @@ -85,6 +85,8 @@ static QString stripColumnRef(QString text)
return text;
}

// C locale for correct parsing of numbers even if the system locale is different
static QLocale cLocale("C");

%}

Expand Down Expand Up @@ -150,8 +152,8 @@ string "'"{str_char}*"'"
"," { return COMMA; }
{num_float} { exp_lval.numberFloat = atof(yytext); return NUMBER_FLOAT; }
{num_int} { exp_lval.numberInt = atoi(yytext); return NUMBER_INT; }
{num_float} { exp_lval.numberFloat = cLocale.toDouble( QString::fromAscii(yytext) ); return NUMBER_FLOAT; }
{num_int} { exp_lval.numberInt = cLocale.toInt( QString::fromAscii(yytext), 0, 10); return NUMBER_INT; }
{string} { TEXT_FILTER(stripText); return STRING; }
Expand Down
22 changes: 17 additions & 5 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
// support for context menu (now handled generically)
connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );

connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) );

connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );

connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) );

currentRuleChanged();
}

QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget()
Expand Down Expand Up @@ -155,13 +159,21 @@ void QgsRuleBasedRendererV2Widget::editRule( const QModelIndex& index )
void QgsRuleBasedRendererV2Widget::removeRule()
{
QItemSelection sel = viewRules->selectionModel()->selection();
QgsDebugMsg( QString("REMOVE RULES!!! ranges: %1").arg( sel.count()) );
QgsDebugMsg( QString( "REMOVE RULES!!! ranges: %1" ).arg( sel.count() ) );
foreach( QItemSelectionRange range, sel )
{
QgsDebugMsg( QString( "RANGE: r %1 - %2").arg(range.top()).arg(range.bottom()) );
QgsDebugMsg( QString( "RANGE: r %1 - %2" ).arg( range.top() ).arg( range.bottom() ) );
if ( range.isValid() )
mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
}
// make sure that the selection is gone
viewRules->selectionModel()->clear();
}

void QgsRuleBasedRendererV2Widget::currentRuleChanged( const QModelIndex& current, const QModelIndex& previous )
{
Q_UNUSED( previous );
btnRefineRule->setEnabled( current.isValid() );
}


Expand Down Expand Up @@ -189,8 +201,8 @@ void QgsRuleBasedRendererV2Widget::refineRule( int type )

// TODO: set initial rule's symbol to NULL (?)

// update model
//mModel->updateRule( index.parent(), index.row() );
// show the newly added rules
viewRules->expand( index );
}

void QgsRuleBasedRendererV2Widget::refineRuleCategories()
Expand Down Expand Up @@ -477,7 +489,7 @@ Qt::ItemFlags QgsRuleBasedRendererV2Model::flags( const QModelIndex &index ) con
return Qt::ItemIsDropEnabled;

// allow drop only at first column
Qt::ItemFlag drop = (index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags);
Qt::ItemFlag drop = ( index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );

return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
Qt::ItemIsEditable |
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv

void setRenderingOrder();

void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );

protected:

void refineRule( int type );
Expand Down
19 changes: 19 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ class TestQgsExpression: public QObject
QCOMPARE( !exp.hasParserError(), valid );
}

void parsing_with_locale()
{
// check that parsing of numbers works correctly even when using some other locale

char* old_locale = setlocale(LC_NUMERIC, NULL);
qDebug("Old locale: %s", old_locale);
setlocale(LC_NUMERIC, "de_DE.UTF8");
char* new_locale = setlocale(LC_NUMERIC, NULL);
qDebug("New locale: %s", new_locale);

QgsExpression exp( "1.23 + 4.56" );
QVERIFY( !exp.hasParserError() );

setlocale(LC_NUMERIC, "");

QVariant v = exp.evaluate();
QCOMPARE( v.toDouble(), 5.79 );
}

void evaluation_data()
{
QTest::addColumn<QString>( "string" );
Expand Down