From: konrad Date: Tue, 29 Dec 2009 14:40:18 +0000 (+0000) Subject: *added wext dir for implementing abstract wobs X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8e7049299684b6988776c95f3855a01cb8fd5a4e;p=web%2Fkonrad%2Fsmoke.git *added wext dir for implementing abstract wobs *made order list tab useable (lots missing yet) git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@366 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/README b/src/README index 3a6b138..f4d6f0f 100644 --- a/src/README +++ b/src/README @@ -9,11 +9,14 @@ The following (sub-)directories exist: wbase Web object base classes. +iface + MagicSmoke web interface classes (derived from wbase/*) + wob generated web objects - auto created by woc from ../wob/magicsmoke.wolf -iface - MagicSmoke web interface classes (derived from wbase/*) +wext + extensions for autogenerated abstract classes (derived from wob/*Abstract.h) widgets some simple helper widgets diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index f6481a3..c79a98f 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -128,7 +128,7 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOrder&o) //FIXME:gl->addWidget(lab=new QLabel(m_order.deliveryAddress()),rw,1); //lab->setWordWrap(true); gl->addWidget(new QLabel(tr("Sold by:")),++rw,0); - gl->addWidget(new QLabel(m_order.seller()),rw,1); + gl->addWidget(new QLabel(m_order.soldby()),rw,1); gl->addWidget(new QLabel(tr("Total Price:")),++rw,0); gl->addWidget(m_total=new QLabel(m_order.totalPriceString()),rw,1); gl->addWidget(new QLabel(tr("Already Paid:")),++rw,0); diff --git a/src/iface/order.cpp b/src/iface/order.cpp index 404ec6a..167628e 100644 --- a/src/iface/order.cpp +++ b/src/iface/order.cpp @@ -41,7 +41,7 @@ MCustomer MOrder::customer()const bool MOrder::isReservation()const { - return state()==Reserved; + return status()==Reserved; } bool MOrder::canOrder()const @@ -62,7 +62,7 @@ bool MOrder::canSell()const QString MOrder::orderStatusString()const { - return OrderState2str(state()); + return OrderState2str(status()); } QString MOrder::totalPriceString(int off)const @@ -77,32 +77,32 @@ QString MOrder::amountPaidString(int off)const bool MOrder::needsPayment()const { - if(state()==Placed || state()==Sent) + if(status()==Placed || status()==Sent) if(amountpaid()0; - if(state()==Placed || state()==Sent) + if(status()==Placed || status()==Sent) return amountpaid()>totalprice(); return false; } int MOrder::amountToPay()const { - if(state()==Placed || state()==Sent) + if(status()==Placed || status()==Sent) if(amountpaid()totalprice()) return amountpaid()-totalprice(); return 0; @@ -121,7 +121,7 @@ QString MOrder::amountToRefundStr(int off)const bool MOrder::isSent()const { //only in placed mode there is a need for action, hence in all other modes we assume sent - return state()!=Placed; + return status()!=Placed; } diff --git a/src/mwin/orderstab.cpp b/src/mwin/orderstab.cpp index 3219067..d5f4dd3 100644 --- a/src/mwin/orderstab.cpp +++ b/src/mwin/orderstab.cpp @@ -76,7 +76,7 @@ MOrdersTab::MOrdersTab(QString pk) p->setEnabled(req->hasRole("orderbyticket")); vl->addWidget(p=new QPushButton(tr("Find by Event...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByEvent())); - p->setEnabled(req->hasRole("getordersbyevents")); + p->setEnabled(req->hasRight(req->RGetOrdersByEvents)); vl->addWidget(p=new QPushButton(tr("Find by Customer...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByCustomer())); p->setEnabled(req->hasRole("getorderlist")); @@ -87,16 +87,28 @@ MOrdersTab::MOrdersTab(QString pk) //fill tables - if(req->hasRole("getorderlist")){ + if(req->hasRight(req->RGetOrderList)){ updateOrders(); }else{ setEnabled(false); } } +qint64 MOrdersTab::oldestOrderStamp(int age) +{ + if(age<0){//age not given, get configuration + QSettings set; + set.beginGroup("profiles/"+profilekey); + age=set.value("maxorderage",0).toInt(); + } + //zero means no limit + if(age<=0)return 0; + //calculate + return QDateTime::currentDateTime().addDays(-age).toTime_t(); +} //helper: finds out whether an order should be printed. -static inline bool candoUpdateOrders(int omode,const MOrder&ord) +static inline bool candoUpdateOrders(int omode,const MOOrderInfo&ord) { if(omode==ORDERALL)return true; if((omode&ORDERPAY)!=0 && ord.needsPayment())return true; @@ -106,32 +118,46 @@ static inline bool candoUpdateOrders(int omode,const MOrder&ord) return false; } -void MOrdersTab::updateOrders() -{/*TODO +void MOrdersTab::resetModel() +{ ordermodel->clear(); ordermodel->setHorizontalHeaderLabels(QStringList()<&cust) +{ + int cl=0; + ordermodel->insertRow(cl); + ordermodel->setHeaderData(cl,Qt::Vertical,ord.orderid().value()); + ordermodel->setData(ordermodel->index(cl,0),ord.orderStatusString()); + ordermodel->setData(ordermodel->index(cl,0),ord.orderid().value(),Qt::UserRole); + ordermodel->setData(ordermodel->index(cl,1),ord.totalPriceString()); + ordermodel->setData(ordermodel->index(cl,2),ord.amountPaidString()); + int cid=ord.customerid(); + //TODO: make this more effective: + for(int j=0;jsetData(ordermodel->index(cl,3),cust[j].fullName()); + cl++; +} + +void MOrdersTab::updateOrders() +{ + resetModel(); int omode=ordermode->itemData(ordermode->currentIndex()).toInt(); if(omode==ORDERNONE)return; - QList orders=req->getAllOrders(); - if(orders.size()==0)return; - QList cust=req->getAllCustomers(); - int cl=0; + MTGetOrderList ol=req->queryGetOrderList(oldestOrderStamp()); + if(ol.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("There was a problem retrieving the order list: %1").arg(ol.errorString())); + return; + } + QList orders=ol.getorders(); + QList cust=ol.getcustomers(); for(int i=0;iinsertRow(cl); - ordermodel->setHeaderData(cl,Qt::Vertical,orders[i].orderID()); - ordermodel->setData(ordermodel->index(cl,0),orders[i].orderStatusString()); - ordermodel->setData(ordermodel->index(cl,0),orders[i].orderID(),Qt::UserRole); - ordermodel->setData(ordermodel->index(cl,1),orders[i].totalPriceString()); - ordermodel->setData(ordermodel->index(cl,2),orders[i].amountPaidString()); - int cid=orders[i].customerID(); - //TODO: make this more effective: - for(int j=0;jsetData(ordermodel->index(cl,3),cust[j].name()); - cl++; + addOrderToModel(orders[i],cust); } - ordertable->resizeColumnsToContents();*/ + ordertable->resizeColumnsToContents(); } void MOrdersTab::orderDetails() @@ -176,7 +202,7 @@ void MOrdersTab::orderByTicket() } void MOrdersTab::orderByEvent() -{/*TODO +{ //display selection dialog QDialog d(this); d.setWindowTitle(tr("Select Event")); @@ -186,6 +212,7 @@ void MOrdersTab::orderByEvent() QTableView*tv; vl->addWidget(tv=new QTableView,10); tv->setEditTriggers(QAbstractItemView::NoEditTriggers); + QStandardItemModel*eventmodel=emit eventModel(); tv->setModel(eventmodel); tv->resizeColumnsToContents(); vl->addLayout(hl=new QHBoxLayout,0); @@ -205,32 +232,24 @@ void MOrdersTab::orderByEvent() return; } //get events - QListeventids; + QListeventids; for(int i=0;idata(eventmodel->index(ilst[i].row(),0),Qt::UserRole).toInt(); if(!eventids.contains(eid))eventids.append(eid); } //request data and display - //TODO: unify this part with updateOrders - ordermodel->clear(); - ordermodel->setHorizontalHeaderLabels(QStringList()< orders=req->getOrdersByEvents(eventids); - if(orders.size()==0)return; - QList cust=req->getAllCustomers(); + resetModel(); + MTGetOrdersByEvents obe=req->queryGetOrdersByEvents(eventids,oldestOrderStamp()); + if(obe.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("There was a problem retrieving the order list: %1").arg(obe.errorString())); + return; + } + QList orders=obe.getorders(); + QList cust=obe.getcustomers(); for(int cl=0;clinsertRow(cl); - ordermodel->setHeaderData(cl,Qt::Vertical,orders[cl].orderID()); - ordermodel->setData(ordermodel->index(cl,0),orders[cl].orderStatusString()); - ordermodel->setData(ordermodel->index(cl,0),orders[cl].orderID(),Qt::UserRole); - ordermodel->setData(ordermodel->index(cl,1),orders[cl].totalPriceString()); - ordermodel->setData(ordermodel->index(cl,2),orders[cl].amountPaidString()); - int cid=orders[cl].customerID(); - //TODO: make this more effective: - for(int j=0;jsetData(ordermodel->index(cl,3),cust[j].name()); + addOrderToModel(orders[cl],cust); } - ordermode->setCurrentIndex(ordermode->count()-1);*/ + ordermode->setCurrentIndex(ordermode->count()-1); } void MOrdersTab::orderByCustomer() diff --git a/src/mwin/orderstab.h b/src/mwin/orderstab.h index 9400813..f9096a5 100644 --- a/src/mwin/orderstab.h +++ b/src/mwin/orderstab.h @@ -27,6 +27,8 @@ class QTabWidget; class QTableView; class MSInterface; +class MOOrderInfo; +class MOCustomerInfo; /**Main Overview Window: order list tab*/ class MOrdersTab:public QWidget @@ -51,7 +53,18 @@ class MOrdersTab:public QWidget /**find and display order by order ID*/ void orderByOrder(); + signals: + /**needs to be connected to the event tab*/ + QStandardItemModel*eventModel(); + private: + /**helper function: enters a single order into the model*/ + void addOrderToModel(const MOOrderInfo&,const QList&); + /**helper function: resets the model to an empty state*/ + void resetModel(); + /**returns timestamp for oldest order; if age is given it returns a timestamp age days in the past, if age is not given it uses the configured time*/ + qint64 oldestOrderStamp(int age=-1); + //the profile associated with this session QString profilekey; //widgets diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index c5e0d26..d70cd2a 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -98,6 +98,7 @@ MOverview::MOverview(QString pk) //Order List Tab tab->addTab(ordertab=new MOrdersTab(pk),tr("Order List")); + connect(ordertab,SIGNAL(eventModel()),eventtab,SLOT(eventModel()),Qt::DirectConnection); //Entrance Control Tab tab->addTab(entrancetab=new MEntranceTab(pk),tr("Entrance")); @@ -126,6 +127,7 @@ MOverview::MOverview(QString pk) m=mb->addMenu(tr("C&onfigure")); m->addAction(tr("&Auto-Refresh settings..."),this,SLOT(setRefresh())); m->addAction(tr("&Server Access settings..."),this,SLOT(webSettings())); + m->addAction(tr("&Display settings..."),this,SLOT(displaySettings())); m=mb->addMenu(tr("&Admin")); m->addAction(tr("Backup &Settings..."),this,SLOT(backupSettings())) @@ -144,10 +146,10 @@ MOverview::MOverview(QString pk) eventtab->setEnabled(false); tab->setTabEnabled(tab->indexOf(eventtab),false); } - if(!req->hasRole("createorder")&&!req->hasRole("createsale")){ + if(!req->hasRight(req->RCreateOrder)&&!req->hasRight(req->RCreateSale)){ tab->setTabEnabled(tab->indexOf(carttab),false); } - if(!req->hasRole("getorderlist")){ + if(!req->hasRight(req->RGetOrderList)){ tab->setTabEnabled(tab->indexOf(ordertab),false); } if(!req->hasRight(req->RGetAllUsers)){ @@ -429,6 +431,47 @@ void MOverview::webSettings(bool showdlg) req->setWebTimeout(timeout*1000); } +void MOverview::displaySettings() +{ + QSettings set; + set.beginGroup("profiles/"+profilekey); + //get settings + int maxage=set.value("maxeventage", 0).toInt(); + int maxageo=set.value("maxorderage", 0).toInt(); + //dialog + QDialog d; + d.setWindowTitle(tr("Display Settings")); + QGridLayout*gl; + QHBoxLayout*hl; + d.setLayout(gl=new QGridLayout); + int cl=0; + gl->addWidget(new QLabel(tr("Maximum event age (days, 0=show all):")),cl,0); + QSpinBox*mage; + gl->addWidget(mage=new QSpinBox,cl,1); + mage->setRange(0,99999); + mage->setValue(maxage); + gl->addWidget(new QLabel(tr("Maximum order list age (days, 0=show all):")),++cl,0); + QSpinBox*oage; + gl->addWidget(oage=new QSpinBox,cl,1); + oage->setRange(0,99999); + oage->setValue(maxageo); + gl->setRowMinimumHeight(++cl,15); + gl->addLayout(hl=new QHBoxLayout,++cl,0,1,2); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("&OK"))); + connect(p,SIGNAL(clicked()),&d,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("&Cancel"))); + connect(p,SIGNAL(clicked()),&d,SLOT(reject())); + if(d.exec()!=QDialog::Accepted)return; + //write settings + maxage=mage->value(); + maxageo=oage->value(); + set.setValue("maxeventage",maxage); + set.setValue("maxorderage",maxageo); +} + + void MOverview::doBackup() { baktimer.stop(); diff --git a/src/mwin/overview.h b/src/mwin/overview.h index 6cb8e53..f905efa 100644 --- a/src/mwin/overview.h +++ b/src/mwin/overview.h @@ -89,6 +89,9 @@ class MOverview:public QMainWindow /**web request settings dialog; shows the dialog per default, just copies settings from registry to webrequest object if false*/ void webSettings(bool dlg=true); + /**display property settings*/ + void displaySettings(); + /**do a backup now*/ void doBackup(); diff --git a/src/smoke.pro b/src/smoke.pro index 1200bd8..bc63839 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -42,4 +42,5 @@ include(dialogs/dialogs.pri) include(mwin/mwin.pri) #build generated stuff last +include(wext/wext.pri) include(wob/wob.pri) diff --git a/src/wext/MOCustomerInfo.h b/src/wext/MOCustomerInfo.h new file mode 100644 index 0000000..998befe --- /dev/null +++ b/src/wext/MOCustomerInfo.h @@ -0,0 +1,27 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOCUSTOMER_H +#define MAGICSMOKE_MOCUSTOMER_H + +#include "MOCustomerInfoAbstract.h" +class MOCustomerInfo:public MOCustomerInfoAbstract +{ + public: + MOCustomerInfo():MOCustomerInfoAbstract(){} + MOCustomerInfo(const MOCustomerInfo&o):MOCustomerInfoAbstract(o){} + MOCustomerInfo(const QDomElement&e):MOCustomerInfoAbstract(e){} + + QString fullName()const{return title()+" "+name()+", "+firstname();} +}; + +#endif diff --git a/src/wext/MOOrder.h b/src/wext/MOOrder.h new file mode 100644 index 0000000..6c91d87 --- /dev/null +++ b/src/wext/MOOrder.h @@ -0,0 +1,26 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOORDER_H +#define MAGICSMOKE_MOORDER_H + +#include "MOOrderAbstract.h" +class MOOrder:public MOOrderAbstract +{ + public: + MOOrder():MOOrderAbstract(){} + MOOrder(const MOOrder&o):MOOrderAbstract(o){} + MOOrder(const QDomElement&e):MOOrderAbstract(e){} + +}; + +#endif diff --git a/src/wext/MOOrderInfo.h b/src/wext/MOOrderInfo.h new file mode 100644 index 0000000..6dd17f6 --- /dev/null +++ b/src/wext/MOOrderInfo.h @@ -0,0 +1,35 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOORDERI_H +#define MAGICSMOKE_MOORDERI_H + +#include "MOOrderInfoAbstract.h" +#include "misc.h" + +class MOOrderInfo:public MOOrderInfoAbstract +{ + public: + MOOrderInfo(const MOOrderInfo&o):MOOrderInfoAbstract(o){} + MOOrderInfo(const QDomElement&e):MOOrderInfoAbstract(e){} + + QString totalPriceString()const{return cent2str(totalprice());} + QString amountPaidString()const{return cent2str(amountpaid());} + QString orderStatusString()const{return OrderState2str(status());} + + bool needsPayment()const{return amountpaid()totalprice();} + bool isSent()const{return status()==Sent;} + bool isReservation()const{return status()==Reserved;} +}; + +#endif \ No newline at end of file diff --git a/src/iface/MORole.h b/src/wext/MORole.h similarity index 100% rename from src/iface/MORole.h rename to src/wext/MORole.h diff --git a/src/wext/MOTicket.h b/src/wext/MOTicket.h new file mode 100644 index 0000000..5b38f97 --- /dev/null +++ b/src/wext/MOTicket.h @@ -0,0 +1,27 @@ +// +// C++ Interface: MOTicket +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOTICKET_H +#define MAGICSMOKE_MOTICKET_H + +#include "MOTicketAbstract.h" +class MOTicket:public MOTicketAbstract +{ + public: + MOTicket():MOTicketAbstract(){} + MOTicket(const MOTicket&m):MOTicketAbstract(m){} + MOTicket(const QDomElement&e):MOTicketAbstract(e){} + + int amountToPay()const{if(status()&MaskPay)return price();else return 0;} +}; + +#endif diff --git a/src/wext/wext.pri b/src/wext/wext.pri new file mode 100644 index 0000000..65b5ae3 --- /dev/null +++ b/src/wext/wext.pri @@ -0,0 +1 @@ +INCLUDEPATH += ./wext