src/EditRecipeTab4.cpp

changeset 136
17030224d919
parent 135
e68b27ad8a40
child 137
ffe8b2e9517b
equal deleted inserted replaced
135:e68b27ad8a40 136:17030224d919
169 } 169 }
170 this->ignoreChanges = false; 170 this->ignoreChanges = false;
171 } 171 }
172 172
173 173
174 /*
175 * Manipulate the memory array and update the miscs table.
176 */
177 void EditRecipe::brewing_salt_sub(QString salt, double val)
178 {
179 QTableWidgetItem *item;
180
181 if (val == 0) {
182 /*
183 * Remove this salt if it is in the table.
184 */
185 for (int i = 0; i < recipe->miscs.size(); i++) {
186 if (salt.contains(recipe->miscs.at(i).m_name)) {
187 qDebug() << " brewing_salt_sub delete" << salt;
188 recipe->miscs.removeAt(i);
189 refreshMiscs();
190 return;
191 }
192 }
193 qDebug() << " brewing_salt_sub delete error";
194 return;
195 }
196
197 /*
198 * First see if this salt is in the table.
199 * If it is, update the amount.
200 */
201 for (int i = 0; i < recipe->miscs.size(); i++) {
202 if (salt.contains(recipe->miscs.at(i).m_name)) {
203 recipe->miscs[i].m_amount = val / 1000.0;
204 if (recipe->miscs.at(i).m_amount_is_weight)
205 item = new QTableWidgetItem(QString("%1 gr").arg(val, 3, 'f', 2, '0'));
206 else
207 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0'));
208 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
209 ui->miscsTable->setItem(i, 4, item);
210 return;
211 }
212 }
213
214 /*
215 * We need a new entry. Search in the database is tricky because
216 * we are here with possible more names for the same salt. The
217 * name can be like 'Lactic Melkzuur'. So we select only the
218 * brewing salts and manually check their names.
219 */
220 QSqlQuery query("SELECT * FROM inventory_miscs WHERE type = 4");
221 while (query.next()) {
222 if (salt.contains(query.value(1).toString())) {
223 qDebug() << " found it, append";
224 Miscs m;
225 m.m_name = query.value(1).toString();
226 m.m_amount = val / 1000.0;
227 m.m_type = query.value(2).toInt();
228 m.m_use_use = query.value(3).toInt();
229 m.m_time = query.value(4).toDouble();
230 m.m_amount_is_weight = query.value(5).toInt() ? true:false;
231 m.m_cost = query.value(10).toDouble();
232 recipe->miscs.append(m);
233 refreshMiscs();
234 return;
235 }
236 }
237
238 qDebug() << "brewing_salt_sub, nothing done." << salt << val;
239 }
240
241
242 /*
243 * Edit brewing salt and recalculate.
244 */
174 void EditRecipe::set_brewing_salt(QString salt, double val) 245 void EditRecipe::set_brewing_salt(QString salt, double val)
175 { 246 {
176 if (this->ignoreChanges) 247 if (this->ignoreChanges)
177 return; 248 return;
178 249
179 qDebug() << "set_brewing_salt" << salt << val; 250 qDebug() << "set_brewing_salt" << salt << val;
180 251 brewing_salt_sub(salt, val);
181
182 calcWater(); 252 calcWater();
183 is_changed(); 253 is_changed();
184 } 254 }
185 255
186 256

mercurial