#include "MTGetEvent"
#include "centbox.h"
#include "pricecatdlg.h"
+#include "formula.h"
MEventEditor::MEventEditor(QWidget*pw,qint64 id)
:QDialog(pw)
ep.setpricecategory(cat);
ep.setpricecategoryid(cat.pricecategoryid());
ep.setflags(cat.flags());
- //TODO: execute formula
+ //execute formula
+ MElamEngine ee;
+ QList<MOEventPrice> prc=event.price();
+ for(int i=0;i<prc.size();i++){
+ ee.setVariable(prc[i].pricecategory().value().abbreviation(), prc[i].price().value());
+ }
+ ep.setprice(ee.evaluate(cat.formula()).toInt());
//get local properties
MEEPriceEdit d(this,ep,capacity->value());
if(d.exec()!=QDialog::Accepted)return;
#include "pricecatdlg.h"
#include "msinterface.h"
+#include "flagedit.h"
#include <QBoxLayout>
#include <QFormLayout>
+#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QMessageBox>
{
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);
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;
}
};
class QLineEdit;
+class QLabel;
/**helper class: edit a price category*/
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
--- /dev/null
+//
+// C++ Implementation: magicsmoke ELAM adaptation
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "formula.h"
+#include "misc.h"
+
+#include <QDebug>
+
+using namespace ELAM;
+
+static QVariant toMoneyFunc(const QList<QVariant>&lf,bool local)
+{
+ if(lf.size()!=1)
+ return Exception(Exception::ArgumentListError, "expecting exactly one argument");
+ if(!lf[0].canConvert<qlonglong>())
+ return Exception(Exception::TypeMismatchError,"cannot convert to int");
+ return cent2str(lf[0].toLongLong(),local);
+}
+static QVariant toMoneyFuncLoc(const QList<QVariant>&lf){return toMoneyFunc(lf,true);}
+static QVariant toMoneyFuncNLoc(const QList<QVariant>&lf){return toMoneyFunc(lf,false);}
+
+static QVariant fromMoneyFunc(const QList<QVariant>&lf,bool local)
+{
+ if(lf.size()!=1)
+ return Exception(Exception::ArgumentListError, "expecting exactly one argument");
+ if(!lf[0].canConvert<QString>())
+ return Exception(Exception::TypeMismatchError,"cannot convert to string");
+ return str2cent(lf[0].toString(),local);
+}
+static QVariant fromMoneyFuncLoc(const QList<QVariant>&lf){return fromMoneyFunc(lf,true);}
+static QVariant fromMoneyFuncNLoc(const QList<QVariant>&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);
+}
--- /dev/null
+//
+// C++ Interface: magicsmoke ELAM adaptation
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (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
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
#include <QBoxLayout>
#include <QCheckBox>
#include <QComboBox>
+#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QInputDialog>
MOverview::~MOverview()
{
+ qDebug()<<"destructing overview"<<hex<<(long)this;
//free requestor
req->deleteLater();
}
MScriptEngine::MScriptEngine(MOverview* par)
:QScriptEngine(par)
{
+ qDebug()<<"creating script engine"<<hex<<(long)this;
//register main window
addObject("MainWindow",par);
//init wob interface
//load init script
evalFile("init.js");
}
+
+MScriptEngine::~MScriptEngine()
+{
+ qDebug()<<"deleting script engine"<<hex<<(long)this;
+}
+
+
void MScriptEngine::addObject(QString name, QObject* object)
{
if(name.size()==0)return;
return true;
}
+class MScriptEngine_DebugHelper
+{
+ QString h;
+ public:
+ MScriptEngine_DebugHelper(QString s){h=s;}
+ MScriptEngine_DebugHelper& operator<<(QString s)
+ {
+ if(h.size()>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()<<h.toAscii().data();}
+};
+
QScriptValue MScriptEngine::evalFile(QString fn)
{
+ qDebug()<<"executing on script engine"<<hex<<(long)this<<"script file"<<fn;
+ MScriptEngine_DebugHelper dh("done executing script engine");
+ dh<<(long)this<<"script file"<<fn;
QScriptContext*context=currentContext();
//normalize file name
if(!normalizeFile(fn)){
public:
///construct the engine with pointer to the main window
MScriptEngine(MOverview*);
+ ///delete engine
+ virtual ~MScriptEngine();
///add another object and its meta object
void addObject(QString name,QObject*object);
}
//expand all
tree->expandAll();
+ tree->resizeColumnToContents(0);
+ tree->resizeColumnToContents(1);
+ tree->resizeColumnToContents(2);
nochange=false;
}
void MTemplateEditor::deleteItem()
public:
MTemplateChoice(const QString&,const QString&,const QStringList&,const QString&);
+ ///returns the choice made by the user
MTemplate choice()const;
private:
//selection box