src/ProdOnTree.cpp

changeset 234
51aea8b798f0
parent 232
6d3ba9c44f95
child 336
e97f9e87d94b
equal deleted inserted replaced
233:baf666307ebb 234:51aea8b798f0
240 record = -2; 240 record = -2;
241 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdOnTree())); 241 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdOnTree()));
242 connect(openButton, SIGNAL(clicked()), this, SLOT(on_openButton_clicked())); 242 connect(openButton, SIGNAL(clicked()), this, SLOT(on_openButton_clicked()));
243 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); 243 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
244 244
245 treeWidget->setColumnCount(4); 245 treeWidget->setColumnCount(5);
246 treeWidget->setHeaderLabels({ tr("Guide"), tr("Group"), tr("Style"), tr("Product") }); 246 treeWidget->setHeaderLabels({ tr("Guide"), tr("Group"), tr("Style"), tr("Code"), tr("Product") });
247 treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); 247 treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
248 treeWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); 248 treeWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
249 249
250 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_clicked(QTreeWidgetItem*, int))); 250 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_clicked(QTreeWidgetItem*, int)));
251 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_doubleclicked(QTreeWidgetItem*, int))); 251 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_doubleclicked(QTreeWidgetItem*, int)));
296 query3.bindValue(":group", query1.value(0).toString()); 296 query3.bindValue(":group", query1.value(0).toString());
297 query3.bindValue(":name", query2.value(0).toString()); 297 query3.bindValue(":name", query2.value(0).toString());
298 query3.exec(); 298 query3.exec();
299 while (query3.next()) { 299 while (query3.next()) {
300 name = new QTreeWidgetItem(QStringList({ "", "", "", 300 name = new QTreeWidgetItem(QStringList({ "", "", "",
301 query3.value(2).toString() + " - " + query3.value(0).toString(), query3.value(1).toString() })); 301 query3.value(2).toString(), query3.value(0).toString(), query3.value(1).toString() }));
302 st_name->addChild( name ); 302 st_name->addChild( name );
303 } 303 }
304 } 304 }
305 treeWidget->expandItem(st_group); 305 treeWidget->expandItem(st_group);
306 } 306 }
333 333
334 /* 334 /*
335 * Fill in basic details of the selected recipe. 335 * Fill in basic details of the selected recipe.
336 */ 336 */
337 QSqlQuery query; 337 QSqlQuery query;
338 query.prepare("SELECT batch_size,boil_size,boil_time,efficiency,est_og,est_fg,est_abv,est_color,color_method,est_ibu,ibu_method,est_carb,notes,name " 338 query.prepare("SELECT batch_size,boil_size,boil_time,efficiency,est_og,est_fg,est_abv,est_color,color_method,est_ibu,ibu_method,est_carb,notes,name,code "
339 "FROM products WHERE record=:record"); 339 "FROM products WHERE record=:record");
340 query.bindValue(":record", record); 340 query.bindValue(":record", record);
341 query.exec(); 341 query.exec();
342 if (query.size() == 1) { 342 if (query.size() == 1) {
343 query.first(); 343 query.first();
353 colormethodEdit->setText(c_method[query.value(8).toInt()]); 353 colormethodEdit->setText(c_method[query.value(8).toInt()]);
354 ibuEdit->setValue(query.value(9).toInt()); 354 ibuEdit->setValue(query.value(9).toInt());
355 ibumethodEdit->setText(i_method[query.value(10).toInt()]); 355 ibumethodEdit->setText(i_method[query.value(10).toInt()]);
356 co2Edit->setValue(query.value(11).toDouble()); 356 co2Edit->setValue(query.value(11).toDouble());
357 remarksEdit->setPlainText(query.value(12).toString()); 357 remarksEdit->setPlainText(query.value(12).toString());
358 recipeBox->setTitle(query.value(13).toString()); 358 recipeBox->setTitle(query.value(14).toString() + " - " + query.value(13).toString());
359 recipeBox->setEnabled(true); 359 recipeBox->setEnabled(true);
360 } else { 360 } else {
361 qDebug() << "Error getting product record" << record; 361 qDebug() << "Error getting product record" << record;
362 } 362 }
363 } 363 }
403 if (item->isExpanded()) { 403 if (item->isExpanded()) {
404 item->setExpanded(false); 404 item->setExpanded(false);
405 } else { 405 } else {
406 item->setExpanded(true); 406 item->setExpanded(true);
407 } 407 }
408 } else if (col == 3) { 408 } else if ((col == 3) || (col == 4)) {
409 /* 409 /*
410 * if a recipe name is selected then: 410 * if a recipe name is selected then:
411 * item column 3 contains the recipe name, 411 * item column 3 contains the product code,
412 * item column 4 contains the recipe record number. 412 * item column 4 contains the product name,
413 * item column 5 contains the product record number.
413 */ 414 */
414 if (item->text(4).toInt() > 0) { 415 if (item->text(5).toInt() > 0) {
415 if (record != item->text(4).toInt()) { 416 if (record != item->text(5).toInt()) {
416 record = item->text(4).toInt(); 417 record = item->text(5).toInt();
417 showRecipe(); 418 showRecipe();
418 } 419 }
419 } 420 }
420 } 421 }
421 } 422 }
422 423
423 424
424 void ProdOnTree::on_item_doubleclicked(QTreeWidgetItem *item, int col) 425 void ProdOnTree::on_item_doubleclicked(QTreeWidgetItem *item, int col)
425 { 426 {
426 if ((col == 3) && (item->text(4).toInt() > 0)) { 427 if (((col == 3) || (col == 4)) && (item->text(5).toInt() > 0)) {
427 edit(item->text(4).toInt()); 428 edit(item->text(5).toInt());
428 } 429 }
429 } 430 }
430 431
431 432

mercurial