//! 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 CQFunctionDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; assert(mpDataModel != NULL); CModel * pModel = mpDataModel->getModel(); if (pModel == NULL) return false; //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CEvaluationTree *> pFunctions; CFunction * pFunction; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && (pFunction = &CRootContainer::getFunctionList()->loadedFunctions()[i->row()]) != NULL && !pFunction->isReadOnly()) pFunctions.append(&CRootContainer::getFunctionList()->loadedFunctions()[i->row()]); } QList <CEvaluationTree *>::const_iterator j; for (j = pFunctions.begin(); j != pFunctions.end(); ++j) { CEvaluationTree * pFunction = *j; size_t delRow = CRootContainer::getFunctionList()->loadedFunctions().CDataVector< CFunction >::getIndex(pFunction); if (delRow != C_INVALID_INDEX) { QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "function", FROM_UTF8(pFunction->getObjectName()), pFunction); if (choice == QMessageBox::Ok) removeRow((int) delRow); } } return true; }
bool CQFunctionDM::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { bool defaultRow = isDefaultRow(index); if (defaultRow) { if (index.data() != value) { mNewName = (index.column() == COL_NAME_FUNCTIONS) ? value.toString() : "function"; insertRow(rowCount(), index); } else return false; } CEvaluationTree *pFunc = &CRootContainer::getFunctionList()->loadedFunctions()[index.row()]; if (pFunc == NULL) return false; if (index.column() == COL_NAME_FUNCTIONS) pFunc->setObjectName(TO_UTF8(value.toString())); else if (index.column() == COL_TYPE_FUNCTIONS) { if (index.data() != value) { QString msg; msg = "Type must not be changed for '" + FROM_UTF8(pFunc->getObjectName()) + "'.\n"; CQMessageBox::information(NULL, "Unable to change Function Type", msg, QMessageBox::Ok, QMessageBox::Ok); } } else if (index.column() == COL_MATH_DESC_FUNCTIONS) { if (index.data() != value) { if (!pFunc->setInfix(TO_UTF8(value.toString()))) { QString msg; msg = "Incorrect mathematical description'" + FROM_UTF8(pFunc->getObjectName()) + "'.\n"; CQMessageBox::information(NULL, "Unable to change mathematical description", msg, QMessageBox::Ok, QMessageBox::Ok); } } } emit dataChanged(index, index); emit notifyGUI(ListViews::ObjectType::FUNCTION, ListViews::CHANGE, pFunc->getCN()); } return true; }
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; }