Skip to content

Commit

Permalink
- issue 3276: resolve items before deleting as they may already be gone
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jan 21, 2025
1 parent f8ac94c commit 43efe50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
27 changes: 14 additions & 13 deletions copasi/UI/CQCompartmentDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,23 +373,24 @@ bool CQCompartmentDM::removeRows(QModelIndexList rows, const QModelIndex& index)
if (rows.isEmpty())
return false;

// Build the list of pointers to items to be deleted
// Build the list of items to be deleted
// before actually deleting any item.
QList <CCompartment *> Compartments;
QModelIndexList::const_iterator i;

for (i = rows.begin(); i != rows.end(); ++i)
if (i->isValid()
&& !isDefaultRow(*i))
QList <std::string> names;

for (const auto& index : rows)
if (index.isValid()
&& !isDefaultRow(index))
{
Compartments.append(&mpCompartments->operator[](i->row()));
names.append(mpCompartments->operator[](index.row()).getObjectName());
}

QList< CCompartment * >::const_iterator j;

for (j = Compartments.begin(); j != Compartments.end(); ++j)
for (const auto& name : names)
{
CCompartment * pCompartment = *j;
auto index = mpCompartments->getIndex(name);
if (index == C_INVALID_INDEX)
continue;

CCompartment * pCompartment = &mpCompartments->operator[](name);

QMessageBox::StandardButton choice =
CQMessageBox::confirmDelete(ListViews::ancestor(this), "compartment",
Expand All @@ -398,7 +399,7 @@ bool CQCompartmentDM::removeRows(QModelIndexList rows, const QModelIndex& index)

if (choice == QMessageBox::Ok)
{
removeRows(mpCompartments->getIndex(pCompartment->getObjectName()), 1);
removeRows(index, 1);
}
}

Expand Down
19 changes: 11 additions & 8 deletions copasi/UI/CQGlobalQuantityDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,26 @@ bool CQGlobalQuantityDM::removeRows(QModelIndexList rows, const QModelIndex& ind
if (rows.isEmpty())
return false;

// Build the list of pointers to items to be deleted
// Build the list of items to be deleted
// before actually deleting any item.
QList< CModelValue * > ModelValues;
QList< std::string > names;
QModelIndexList::const_iterator i;

for (i = rows.begin(); i != rows.end(); ++i)
if (i->isValid()
&& !isDefaultRow(*i))
{
ModelValues.append(&mpGlobalQuantities->operator[](i->row()));
names.append(mpGlobalQuantities->operator[](i->row()).getObjectName());
}

QList< CModelValue * >::const_iterator j;

for (j = ModelValues.begin(); j != ModelValues.end(); ++j)

for (auto& objName : names)
{
CModelValue * pModelValue = *j;
auto index = mpGlobalQuantities->getIndex(objName);
if (index == C_INVALID_INDEX)
continue;

CModelValue * pModelValue = &mpGlobalQuantities->operator[](objName);

QMessageBox::StandardButton choice =
CQMessageBox::confirmDelete(ListViews::ancestor(this), "quantity",
Expand All @@ -396,7 +399,7 @@ bool CQGlobalQuantityDM::removeRows(QModelIndexList rows, const QModelIndex& ind

if (choice == QMessageBox::Ok)
{
removeRows(mpGlobalQuantities->getIndex(pModelValue->getObjectName()), 1);
removeRows(index, 1);
}
}

Expand Down
26 changes: 13 additions & 13 deletions copasi/UI/CQSpecieDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,23 @@ bool CQSpecieDM::removeRows(QModelIndexList rows, const QModelIndex & parent)
if (rows.isEmpty())
return false;

//Build the list of pointers to items to be deleted
//Build the list of items to be deleted
//before actually deleting any item.
QList <CMetab *> Species;
QModelIndexList::const_iterator i;
QList <std::string> names;

size_t numSpecies = mpMetabolites->size();

for (i = rows.begin(); i != rows.end(); ++i)
for (const auto& index : rows)
{
if (i->isValid()
&& !isDefaultRow(*i))
Species.append(&mpMetabolites->operator[](i->row()));
if (index.isValid() && !isDefaultRow(index))
names.append(mpMetabolites->operator[](index.row()).getStringCN());
}

QList< CMetab * >::const_iterator j;

for (j = Species.begin(); j != Species.end(); ++j)

for (auto& objectCn : names)
{
CMetab * pSpecies = *j;
CMetab* pSpecies = const_cast< CMetab* >( dynamic_cast<const CMetab*> (mpMetabolites->getObjectDataModel()->getObject(CRegisteredCommonName(objectCn))));
if (!pSpecies)
continue;

QMessageBox::StandardButton choice =
CQMessageBox::confirmDelete(ListViews::ancestor(this), "species",
Expand All @@ -611,6 +611,6 @@ bool CQSpecieDM::removeRows(QModelIndexList rows, const QModelIndex & parent)
removeRows(mpMetabolites->getIndex(pSpecies), 1);
}
}

return true;
}

0 comments on commit 43efe50

Please sign in to comment.