//! Slot for being activated whenever Delete button is clicked void FunctionWidget1::slotBtnDelete() { CFunctionDB * pFunctionDB = CCopasiRootContainer::getFunctionList(); if (pFunctionDB == NULL) return; CEvaluationTree * pFunction = dynamic_cast<CEvaluationTree *>(CCopasiRootContainer::getKeyFactory()->get(mKey)); if (pFunction == NULL) return; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "function", FROM_UTF8(pFunction->getObjectName()), pFunction->getDeletedObjects()); /* Check if user chooses to deleted Functions */ switch (choice) { case QMessageBox::Ok: // Yes or Enter { CCopasiRootContainer::getFunctionList()->removeFunction(mKey); protectedNotify(ListViews::FUNCTION, ListViews::DELETE, mKey); protectedNotify(ListViews::FUNCTION, ListViews::DELETE, "");//Refresh all as there may be dependencies. break; } default: // No or Escape break; } }
bool FunctionWidget1::leave() { assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel(); if (pModel == NULL) return true; // :TODO: We should check what changes have been done to the function // CFunctionDB * pFunctionDB = CCopasiRootContainer::getFunctionList(); if (pFunctionDB == NULL) return true; CEvaluationTree * pFunction = dynamic_cast<CEvaluationTree *>(CCopasiRootContainer::getKeyFactory()->get(mKey)); if (pFunction == NULL) return true; bool Used = false; if (functionParametersChanged()) { QString msg = QString("Cannot modify function: \n %1\n").arg(FROM_UTF8(pFunction->getObjectName())); std::set< const CCopasiObject * > Functions; std::set< const CCopasiObject * > Reactions; std::set< const CCopasiObject * > Metabolites; std::set< const CCopasiObject * > Values; std::set< const CCopasiObject * > Compartments; std::set< const CCopasiObject * > Events; std::set< const CCopasiObject * > DeletedObjects = pFunction->getDeletedObjects(); Used |= pFunctionDB->appendDependentFunctions(DeletedObjects, Functions); if (Functions.size() > 0) { msg.append("Following functions(s) reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Functions.begin(); std::set< const CCopasiObject * >::const_iterator end = Functions.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } Used |= pModel->appendDependentModelObjects(DeletedObjects, Reactions, Metabolites, Compartments, Values, Events); if (Reactions.size() > 0) { msg.append("Following reactions(s) reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Reactions.begin(); std::set< const CCopasiObject * >::const_iterator end = Reactions.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } if (Metabolites.size() > 0) { msg.append("Following species reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Metabolites.begin(); std::set< const CCopasiObject * >::const_iterator end = Metabolites.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } if (Values.size() > 0) { msg.append("Following global quantities reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Values.begin(); std::set< const CCopasiObject * >::const_iterator end = Values.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } if (Compartments.size() > 0) { msg.append("Following compartment(s) reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Compartments.begin(); std::set< const CCopasiObject * >::const_iterator end = Compartments.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } if (Events.size() > 0) { msg.append("Following event(s) reference above:\n "); std::set< const CCopasiObject * >::const_iterator it = Events.begin(); std::set< const CCopasiObject * >::const_iterator end = Events.end(); for (; it != end; ++it) { msg.append(FROM_UTF8((*it)->getObjectName())); msg.append("\n "); } msg.remove(msg.length() - 2, 2); } if (Used) { CQMessageBox::information(this, "Modification not possible", msg, QMessageBox::Ok, QMessageBox::Ok); return true; } } if (isValid) { saveToFunction(); mpExpressionEMSW->updateWidget(); } //update pFunction values /* Remove line breaks from the function description */ /*std::string desc = TO_UTF8(textBrowser->text()); unsigned int loc = 0; while (1) { loc = desc.find('\n', loc); if (loc == std::string::npos) break; desc.erase(loc, 1); } textBrowser->setText(FROM_UTF8(desc));*/ //mScrollView->hide(); return true; }