Fri, 29 Apr 2022 21:42:00 +0200
Add hops inventory update during product load.
src/EditProduct.cpp | file | annotate | diff | comparison | revisions | |
src/EditProductTab4.cpp | file | annotate | diff | comparison | revisions | |
ui/EditProduct.ui | file | annotate | diff | comparison | revisions |
--- a/src/EditProduct.cpp Fri Apr 29 20:29:26 2022 +0200 +++ b/src/EditProduct.cpp Fri Apr 29 21:42:00 2022 +0200 @@ -411,6 +411,8 @@ QJsonObject obj = hops.array().at(i).toObject(); //qDebug() << i << obj; Hops h; + h.h_avail = false; + h.h_inventory = 0; h.h_name = obj["h_name"].toString(); h.h_origin = obj["h_origin"].toString(); h.h_amount = obj["h_amount"].toDouble(); @@ -427,6 +429,15 @@ h.h_cohumulone = obj["h_cohumulone"].toDouble(); h.h_myrcene = obj["h_myrcene"].toDouble(); h.h_total_oil = obj["h_total_oil"].toDouble(); + /* Check and update inventory */ + yquery.prepare("SELECT inventory FROM inventory_hops WHERE name=:name AND origin=:origin"); + yquery.bindValue(":name", h.h_name); + yquery.bindValue(":origin", h.h_origin); + yquery.exec(); + if (yquery.first()) { + h.h_avail = true; + h.h_inventory = yquery.value(0).toDouble(); + } product->hops.append(h); } qDebug() << "hops" << product->hops.size();
--- a/src/EditProductTab4.cpp Fri Apr 29 20:29:26 2022 +0200 +++ b/src/EditProductTab4.cpp Fri Apr 29 21:42:00 2022 +0200 @@ -46,20 +46,21 @@ std::sort(product->hops.begin(), product->hops.end(), hop_sort_test); const QStringList labels({tr("Origin"), tr("Hop"), tr("Type"), tr("Form"), tr("Alpha"), tr("Use at"), tr("Time"), - tr("IBU"), tr("Amount"), tr("Delete"), tr("Edit") }); + tr("IBU"), tr("Amount"), tr("Stock"), tr("Delete"), tr("Edit") }); - ui->hopsTable->setColumnCount(11); - ui->hopsTable->setColumnWidth(0, 150); /* Origin */ + ui->hopsTable->setColumnCount(12); + ui->hopsTable->setColumnWidth(0, 130); /* Origin */ ui->hopsTable->setColumnWidth(1, 225); /* Hop */ - ui->hopsTable->setColumnWidth(2, 84); /* Type */ + ui->hopsTable->setColumnWidth(2, 74); /* Type */ ui->hopsTable->setColumnWidth(3, 84); /* Form */ - ui->hopsTable->setColumnWidth(4, 75); /* Alpha% */ + ui->hopsTable->setColumnWidth(4, 55); /* Alpha% */ ui->hopsTable->setColumnWidth(5, 75); /* Added */ - ui->hopsTable->setColumnWidth(6, 75); /* Time */ - ui->hopsTable->setColumnWidth(7, 60); /* IBU */ - ui->hopsTable->setColumnWidth(8, 90); /* Amount */ - ui->hopsTable->setColumnWidth(9, 80); /* Delete */ - ui->hopsTable->setColumnWidth(10, 80); /* Edit */ + ui->hopsTable->setColumnWidth(6, 65); /* Time */ + ui->hopsTable->setColumnWidth(7, 50); /* IBU */ + ui->hopsTable->setColumnWidth(8, 80); /* Amount */ + ui->hopsTable->setColumnWidth(9, 80); /* Stock */ + ui->hopsTable->setColumnWidth(10, 80); /* Delete */ + ui->hopsTable->setColumnWidth(11, 80); /* Edit */ ui->hopsTable->setHorizontalHeaderLabels(labels); ui->hopsTable->verticalHeader()->hide(); ui->hopsTable->setRowCount(product->hops.size()); @@ -109,6 +110,14 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->hopsTable->setItem(i, 8, item); + if (product->hops.at(i).h_inventory < 1.0) { + item = new QTableWidgetItem(QString("%1 gr").arg(product->hops.at(i).h_inventory * 1000.0, 2, 'f', 1, '0')); + } else { + item = new QTableWidgetItem(QString("%1 kg").arg(product->hops.at(i).h_inventory, 4, 'f', 3, '0')); + } + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->hopsTable->setItem(i, 9, item); + /* Add the Delete row button */ pWidget = new QWidget(); QPushButton* btn_dele = new QPushButton(); @@ -119,7 +128,7 @@ pLayout->addWidget(btn_dele); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->hopsTable->setCellWidget(i, 9, pWidget); + ui->hopsTable->setCellWidget(i, 10, pWidget); pWidget = new QWidget(); QPushButton* btn_edit = new QPushButton(); @@ -130,7 +139,7 @@ pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->hopsTable->setCellWidget(i, 10, pWidget); + ui->hopsTable->setCellWidget(i, 11, pWidget); } }
--- a/ui/EditProduct.ui Fri Apr 29 20:29:26 2022 +0200 +++ b/ui/EditProduct.ui Fri Apr 29 21:42:00 2022 +0200 @@ -2559,9 +2559,9 @@ <widget class="QLabel" name="hop_tasteLabel"> <property name="geometry"> <rect> - <x>220</x> + <x>225</x> <y>10</y> - <width>131</width> + <width>126</width> <height>20</height> </rect> </property> @@ -5892,6 +5892,10 @@ </attribute> </widget> <widget class="QWidget" name="ferment"> + <attribute name="icon"> + <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <normaloff>:/icons/bms/fermenter.png</normaloff>:/icons/bms/fermenter.png</iconset> + </attribute> <attribute name="title"> <string>Fermenting</string> </attribute>