#include <QMessageBox>
#include <QPushButton>
-MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw)
+MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw,bool showselect)
:QDialog(pw)
{
m_cat=req->queryGetAllPriceCategories().getpricecategories();
QPushButton*p;
hl->addWidget(p=new QPushButton(tr("New...","new price category")),0);
connect(p,SIGNAL(clicked()),this,SLOT(newCat()));
- p->setEnabled(req->hasRight(req->RCreateArtist));
- hl->addWidget(p=new QPushButton(tr("Select","select price category")),0);
- connect(p,SIGNAL(clicked()),this,SLOT(accept()));
- hl->addWidget(p=new QPushButton(tr("Cancel")),0);
- connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+ p->setEnabled(req->hasRight(req->RCreatePriceCategory));
+ hl->addWidget(p=new QPushButton(tr("Edit...","edit price category")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(editCat()));
+ p->setEnabled(req->hasRight(req->RChangePriceCategory));
+ if(showselect){
+ hl->addWidget(p=new QPushButton(tr("Select","select price category")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+ }else{
+ hl->addWidget(p=new QPushButton(tr("Close")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+ }
}
MOPriceCategory MPriceCategoryDialog::selection()const
return m_cat[wlst[0]->data(Qt::UserRole).toInt()];
}
+/**helper class: edit a price category*/
+class MPCDEdit:public QDialog
+{
+ public:
+ MPCDEdit(QWidget*,const MOPriceCategory&);
+ MOPriceCategory result()const;
+ private:
+ MOPriceCategory cat;
+ QLineEdit*name,*abbr;
+};
+
void MPriceCategoryDialog::newCat()
{
- //TODO: remaining properties
- //dialog
- QDialog d;
- d.setWindowTitle(tr("New Price Category"));
- QVBoxLayout*vl;
- d.setLayout(vl=new QVBoxLayout);
- QFormLayout*fl;
- vl->addLayout(fl=new QFormLayout,1);
- QLineEdit*name,*abbr;
- fl->addRow(tr("Category Name:"),name=new QLineEdit);
- fl->addRow(tr("Category Abbreviation:"),abbr=new QLineEdit);
- vl->addSpacing(10);
- QHBoxLayout*hl;
- vl->addLayout(hl=new QHBoxLayout,0);
- hl->addStretch(10);
- QPushButton*p;
- hl->addWidget(p=new QPushButton(tr("Create")),0);
- connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
- hl->addWidget(p=new QPushButton(tr("Cancel")),0);
- connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ MPCDEdit d(this,MOPriceCategory());
//ask
if(d.exec()!=QDialog::Accepted)return;
//get props, create cat
- MOPriceCategory cat;
- cat.setname(name->text());
- cat.setabbreviation(abbr->text());
+ MOPriceCategory cat=d.result();
MTCreatePriceCategory cpc=req->queryCreatePriceCategory(cat);
if(cpc.hasError()){
QMessageBox::warning(this,tr("Warning"),tr("Error while creating new price category: %1").arg(cpc.errorString()));
m_list->addItem(it);
m_list->setCurrentItem(it);
}
+
+void MPriceCategoryDialog::editCat()
+{
+ //get current
+ QList<QListWidgetItem*>wlst=m_list->selectedItems();
+ if(wlst.size()<1)return;
+ //ask
+ int pcidx=wlst[0]->data(Qt::UserRole).toInt();
+ MPCDEdit d(this,m_cat[pcidx]);
+ if(d.exec()!=QDialog::Accepted)return;
+ //get props, create cat
+ MOPriceCategory cat=d.result();
+ MTChangePriceCategory cpc=req->queryChangePriceCategory(cat);
+ if(cpc.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while creating new price category: %1").arg(cpc.errorString()));
+ return;
+ }
+ //add and select
+ cat=cpc.getpricecategory();
+ m_cat[pcidx]=cat;
+ wlst[0]->setText(cat.name());
+}
+
+
+
+MPCDEdit::MPCDEdit(QWidget*par,const MOPriceCategory&c)
+ :QDialog(par),cat(c)
+{
+ //TODO: remaining properties
+ //dialog
+ bool b=cat.pricecategoryid().isNull();
+ setWindowTitle(b?tr("New Price Category"):tr("Change Price Category"));
+ QVBoxLayout*vl;
+ 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()));
+ 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()));
+}
+MOPriceCategory MPCDEdit::result()const
+{
+ MOPriceCategory rcat(cat);
+ rcat.setname(name->text());
+ rcat.setabbreviation(abbr->text());
+ return rcat;
+}