Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for adding and reordering steps #870

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ happens, so I'm now setting it to a slightly arbitrary time early in the morning
* Additional methods for calculating IBU
* We'll list other new features here...

## v4.0.10
Bug fixes and minor enhancements.

### New Features
* Danish translation

### Bug Fixes
* Crash when copying recipe, then on adding new steps in mash, ferment, boil, others [868](https://github.com/Brewtarget/brewtarget/issues/868)

### Release Timestamp
Sun, 3 Nov 2024 04:00:10 +0100

## v4.0.9
Bug fixes and minor enhancements.

Expand Down
20 changes: 13 additions & 7 deletions src/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,20 @@ AboutDialog::AboutDialog(QWidget * parent) :
// 2013 U-CHIMCHIM\mik <mik@chimchim.(none)> // Incomplete name and email
" </ul>"
""
// **********************************************************************************************************
// * Note that the HTML source indentation here is different than above so that we don't pick up testers as *
// * copyright holders in the awk command above! *
// **********************************************************************************************************
" <p>The following people have made notable contributions with testing and bug reports:</p>"
// ***********************************************************************************************************
// * Note that the HTML source indentation here is different than above so that we don't pick up translators *
// * as software copyright holders in the awk command above! *
// * *
// * This list is currently somewhat incomplete, partly as I haven't yet found a record of who did all the *
// * original translations, and partly as some GitHub users do not have their name in their profile. *
// ***********************************************************************************************************
" <p>The following people are amongst those who have provided translations:</p>"
" <ul>"
" <li>Mik Firestone &lt;[email protected]&gt;</li>"
" <li>Nikolas &quot;Jazzbeerman&quot; </li>"
" <li>André Rodrigues (Brazilian Portuguese)</li>"
" <li>Orla Valbjørn Møller (Danish)</li>"
" <li>Marcel Koek (Dutch)</li>"
" <li>Mattias Måhl (Swedish)</li>"
" <li>Mikhail Gorbunov (Russian)</li>"
" </ul>"
""
" <h2>License (GPLv3)</h2>"
Expand Down
4 changes: 2 additions & 2 deletions src/BrewDayFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ QString BrewDayFormatter::buildInstructionHtml() {
.arg(tr("Step"));

bool useAlt = true;
for (auto instruction : recObs->steps()) {
for (auto instruction : recObs->instructions()) {
useAlt = !useAlt;
QString stepTime, tmp;
QList<QString> reagents;
Expand Down Expand Up @@ -259,7 +259,7 @@ QList<QStringList> BrewDayFormatter::buildInstructionList() {
ret.append(row);
row.clear();

for (auto instruction : recObs->steps()) {
for (auto instruction : recObs->instructions()) {
QString stepTime, tmp;
QList<QString> reagents;

Expand Down
20 changes: 10 additions & 10 deletions src/BrewDayScrollWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BrewDayScrollWidget::BrewDayScrollWidget(QWidget* parent) : QWidget{parent},
BrewDayScrollWidget::~BrewDayScrollWidget() = default;

void BrewDayScrollWidget::saveInstruction() {
this->m_recObs->steps()[ listWidget->currentRow() ]->setDirections( btTextEdit->toPlainText() );
this->m_recObs->instructions()[ listWidget->currentRow() ]->setDirections( btTextEdit->toPlainText() );
return;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ void BrewDayScrollWidget::generateInstructions() {
// TODO: Would be neat to make this an undoable action
//
bool proceed = true;
if (this->m_recObs->numSteps() > 0) {
if (this->m_recObs->instructions().size() > 0) {
proceed = QMessageBox::Yes == QMessageBox::question(
this,
tr("Overwrite Existing Instructions"),
Expand Down Expand Up @@ -143,7 +143,7 @@ void BrewDayScrollWidget::removeSelectedInstruction() {
if (row < 0) {
return;
}
this->m_recObs->removeStep(this->m_recIns[row]);
this->m_recObs->m_instructions.remove(this->m_recIns[row]);

// After updating the model, this is the simplest way to update the display
this->setRecipe(this->m_recObs);
Expand Down Expand Up @@ -171,7 +171,7 @@ void BrewDayScrollWidget::pushInstructionUp() {
return;
}

this->m_recObs->swapSteps(*this->m_recIns[row], *this->m_recIns[row-1]);
this->m_recObs->m_instructions.swap(*this->m_recIns[row], *this->m_recIns[row-1]);

// After updating the model, this is the simplest way to update the display
this->setRecipe(this->m_recObs);
Expand All @@ -190,7 +190,7 @@ void BrewDayScrollWidget::pushInstructionDown() {
return;
}

this->m_recObs->swapSteps(*this->m_recIns[row], *this->m_recIns[row+1]);
this->m_recObs->m_instructions.swap(*this->m_recIns[row], *this->m_recIns[row+1]);

// After updating the model, this is the simplest way to update the display
this->setRecipe(this->m_recObs);
Expand Down Expand Up @@ -248,7 +248,7 @@ void BrewDayScrollWidget::setRecipe(Recipe* rec) {
this->m_recObs = rec;
connect(this->m_recObs, &Recipe::changed, this, &BrewDayScrollWidget::acceptChanges);

m_recIns = this->m_recObs->steps();
m_recIns = this->m_recObs->m_instructions.items();
for (auto ins : m_recIns) {
connect(ins.get(), &Instruction::changed, this, &BrewDayScrollWidget::acceptInsChanges);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ void BrewDayScrollWidget::insertInstruction() {
lineEdit_name->clear();

pos = qBound(1, pos, this->m_recIns.size());
this->m_recObs->insertStep(instruction, pos);
this->m_recObs->m_instructions.insert(instruction, pos);

// After updating the model, this is the simplest way to update the display
this->setRecipe(this->m_recObs);
Expand All @@ -298,12 +298,12 @@ void BrewDayScrollWidget::insertInstruction() {
}

void BrewDayScrollWidget::acceptChanges(QMetaProperty prop, QVariant /*value*/) {
if (m_recObs && QString(prop.name()) == PropertyNames::SteppedOwnerBase::steps) {
if (m_recObs && QString(prop.name()) == PropertyNames::Recipe::instructions) {
// An instruction has been added or deleted, so update internal list.
for (auto ins : m_recIns ) {
disconnect(ins.get(), nullptr, this, nullptr);
}
m_recIns = this->m_recObs->steps(); // Already sorted by instruction numbers.
m_recIns = this->m_recObs->m_instructions.items(); // Already sorted by instruction numbers.
for (auto ins : m_recIns ) {
connect(ins.get(), &Instruction::changed, this, &BrewDayScrollWidget::acceptInsChanges);
}
Expand Down Expand Up @@ -438,7 +438,7 @@ QString BrewDayScrollWidget::buildInstructionTable() {
.arg(tr("Time"))
.arg(tr("Step"));

auto instructions = this->m_recObs->steps();
auto instructions = this->m_recObs->m_instructions.items();
auto mashSteps = this->m_recObs->mash()->mashSteps();
int size = instructions.size();
for (int i = 0; i < size; ++i ) {
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ void MainWindow::showChanges(QMetaProperty* prop) {
if (this->pimpl->m_recipeObs->boil() &&
(updateAll ||
propName == PropertyNames::Recipe::boil ||
propName == PropertyNames::SteppedOwnerBase::steps)) {
propName == PropertyNames::StepOwnerBase::steps)) {
this->pimpl->m_boilStepTableModel->setBoil(this->pimpl->m_recipeObs->boil());
}
// See if we need to change the fermentation in the table.
Expand Down
4 changes: 2 additions & 2 deletions src/RecipeFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class RecipeFormatter::impl {
return "";
}

auto instructions = this->rec->steps();
auto instructions = this->rec->instructions();
int size = instructions.size();
if ( size < 1 ) {
return "";
Expand Down Expand Up @@ -952,7 +952,7 @@ class RecipeFormatter::impl {

QStringList num, text;

auto instructions = rec->steps();
auto instructions = rec->instructions();
int size = instructions.size();
if ( size > 0 ) {
for (int ii = 0; ii < size; ++ii) {
Expand Down
2 changes: 1 addition & 1 deletion src/WaterDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#include "ui_waterDialog.h"

#include "measurement/Unit.h"
#include "model/Salt.h"
#include "model/Water.h"

class WaterListModel;
class WaterSortFilterProxyModel;
class WaterEditor;
class RecipeAdjustmentSaltTableModel;
class RecipeAdjustmentSaltItemDelegate;
class Salt;

/*!
* \class WaterDialog
Expand Down
53 changes: 53 additions & 0 deletions src/database/DatabaseSchemaHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,59 @@ namespace {
"WHERE reversed_step_number = 1 "
"AND recipe.mash_id = last_mash_step.mash_id"
), {QVariant{false}, QVariant{true}}},
//
// But wait, we're not done on pre-boil step. We also need to handle the case where a recipe has a mash that
// does not have any mash steps. Eg the supplied "Extract" recipes are like this.
//
// It may be there is a way to combine this with the SQL query above, but I think it's simpler not to and just
// live with some horrible copy-and-paste here in a query that just creates a (hopefully sane) pre-boil step
// for any recipes that don't have one. We make a heroic assumption that the start temperature is 15°C (ie
// about 60 °F) which is about what you might expect tap water temperature to be a lot of the time in a lot of
// places.
//
{QString("INSERT INTO boil_step ("
"name , "
"deleted , "
"display , "
"step_time_mins , "
"end_temp_c , "
"ramp_time_mins , "
"step_number , "
"boil_id , "
"description , "
"start_acidity_ph, "
"end_acidity_ph , "
"start_temp_c , "
"start_gravity_sg, "
"end_gravity_sg , "
"chilling_type "
") SELECT "
"'Pre-boil for ' || recipe.name, " // name
"?, " // deleted
"?, " // display
"NULL, " // step_time_mins
"100.0, " // end_temp_c
"NULL, " // ramp_time_mins
"1, " // step_number
"recipe.boil_id, " // boil_id
"'Automatically-generated pre-boil step for ' || recipe.name, " // description
"NULL, " // start_acidity_ph
"NULL, " // end_acidity_ph
"15, " // start_temp_c
"NULL, " // start_gravity_sg
"NULL, " // end_gravity_sg
"NULL " // chilling_type
"FROM recipe "
"WHERE recipe.boil_id in ( "
"SELECT boil_id "
"FROM boil "
"WHERE boil_id NOT IN ( "
"SELECT boil_id "
"FROM boil_step "
"WHERE step_number = 1 "
")"
")"
), {QVariant{false}, QVariant{true}}},
// Adding the second step for the actual boil itself is easier
{QString("INSERT INTO boil_step ("
"name , "
Expand Down
3 changes: 3 additions & 0 deletions src/database/ObjectStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,9 @@ class ObjectStore::impl {
qDebug() <<
Q_FUNC_INFO << "Updating" << object.metaObject()->className() << "property" << propertyName <<
"with database query" << queryString;
// Normally leave the next debug output commented, as it can generate a lot of logging. But it's useful to
// uncomment if you're seeing a lot of DB updates and the cause is not clear.
// qDebug().noquote() << Q_FUNC_INFO << Logging::getStackTrace();

//
// Bind the values
Expand Down
16 changes: 8 additions & 8 deletions src/database/ObjectStoreTyped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ namespace {
// NB: MashSteps don't have folders, as each one is owned by a Mash
{ObjectStore::FieldType::Double, "end_temp_c" , PropertyNames:: Step::endTemp_c },
{ObjectStore::FieldType::Double, "infuse_temp_c" , PropertyNames:: MashStep::infuseTemp_c },
{ObjectStore::FieldType::Int , "mash_id" , PropertyNames::SteppedBase::ownerId , &PRIMARY_TABLE<Mash>},
{ObjectStore::FieldType::Int , "mash_id" , PropertyNames::EnumeratedBase::ownerId , &PRIMARY_TABLE<Mash>},
{ObjectStore::FieldType::Enum , "mstype" , PropertyNames:: MashStep::type , &MashStep::typeStringMapping},
{ObjectStore::FieldType::Double, "ramp_time_mins" , PropertyNames:: StepBase::rampTime_mins },
{ObjectStore::FieldType::Int , "step_number" , PropertyNames::SteppedBase::stepNumber },
{ObjectStore::FieldType::Int , "step_number" , PropertyNames::EnumeratedBase::stepNumber },
{ObjectStore::FieldType::Double, "step_temp_c" , PropertyNames:: StepBase::startTemp_c },
{ObjectStore::FieldType::Double, "step_time_mins" , PropertyNames:: StepBase::stepTime_mins },
// Now we support BeerJSON, amount_l unifies and replaces infuseAmount_l and decoctionAmount_l
Expand Down Expand Up @@ -360,8 +360,8 @@ namespace {
{ObjectStore::FieldType::Double, "start_temp_c" , PropertyNames:: StepBase::startTemp_c },
{ObjectStore::FieldType::Double, "end_temp_c" , PropertyNames:: Step::endTemp_c },
{ObjectStore::FieldType::Double, "ramp_time_mins" , PropertyNames:: StepBase::rampTime_mins },
{ObjectStore::FieldType::Int , "step_number" , PropertyNames:: SteppedBase::stepNumber },
{ObjectStore::FieldType::Int , "boil_id" , PropertyNames:: SteppedBase::ownerId , &PRIMARY_TABLE<Boil>},
{ObjectStore::FieldType::Int , "step_number" , PropertyNames:: EnumeratedBase::stepNumber },
{ObjectStore::FieldType::Int , "boil_id" , PropertyNames:: EnumeratedBase::ownerId , &PRIMARY_TABLE<Boil>},
{ObjectStore::FieldType::String, "description" , PropertyNames:: Step::description },
{ObjectStore::FieldType::Double, "start_acidity_ph", PropertyNames:: Step::startAcidity_pH},
{ObjectStore::FieldType::Double, "end_acidity_ph" , PropertyNames:: Step::endAcidity_pH },
Expand Down Expand Up @@ -410,8 +410,8 @@ namespace {
{ObjectStore::FieldType::Double, "step_time_mins" , PropertyNames:: StepBase::stepTime_mins },
{ObjectStore::FieldType::Double, "start_temp_c" , PropertyNames:: StepBase::startTemp_c },
{ObjectStore::FieldType::Double, "end_temp_c" , PropertyNames:: Step::endTemp_c },
{ObjectStore::FieldType::Int , "step_number" , PropertyNames:: SteppedBase::stepNumber },
{ObjectStore::FieldType::Int , "fermentation_id" , PropertyNames:: SteppedBase::ownerId , &PRIMARY_TABLE<Fermentation>},
{ObjectStore::FieldType::Int , "step_number" , PropertyNames:: EnumeratedBase::stepNumber },
{ObjectStore::FieldType::Int , "fermentation_id" , PropertyNames:: EnumeratedBase::ownerId , &PRIMARY_TABLE<Fermentation>},
{ObjectStore::FieldType::String, "description" , PropertyNames:: Step::description },
{ObjectStore::FieldType::Double, "start_acidity_ph", PropertyNames:: Step::startAcidity_pH},
{ObjectStore::FieldType::Double, "end_acidity_ph" , PropertyNames:: Step:: endAcidity_pH},
Expand Down Expand Up @@ -846,8 +846,8 @@ namespace {
{ObjectStore::FieldType::String, "name" , PropertyNames::NamedEntity::name },
{ObjectStore::FieldType::Bool , "display" , PropertyNames::NamedEntity::display },
{ObjectStore::FieldType::Bool , "deleted" , PropertyNames::NamedEntity::deleted },
{ObjectStore::FieldType::Int , "recipe_id" , PropertyNames::SteppedBase::ownerId , &PRIMARY_TABLE<Recipe>},
{ObjectStore::FieldType::Int , "step_number" , PropertyNames::SteppedBase::stepNumber},
{ObjectStore::FieldType::Int , "recipe_id" , PropertyNames::EnumeratedBase::ownerId , &PRIMARY_TABLE<Recipe>},
{ObjectStore::FieldType::Int , "step_number" , PropertyNames::EnumeratedBase::stepNumber},
{ObjectStore::FieldType::String, "directions" , PropertyNames::Instruction::directions},
{ObjectStore::FieldType::Bool , "has_timer" , PropertyNames::Instruction::hasTimer },
{ObjectStore::FieldType::String, "timer_value" , PropertyNames::Instruction::timerValue},
Expand Down
4 changes: 2 additions & 2 deletions src/model/Boil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//======================================================================================================================
//========================================== Start of property name constants ==========================================
// See comment in model/NamedEntity.h
#define AddPropertyName(property) namespace PropertyNames::Boil { BtStringConst const property{#property}; }
#define AddPropertyName(property) namespace PropertyNames::Boil { inline BtStringConst const property{#property}; }
AddPropertyName(description )
AddPropertyName(notes )
AddPropertyName(preBoilSize_l)
Expand Down Expand Up @@ -72,7 +72,7 @@ class Boil : public NamedEntity,
STEP_OWNER_COMMON_DECL(Boil, boil)
// See model/FolderBase.h for info, getters and setters for these properties
Q_PROPERTY(QString folder READ folder WRITE setFolder )
// See model/SteppedOwnerBase.h for info, getters and setters for these properties
// See model/StepOwnerBase.h for info, getters and setters for these properties
Q_PROPERTY(QList<std::shared_ptr<BoilStep>> steps READ steps WRITE setSteps STORED false)
Q_PROPERTY(unsigned int numSteps READ numSteps STORED false)

Expand Down
Loading
Loading