bool MashStepTableModel::setData( const QModelIndex& index, const QVariant& value, int role ) { MashStep *row; unitDisplay unit; if( mashObs == 0 ) return false; if( index.row() >= (int)(steps.size()) || role != Qt::EditRole ) return false; else row = steps[index.row()]; switch( index.column() ) { case MASHSTEPNAMECOL: if( value.canConvert(QVariant::String)) { row->setName(value.toString()); return true; } else return false; case MASHSTEPTYPECOL: if( value.canConvert(QVariant::Int) ) { row->setType(static_cast<MashStep::Type>(value.toInt())); return true; } else return false; case MASHSTEPAMOUNTCOL: if( value.canConvert(QVariant::String) ) { unit = displayUnit(MASHSTEPAMOUNTCOL); if( row->type() == MashStep::Decoction ) row->setDecoctionAmount_l( Brewtarget::qStringToSI(value.toString(),Units::liters,unit) ); else row->setInfuseAmount_l( Brewtarget::qStringToSI(value.toString(),Units::liters,unit) ); return true; } else return false; case MASHSTEPTEMPCOL: if( value.canConvert(QVariant::String) && row->type() != MashStep::Decoction ) { unit = displayUnit(MASHSTEPTEMPCOL); row->setInfuseTemp_c( Brewtarget::qStringToSI(value.toString(),Units::celsius,unit) ); return true; } else return false; case MASHSTEPTARGETTEMPCOL: if( value.canConvert(QVariant::String) ) { unit = displayUnit(MASHSTEPTARGETTEMPCOL); row->setStepTemp_c( Brewtarget::qStringToSI(value.toString(),Units::celsius,unit) ); row->setEndTemp_c( Brewtarget::qStringToSI(value.toString(),Units::celsius,unit) ); return true; } else return false; case MASHSTEPTIMECOL: if( value.canConvert(QVariant::String) ) { row->setStepTime_min( Brewtarget::qStringToSI(value.toString(),Units::minutes) ); return true; } else return false; default: return false; } }
void ScaleRecipeTool::scale(Equipment* equip, double newEff) { if( recObs == 0 || equip == 0 ) return; int i, size; // Calculate volume ratio double currentBatchSize_l = recObs->batchSize_l(); double newBatchSize_l = equip->batchSize_l(); double volRatio = newBatchSize_l / currentBatchSize_l; // Calculate efficiency ratio double oldEfficiency = recObs->efficiency_pct(); double effRatio = oldEfficiency / newEff; Database::instance().addToRecipe(recObs, equip); recObs->setBatchSize_l(newBatchSize_l); recObs->setBoilSize_l(equip->boilSize_l()); recObs->setEfficiency_pct(newEff); recObs->setBoilTime_min(equip->boilTime_min()); QList<Fermentable*> ferms = recObs->fermentables(); size = ferms.size(); for( i = 0; i < size; ++i ) { Fermentable* ferm = ferms[i]; // NOTE: why the hell do we need this? if( ferm == 0 ) continue; if( !ferm->isSugar() && !ferm->isExtract() ) { ferm->setAmount_kg(ferm->amount_kg() * effRatio * volRatio); } else { ferm->setAmount_kg(ferm->amount_kg() * volRatio); } } QList<Hop*> hops = recObs->hops(); size = hops.size(); for( i = 0; i < size; ++i ) { Hop* hop = hops[i]; // NOTE: why the hell do we need this? if( hop == 0 ) continue; hop->setAmount_kg(hop->amount_kg() * volRatio); } QList<Misc*> miscs = recObs->miscs(); size = miscs.size(); for( i = 0; i < size; ++i ) { Misc* misc = miscs[i]; // NOTE: why the hell do we need this? if( misc == 0 ) continue; misc->setAmount( misc->amount() * volRatio ); } QList<Water*> waters = recObs->waters(); size = waters.size(); for( i = 0; i < size; ++i ) { Water* water = waters[i]; // NOTE: why the hell do we need this? if( water == 0 ) continue; water->setAmount_l(water->amount_l() * volRatio); } Mash* mash = recObs->mash(); if( mash == 0 ) return; QList<MashStep*> mashSteps = mash->mashSteps(); size = mashSteps.size(); for( i = 0; i < size; ++i ) { MashStep* step = mashSteps[i]; // NOTE: why the hell do we need this? if( step == 0 ) continue; // Reset all these to zero so that the user // will know to re-run the mash wizard. step->setDecoctionAmount_l(0); step->setInfuseAmount_l(0); } // I don't think I should scale the yeasts. // Let the user know what happened. QMessageBox::information(this, tr("Recipe Scaled"), tr("The equipment and mash have been reset due to the fact that mash temperatures do not scale easily. Please re-run the mash wizard.") ); }