Spreadsheet: Replaced own Expression classed by the ones in App.

This commit is contained in:
Eivind Kvedalen 2015-09-19 21:37:09 +02:00 committed by wmayer
parent 67800ec8c4
commit 4d5646fa5d
16 changed files with 694 additions and 2490 deletions

View File

@ -37,15 +37,7 @@ void SpreadsheetExport initSpreadsheet() {
Spreadsheet::PropertySheet::init();
Spreadsheet::Sheet::init();
Spreadsheet::Expression::init();
Spreadsheet::UnitExpression::init();
Spreadsheet::NumberExpression::init();
Spreadsheet::ConstantExpression::init();
Spreadsheet::FunctionExpression::init();
Spreadsheet::OperatorExpression::init();
Spreadsheet::VariableExpression::init();
Spreadsheet::ConditionalExpression::init();
Spreadsheet::StringExpression::init();
Spreadsheet::AggregateFunctionExpression::init();
Spreadsheet::RangeExpression::init();
return;

View File

@ -147,7 +147,7 @@ Cell::~Cell()
*
*/
void Cell::setExpression(Expression *expr)
void Cell::setExpression(App::Expression *expr)
{
PropertySheet::Signaller signaller(*owner);
@ -170,7 +170,7 @@ void Cell::setExpression(Expression *expr)
*
*/
const Expression *Cell::getExpression() const
const App::Expression *Cell::getExpression() const
{
return expression;
}
@ -183,8 +183,8 @@ const Expression *Cell::getExpression() const
bool Cell::getStringContent(std::string & s) const
{
if (expression) {
if (freecad_dynamic_cast<StringExpression>(expression)) {
s = static_cast<StringExpression*>(expression)->getText();
if (freecad_dynamic_cast<App::StringExpression>(expression)) {
s = static_cast<App::StringExpression*>(expression)->getText();
char * end;
errno = 0;
double d = strtod(s.c_str(), &end);
@ -192,9 +192,9 @@ bool Cell::getStringContent(std::string & s) const
if (!*end && errno == 0)
s = "'" + s;
}
else if (freecad_dynamic_cast<ConstantExpression>(expression))
else if (freecad_dynamic_cast<App::ConstantExpression>(expression))
s = "=" + expression->toString();
else if (freecad_dynamic_cast<NumberExpression>(expression))
else if (freecad_dynamic_cast<App::NumberExpression>(expression))
s = expression->toString();
else
s = "=" + expression->toString();
@ -210,28 +210,28 @@ bool Cell::getStringContent(std::string & s) const
void Cell::setContent(const char * value)
{
PropertySheet::Signaller signaller(*owner);
Expression * expr = 0;
App::Expression * expr = 0;
setUsed(PARSE_EXCEPTION_SET, false);
if (value != 0) {
if (*value == '=') {
try {
expr = ExpressionParser::parse(owner->sheet(), value + 1);
expr = Spreadsheet::ExpressionParser::parse(owner->sheet(), value + 1);
}
catch (Base::Exception & e) {
QString msg = QString::fromUtf8("ERR: %1").arg(QString::fromUtf8(e.what()));
expr = new StringExpression(owner->sheet(), value);
expr = new App::StringExpression(owner->sheet(), value);
setUsed(PARSE_EXCEPTION_SET);
}
}
else if (*value == '\'')
expr = new StringExpression(owner->sheet(), value + 1);
expr = new App::StringExpression(owner->sheet(), value + 1);
else if (*value != '\0') {
char * end;
errno = 0;
double float_value = strtod(value, &end);
if (!*end && errno == 0)
expr = new NumberExpression(owner->sheet(), float_value);
expr = new App::NumberExpression(owner->sheet(), float_value);
else {
try {
expr = ExpressionParser::parse(owner->sheet(), value);
@ -239,7 +239,7 @@ void Cell::setContent(const char * value)
delete expr->eval();
}
catch (Base::Exception &) {
expr = new StringExpression(owner->sheet(), value);
expr = new App::StringExpression(owner->sheet(), value);
}
}
}
@ -365,7 +365,7 @@ void Cell::setDisplayUnit(const std::string &unit)
{
DisplayUnit newDisplayUnit;
if (unit.size() > 0) {
std::auto_ptr<UnitExpression> e(ExpressionParser::parseUnit(owner->sheet(), unit.c_str()));
std::auto_ptr<App::UnitExpression> e(ExpressionParser::parseUnit(owner->sheet(), unit.c_str()));
newDisplayUnit = DisplayUnit(unit, e->getUnit(), e->getScaler());
}
@ -673,7 +673,7 @@ bool Cell::isUsed() const
return used != 0;
}
void Cell::visit(ExpressionVisitor &v)
void Cell::visit(App::ExpressionVisitor &v)
{
if (expression)
expression->visit(v);

View File

@ -35,12 +35,15 @@ class XMLReader;
class Writer;
}
namespace App {
class Expression;
class ExpressionVisitor;
}
namespace Spreadsheet {
class PropertySheet;
class Expression;
class DisplayUnit;
class ExpressionVisitor;
class SpreadsheetExport Cell {
@ -54,7 +57,7 @@ public:
~Cell();
const Expression * getExpression() const;
const App::Expression * getExpression() const;
bool getStringContent(std::string & s) const;
@ -114,7 +117,7 @@ public:
bool spansChanged() const { return isUsed(SPANS_UPDATED); }
void visit(ExpressionVisitor & v);
void visit(App::ExpressionVisitor & v);
CellAddress getAddress() const { return address; }
@ -143,7 +146,7 @@ private:
//void setExpression(const Expression * expr);
void setExpression(Expression *expr);
void setExpression(App::Expression *expr);
void setUsed(int mask, bool state = true);
@ -173,7 +176,7 @@ private:
PropertySheet * owner;
int used;
Expression * expression;
App::Expression * expression;
int alignment;
std::set<std::string> style;
App::Color foregroundColor;

View File

@ -12,7 +12,7 @@
#define strdup _strdup
#endif
extern std::stack<FunctionExpression::Function> functions; /**< Function identifier */
extern std::stack<App::FunctionExpression::Function> functions; /**< Function identifier */
%}
@ -239,9 +239,9 @@ EXPO [eE][-+]?[0-9]+
"rad" yylval.quantity.scaler = Quantity::Radian; yylval.quantity.unitStr = yytext; return UNIT; // radian
"gon" yylval.quantity.scaler = Quantity::Gon; yylval.quantity.unitStr = yytext; return UNIT; // gon
{DIGIT}*"."{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,'.',','); return NUM;
{DIGIT}*","{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,',','.'); return NUM;
{DIGIT}+ yylval.ivalue = strtoll( yytext, NULL, 0 ); return INTEGER;
{DIGIT}*"."{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,'.',','); return yylval.fvalue == 1 ? ONE : NUM;
{DIGIT}*","{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM;
{DIGIT}+ yylval.ivalue = strtoll( yytext, NULL, 0 ); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
"pi" yylval.constant.fvalue = M_PI; yylval.constant.name = "pi"; return CONSTANT; // constant pi
"e" yylval.constant.fvalue = M_E; yylval.constant.name = "e"; return CONSTANT; // constant e
@ -256,7 +256,7 @@ $[A-Za-z]{1,2}{DIGIT}+ yylval.string = yytext; return CELLADDRESS;
while (isspace(s[i]))
--i;
s.erase(i + 1);
std::map<std::string, FunctionExpression::Function>::const_iterator j = registered_functions.find(s);
std::map<std::string, App::FunctionExpression::Function>::const_iterator j = registered_functions.find(s);
if (j != registered_functions.end())
yylval.func = j->second;
else

File diff suppressed because it is too large Load Diff

View File

@ -38,26 +38,27 @@
know about them. */
enum yytokentype {
FUNC = 258,
NUM = 259,
IDENTIFIER = 260,
UNIT = 261,
INTEGER = 262,
CONSTANT = 263,
CELLADDRESS = 264,
EQ = 265,
NEQ = 266,
LT = 267,
GT = 268,
GTE = 269,
LTE = 270,
STRING = 271,
MINUSSIGN = 272,
PROPERTY_REF = 273,
DOCUMENT = 274,
OBJECT = 275,
EXPONENT = 276,
NEG = 277,
POS = 278
ONE = 259,
NUM = 260,
IDENTIFIER = 261,
UNIT = 262,
INTEGER = 263,
CONSTANT = 264,
CELLADDRESS = 265,
EQ = 266,
NEQ = 267,
LT = 268,
GT = 269,
GTE = 270,
LTE = 271,
STRING = 272,
MINUSSIGN = 273,
PROPERTY_REF = 274,
DOCUMENT = 275,
OBJECT = 276,
EXPONENT = 277,
NEG = 278,
POS = 279
};
#endif

View File

@ -6,29 +6,7 @@
%{
class semantic_type {
public:
struct {
Quantity scaler;
std::string unitStr;
} quantity;
Expression * expr;
Path path;
std::deque<Path::Component> components;
int ivalue;
double fvalue;
struct {
std::string name;
double fvalue;
} constant;
std::vector<Expression*> arguments;
std::string string;
FunctionExpression::Function func;
Path::String string_or_identifier;
semantic_type() {}
};
#define YYSTYPE semantic_type
#define YYSTYPE App::ExpressionParser::semantic_type
std::stack<FunctionExpression::Function> functions; /**< Function identifier */
@ -39,6 +17,7 @@ std::stack<FunctionExpression::Function> functions; /**< Function
/* Bison declarations. */
%token FUNC
%token ONE
%token NUM
%token IDENTIFIER
%token UNIT
@ -55,15 +34,19 @@ std::stack<FunctionExpression::Function> functions; /**< Function
%type <string> STRING IDENTIFIER CELLADDRESS
%type <ivalue> INTEGER
%type <string> PROPERTY_REF
%type <fvalue> ONE
%type <fvalue> NUM
%type <constant> CONSTANT
%type <expr> num
%type <expr> basic_num
%type <expr> range
%type <path> identifier
%type <components> path
%type <components> path subpath
%type <func> FUNC
%type <string_or_identifier> document
%type <string_or_identifier> object
%type <ivalue> integer
%left ONE
%left NUM
%left INTEGER
%left CONSTANT
@ -98,15 +81,18 @@ exp: num { $$ = $1;
| exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); }
| exp '^' exp %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, $3); }
| '(' exp ')' { $$ = $2; }
| FUNC args ')' { $$ = new FunctionExpression(DocumentObject, $1, $2); }
| FUNC args ')' { $$ = new AggregateFunctionExpression(DocumentObject, $1, $2); }
| cond '?' exp ':' exp { $$ = new ConditionalExpression(DocumentObject, $1, $3, $5); }
;
num: NUM { $$ = new NumberExpression(DocumentObject, $1); }
| INTEGER { $$ = new NumberExpression(DocumentObject, (double)$1); }
| CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, $1.fvalue); }
| NUM unit_exp %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, $1), OperatorExpression::UNIT, $2); }
| INTEGER unit_exp { $$ = new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, (double)$1), OperatorExpression::UNIT, $2); }
basic_num: ONE { $$ = new NumberExpression(DocumentObject, $1); }
| NUM { $$ = new NumberExpression(DocumentObject, $1); }
| INTEGER { $$ = new NumberExpression(DocumentObject, (double)$1); }
;
num: basic_num { $$ = $1; }
| CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, $1.fvalue); }
| basic_num unit_exp %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2); }
| CONSTANT unit_exp { $$ = new OperatorExpression(DocumentObject, new ConstantExpression(DocumentObject, $1.name, $1.fvalue), OperatorExpression::UNIT, $2); }
;
@ -130,52 +116,71 @@ cond: exp EQ exp { $$ = new OperatorExpression(Do
| exp LTE exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::LTE, $3); }
;
unit_exp: UNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); }
| unit_exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); }
| unit_exp '*' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); }
| unit_exp '^' exp %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, $3); }
| '(' unit_exp ')' { $$ = $2; }
unit_exp: UNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); }
| ONE '/' unit_exp { $$ = new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, $1), OperatorExpression::DIV, $3); }
| unit_exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); }
| unit_exp '*' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); }
| unit_exp '^' basic_num %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, $3); }
| unit_exp '^' MINUSSIGN basic_num %prec EXPONENT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new OperatorExpression(DocumentObject, $4, OperatorExpression::NEG, new NumberExpression(DocumentObject, -1))); }
| '(' unit_exp ')' { $$ = $2; }
;
identifier: path { /* Path to property within document object */
$$ = Path(DocumentObject);
$$ = ObjectIdentifier(DocumentObject);
$$.addComponents($1);
}
| object '.' path { /* Path to property within document object */
$$ = Path(DocumentObject);
$$ = ObjectIdentifier(DocumentObject);
$$.setDocumentObjectName($1, true);
$$.addComponents($3);
}
| document '#' path { /* Path to property from an external document, within a named document object */
$$ = Path(DocumentObject);
$$ = ObjectIdentifier(DocumentObject);
$$.setDocumentName($1, true);
$$.addComponents($3);
}
| document '#' object '.' path { /* Path to property from an external document, within a named document object */
$$ = Path(DocumentObject);
$$ = ObjectIdentifier(DocumentObject);
$$.setDocumentName($1, true);
$$.setDocumentObjectName($3, true);
$$.addComponents($5);
}
;
path: IDENTIFIER { $$.push_front(Path::Component::SimpleComponent($1)); }
| CELLADDRESS { $$.push_front(Path::Component::SimpleComponent($1)); }
| IDENTIFIER '[' INTEGER ']' { $$.push_front(Path::Component::ArrayComponent($1, $3)); }
| IDENTIFIER '[' INTEGER ']' '.' path { $6.push_front(Path::Component::ArrayComponent($1, $3)); $$ = $6; }
| IDENTIFIER '[' STRING ']' { $$.push_front(Path::Component::MapComponent($1, Path::String($3, true))); }
| IDENTIFIER '[' IDENTIFIER ']' { $$.push_front(Path::Component::MapComponent($1, $3)); }
| IDENTIFIER '[' STRING ']' '.' path { $6.push_front(Path::Component::MapComponent($1, Path::String($3, true))); $$ = $6; }
| IDENTIFIER '[' IDENTIFIER ']' '.' path { $6.push_front(Path::Component::MapComponent($1, $3)); $$ = $6; }
| IDENTIFIER '.' path { $3.push_front(Path::Component::SimpleComponent($1)); $$ = $3; }
integer: INTEGER { $$ = $1; }
| ONE { $$ = $1; }
;
path: IDENTIFIER { $$.push_front(ObjectIdentifier::Component::SimpleComponent($1)); }
| CELLADDRESS { $$.push_front(ObjectIdentifier::Component::SimpleComponent($1)); }
| IDENTIFIER '[' integer ']' { $$.push_front(ObjectIdentifier::Component::ArrayComponent($1, $3)); }
| IDENTIFIER '[' integer ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::ArrayComponent($1, $3)); $$ = $6; }
| IDENTIFIER '[' STRING ']' { $$.push_front(ObjectIdentifier::Component::MapComponent($1, ObjectIdentifier::String($3, true))); }
| IDENTIFIER '[' IDENTIFIER ']' { $$.push_front(ObjectIdentifier::Component::MapComponent($1, $3)); }
| IDENTIFIER '[' STRING ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::MapComponent($1, ObjectIdentifier::String($3, true))); $$ = $6; }
| IDENTIFIER '[' IDENTIFIER ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::MapComponent($1, $3)); $$ = $6; }
| IDENTIFIER '.' subpath { $3.push_front(ObjectIdentifier::Component::SimpleComponent($1)); $$ = $3; }
;
document: STRING { $$ = Path::String($1, true); }
| IDENTIFIER { $$ = Path::String($1); }
subpath: IDENTIFIER { $$.push_front(ObjectIdentifier::Component::SimpleComponent($1)); }
| STRING { $$.push_front(ObjectIdentifier::Component::SimpleComponent($1)); }
| CELLADDRESS { $$.push_front(ObjectIdentifier::Component::SimpleComponent($1)); }
| IDENTIFIER '[' integer ']' { $$.push_front(ObjectIdentifier::Component::ArrayComponent($1, $3)); }
| IDENTIFIER '[' integer ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::ArrayComponent($1, $3)); $$ = $6; }
| IDENTIFIER '[' STRING ']' { $$.push_front(ObjectIdentifier::Component::MapComponent($1, ObjectIdentifier::String($3, true))); }
| IDENTIFIER '[' IDENTIFIER ']' { $$.push_front(ObjectIdentifier::Component::MapComponent($1, $3)); }
| IDENTIFIER '[' STRING ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::MapComponent($1, ObjectIdentifier::String($3, true))); $$ = $6; }
| IDENTIFIER '[' IDENTIFIER ']' '.' subpath { $6.push_front(ObjectIdentifier::Component::MapComponent($1, $3)); $$ = $6; }
| IDENTIFIER '.' subpath { $3.push_front(ObjectIdentifier::Component::SimpleComponent($1)); $$ = $3; }
;
document: STRING { $$ = ObjectIdentifier::String($1, true); }
| IDENTIFIER { $$ = ObjectIdentifier::String($1); }
;
object: STRING { $$ = Path::String($1, true); }
| CELLADDRESS { $$ = Path::String($1, true); }
object: STRING { $$ = ObjectIdentifier::String($1, true); }
| CELLADDRESS { $$ = ObjectIdentifier::String($1, true); }
;
%%

