diff -r 58e4ce7dd217 -r e71642121fb6 src/RecipesTree.cpp --- a/src/RecipesTree.cpp Fri Apr 22 13:46:59 2022 +0200 +++ b/src/RecipesTree.cpp Sat Apr 23 08:47:50 2022 +0200 @@ -251,17 +251,12 @@ connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromRecipesTree())); connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); connect(openButton, SIGNAL(clicked()), this, SLOT(on_openButton_clicked())); - connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); -// treeWidget->setAutoExpandDelay(1); -// treeWidget->setUpdatesEnabled(true); -// treeWidget->collapseAll(); -// treeWidget->setRootIsDecorated(false); treeWidget->setColumnCount(4); treeWidget->setHeaderLabels({ tr("Guide"), tr("Group"), tr("Style"), tr("Recipe") }); treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); -// treeWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + treeWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_clicked(QTreeWidgetItem*, int))); connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_doubleclicked(QTreeWidgetItem*, int))); @@ -274,18 +269,15 @@ { QTreeWidgetItem *st_guide, *st_group, *st_name, *name; - qDebug() << "RecipesTree reload" << treeWidget->autoExpandDelay(); + qDebug() << "RecipesTree reload"; treeWidget->clear(); QSqlQuery query0; query0.prepare("SELECT DISTINCT st_guide FROM recipes ORDER BY st_guide"); query0.exec(); - query0.first(); - for (int i = 0; i < query0.size() ; i++) { - st_guide = new QTreeWidgetItem(treeWidget); - st_guide->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled ); - st_guide->setText(0, query0.value(0).toString()); + while (query0.next()) { + st_guide = new QTreeWidgetItem( QStringList( { query0.value(0).toString() } )); treeWidget->addTopLevelItem( st_guide ); st_guide->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); @@ -293,11 +285,8 @@ query1.prepare("SELECT DISTINCT st_letter FROM recipes WHERE st_guide=:guide ORDER BY st_letter"); query1.bindValue(":guide", query0.value(0).toString()); query1.exec(); - query1.first(); - for (int j = 0; j < query1.size(); j++) { - st_group = new QTreeWidgetItem(treeWidget); - st_group->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled ); - st_group->setText(1, query1.value(0).toString()); + while (query1.next()) { + st_group = new QTreeWidgetItem(QStringList({ "", query1.value(0).toString() })); st_group->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); st_guide->addChild( st_group ); @@ -306,10 +295,8 @@ query2.bindValue(":guide", query0.value(0).toString()); query2.bindValue(":group", query1.value(0).toString()); query2.exec(); - query2.first(); - for (int k = 0; k < query2.size(); k++) { - st_name = new QTreeWidgetItem(treeWidget); - st_name->setText(2, query2.value(0).toString()); + while (query2.next()) { + st_name = new QTreeWidgetItem(QStringList({ "", "", query2.value(0).toString() })); st_name->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); st_group->addChild( st_name ); @@ -319,24 +306,17 @@ query3.bindValue(":group", query1.value(0).toString()); query3.bindValue(":name", query2.value(0).toString()); query3.exec(); - query3.first(); - for (int l = 0; l < query3.size(); l++) { - name = new QTreeWidgetItem(treeWidget); - name->setText(3, query3.value(0).toString()); - name->setText(4, query3.value(1).toString()); + while (query3.next()) { + name = new QTreeWidgetItem(QStringList({ "", "", "", query3.value(0).toString(), query3.value(1).toString() })); st_name->addChild( name ); - - query3.next(); } - - query2.next(); } - query1.next(); + treeWidget->expandItem(st_group); } - query0.next(); + treeWidget->expandItem(st_guide); } - QSqlQuery query("SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name"); + QSqlQuery query("SELECT record FROM recipes"); emit setStatus(QString(tr("Total items: %1")).arg(query.size())); showRecipe(); @@ -389,7 +369,6 @@ } else { qDebug() << "Error getting recipe record" << record; } - qDebug() << "showRecipe done"; } @@ -398,13 +377,11 @@ void RecipesTree::edit(int recno) { - qDebug() << "edit" << recno; EditRecipe dialog(recno, this); /* Signal from editor if a refresh is needed */ connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); dialog.setModal(true); - int rc = dialog.exec(); - qDebug() << "edit is ready rc=" << rc; + dialog.exec(); } @@ -423,32 +400,25 @@ void RecipesTree::on_item_clicked(QTreeWidgetItem *item, int col) { -// qDebug() << Q_FUNC_INFO << item->text(col) << "col:" << col << item->text(4); - record = -2; // Invalid if (col == 0) { - qDebug() << item->text(0) << item->text(0).length() << item->isExpanded(); if (item->isExpanded()) { treeWidget->collapseItem(item); } else { treeWidget->expandItem(item); } } else if (col == 1) { - qDebug() << item->text(1) << item->text(1).length() << item->isExpanded(); if (item->isExpanded()) { treeWidget->collapseItem(item); } else { treeWidget->expandItem(item); } } else if (col == 2 && item->text(2).length()) { - qDebug() << item->text(2) << item->text(2).length() << item->isExpanded(); if (item->isExpanded()) { item->setExpanded(false); - treeWidget->collapseItem(item); } else { item->setExpanded(true); - treeWidget->expandItem(item); } } else if (col == 3) { /* @@ -457,7 +427,6 @@ * item column 4 contains the recipe record number. */ if (item->text(4).toInt() > 0) { - qDebug() << "save for openButton" << item->text(4); if (record != item->text(4).toInt()) { record = item->text(4).toInt(); showRecipe(); @@ -469,13 +438,8 @@ void RecipesTree::on_item_doubleclicked(QTreeWidgetItem *item, int col) { -// qDebug() << Q_FUNC_INFO << item->text(col) << "col:" << col; - if ((col == 3) && (item->text(4).toInt() > 0)) { - qDebug() << "shorcut open record" << item->text(4); edit(item->text(4).toInt()); - } else if (item->text(col).length() > 0) { - qDebug() << "doubleclick on" << item->text(col); } }