QVariant MashStepTableModel::data( const QModelIndex& index, int role ) const { MashStep* row; unitDisplay unit; unitScale scale; int col = index.column(); if( mashObs == 0 ) return QVariant(); // Ensure the row is ok. if( index.row() >= (int)(steps.size()) ) { Brewtarget::logW(tr("Bad model index. row = %1").arg(index.row())); return QVariant(); } else row = steps[index.row()]; // Make sure we only respond to the DisplayRole role. if( role != Qt::DisplayRole ) return QVariant(); switch( col ) { case MASHSTEPNAMECOL: return QVariant(row->name()); case MASHSTEPTYPECOL: return QVariant(row->typeStringTr()); case MASHSTEPAMOUNTCOL: unit = displayUnit(col); scale = displayScale(col); return (row->type() == MashStep::Decoction) ? QVariant( Brewtarget::displayAmount(row->decoctionAmount_l(), Units::liters, 3, unit, scale ) ) : QVariant( Brewtarget::displayAmount(row->infuseAmount_l(), Units::liters, 3, unit, scale) ); case MASHSTEPTEMPCOL: unit = displayUnit(col); return (row->type() == MashStep::Decoction) ? QVariant("---") : QVariant( Brewtarget::displayAmount(row->infuseTemp_c(), Units::celsius, 3, unit, noScale) ); case MASHSTEPTARGETTEMPCOL: unit = displayUnit(col); return QVariant( Brewtarget::displayAmount(row->stepTemp_c(), Units::celsius,3, unit, noScale) ); case MASHSTEPTIMECOL: scale = displayScale(col); return QVariant( Brewtarget::displayAmount(row->stepTime_min(), Units::minutes,0,noUnit,scale) ); default : Brewtarget::logW(tr("Bad column: %1").arg(index.column())); return QVariant(); } }
bool operator==(MashStep &m1, MashStep &m2) { return m1.name() == m2.name(); }
bool operator<(MashStep &m1, MashStep &m2) { return m1.name() < m2.name(); }