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);
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);
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);
{
}
+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();
QList<MOShipping>ship=sh.getshipping();
- for(int i=0;i<ship.size();i++)
- cartship->addItem(ship[i].description(),(int)ship[i].shipid());
+ for(int i=0;i<ship.size();i++){
+ cartship->addItem(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());
cartship->setCurrentIndex(0);
//reset colors
resetColor();
+ //update price display
+ updatePrice();
}
void MCartTab::resetColor(bool addronly)
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?
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()+")";
if(!idx.isValid())return;
//remove row
cartmodel->removeRow(idx.row());
+ //update display
+ updatePrice();
}
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;
//TODO: implement items
}
+void MCartTab::updatePrice()
+{
+ int prc=0;
+ //get items in table
+ for(int i=0;i<cartmodel->rowCount();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)