src/EditRecipeTab5.cpp

changeset 141
eea8a9e7e1f6
parent 128
0f4eee875ea6
child 142
1caa15a0eefc
equal deleted inserted replaced
140:6638609328c2 141:eea8a9e7e1f6
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */ 18 */
19 19
20 20
21 void EditRecipe::refreshYeasts() 21 bool EditRecipe::yeast_sort_test(const Yeasts &D1, const Yeasts &D2)
22 { 22 {
23 if (D1.y_use > D2.y_use)
24 return false;
25 if (D1.y_use < D2.y_use)
26 return true;
27 return (D1.y_amount > D2.y_amount);
23 } 28 }
24 29
25 30
31 void EditRecipe::refreshYeasts()
32 {
33 QString w;
34 QWidget* pWidget;
35 QHBoxLayout* pLayout;
36 QTableWidgetItem *item;
37
38 qDebug() << "refreshYeasts" << recipe->yeasts.size();
39 std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test);
40
41 /*
42 * During filling the table turn off the cellChanged signal because every cell that is filled
43 * triggers the cellChanged signal. The QTableWidget has no better signal to use.
44 */
45 this->ignoreChanges = true;
46
47 const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"),
48 tr("Tol. %"), tr("Attn. %"), tr("Amount"), tr("Delete"), tr("Edit") });
49
50 ui->yeastsTable->setColumnCount(12);
51 ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */
52 ui->yeastsTable->setColumnWidth(1, 125); /* Laboratory */
53 ui->yeastsTable->setColumnWidth(2, 80); /* Code */
54 ui->yeastsTable->setColumnWidth(3, 80); /* Type */
55 ui->yeastsTable->setColumnWidth(4, 100); /* Usage */
56 ui->yeastsTable->setColumnWidth(5, 60); /* Min. */
57 ui->yeastsTable->setColumnWidth(6, 60); /* Max. */
58 ui->yeastsTable->setColumnWidth(7, 60); /* Tolerance */
59 ui->yeastsTable->setColumnWidth(8, 60); /* Attenuation */
60 ui->yeastsTable->setColumnWidth(9, 90); /* Amount */
61 ui->yeastsTable->setColumnWidth(10, 80); /* Delete */
62 ui->yeastsTable->setColumnWidth(11, 80); /* Edit */
63 ui->yeastsTable->setHorizontalHeaderLabels(labels);
64 ui->yeastsTable->verticalHeader()->hide();
65 ui->yeastsTable->setRowCount(recipe->yeasts.size());
66
67 for (int i = 0; i < recipe->yeasts.size(); i++) {
68
69 ui->yeastsTable->setItem(i, 0, new QTableWidgetItem(recipe->yeasts.at(i).y_name));
70 ui->yeastsTable->setItem(i, 1, new QTableWidgetItem(recipe->yeasts.at(i).y_laboratory));
71 ui->yeastsTable->setItem(i, 2, new QTableWidgetItem(recipe->yeasts.at(i).y_product_id));
72
73 item = new QTableWidgetItem(y_types[recipe->yeasts.at(i).y_type]);
74 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
75 ui->yeastsTable->setItem(i, 3, item);
76
77 item = new QTableWidgetItem(y_use[recipe->yeasts.at(i).y_use]);
78 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
79 ui->yeastsTable->setItem(i, 4, item);
80
81 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_min_temperature, 2, 'f', 1, '0'));
82 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
83 ui->yeastsTable->setItem(i, 5, item);
84
85 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_max_temperature, 2, 'f', 1, '0'));
86 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
87 ui->yeastsTable->setItem(i, 6, item);
88
89 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_tolerance, 2, 'f', 1, '0'));
90 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
91 ui->yeastsTable->setItem(i, 7, item);
92
93 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_attenuation, 2, 'f', 1, '0'));
94 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
95 ui->yeastsTable->setItem(i, 8, item);
96
97 if (recipe->yeasts.at(i).y_type == 0)
98 item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
99 else if (recipe->yeasts.at(i).y_type == 1)
100 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
101 else
102 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
103 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
104 ui->yeastsTable->setItem(i, 9, item);
105
106 pWidget = new QWidget();
107 QPushButton* btn_dele = new QPushButton();
108 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */
109 btn_dele->setText(tr("Delete"));
110 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteYeastRow_clicked()));
111 pLayout = new QHBoxLayout(pWidget);
112 pLayout->addWidget(btn_dele);
113 pLayout->setContentsMargins(5, 0, 5, 0);
114 pWidget->setLayout(pLayout);
115 ui->yeastsTable->setCellWidget(i, 10, pWidget);
116
117 pWidget = new QWidget();
118 QPushButton* btn_edit = new QPushButton();
119 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */
120 btn_edit->setText(tr("Edit"));
121 connect(btn_edit, SIGNAL(clicked()), this, SLOT(editYeastRow_clicked()));
122 pLayout = new QHBoxLayout(pWidget);
123 pLayout->addWidget(btn_edit);
124 pLayout->setContentsMargins(5, 0, 5, 0);
125 pWidget->setLayout(pLayout);
126 ui->yeastsTable->setCellWidget(i, 11, pWidget);
127 }
128
129 this->ignoreChanges = false;
130 }
131
132
133 void EditRecipe::addYeastRow_clicked()
134 {
135
136 }
137
138
139 void EditRecipe::deleteYeastRow_clicked()
140 {
141 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
142 int row = pb->objectName().toInt();
143 qDebug() << "Delete yeast row" << row << recipe->yeasts.size();
144
145 if (recipe->yeasts.size() < 1)
146 return;
147
148 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name),
149 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
150 if (rc == QMessageBox::No)
151 return;
152
153 this->ignoreChanges = true;
154 recipe->yeasts.removeAt(row);
155 this->ignoreChanges = false;
156 is_changed();
157 emit refreshAll();
158 }
159
160
161 void EditRecipe::editYeastRow_clicked()
162 {
163 QSqlQuery query;
164
165 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
166 recipe->yeasts_row = pb->objectName().toInt();
167 qDebug() << "Edit yeast row" << recipe->yeasts_row;
168 Yeasts backup = recipe->yeasts.at(recipe->yeasts_row);
169
170 QDialog* dialog = new QDialog(this);
171 dialog->resize(738, 230);
172 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
173 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
174 buttonBox->setGeometry(QRect(30, 180, 671, 32));
175 buttonBox->setLayoutDirection(Qt::LeftToRight);
176 buttonBox->setOrientation(Qt::Horizontal);
177 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
178 buttonBox->setCenterButtons(true);
179
180
181
182 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
183 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
184
185
186
187 disconnect(buttonBox, nullptr, nullptr, nullptr);
188
189 emit refreshAll();
190 }
191

mercurial