src/EditProductTab5.cpp

changeset 260
42b88d85fefc
parent 194
ea8cce5e7eb9
child 280
efc213beb605
equal deleted inserted replaced
259:78830c2ec792 260:42b88d85fefc
108 /* 108 /*
109 * Add the Delete and Edit row buttons. 109 * Add the Delete and Edit row buttons.
110 * Not for water agents, these are set on the water tab. 110 * Not for water agents, these are set on the water tab.
111 */ 111 */
112 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { 112 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) {
113 ui->miscsTable->removeCellWidget(i, 6); /* to remove the unneeded button */
113 item = new QTableWidgetItem(""); 114 item = new QTableWidgetItem("");
114 item->setToolTip(tr("Edit this from the water tab")); 115 item->setToolTip(tr("Edit this from the water tab"));
115 ui->miscsTable->setItem(i, 6, item); 116 ui->miscsTable->setItem(i, 6, item);
117 ui->miscsTable->removeCellWidget(i, 7);
116 item = new QTableWidgetItem(""); 118 item = new QTableWidgetItem("");
117 item->setToolTip(tr("Edit this from the water tab")); 119 item->setToolTip(tr("Edit this from the water tab"));
118 ui->miscsTable->setItem(i, 7, item); 120 ui->miscsTable->setItem(i, 7, item);
119 } else { 121 } else {
122 if (ui->miscsTable->item(i, 6)) {
123 ui->miscsTable->takeItem(i, 6); /* to remove the old tooltip */
124 }
125 if (ui->miscsTable->item(i, 7)) {
126 ui->miscsTable->takeItem(i, 7);
127 }
120 pWidget = new QWidget(); 128 pWidget = new QWidget();
121 QPushButton* btn_dele = new QPushButton(); 129 QPushButton* btn_dele = new QPushButton();
122 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ 130 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */
123 btn_dele->setText(tr("Delete")); 131 btn_dele->setText(tr("Delete"));
124 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteMiscRow_clicked())); 132 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteMiscRow_clicked()));
302 newm.m_time = 0; 310 newm.m_time = 0;
303 newm.m_amount_is_weight = true; 311 newm.m_amount_is_weight = true;
304 newm.m_cost = 0; 312 newm.m_cost = 0;
305 product->miscs.append(newm); 313 product->miscs.append(newm);
306 is_changed(); 314 is_changed();
307 emit refreshAll(); 315 refreshMiscs();
308 } 316 }
309 317
310 318
311 void EditProduct::deleteMiscRow_clicked() 319 void EditProduct::deleteMiscRow_clicked()
312 { 320 {
460 if (product->miscs.at(product->miscs_row).m_inventory < product->miscs.at(product->miscs_row).m_amount) 468 if (product->miscs.at(product->miscs_row).m_inventory < product->miscs.at(product->miscs_row).m_amount)
461 item->setForeground(QBrush(QColor(Qt::red))); 469 item->setForeground(QBrush(QColor(Qt::red)));
462 ui->miscsTable->setItem(product->miscs_row, 5, item); 470 ui->miscsTable->setItem(product->miscs_row, 5, item);
463 471
464 is_changed(); 472 is_changed();
465 emit refreshAll(); 473 qDebug() << "before" << product->miscs_row;
474 refreshMiscs();
475 /*
476 * The order of the list is changed, lookup the item we just added.
477 */
478 for (int i = 0; i < product->miscs.size(); i++) {
479 if ((product->miscs.at(i).m_name == query.value(0).toString()) &&
480 (product->miscs.at(i).m_type == query.value(1).toInt()) &&
481 (product->miscs.at(i).m_use_use == query.value(2).toInt())) {
482 product->miscs_row = i;
483 break;
484 }
485 }
486 qDebug() << "after" << product->miscs_row;
466 } 487 }
467 488
468 489
469 void EditProduct::misc_instock_changed(bool val) 490 void EditProduct::misc_instock_changed(bool val)
470 { 491 {

mercurial