View File

@ -42,22 +42,12 @@
#include "Utils.h"
#include <PropertySheetPy.h>
using namespace App;
using namespace Base;
using namespace Spreadsheet;
namespace Spreadsheet {
class ResolveExpressionVisitor : public ExpressionVisitor {
public:
void visit(Expression * node) {
VariableExpression *expr = freecad_dynamic_cast<VariableExpression>(node);
if (expr)
expr->resolve();
}
};
class RelabelDocumentObjectExpressionVisitor : public ExpressionVisitor {
public:
@ -872,16 +862,12 @@ void PropertySheet::addDependencies(CellAddress key)
if (expression == 0)
return;
std::set<Path> expressionDeps;
// Resolve expression, if any
ResolveExpressionVisitor v;
cell->visit(v);
std::set<ObjectIdentifier> expressionDeps;
// Get dependencies from expression
expression->getDeps(expressionDeps);
std::set<Path>::const_iterator i = expressionDeps.begin();
std::set<ObjectIdentifier>::const_iterator i = expressionDeps.begin();
while (i != expressionDeps.end()) {
const Property * prop = i->getProperty();
const App::DocumentObject * docObj = i->getDocumentObject();

View File

@ -167,12 +167,12 @@ private:
friend class Cell;
/*! Cell data in this property */
std::map<CellAddress, Cell*> data;
/*! Set of cells that have been marked dirty */
std::set<CellAddress> dirty;
/*! Cell data in this property */
std::map<CellAddress, Cell*> data;
/*! Merged cells; cell -> anchor cell */
std::map<CellAddress, CellAddress> mergedCells;

View File

@ -53,6 +53,7 @@
#include <deque>
using namespace Base;
using namespace App;
using namespace Spreadsheet;
PROPERTY_SOURCE(Spreadsheet::Sheet, App::DocumentObject)
@ -75,21 +76,21 @@ typedef Traits::edge_descriptor Edge;
*/
Sheet::Sheet()
: App::DocumentObject()
: DocumentObject()
, props(this)
, cells(this)
{
ADD_PROPERTY_TYPE(docDeps, (0), "Spreadsheet", (App::PropertyType)(App::Prop_Transient|App::Prop_ReadOnly|App::Prop_Hidden), "Dependencies");
ADD_PROPERTY_TYPE(cells, (), "Spreadsheet", (App::PropertyType)(App::Prop_ReadOnly|App::Prop_Hidden), "Cell contents");
ADD_PROPERTY_TYPE(columnWidths, (), "Spreadsheet", (App::PropertyType)(App::Prop_ReadOnly|App::Prop_Hidden), "Column widths");
ADD_PROPERTY_TYPE(rowHeights, (), "Spreadsheet", (App::PropertyType)(App::Prop_ReadOnly|App::Prop_Hidden), "Row heights");
ADD_PROPERTY_TYPE(currRow, (0), "Spreadsheet", (App::PropertyType)(App::Prop_ReadOnly|App::Prop_Hidden), "Current row");
ADD_PROPERTY_TYPE(currColumn, (0), "Spreadsheet", (App::PropertyType)(App::Prop_ReadOnly|App::Prop_Hidden), "Current column");
ADD_PROPERTY_TYPE(docDeps, (0), "Spreadsheet", (PropertyType)(Prop_Transient|Prop_ReadOnly|Prop_Hidden), "Dependencies");
ADD_PROPERTY_TYPE(cells, (), "Spreadsheet", (PropertyType)(Prop_ReadOnly|Prop_Hidden), "Cell contents");
ADD_PROPERTY_TYPE(columnWidths, (), "Spreadsheet", (PropertyType)(Prop_ReadOnly|Prop_Hidden), "Column widths");
ADD_PROPERTY_TYPE(rowHeights, (), "Spreadsheet", (PropertyType)(Prop_ReadOnly|Prop_Hidden), "Row heights");
ADD_PROPERTY_TYPE(currRow, (0), "Spreadsheet", (PropertyType)(Prop_ReadOnly|Prop_Hidden), "Current row");
ADD_PROPERTY_TYPE(currColumn, (0), "Spreadsheet", (PropertyType)(Prop_ReadOnly|Prop_Hidden), "Current column");
docDeps.setSize(0);
onRenamedDocumentConnection = App::GetApplication().signalRenameDocument.connect(boost::bind(&Spreadsheet::Sheet::onRenamedDocument, this, _1));
onRelabledDocumentConnection = App::GetApplication().signalRelabelDocument.connect(boost::bind(&Spreadsheet::Sheet::onRelabledDocument, this, _1));
onRenamedDocumentConnection = GetApplication().signalRenameDocument.connect(boost::bind(&Spreadsheet::Sheet::onRenamedDocument, this, _1));
onRelabledDocumentConnection = GetApplication().signalRelabelDocument.connect(boost::bind(&Spreadsheet::Sheet::onRelabledDocument, this, _1));
}
/**
@ -237,7 +238,7 @@ bool Sheet::exportToFile(const std::string &filename, char delimiter, char quote
std::set<CellAddress>::const_iterator i = usedCells.begin();
while (i != usedCells.end()) {
App::Property * prop = getProperty(*i);
Property * prop = getProperty(*i);
if (prevRow != -1 && prevRow != i->row()) {
for (int j = prevRow; j < i->row(); ++j)
@ -251,12 +252,12 @@ bool Sheet::exportToFile(const std::string &filename, char delimiter, char quote
std::stringstream field;
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId())))
field << static_cast<App::PropertyQuantity*>(prop)->getValue();
else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId())))
field << static_cast<App::PropertyFloat*>(prop)->getValue();
else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId())))
field << static_cast<App::PropertyString*>(prop)->getValue();
if (prop->isDerivedFrom((PropertyQuantity::getClassTypeId())))
field << static_cast<PropertyQuantity*>(prop)->getValue();
else if (prop->isDerivedFrom((PropertyFloat::getClassTypeId())))
field << static_cast<PropertyFloat*>(prop)->getValue();
else if (prop->isDerivedFrom((PropertyString::getClassTypeId())))
field << static_cast<PropertyString*>(prop)->getValue();
else
assert(0);
@ -399,7 +400,7 @@ PyObject *Sheet::getPyObject(void)
*
*/
App::Property * Sheet::getProperty(CellAddress key) const
Property * Sheet::getProperty(CellAddress key) const
{
return props.getDynamicPropertyByName(key.toString().c_str());
}
@ -410,7 +411,7 @@ App::Property * Sheet::getProperty(CellAddress key) const
* @return Pointer to property, or 0 if it does not exist.
*/
App::Property * Sheet::getProperty(const char * addr) const
Property * Sheet::getProperty(const char * addr) const
{
return props.getDynamicPropertyByName(addr);
}
@ -421,9 +422,9 @@ App::Property * Sheet::getProperty(const char * addr) const
*
*/
void Sheet::getCellAddress(const App::Property *prop, CellAddress & address)
void Sheet::getCellAddress(const Property *prop, CellAddress & address)
{
std::map<const App::Property*, CellAddress >::const_iterator i = propAddress.find(prop);
std::map<const Property*, CellAddress >::const_iterator i = propAddress.find(prop);
if (i != propAddress.end())
address = i->second;
@ -498,21 +499,21 @@ void Sheet::onSettingDocument()
*
*/
App::Property * Sheet::setFloatProperty(CellAddress key, double value)
Property * Sheet::setFloatProperty(CellAddress key, double value)
{
App::Property * prop = props.getPropertyByName(key.toString().c_str());
App::PropertyFloat * floatProp;
Property * prop = props.getPropertyByName(key.toString().c_str());
PropertyFloat * floatProp;
if (!prop || prop->getTypeId() != App::PropertyFloat::getClassTypeId()) {
if (!prop || prop->getTypeId() != PropertyFloat::getClassTypeId()) {
if (prop) {
props.removeDynamicProperty(key.toString().c_str());
propAddress.erase(prop);
}
floatProp = freecad_dynamic_cast<App::PropertyFloat>(props.addDynamicProperty("App::PropertyFloat", key.toString().c_str(), 0, 0, App::Prop_ReadOnly | App::Prop_Transient, true, true));
floatProp = freecad_dynamic_cast<PropertyFloat>(props.addDynamicProperty("App::PropertyFloat", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true));
floatProp->StatusBits.set(3);
}
else
floatProp = static_cast<App::PropertyFloat*>(prop);
floatProp = static_cast<PropertyFloat*>(prop);
propAddress[floatProp] = key;
floatProp->setValue(value);
@ -530,9 +531,9 @@ App::Property * Sheet::setFloatProperty(CellAddress key, double value)
*
*/
App::Property * Sheet::setQuantityProperty(CellAddress key, double value, const Base::Unit & unit)
Property * Sheet::setQuantityProperty(CellAddress key, double value, const Base::Unit & unit)
{
App::Property * prop = props.getPropertyByName(key.toString().c_str());
Property * prop = props.getPropertyByName(key.toString().c_str());
PropertySpreadsheetQuantity * quantityProp;
if (!prop || prop->getTypeId() != PropertySpreadsheetQuantity::getClassTypeId()) {
@ -540,7 +541,7 @@ App::Property * Sheet::setQuantityProperty(CellAddress key, double value, const
props.removeDynamicProperty(key.toString().c_str());
propAddress.erase(prop);
}
App::Property * p = props.addDynamicProperty("Spreadsheet::PropertySpreadsheetQuantity", key.toString().c_str(), 0, 0, App::Prop_ReadOnly | App::Prop_Transient, true, true);
Property * p = props.addDynamicProperty("Spreadsheet::PropertySpreadsheetQuantity", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true);
quantityProp = freecad_dynamic_cast<PropertySpreadsheetQuantity>(p);
quantityProp->StatusBits.set(3);
}
@ -565,17 +566,17 @@ App::Property * Sheet::setQuantityProperty(CellAddress key, double value, const
*
*/
App::Property * Sheet::setStringProperty(CellAddress key, const std::string & value)
Property * Sheet::setStringProperty(CellAddress key, const std::string & value)
{
App::Property * prop = props.getPropertyByName(key.toString().c_str());
App::PropertyString * stringProp = freecad_dynamic_cast<App::PropertyString>(prop);
Property * prop = props.getPropertyByName(key.toString().c_str());
PropertyString * stringProp = freecad_dynamic_cast<PropertyString>(prop);
if (!stringProp) {
if (prop) {
props.removeDynamicProperty(key.toString().c_str());
propAddress.erase(prop);
}
stringProp = freecad_dynamic_cast<App::PropertyString>(props.addDynamicProperty("App::PropertyString", key.toString().c_str(), 0, 0, App::Prop_ReadOnly | App::Prop_Transient, true, true));
stringProp = freecad_dynamic_cast<PropertyString>(props.addDynamicProperty("App::PropertyString", key.toString().c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true));
stringProp->StatusBits.set(3);
}
@ -593,7 +594,7 @@ App::Property * Sheet::setStringProperty(CellAddress key, const std::string & va
void Sheet::updateAlias(CellAddress key)
{
std::string alias;
App::Property * prop = props.getDynamicPropertyByName(key.toString().c_str());
Property * prop = props.getDynamicPropertyByName(key.toString().c_str());
if (!prop)
return;
@ -601,7 +602,7 @@ void Sheet::updateAlias(CellAddress key)
Cell * cell = getCell(key);
if (cell && cell->getAlias(alias)) {
App::Property * aliasProp = props.getDynamicPropertyByName(alias.c_str());
Property * aliasProp = props.getDynamicPropertyByName(alias.c_str());
/* Update or create alias? */
if (aliasProp) {
@ -613,7 +614,7 @@ void Sheet::updateAlias(CellAddress key)
}
if (!aliasProp)
aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, App::Prop_ReadOnly | App::Prop_Transient, true, true);
aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true);
aliasProp->Paste(*prop);
}
@ -674,9 +675,9 @@ void Sheet::updateProperty(CellAddress key)
*
*/
App::Property *Sheet::getPropertyByName(const char* name) const
Property *Sheet::getPropertyByName(const char* name) const
{
App::Property * prop = getProperty(name);
Property * prop = getProperty(name);
if (prop)
return prop;
@ -690,7 +691,7 @@ App::Property *Sheet::getPropertyByName(const char* name) const
* @return Pointer to string.
*/
const char *Sheet::getPropertyName(const App::Property *prop) const
const char *Sheet::getPropertyName(const Property *prop) const
{
const char * name = props.getPropertyName(prop);
@ -743,7 +744,7 @@ void Sheet::recomputeCell(CellAddress p)
*
*/
App::DocumentObjectExecReturn *Sheet::execute(void)
DocumentObjectExecReturn *Sheet::execute(void)
{
// Remove all aliases first
removeAliases();
@ -852,20 +853,20 @@ App::DocumentObjectExecReturn *Sheet::execute(void)
currRow.purgeTouched();
currColumn.purgeTouched();
std::set<App::DocumentObject*> ds(cells.getDocDeps());
std::set<DocumentObject*> ds(cells.getDocDeps());
// Make sure we don't reference ourselves
ds.erase(this);
std::vector<App::DocumentObject*> dv(ds.begin(), ds.end());
std::vector<DocumentObject*> dv(ds.begin(), ds.end());
docDeps.setValues(dv);
purgeTouched();
if (cellErrors.size() == 0)
return App::DocumentObject::StdReturn;
return DocumentObject::StdReturn;
else
return new App::DocumentObjectExecReturn("One or more cells failed contains errors.", this);
return new DocumentObjectExecReturn("One or more cells failed contains errors.", this);
}
/**
@ -899,7 +900,7 @@ void Sheet::clear(CellAddress address, bool all)
{
Cell * cell = getCell(address);
std::string addr = address.toString();
App::Property * prop = props.getDynamicPropertyByName(addr.c_str());
Property * prop = props.getDynamicPropertyByName(addr.c_str());
// Remove alias, if defined
std::string aliasStr;
@ -909,12 +910,12 @@ void Sheet::clear(CellAddress address, bool all)
cells.clear(address);
// Update dependencies
std::set<App::DocumentObject*> ds(cells.getDocDeps());
std::set<DocumentObject*> ds(cells.getDocDeps());
// Make sure we don't reference ourselves
ds.erase(this);
std::vector<App::DocumentObject*> dv(ds.begin(), ds.end());
std::vector<DocumentObject*> dv(ds.begin(), ds.end());
docDeps.setValues(dv);
propAddress.erase(prop);
@ -1105,7 +1106,7 @@ void Sheet::setStyle(CellAddress address, const std::set<std::string> &style)
* @param color New color
*/
void Sheet::setForeground(CellAddress address, const App::Color &color)
void Sheet::setForeground(CellAddress address, const Color &color)
{
cells.setForeground(address, color);
}
@ -1116,7 +1117,7 @@ void Sheet::setForeground(CellAddress address, const App::Color &color)
* @param color New color
*/
void Sheet::setBackground(CellAddress address, const App::Color &color)
void Sheet::setBackground(CellAddress address, const Color &color)
{
cells.setBackground(address, color);
}
@ -1182,7 +1183,7 @@ void Sheet::moveCell(CellAddress currPos, CellAddress newPos)
* @param docObj Renamed document object.
*/
void Sheet::renamedDocumentObject(const App::DocumentObject * docObj)
void Sheet::renamedDocumentObject(const DocumentObject * docObj)
{
cells.renamedDocumentObject(docObj);
cells.touch();
@ -1252,7 +1253,7 @@ void Sheet::onDocumentRestored()
* @param document Relabelled document.
*/
void Sheet::onRelabledDocument(const App::Document &document)
void Sheet::onRelabledDocument(const Document &document)
{
cells.renamedDocument(&document);
cells.purgeTouched();
@ -1263,7 +1264,7 @@ void Sheet::onRelabledDocument(const App::Document &document)
* @param document
*/
void Sheet::onRenamedDocument(const App::Document &document)
void Sheet::onRenamedDocument(const Document &document)
{
}
@ -1272,7 +1273,7 @@ void Sheet::onRenamedDocument(const App::Document &document)
* @param document document to observer.
*/
void Sheet::observeDocument(App::Document * document)
void Sheet::observeDocument(Document * document)
{
ObserverMap::const_iterator it = observers.find(document->getName());
@ -1290,7 +1291,7 @@ void Sheet::observeDocument(App::Document * document)
TYPESYSTEM_SOURCE(Spreadsheet::PropertySpreadsheetQuantity, App::PropertyQuantity);
App::Property *PropertySpreadsheetQuantity::Copy() const
Property *PropertySpreadsheetQuantity::Copy() const
{
PropertySpreadsheetQuantity * obj = new PropertySpreadsheetQuantity();

View File

@ -48,7 +48,6 @@ namespace Spreadsheet
class Sheet;
class Cell;
class Expression;
class Range;
class SheetObserver;

View File

@ -41,7 +41,7 @@ public:
App::Document* getDocument() const { return App::DocumentObserver::getDocument(); }
private:
std::set<std::string> isUpdating;
int refCount;
unsigned int refCount;
PropertySheet * sheet;
};

File diff suppressed because it is too large Load Diff

View File

@ -35,318 +35,7 @@
namespace Spreadsheet {
class Expression;
class SpreadsheetExport ExpressionVisitor {
public:
virtual ~ExpressionVisitor() {}
virtual void visit(Expression * e) = 0;
};
class SpreadsheetExport Path {
public:
class String {
public:
String(const std::string & s = "", bool _isRealString = false) : str(s), isString(_isRealString) { }
std::string getString() const { return str; }
operator std::string() const { return str; }
operator const char *() const { return str.c_str(); }
bool operator==(const String & other) const { return str == other.str; }
bool operator!=(const String & other) const { return str != other.str; }
bool operator>=(const String & other) const { return str >= other.str; }
bool operator<(const String & other) const { return str < other.str; }
bool operator>(const String & other) const { return str > other.str; }
std::string toString() const;
bool isRealString() const { return isString; }
std::string str;
bool isString;
};
struct SpreadsheetExport Component {
enum typeEnum {
SIMPLE,
MAP,
ARRAY
} ;
std::string component;
typeEnum type;
int index;
String key;
bool keyIsString;
Component(const std::string & _component, typeEnum _type = SIMPLE, int _index = -1, String _key = String());
static Component SimpleComponent(const std::string & _component);
static Component ArrayComponent(const std::string & _component, int _index);
static Component MapComponent(const std::string & _component, const String &_key);
bool operator==(const Component & other) const;
bool isSimple() const { return type == SIMPLE; }
bool isMap() const { return type == MAP; }
bool isArray() const { return type == ARRAY; }
std::string toString() const;
};
Path(const App::DocumentObject * _owner = 0, const std::string & property = std::string());
void addComponent(const Component &c) { components.push_back(c); resolve(); }
template<typename C>
void addComponents(const C &cs) { components.insert(components.end(), cs.begin(), cs.end()); resolve(); }
void setDocumentName(const String & name, bool force = false) { documentName = name; documentNameSet = force; }
const String getDocumentName() const { return documentName; }
void setDocumentObjectName(const String & name, bool force = false) { documentObjectName = name; documentObjectNameSet = force; }
const String getDocumentObjectName() const { return documentObjectName; }
const std::string & getPropertyName() const { return components[propertyIndex].component; }
const Component & getPropertyComponent(std::size_t i) const { assert(i < components.size()); return components[propertyIndex + i]; }
std::string getSubPathStr() const;
bool operator==(const Path & other) const;
bool operator!=(const Path & other) const { return !(operator==)(other); }
bool operator<(const Path &other) const;
int numComponents() const;
static Path parse(const App::DocumentObject * _owner, const char * expr);
virtual std::string toString() const;
void resolve();
void resetResolve();
const App::Property *getProperty() const;
std::string getPythonAccessor() const;
void renameDocumentObject(const std::string & oldName, const std::string & newName);
void renameDocument(const std::string &oldName, const std::string &newName);
App::Document *getDocument() const;
const App::DocumentObject *getDocumentObject() const;
protected:
const App::DocumentObject *getDocumentObject(const App::Document *doc, const std::string &name) const;
const App::DocumentObject * owner;
mutable int propertyIndex;
String documentName;
bool documentNameSet;
String documentObjectName;
bool documentObjectNameSet;
std::string propertyName;
std::vector<Component> components;
};
/**
* Base class for expressions.
*
*/
class SpreadsheetExport Expression : public Base::BaseClass {
TYPESYSTEM_HEADER();
public:
Expression(const App::DocumentObject * _owner);
virtual ~Expression();
virtual bool isTouched() const { return false; }
virtual Expression * eval() const = 0;
virtual std::string toString() const = 0;
static Expression * parse(const App::DocumentObject * owner, const std::string& buffer);
virtual Expression * copy() const = 0;
virtual int priority() const { return 0; }
virtual void getDeps(std::set<Path> &props) const { }
virtual Expression * simplify() const = 0;
virtual void visit(ExpressionVisitor & v) { v.visit(this); }
class Exception : public Base::Exception {
public:
Exception(const char *sMessage) : Base::Exception(sMessage) { }
};
const App::DocumentObject * getOwner() const { return owner; }
protected:
const App::DocumentObject * owner; /**< The document object used to access unqualified variables (i.e local scope) */
};
/**
* Part of an expressions that contains a unit.
*
*/
class SpreadsheetExport UnitExpression : public Expression {
TYPESYSTEM_HEADER();
public:
UnitExpression(const App::DocumentObject *_owner = 0, const Base::Quantity & _quantity = Base::Quantity(), const std::string & _unitStr = std::string());
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual std::string toString() const;
virtual Expression * copy() const;
virtual int priority() const { return 20; }
void setUnit(const Base::Quantity &_quantity);
double getValue() const { return quantity.getValue(); }
const Base::Unit & getUnit() const { return quantity.getUnit(); }
const Base::Quantity & getQuantity() const { return quantity; }
const std::string getUnitString() const { return unitStr; }
double getScaler() const { return quantity.getValue(); }
protected:
Base::Quantity quantity;
std::string unitStr; /**< The unit string from the original parsed string */
};
/**
* Class implementing a number with an optional unit
*/
class SpreadsheetExport NumberExpression : public UnitExpression {
TYPESYSTEM_HEADER();
public:
NumberExpression(const App::DocumentObject *_owner = 0, const Base::Quantity & quantity = Base::Quantity());
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual Expression * copy() const;
virtual int priority() const { return 20; }
void negate();
virtual std::string toString() const;
protected:
};
class SpreadsheetExport ConstantExpression : public NumberExpression {
TYPESYSTEM_HEADER();
public:
ConstantExpression(const App::DocumentObject *_owner = 0, std::string _name = "", const Base::Quantity &_quantity = Base::Quantity());
virtual std::string toString() const;
virtual Expression * copy() const;
virtual int priority() const { return 20; }
std::string getName() const { return name; }
protected:
std::string name; /**< Constant's name */
};
/**
* Class implementing an infix expression.
*
*/
class SpreadsheetExport OperatorExpression : public UnitExpression {
TYPESYSTEM_HEADER();
public:
enum Operator {
NONE,
ADD,
SUB,
MUL,
DIV,
POW,
EQ,
NEQ,
LT,
GT,
LTE,
GTE,
UNIT,
NEG,
POS
};
OperatorExpression(const App::DocumentObject *_owner = 0, Expression * _left = 0, Operator _op = NONE, Expression * _right = 0);
virtual ~OperatorExpression();
virtual bool isTouched() const;
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual std::string toString() const;
virtual Expression * copy() const;
virtual int priority() const;
virtual void getDeps(std::set<Path> &props) const;
virtual void visit(ExpressionVisitor & v);
protected:
Operator op; /**< Operator working on left and right */
Expression * left; /**< Left operand */
Expression * right; /**< Right operand */
};
class SpreadsheetExport RangeExpression : public Expression {
class SpreadsheetExport RangeExpression : public App::Expression {
TYPESYSTEM_HEADER();
public:
RangeExpression(const App::DocumentObject * _owner = 0, const std::string & begin = std::string(), const std::string & end = std::string());
@ -363,9 +52,9 @@ public:
virtual int priority() const { return 20; }
virtual void getDeps(std::set<Path> &props) const;
virtual void getDeps(std::set<App::ObjectIdentifier> &props) const;
virtual Expression * simplify() const;
virtual App::Expression * simplify() const;
Range getRange() const { return range; }
@ -375,68 +64,19 @@ protected:
Range range;
};
class SpreadsheetExport ConditionalExpression : public Expression {
TYPESYSTEM_HEADER();
public:
ConditionalExpression(const App::DocumentObject *_owner = 0, Expression * _condition = 0,Expression * _trueExpr = 0, Expression * _falseExpr = 0);
virtual ~ConditionalExpression();
virtual bool isTouched() const;
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual std::string toString() const;
virtual Expression * copy() const;
virtual int priority() const;
virtual void getDeps(std::set<Path> &props) const;
virtual void visit(ExpressionVisitor & v);
protected:
Expression * condition; /**< Condition */
Expression * trueExpr; /**< Expression if abs(condition) is > 0.5 */
Expression * falseExpr; /**< Expression if abs(condition) is < 0.5 */
};
/**
* Class implementing various functions, e.g sin, cos, etc.
*
*/
class SpreadsheetExport FunctionExpression : public UnitExpression {
class SpreadsheetExport AggregateFunctionExpression : public App::FunctionExpression {
TYPESYSTEM_HEADER();
public:
enum Function {
NONE,
// Normal functions taking one or two arguments
ACOS,
ASIN,
ATAN,
ABS,
EXP,
LOG,
LOG10,
SIN,
SINH,
TAN,
TANH,
SQRT,
COS,
COSH,
ATAN2,
MOD,
POW,
// Aggregates
SUM,
SUM = App::FunctionExpression::LAST,
AVERAGE,
STDDEV,
COUNT,
@ -444,110 +84,21 @@ public:
MAX
};
FunctionExpression(const App::DocumentObject *_owner = 0, Function _f = NONE, std::vector<Expression *> _args = std::vector<Expression*>());
AggregateFunctionExpression(const App::DocumentObject *_owner = 0,
App::FunctionExpression::Function _f = App::FunctionExpression::NONE,
std::vector<Expression *> _args = std::vector<Expression*>());
virtual ~FunctionExpression();
virtual ~AggregateFunctionExpression();
virtual bool isTouched() const;
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual App::Expression * eval() const;
virtual std::string toString() const;
virtual Expression * copy() const;
virtual int priority() const { return 20; }
virtual void getDeps(std::set<Path> &props) const;
virtual void visit(ExpressionVisitor & v);
protected:
Function f; /**< Function to execute */
std::vector<Expression *> args; /** Arguments to function*/
};
/**
* Class implementing a reference to a property. If the name is unqualified,
* the owner of the expression is searched. If it is qualified, the document
* that contains the owning document object is searched for other document
* objects to search. Both labels and internal document names are searched.
*
*/
class SpreadsheetExport VariableExpression : public UnitExpression {
TYPESYSTEM_HEADER();
public:
VariableExpression(const App::DocumentObject *_owner = 0, Path _var = Path());
~VariableExpression();
virtual bool isTouched() const;
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual std::string toString() const { return var.toString(); }
virtual Expression * copy() const;
virtual int priority() const { return 20; }
virtual void getDeps(std::set<Path> &props) const;
std::string name() const { return var.getPropertyName(); }
Path getPath() const { return var; }
void setName(const std::string & name) { assert(0); }
void resolve();
void renameDocumentObject(const std::string & oldName, const std::string & newName);
void renameDocument(const std::string &oldName, const std::string &newName);
const App::Property *getProperty() const;
protected:
Path var; /**< Variable name */
};
/**
* Class implementing a string. Used to signal either a genuine string or
* a failed evaluation of an expression.
*/
class SpreadsheetExport StringExpression : public Expression {
TYPESYSTEM_HEADER();
public:
StringExpression(const App::DocumentObject *_owner = 0, const std::string & _text = std::string());
virtual Expression * eval() const;
virtual Expression * simplify() const;
virtual std::string toString() const;
virtual std::string getText() const { return text; }
virtual int priority() const { return 20; }
virtual Expression * copy() const;
protected:
std::string text; /**< Text string */
};
namespace ExpressionParser {
SpreadsheetExport Expression * parse(const App::DocumentObject *owner, const char *buffer);
SpreadsheetExport UnitExpression * parseUnit(const App::DocumentObject *owner, const char *buffer);
SpreadsheetExport Path parsePath(const App::DocumentObject *owner, const char* buffer);
SpreadsheetExport App::Expression * parse(const App::DocumentObject *owner, const char *buffer);
SpreadsheetExport App::UnitExpression * parseUnit(const App::DocumentObject *owner, const char *buffer);
SpreadsheetExport App::ObjectIdentifier parsePath(const App::DocumentObject *owner, const char* buffer);
}
}

View File

@ -5607,7 +5607,7 @@ char *ExpressionParsertext;
#define strdup _strdup
#endif
extern std::stack<FunctionExpression::Function> functions; /**< Function identifier */
extern std::stack<App::FunctionExpression::Function> functions; /**< Function identifier */
/*** Flex Declarations and Options ***/
/* change the name of the scanner class. */
@ -6280,17 +6280,17 @@ yylval.quantity.scaler = Quantity::Gon; yylval.quantity.unitStr
case 80:
YY_RULE_SETUP
#line 242 "ExpressionParser.l"
yylval.fvalue = num_change(ExpressionParsertext,'.',','); return NUM;
yylval.fvalue = num_change(ExpressionParsertext,'.',','); return yylval.fvalue == 1 ? ONE : NUM;
YY_BREAK
case 81:
YY_RULE_SETUP
#line 243 "ExpressionParser.l"
yylval.fvalue = num_change(ExpressionParsertext,',','.'); return NUM;
yylval.fvalue = num_change(ExpressionParsertext,',','.'); return yylval.fvalue == 1 ? ONE : NUM;
YY_BREAK
case 82:
YY_RULE_SETUP
#line 244 "ExpressionParser.l"
yylval.ivalue = strtoll( ExpressionParsertext, NULL, 0 ); return INTEGER;
yylval.ivalue = strtoll( ExpressionParsertext, NULL, 0 ); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
YY_BREAK
case 83:
YY_RULE_SETUP
@ -6326,7 +6326,7 @@ YY_RULE_SETUP
while (isspace(s[i]))
--i;
s.erase(i + 1);
std::map<std::string, FunctionExpression::Function>::const_iterator j = registered_functions.find(s);
std::map<std::string, App::FunctionExpression::Function>::const_iterator j = registered_functions.find(s);
if (j != registered_functions.end())
yylval.func = j->second;
else

View File

@ -27,6 +27,7 @@
#include <Gui/Command.h>
#include "ui_PropertiesDialog.h"
using namespace App;
using namespace Spreadsheet;
using namespace SpreadsheetGui;
@ -182,7 +183,7 @@ void PropertiesDialog::displayUnitChanged(const QString & text)
QPalette palette = ui->displayUnit->palette();
try {
std::auto_ptr<UnitExpression> e(ExpressionParser::parseUnit(sheet, text.toUtf8().constData()));
std::auto_ptr<UnitExpression> e(Spreadsheet::ExpressionParser::parseUnit(sheet, text.toUtf8().constData()));
displayUnit = DisplayUnit(text.toUtf8().constData(), e->getUnit(), e->getScaler());
palette.setColor(QPalette::Text, Qt::black);