From d8e22fdea5079f92e396624bebdb238f85ab3d8c Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 16 May 2010 18:17:56 +0000 Subject: [PATCH] show total price tag in cart git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@464 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/mwin/carttab.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- src/mwin/carttab.h | 4 +++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/mwin/carttab.cpp b/src/mwin/carttab.cpp index 93cab93..a2cda8f 100644 --- a/src/mwin/carttab.cpp +++ b/src/mwin/carttab.cpp @@ -50,6 +50,7 @@ MCartTab::MCartTab(QString pk) carttable->setModel(cartmodel=new QStandardItemModel(this)); carttable->setSelectionMode(QAbstractItemView::SingleSelection); carttable->setItemDelegate(new MCartTableDelegate(this)); + connect(cartmodel,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(updatePrice())); QHBoxLayout*hl2; vl2->addLayout(hl2=new QHBoxLayout,0); hl2->addStretch(10); @@ -64,6 +65,11 @@ MCartTab::MCartTab(QString pk) hl2->addSpacing(15); hl2->addWidget(p=new QPushButton(tr("Remove Line")),0); connect(p,SIGNAL(clicked()),this,SLOT(cartRemoveItem())); + vl2->addLayout(hl2=new QHBoxLayout,0); + hl2->addWidget(new QLabel(tr("Total Price Sum:"))); + hl2->addWidget(price=new QLabel("0.0")); + hl2->addStretch(1); + QFrame*frm; hl->addWidget(frm=new QFrame,0); frm->setFrameShape(QFrame::VLine); @@ -90,6 +96,7 @@ MCartTab::MCartTab(QString pk) vl2->addWidget(new QLabel(tr("Shipping Method:")),0); vl2->addWidget(cartship=new QComboBox,0); cartship->setEditable(false); + connect(cartship,SIGNAL(currentIndexChanged(int)),this,SLOT(updatePrice())); vl2->addSpacing(10); vl2->addWidget(new QLabel(tr("Comments:")),0); vl2->addWidget(cartcomment=new QTextEdit); @@ -136,14 +143,20 @@ MCartTab::~MCartTab() { } +static const int SHIPPING_IDROLE = Qt::UserRole; +static const int SHIPPING_PRICEROLE = Qt::UserRole+1; + void MCartTab::updateShipping() { cartship->clear(); cartship->addItem(tr("(No Shipping)"),-1); MTGetAllShipping sh=MTGetAllShipping::query(); QListship=sh.getshipping(); - for(int i=0;iaddItem(ship[i].description(),(int)ship[i].shipid()); + for(int i=0;iaddItem(ship[i].description()); + cartship->setItemData(cartship->count()-1,(int)ship[i].shipid(),SHIPPING_IDROLE); + cartship->setItemData(cartship->count()-1,(int)ship[i].cost(),SHIPPING_PRICEROLE); + } QPalette pal2=QComboBox().palette(); cartship->setPalette(pal2); cartship->setToolTip(QString()); @@ -167,6 +180,8 @@ void MCartTab::initCart() cartship->setCurrentIndex(0); //reset colors resetColor(); + //update price display + updatePrice(); } void MCartTab::resetColor(bool addronly) @@ -244,7 +259,7 @@ static const int CART_VOUCHER=2; static const int CART_IDROLE=Qt::UserRole;//ticket id static const int CART_PRICEIDROLE=Qt::UserRole+3;//for tickets: price category id -static const int CART_PRICEROLE=Qt::UserRole+3;//voucher price +static const int CART_PRICEROLE=Qt::UserRole+4;//voucher/ticket price static const int CART_VALUEROLE=Qt::UserRole+1;//voucher value static const int CART_TYPEROLE=Qt::UserRole+2;//which is it? ticket or voucher? @@ -329,6 +344,7 @@ void MCartTab::addTicketForEvent(qint64 id) cartmodel->setData(cartmodel->index(cr,0),id,CART_IDROLE); cartmodel->setData(cartmodel->index(cr,0),CART_TICKET,CART_TYPEROLE); cartmodel->setData(cartmodel->index(cr,0),ep[pcidx].pricecategoryid().value(),CART_PRICEIDROLE); + cartmodel->setData(cartmodel->index(cr,0),ep[pcidx].price().value(),CART_PRICEROLE); cartmodel->setData(cartmodel->index(cr,1),ev.title().value()); cartmodel->setData(cartmodel->index(cr,2),ev.startTimeString()); QString pcn=cent2str(ep[pcidx].price())+" ("+ep[pcidx].pricecategory().value().name().value()+")"; @@ -419,6 +435,8 @@ void MCartTab::cartRemoveItem() if(!idx.isValid())return; //remove row cartmodel->removeRow(idx.row()); + //update display + updatePrice(); } void MCartTab::cartOrder(bool isreserve,bool issale) @@ -440,7 +458,7 @@ void MCartTab::cartOrder(bool isreserve,bool issale) cartTableToOrder(cord); //set shipping info if(cartship->currentIndex()>0) - cord.setshippingtypeid(cartship->itemData(cartship->currentIndex()).toInt()); + cord.setshippingtypeid(cartship->itemData(cartship->currentIndex(),SHIPPING_IDROLE).toInt()); ///// //send MOOrder ord; @@ -637,6 +655,22 @@ void MCartTab::verifyOrderItems(const QList&) //TODO: implement items } +void MCartTab::updatePrice() +{ + int prc=0; + //get items in table + for(int i=0;irowCount();i++){ + QModelIndex idx=cartmodel->index(i,0); + int amt=cartmodel->data(idx).toInt(); + int itp=cartmodel->data(idx,CART_PRICEROLE).toInt(); + prc+=amt*itp; + } + //get shipping + prc+=cartship->itemData(cartship->currentIndex(),SHIPPING_PRICEROLE).toInt(); + //display + price->setText(cent2str(prc)); +} + /********************************************************************************/ MCartTableDelegate::MCartTableDelegate(QObject*p) diff --git a/src/mwin/carttab.h b/src/mwin/carttab.h index 2e9b35d..384114a 100644 --- a/src/mwin/carttab.h +++ b/src/mwin/carttab.h @@ -101,6 +101,8 @@ class MCartTab:public QWidget void cartSell(); /**reset the colors of the tab*/ void resetColor(bool addronly=false); + /**update the price shown*/ + void updatePrice(); private: //the profile associated with this session @@ -108,7 +110,7 @@ class MCartTab:public QWidget //widgets QTableView*carttable; QStandardItemModel*cartmodel; - QLabel*cartcustomer,*deliveryaddr,*invoiceaddr; + QLabel*cartcustomer,*deliveryaddr,*invoiceaddr,*price; QTextEdit *cartcomment; QComboBox*cartship; //cart -- 1.7.2.5