diff --git a/src/WaterDialog.cpp b/src/WaterDialog.cpp index 1f90c6d13..c21eec560 100644 --- a/src/WaterDialog.cpp +++ b/src/WaterDialog.cpp @@ -348,8 +348,7 @@ void WaterDialog::newTotals() { } btDigit_ph->setText( calculateMashpH(), 2 ); - } - else { + } else { for (int i = 0; i < static_cast(Water::Ions::numIons); ++i ) { Water::Ions ion = static_cast(i); m_ppm_digits[i]->setText( m_salt_table_model->total(ion) / allTheWaters, 0 ); @@ -365,6 +364,7 @@ void WaterDialog::removeSalts() { deadSalts.append( i.row() ); } m_salt_table_model->removeSalts(deadSalts); + return; } //! \brief Calcuates the residual alkalinity of the mash water. @@ -411,8 +411,7 @@ double WaterDialog::calculateSaltpH() { } //! \brief Calculates the pH delta caused by any salt additions. -double WaterDialog::calculateAddedSaltpH() -{ +double WaterDialog::calculateAddedSaltpH() { // We need the value from the salt table model, because we need all the // added salts, but not the base. diff --git a/src/database/ObjectStoreWrapper.h b/src/database/ObjectStoreWrapper.h index dc6756287..486b77f49 100644 --- a/src/database/ObjectStoreWrapper.h +++ b/src/database/ObjectStoreWrapper.h @@ -104,9 +104,12 @@ namespace ObjectStoreWrapper { if (id > 0 && objectStore.contains(id)) { return objectStore.getById(id); } - qDebug() << + // If the object isn't stored in the DB then we can create a shared pointer for it, but this is dangerous as there + // might already be another shared pointer to it. At minimum we should log a warning. In the long run we should + // Q_ASSERT(false) here. + qWarning() << Q_FUNC_INFO << "Creating new shared_ptr for unstored" << ne->metaObject()->className() << "#" << id << " :" << - ne->name(); + ne->name() << ". This may be a bug - eg if a shared_ptr already exists for this object!"; return std::shared_ptr{ne}; } diff --git a/src/tableModels/BtTableModel.h b/src/tableModels/BtTableModel.h index 197cb2d27..be46d4557 100644 --- a/src/tableModels/BtTableModel.h +++ b/src/tableModels/BtTableModel.h @@ -32,9 +32,9 @@ #include "BtFieldType.h" #include "measurement/UnitSystem.h" +#include "model/NamedEntity.h" class Recipe; -class NamedEntity; /** * \class BtTableModelData @@ -75,8 +75,9 @@ class NamedEntity; * * (I did start trying to do something clever with a common base class to try to expose functions from * \c BtTableModelData to the implementation of \c BtTableModel / \c BtTableModelRecipeObserver / - * \c BtTableModelInventory, but it quickly starts getting more complicated than it's worth IMHO because (a) - * \c BtTableModelData is templated but a common base class cannot be and (b) templated functions cannot be virtual.) + * \c BtTableModelInventory, but it quickly gets more complicated than it's worth IMHO because (a) + * \c BtTableModelData is templated but a common base class cannot be and (b) templated functions cannot be + * virtual.) */ template class BtTableModelData { @@ -84,12 +85,14 @@ class BtTableModelData { BtTableModelData() : rows{} { return; } + // Need a virtual destructor as we have a virtual member function + virtual ~BtTableModelData() = default; public: /** * \brief Return the \c i-th row in the model. * Returns \c nullptr on failure. */ - std::shared_ptr getRow(int ii) { + std::shared_ptr getRow(int ii) const { if (!(this->rows.isEmpty())) { if (ii >= 0 && ii < this->rows.size()) { return this->rows[ii]; @@ -118,12 +121,37 @@ class BtTableModelData { return tmp; } + /** + * \brief Given a raw pointer, find the index of the corresponding shared pointer in \c this->rows + * + * This is useful because the Qt signals and slots framework allows the slot receiving a signal to get a raw + * pointer to the object that sent the signal, and we often want to find the corresponding shared pointer in + * our list. + * + * Note that using this function is a lot safer than, say, calling ObjectStoreWrapper::getSharedFromRaw(), as + * that only works for objects that are already stored in the database, something which is not guaranteed to + * be the case with our rows. (Eg in SaltTableModel, new Salts are only stored in the DB when the window is + * closed with OK.) + * + * Function name is for consistency with \c QList::indexOf + * + * \param object what to search for + * \return index of object in this->rows or -1 if it's not found + */ + int findIndexOf(NE const * object) const { + for (int index = 0; index < this->rows.size(); ++index) { + if (this->rows.at(index).get() == object) { + return index; + } + } + return -1; + } + protected: virtual std::shared_ptr getRowAsNamedEntity(int ii) { return std::static_pointer_cast(this->getRow(ii)); } - QList< std::shared_ptr > rows; }; diff --git a/src/tableModels/FermentableTableModel.cpp b/src/tableModels/FermentableTableModel.cpp index 81e776a8f..0e3467483 100644 --- a/src/tableModels/FermentableTableModel.cpp +++ b/src/tableModels/FermentableTableModel.cpp @@ -1,6 +1,6 @@ /* * FermentableTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Mik Firestone * - Philip Greggory Lee @@ -44,7 +44,6 @@ #include "MainWindow.h" #include "measurement/Measurement.h" #include "measurement/Unit.h" -#include "model/Fermentable.h" #include "model/Inventory.h" #include "model/Recipe.h" #include "PersistentSettings.h" @@ -172,7 +171,8 @@ void FermentableTableModel::addFermentables(QList > } } -void FermentableTableModel::removeFermentable(int fermId, std::shared_ptr object) { +void FermentableTableModel::removeFermentable([[maybe_unused]] int fermId, + std::shared_ptr object) { this->remove(std::static_pointer_cast(object)); return; } @@ -235,14 +235,13 @@ void FermentableTableModel::changedInventory(int invKey, BtStringConst const & p return; } -void FermentableTableModel::changed(QMetaProperty prop, QVariant /*val*/) { +void FermentableTableModel::changed(QMetaProperty prop, [[maybe_unused]] QVariant val) { qDebug() << Q_FUNC_INFO << prop.name(); // Is sender one of our fermentables? Fermentable* fermSender = qobject_cast(sender()); if (fermSender) { - auto spFermSender = ObjectStoreWrapper::getSharedFromRaw(fermSender); - int ii = this->rows.indexOf(spFermSender); + int ii = this->findIndexOf(fermSender); if (ii < 0) { return; } @@ -295,7 +294,7 @@ QVariant FermentableTableModel::data(QModelIndex const & index, int role) const return QVariant(row->typeStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->type()); + return QVariant(static_cast(row->type())); } break; case FERMINVENTORYCOL: @@ -325,7 +324,7 @@ QVariant FermentableTableModel::data(QModelIndex const & index, int role) const return QVariant(row->additionMethodStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->additionMethod()); + return QVariant(static_cast(row->additionMethod())); } break; case FERMAFTERBOIL: @@ -333,7 +332,7 @@ QVariant FermentableTableModel::data(QModelIndex const & index, int role) const return QVariant(row->additionTimeStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->additionTime()); + return QVariant(static_cast(row->additionTime())); } break; case FERMYIELDCOL: @@ -402,7 +401,9 @@ Qt::ItemFlags FermentableTableModel::flags(const QModelIndex& index ) const { } -bool FermentableTableModel::setData(QModelIndex const & index, QVariant const & value, int role) { +bool FermentableTableModel::setData(QModelIndex const & index, + QVariant const & value, + [[maybe_unused]] int role) { if (index.row() >= static_cast(this->rows.size())) { return false; } @@ -525,7 +526,7 @@ FermentableItemDelegate::FermentableItemDelegate(QObject* parent) : QItemDelegat } QWidget* FermentableItemDelegate::createEditor(QWidget *parent, - QStyleOptionViewItem const & option, + [[maybe_unused]] QStyleOptionViewItem const & option, QModelIndex const & index) const { if (index.column() == FERMTYPECOL ) { @@ -564,13 +565,10 @@ QWidget* FermentableItemDelegate::createEditor(QWidget *parent, int type = index.model()->index(index.row(), FERMTYPECOL).data(Qt::UserRole).toInt(); // Hide the unsuitable item keeping the same enumeration - if(type == Fermentable::Grain) - { - list->item(Fermentable::Not_Mashed)->setHidden(true); - } - else - { - list->item(Fermentable::Steeped)->setHidden(true); + if (type == static_cast(Fermentable::Type::Grain)) { + list->item(static_cast(Fermentable::AdditionMethod::Not_Mashed))->setHidden(true); + } else { + list->item(static_cast(Fermentable::AdditionMethod::Steeped))->setHidden(true); } return box; @@ -645,7 +643,8 @@ void FermentableItemDelegate::setModelData(QWidget *editor, QAbstractItemModel * } } -void FermentableItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ +void FermentableItemDelegate::updateEditorGeometry(QWidget * editor, + QStyleOptionViewItem const & option, + [[maybe_unused]] QModelIndex const & index) const { editor->setGeometry(option.rect); } diff --git a/src/tableModels/FermentableTableModel.h b/src/tableModels/FermentableTableModel.h index e3af3306c..a821fdefe 100644 --- a/src/tableModels/FermentableTableModel.h +++ b/src/tableModels/FermentableTableModel.h @@ -35,6 +35,7 @@ #include #include "measurement/Unit.h" +#include "model/Fermentable.h" #include "tableModels/BtTableModelInventory.h" // Forward declarations. diff --git a/src/tableModels/HopTableModel.cpp b/src/tableModels/HopTableModel.cpp index 0b5bdcea9..ed00517ec 100644 --- a/src/tableModels/HopTableModel.cpp +++ b/src/tableModels/HopTableModel.cpp @@ -1,6 +1,6 @@ /* * HopTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Luke Vincent * - Matt Young * - Mik Firestone @@ -189,7 +189,8 @@ bool HopTableModel::remove(std::shared_ptr hop) { return false; } -void HopTableModel::removeHop(int hopId, std::shared_ptr object) { +void HopTableModel::removeHop([[maybe_unused]] int hopId, + std::shared_ptr object) { this->remove(std::static_pointer_cast(object)); return; } @@ -220,13 +221,12 @@ void HopTableModel::changedInventory(int invKey, BtStringConst const & propertyN return; } -void HopTableModel::changed(QMetaProperty prop, QVariant /*val*/) { +void HopTableModel::changed(QMetaProperty prop, [[maybe_unused]] QVariant val) { // Find the notifier in the list Hop * hopSender = qobject_cast(sender()); if (hopSender) { - auto spHopSender = ObjectStoreWrapper::getSharedFromRaw(hopSender); - int ii = this->rows.indexOf(spHopSender); + int ii = this->findIndexOf(hopSender); if (ii < 0) { return; } @@ -299,7 +299,7 @@ QVariant HopTableModel::data(const QModelIndex & index, int role) const { return QVariant(row->useStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->use()); + return QVariant(static_cast(row->use())); } break; case HOPTIMECOL: @@ -314,7 +314,7 @@ QVariant HopTableModel::data(const QModelIndex & index, int role) const { if (role == Qt::DisplayRole) { return QVariant(row->formStringTr()); } else if (role == Qt::UserRole) { - return QVariant(row->form()); + return QVariant(static_cast(row->form())); } break; default : diff --git a/src/tableModels/MashStepTableModel.cpp b/src/tableModels/MashStepTableModel.cpp index d156aee14..58c4a9f99 100644 --- a/src/tableModels/MashStepTableModel.cpp +++ b/src/tableModels/MashStepTableModel.cpp @@ -1,6 +1,6 @@ /* * MashStepTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Maxime Lavigne * - Mik Firestone @@ -200,12 +200,12 @@ void MashStepTableModel::mashChanged() { return; } -void MashStepTableModel::mashStepChanged(QMetaProperty prop, QVariant val) { +void MashStepTableModel::mashStepChanged(QMetaProperty prop, + [[maybe_unused]] QVariant val) { qDebug() << Q_FUNC_INFO; - MashStep* stepSenderRaw = qobject_cast(sender()); - if (stepSenderRaw) { - auto stepSender = ObjectStoreWrapper::getSharedFromRaw(stepSenderRaw); + MashStep* stepSender = qobject_cast(sender()); + if (stepSender) { if (stepSender->getMashId() != this->mashObs->key()) { // It really shouldn't happen that we get a notification for a MashStep that's not in the Mash we're watching, // but, if we do, then stop trying to process the update. @@ -216,10 +216,10 @@ void MashStepTableModel::mashStepChanged(QMetaProperty prop, QVariant val) { return; } - int ii = this->rows.indexOf(stepSender); + int ii = this->findIndexOf(stepSender); if (ii >= 0) { if (prop.name() == PropertyNames::MashStep::stepNumber) { - this->reorderMashStep(stepSender, ii); + this->reorderMashStep(this->rows.at(ii), ii); } emit dataChanged( QAbstractItemModel::createIndex(ii, 0), @@ -267,7 +267,7 @@ QVariant MashStepTableModel::data(QModelIndex const & index, int role) const { return QVariant( Measurement::displayAmount( Measurement::Amount{ - row->type() == MashStep::Decoction ? row->decoctionAmount_l() : row->infuseAmount_l(), + row->type() == MashStep::Type::Decoction ? row->decoctionAmount_l() : row->infuseAmount_l(), Measurement::Units::liters }, 3, @@ -276,7 +276,7 @@ QVariant MashStepTableModel::data(QModelIndex const & index, int role) const { ) ); case MASHSTEPTEMPCOL: - if (row->type() == MashStep::Decoction) { + if (row->type() == MashStep::Type::Decoction) { return QVariant("---"); } return QVariant( @@ -361,7 +361,7 @@ bool MashStepTableModel::setData(QModelIndex const & index, QVariant const & val case MASHSTEPAMOUNTCOL: if (value.canConvert(QVariant::String)) { - if (row->type() == MashStep::Decoction ) { + if (row->type() == MashStep::Type::Decoction ) { MainWindow::instance().doOrRedoUpdate( *row, PropertyNames::MashStep::decoctionAmount_l, @@ -387,7 +387,7 @@ bool MashStepTableModel::setData(QModelIndex const & index, QVariant const & val return false; case MASHSTEPTEMPCOL: - if (value.canConvert(QVariant::String) && row->type() != MashStep::Decoction) { + if (value.canConvert(QVariant::String) && row->type() != MashStep::Type::Decoction) { MainWindow::instance().doOrRedoUpdate( *row, PropertyNames::MashStep::infuseTemp_c, diff --git a/src/tableModels/MiscTableModel.cpp b/src/tableModels/MiscTableModel.cpp index b864e987c..14b3ed312 100644 --- a/src/tableModels/MiscTableModel.cpp +++ b/src/tableModels/MiscTableModel.cpp @@ -1,6 +1,6 @@ /* * MiscTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Mik Firestone * - Philip Greggory Lee @@ -31,7 +31,6 @@ #include "measurement/Measurement.h" #include "measurement/Unit.h" #include "model/Inventory.h" -#include "model/Misc.h" #include "model/Recipe.h" #include "PersistentSettings.h" #include "utils/BtStringConst.h" @@ -148,7 +147,8 @@ void MiscTableModel::addMiscs(QList > miscs) { } // Returns true when misc is successfully found and removed. -void MiscTableModel::removeMisc(int miscId, std::shared_ptr object) { +void MiscTableModel::removeMisc([[maybe_unused]] int miscId, + std::shared_ptr object) { this->remove(std::static_pointer_cast(object)); return; } @@ -208,7 +208,7 @@ QVariant MiscTableModel::data(QModelIndex const & index, int role) const { return QVariant(row->typeStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->type()); + return QVariant(static_cast(row->type())); } break; case MISCUSECOL: @@ -216,7 +216,7 @@ QVariant MiscTableModel::data(QModelIndex const & index, int role) const { return QVariant(row->useStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->use()); + return QVariant(static_cast(row->use())); } return QVariant(); case MISCTIMECOL: @@ -260,7 +260,7 @@ QVariant MiscTableModel::data(QModelIndex const & index, int role) const { return QVariant(row->amountTypeStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->amountType()); + return QVariant(static_cast(row->amountType())); } break; default: @@ -290,7 +290,9 @@ Qt::ItemFlags MiscTableModel::flags(QModelIndex const & index) const { } } -bool MiscTableModel::setData(QModelIndex const & index, QVariant const & value, int role) { +bool MiscTableModel::setData(QModelIndex const & index, + QVariant const & value, + [[maybe_unused]] int role) { if (index.row() >= static_cast(this->rows.size())) { return false; @@ -402,17 +404,14 @@ void MiscTableModel::changedInventory(int invKey, BtStringConst const & property return; } -void MiscTableModel::changed(QMetaProperty prop, QVariant /*val*/) { +void MiscTableModel::changed(QMetaProperty prop, [[maybe_unused]] QVariant val) { Misc * miscSender = qobject_cast(sender()); if (miscSender) { - auto spMiscSender = ObjectStoreWrapper::getSharedFromRaw(miscSender); - int i = this->rows.indexOf(spMiscSender); - if (i < 0) { - return; + int ii = this->findIndexOf(miscSender); + if (ii >= 0) { + emit dataChanged( QAbstractItemModel::createIndex(ii, 0), + QAbstractItemModel::createIndex(ii, MISCNUMCOLS-1) ); } - - emit dataChanged( QAbstractItemModel::createIndex(i, 0), - QAbstractItemModel::createIndex(i, MISCNUMCOLS-1) ); return; } @@ -521,6 +520,6 @@ void MiscItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, void MiscItemDelegate::updateEditorGeometry(QWidget * editor, QStyleOptionViewItem const & option, - QModelIndex const & index) const { + [[maybe_unused]] QModelIndex const & index) const { editor->setGeometry(option.rect); } diff --git a/src/tableModels/MiscTableModel.h b/src/tableModels/MiscTableModel.h index 3b6035974..118e40a68 100644 --- a/src/tableModels/MiscTableModel.h +++ b/src/tableModels/MiscTableModel.h @@ -36,9 +36,9 @@ #include #include "measurement/Unit.h" +#include "model/Misc.h" #include "tableModels/BtTableModelInventory.h" - // Forward declarations. class BtStringConst; class MiscItemDelegate; diff --git a/src/tableModels/SaltTableModel.cpp b/src/tableModels/SaltTableModel.cpp index 08a70afda..066c59eca 100644 --- a/src/tableModels/SaltTableModel.cpp +++ b/src/tableModels/SaltTableModel.cpp @@ -1,6 +1,6 @@ /* * SaltTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Mik Firestone * - Philip Greggory Lee @@ -42,7 +42,6 @@ #include "model/Mash.h" #include "model/MashStep.h" #include "model/Recipe.h" -#include "model/Salt.h" #include "PersistentSettings.h" #include "WaterDialog.h" @@ -346,33 +345,31 @@ void SaltTableModel::removeAll() { endRemoveRows(); } -void SaltTableModel::changed(QMetaProperty prop, QVariant /*val*/) -{ - int i; - +void SaltTableModel::changed(QMetaProperty prop, [[maybe_unused]] QVariant val) { // Find the notifier in the list - Salt* saltSender = qobject_cast(sender()); - if (saltSender ) { - auto spSaltSender = ObjectStoreWrapper::getSharedFromRaw(saltSender); - i = this->rows.indexOf(spSaltSender); - if (i >= 0 ) - emit dataChanged( QAbstractItemModel::createIndex(i, 0), - QAbstractItemModel::createIndex(i, SALTNUMCOLS-1)); - emit headerDataChanged( Qt::Vertical, i, i); + Salt * saltSender = qobject_cast(sender()); + if (saltSender) { + int ii = this->findIndexOf(saltSender); + if (ii >= 0) { + emit dataChanged(QAbstractItemModel::createIndex(ii, 0), + QAbstractItemModel::createIndex(ii, SALTNUMCOLS-1)); + emit headerDataChanged(Qt::Vertical, ii, ii); + } return; } // See if sender is our recipe. Recipe* recSender = qobject_cast(sender()); - if (recSender && recSender == this->recObs ) - { - if (QString(prop.name()) == "salts" ) { + if (recSender && recSender == this->recObs ) { + if (QString(prop.name()) == "salts") { removeAll(); addSalts(this->recObs->getAll()); } - if (rowCount() > 0 ) + if (rowCount() > 0) { emit headerDataChanged( Qt::Vertical, 0, rowCount()-1 ); + } } + return; } int SaltTableModel::rowCount(const QModelIndex& /*parent*/) const diff --git a/src/tableModels/WaterTableModel.cpp b/src/tableModels/WaterTableModel.cpp index b5eb6f84c..1dde0178c 100644 --- a/src/tableModels/WaterTableModel.cpp +++ b/src/tableModels/WaterTableModel.cpp @@ -1,6 +1,6 @@ /* * WaterTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Mik Firestone * - Philip Greggory Lee @@ -37,7 +37,6 @@ #include "measurement/Measurement.h" #include "measurement/Unit.h" #include "model/Recipe.h" -#include "model/Water.h" #include "PersistentSettings.h" #include "WaterTableWidget.h" @@ -149,7 +148,8 @@ void WaterTableModel::addWaters(QList > waters) { } -void WaterTableModel::removeWater(int waterId, std::shared_ptr object) { +void WaterTableModel::removeWater([[maybe_unused]] int waterId, + std::shared_ptr object) { auto water = std::static_pointer_cast(object); int i = rows.indexOf(water); if (i >= 0) { @@ -179,11 +179,10 @@ void WaterTableModel::changed(QMetaProperty prop, QVariant val) { // Find the notifier in the list Water * waterSender = qobject_cast(sender()); if (waterSender) { - auto spWaterSender = ObjectStoreWrapper::getSharedFromRaw(waterSender); - int i = rows.indexOf(spWaterSender); - if (i >= 0) { - emit dataChanged(QAbstractItemModel::createIndex(i, 0), - QAbstractItemModel::createIndex(i, WATERNUMCOLS - 1)); + int ii = findIndexOf(waterSender); + if (ii >= 0) { + emit dataChanged(QAbstractItemModel::createIndex(ii, 0), + QAbstractItemModel::createIndex(ii, WATERNUMCOLS - 1)); } } return; diff --git a/src/tableModels/WaterTableModel.h b/src/tableModels/WaterTableModel.h index 1b86998de..7ffc7c9be 100644 --- a/src/tableModels/WaterTableModel.h +++ b/src/tableModels/WaterTableModel.h @@ -32,6 +32,7 @@ #include #include "measurement/Unit.h" +#include "model/Water.h" #include "tableModels/BtTableModel.h" // Forward declarations. diff --git a/src/tableModels/YeastTableModel.cpp b/src/tableModels/YeastTableModel.cpp index dd0cb408d..cd9f4e3f6 100644 --- a/src/tableModels/YeastTableModel.cpp +++ b/src/tableModels/YeastTableModel.cpp @@ -1,6 +1,6 @@ /* * YeastTableModel.cpp is part of Brewtarget, and is Copyright the following - * authors 2009-2021 + * authors 2009-2022 * - Matt Young * - Mik Firestone * - Philip Greggory Lee @@ -41,7 +41,6 @@ #include "measurement/Unit.h" #include "model/Inventory.h" #include "model/Recipe.h" -#include "model/Yeast.h" #include "PersistentSettings.h" #include "utils/BtStringConst.h" @@ -159,7 +158,8 @@ void YeastTableModel::addYeasts(QList > yeasts) { return; } -void YeastTableModel::removeYeast(int yeastId, std::shared_ptr object) { +void YeastTableModel::removeYeast([[maybe_unused]] int yeastId, + std::shared_ptr object) { this->remove(std::static_pointer_cast(object)); return; } @@ -204,14 +204,11 @@ void YeastTableModel::changed(QMetaProperty prop, QVariant /*val*/) { // Find the notifier in the list Yeast * yeastSender = qobject_cast(sender()); if (yeastSender) { - auto spYeastSender = ObjectStoreWrapper::getSharedFromRaw(yeastSender); - int ii = this->rows.indexOf(spYeastSender); - if (ii < 0) { - return; + int ii = this->findIndexOf(yeastSender); + if (ii >= 0) { + emit dataChanged(QAbstractItemModel::createIndex(ii, 0), + QAbstractItemModel::createIndex(ii, YEASTNUMCOLS - 1)); } - - emit dataChanged(QAbstractItemModel::createIndex(ii, 0), - QAbstractItemModel::createIndex(ii, YEASTNUMCOLS - 1)); return; } @@ -254,7 +251,7 @@ QVariant YeastTableModel::data(QModelIndex const & index, int role) const { return QVariant(row->typeStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->type()); + return QVariant(static_cast(row->type())); } break; case YEASTLABCOL: @@ -272,7 +269,7 @@ QVariant YeastTableModel::data(QModelIndex const & index, int role) const { return QVariant(row->formStringTr()); } if (role == Qt::UserRole) { - return QVariant(row->form()); + return QVariant(static_cast(row->form())); } break; case YEASTINVENTORYCOL: diff --git a/src/tableModels/YeastTableModel.h b/src/tableModels/YeastTableModel.h index bcf51ad57..aedfdf403 100644 --- a/src/tableModels/YeastTableModel.h +++ b/src/tableModels/YeastTableModel.h @@ -36,10 +36,10 @@ #include "measurement/Unit.h" #include "tableModels/BtTableModelInventory.h" +#include "model/Yeast.h" // Forward declarations. class BtStringConst; -class Yeast; class YeastTableWidget; class YeastItemDelegate; class Recipe;