From: konrad Date: Sun, 28 Nov 2010 22:44:33 +0000 (+0000) Subject: add new formula engine (ELAM based) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=e186d20bfada675d50bf583ca3622c221b715e71;p=web%2Fkonrad%2Fsmoke.git add new formula engine (ELAM based) some work on using it for calculating prices some work on template editing git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@642 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/dialogs/eventedit.cpp b/src/dialogs/eventedit.cpp index f45367a..8661775 100644 --- a/src/dialogs/eventedit.cpp +++ b/src/dialogs/eventedit.cpp @@ -35,6 +35,7 @@ #include "MTGetEvent" #include "centbox.h" #include "pricecatdlg.h" +#include "formula.h" MEventEditor::MEventEditor(QWidget*pw,qint64 id) :QDialog(pw) @@ -279,7 +280,13 @@ void MEventEditor::addPrice() ep.setpricecategory(cat); ep.setpricecategoryid(cat.pricecategoryid()); ep.setflags(cat.flags()); - //TODO: execute formula + //execute formula + MElamEngine ee; + QList prc=event.price(); + for(int i=0;ivalue()); if(d.exec()!=QDialog::Accepted)return; diff --git a/src/dialogs/pricecatdlg.cpp b/src/dialogs/pricecatdlg.cpp index 6863bc8..0b5dcb1 100644 --- a/src/dialogs/pricecatdlg.cpp +++ b/src/dialogs/pricecatdlg.cpp @@ -12,9 +12,11 @@ #include "pricecatdlg.h" #include "msinterface.h" +#include "flagedit.h" #include #include +#include #include #include #include @@ -25,6 +27,7 @@ MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw,bool showselect) { m_cat=req->queryGetAllPriceCategories().getpricecategories(); setWindowTitle(tr("Select a Price Category")); + setSizeGripEnabled(true); QVBoxLayout*vl; setLayout(vl=new QVBoxLayout); vl->addWidget(m_list=new QListWidget,10); @@ -115,25 +118,39 @@ MPCDEdit::MPCDEdit(QWidget*par,const MOPriceCategory&c) bool b=cat.pricecategoryid().isNull(); setWindowTitle(b?tr("New Price Category"):tr("Change Price Category")); QVBoxLayout*vl; + QHBoxLayout*hl; + QPushButton*p; setLayout(vl=new QVBoxLayout); QFormLayout*fl; vl->addLayout(fl=new QFormLayout,1); fl->addRow(tr("Category Name:"),name=new QLineEdit(cat.name())); fl->addRow(tr("Category Abbreviation:"),abbr=new QLineEdit(cat.abbreviation())); + fl->addRow(tr("Formula:"),form=new QLineEdit(cat.formula())); + fl->addRow(tr("Flags:"),hl=new QHBoxLayout); + hl->addWidget(flags=new QLabel(cat.flags()),1); + hl->addWidget(p=new QPushButton("...")); + connect(p,SIGNAL(clicked(bool)),this,SLOT(editFlags())); vl->addSpacing(10); - QHBoxLayout*hl; vl->addLayout(hl=new QHBoxLayout,0); hl->addStretch(10); - QPushButton*p; hl->addWidget(p=new QPushButton(b?tr("Create"):tr("Save")),0); connect(p,SIGNAL(clicked()),this,SLOT(accept())); hl->addWidget(p=new QPushButton(tr("Cancel")),0); connect(p,SIGNAL(clicked()),this,SLOT(reject())); + setSizeGripEnabled(true); } + +void MPCDEdit::editFlags() +{ + flags->setText(MFlagEditor::edit(this, flags->text(), tr("Flags of price category '%1':").arg(name->text()))); +} + MOPriceCategory MPCDEdit::result()const { MOPriceCategory rcat(cat); rcat.setname(name->text()); rcat.setabbreviation(abbr->text()); + rcat.setformula(form->text()); + rcat.setflags(flags->text()); return rcat; } diff --git a/src/dialogs/pricecatdlg.h b/src/dialogs/pricecatdlg.h index 8012dbe..c583bb4 100644 --- a/src/dialogs/pricecatdlg.h +++ b/src/dialogs/pricecatdlg.h @@ -39,6 +39,7 @@ class MPriceCategoryDialog:public QDialog }; class QLineEdit; +class QLabel; /**helper class: edit a price category*/ class MPCDEdit:public QDialog @@ -47,9 +48,12 @@ class MPCDEdit:public QDialog public: MPCDEdit(QWidget*,const MOPriceCategory&); MOPriceCategory result()const; + private slots: + void editFlags(); private: MOPriceCategory cat; - QLineEdit*name,*abbr; + QLineEdit*name,*abbr,*form; + QLabel*flags; }; #endif diff --git a/src/misc/formula.cpp b/src/misc/formula.cpp new file mode 100644 index 0000000..e70afd5 --- /dev/null +++ b/src/misc/formula.cpp @@ -0,0 +1,62 @@ +// +// C++ Implementation: magicsmoke ELAM adaptation +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "formula.h" +#include "misc.h" + +#include + +using namespace ELAM; + +static QVariant toMoneyFunc(const QList&lf,bool local) +{ + if(lf.size()!=1) + return Exception(Exception::ArgumentListError, "expecting exactly one argument"); + if(!lf[0].canConvert()) + return Exception(Exception::TypeMismatchError,"cannot convert to int"); + return cent2str(lf[0].toLongLong(),local); +} +static QVariant toMoneyFuncLoc(const QList&lf){return toMoneyFunc(lf,true);} +static QVariant toMoneyFuncNLoc(const QList&lf){return toMoneyFunc(lf,false);} + +static QVariant fromMoneyFunc(const QList&lf,bool local) +{ + if(lf.size()!=1) + return Exception(Exception::ArgumentListError, "expecting exactly one argument"); + if(!lf[0].canConvert()) + return Exception(Exception::TypeMismatchError,"cannot convert to string"); + return str2cent(lf[0].toString(),local); +} +static QVariant fromMoneyFuncLoc(const QList&lf){return fromMoneyFunc(lf,true);} +static QVariant fromMoneyFuncNLoc(const QList&lf){return fromMoneyFunc(lf,false);} + +MElamEngine::MElamEngine(QObject* parent): Engine(parent) +{ + //configure character classes + QString alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; + characterClasses().setNameClass(alpha,alpha+"0123456789.:"); + if(!characterClasses().isConsistent()) + qDebug()<<"Warning: built-in calculator is inconsistent."; + //load default engines + IntEngine::configureIntEngine(*this); + FloatEngine::configureFloatEngine(*this); + BoolEngine::configureBoolEngine(*this); + BoolEngine::configureLogicEngine(*this); + StringEngine::configureStringEngine(*this); + //add money class + setFunction("toMoney",toMoneyFuncLoc); + setFunction("toMoneyLocal",toMoneyFuncLoc); + setFunction("toMoneyNL",toMoneyFuncNLoc); + setFunction("fromMoney",fromMoneyFuncLoc); + setFunction("fromMoneyLocal",fromMoneyFuncLoc); + setFunction("fromMoneyNL",fromMoneyFuncNLoc); +} diff --git a/src/misc/formula.h b/src/misc/formula.h new file mode 100644 index 0000000..49c915a --- /dev/null +++ b/src/misc/formula.h @@ -0,0 +1,24 @@ +// +// C++ Interface: magicsmoke ELAM adaptation +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_ELAM_H +#define MAGICSMOKE_ELAM_H + +#include "elam.h" + +class MElamEngine:public ELAM::Engine +{ + public: + MElamEngine(QObject*parent=0); +}; + +#endif diff --git a/src/misc/misc.pri b/src/misc/misc.pri index 9f81207..a1fec82 100644 --- a/src/misc/misc.pri +++ b/src/misc/misc.pri @@ -2,13 +2,15 @@ HEADERS += \ misc/debug.h \ misc/misc.h \ misc/waitcursor.h \ - misc/sclock.h + misc/sclock.h \ + misc/formula.h SOURCES += \ misc/code39.cpp \ misc/debug.cpp \ misc/misc.cpp \ misc/waitcursor.cpp \ - misc/sclock.cpp + misc/sclock.cpp \ + misc/formula.cpp INCLUDEPATH += ./misc \ No newline at end of file diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index e3c7858..565dd02 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,7 @@ void MOverview::closeEvent(QCloseEvent*ce) MOverview::~MOverview() { + qDebug()<<"destructing overview"<deleteLater(); } diff --git a/src/script/jsengine.cpp b/src/script/jsengine.cpp index d1e034d..c1997ea 100644 --- a/src/script/jsengine.cpp +++ b/src/script/jsengine.cpp @@ -42,6 +42,7 @@ QStringList MScriptEngine::m_basepath; MScriptEngine::MScriptEngine(MOverview* par) :QScriptEngine(par) { + qDebug()<<"creating script engine"<0)h+=" "; + h+=s; + return *this; + } + MScriptEngine_DebugHelper& operator<<(long l) + { + if(h.size()>0)h+=" "; + h+=QString::number(l,16); + return *this; + } + ~MScriptEngine_DebugHelper(){qDebug()<expandAll(); + tree->resizeColumnToContents(0); + tree->resizeColumnToContents(1); + tree->resizeColumnToContents(2); nochange=false; } void MTemplateEditor::deleteItem() diff --git a/src/templates/templatedlg.h b/src/templates/templatedlg.h index b5a7bc8..2dc43b9 100644 --- a/src/templates/templatedlg.h +++ b/src/templates/templatedlg.h @@ -31,6 +31,7 @@ class MTemplateChoice:public QDialog public: MTemplateChoice(const QString&,const QString&,const QStringList&,const QString&); + ///returns the choice made by the user MTemplate choice()const; private: //selection box