Commit 1cef9d45 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Insert before/after in ingredients: use the same type as the item currently selected, fixes #2

parent 32c3f13f
......@@ -102,6 +102,7 @@ public:
static void downloadUpdate(QString adresse, QWidget *parent);
static bool is_config_valid(int id);
static void write_categories_file(QStringList new_cats);
static QString get_ingredient_type(QString ingr);
};
#endif // FUNCTIONS_H
......@@ -1700,3 +1700,14 @@ void Functions::write_categories_file(QStringList new_cats) {
writer.writeEndElement();
confCatFile->close();
}
QString Functions::get_ingredient_type(QString ingr) {
QRegExp expIngr("\\d+\\|ingr#.+");
QRegExp expIngrGrp("\\d+\\|.+");
if (expIngr.exactMatch(ingr))
return "ingredient";
else if (expIngrGrp.exactMatch(ingr))
return "ingredient_group";
else
return "comment";
}
......@@ -3521,7 +3521,7 @@ void QRecipeWriter::modifierIngr(const QModelIndex &index)
}
else {
idIngr = parts[0].toInt();
QRegExp expIngr("ingr#(.+)?#(.*)#(.+)");
QRegExp expIngr("ingr#(.+)?#(.*)#(.*)");
if (parts[1].contains(expIngr)) {
QString quantity = expIngr.cap(1);
QString unit = expIngr.cap(2);
......@@ -3925,9 +3925,14 @@ void QRecipeWriter::on_listIngr_customContextMenuRequested(const QPoint &pos)
{
//Insérer un élément après is handled
ingrEdit = ui->listIngr->selectionModel()->selectedIndexes().at(0).row();
int puce = model1->item(ingrEdit)->text().split("|").at(0).toInt();
QString ingr_to_edit = model1->item(ingrEdit)->text();
QString puce = ingr_to_edit.split("|").at(0);
ingrEdit++;
model1->insertRow(ingrEdit, new QStandardItem(QString::number(puce) + "|"));
QString typeIngr = Functions::get_ingredient_type(ingr_to_edit);
if (typeIngr == "ingredient")
model1->insertRow(ingrEdit, new QStandardItem(puce + "|ingr###"));
else
model1->insertRow(ingrEdit, new QStandardItem(puce + "|"));
modifierIngr(model1->index(ingrEdit, 0));
}
else if (s == cont_menu.at(3))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment