int CQTaskMethodParametersDM::getRow(const CCopasiParameter * pNode) const { if (pNode == NULL) { return -1; } CCopasiParameterGroup * pParent = static_cast< CCopasiParameterGroup * >(pNode->getObjectParent()); if (pParent == NULL) { return 0; } if (isMethod(pParent)) { QVector< CCopasiMethod * >::const_iterator itMethod = mMethods.constBegin(); QVector< CCopasiMethod * >::const_iterator endMethod = mMethods.constEnd(); int i = 0; for (; itMethod != endMethod; ++itMethod) { CCopasiParameterGroup::index_iterator it = pParent->beginIndex(); CCopasiParameterGroup::index_iterator end = pParent->endIndex(); for (; it != end; ++it, ++i) if (*it == pNode) { return i; } } } else { int i = 0; CCopasiParameterGroup::index_iterator it = pParent->beginIndex(); CCopasiParameterGroup::index_iterator end = pParent->endIndex(); for (; it != end; ++it, ++i) if (*it == pNode) { return i; } } return -1; }
// virtual QModelIndex CQTaskMethodParametersDM::index(int row, int column, const QModelIndex & parent) const { CCopasiParameterGroup * pParent = static_cast< CCopasiParameterGroup * >(nodeFromIndex(parent)); if (pParent == NULL && mMethods.size() > 0) { QVector< CCopasiMethod * >::const_iterator it = mMethods.constBegin(); QVector< CCopasiMethod * >::const_iterator end = mMethods.constEnd(); int Row = row; for (; it != end; ++it) if (Row < (int)(*it)->size()) { return createIndex(row, column, *((*it)->beginIndex() + Row)); } else { Row -= (int)(*it)->size(); } return QModelIndex(); } if (pParent != NULL && row < (int) pParent->size()) return createIndex(row, column, *(pParent->beginIndex() + row)); else return QModelIndex(); }
void CQParameterGroupView::modifySelectCNs(CCopasiParameterGroup & group, const CCopasiParameter & cnTemplate) { // OpenSelectionDialog std::vector< const CDataObject * > Selection; CObjectInterface::ContainerList ContainerList; ContainerList.push_back(group.getObjectDataModel()); // Create the current selection CCopasiParameterGroup::elements::iterator it = group.beginIndex(); CCopasiParameterGroup::elements::iterator end = group.endIndex(); for (; it != end; ++it) { const CDataObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ContainerList, (*it)->getValue< CCommonName >())); if (pObject != NULL) { Selection.push_back(pObject); } } CModel * pModel = group.getObjectDataModel()->getModel(); std::vector<const CDataObject * > ValidObjects; const std::vector< std::pair < CCommonName, CCommonName > > & ValidValues = cnTemplate.getValidValues< CCommonName >(); std::vector< std::pair < CCommonName, CCommonName > >::const_iterator itValidValues = ValidValues.begin(); std::vector< std::pair < CCommonName, CCommonName > >::const_iterator endValidValues = ValidValues.end(); for (; itValidValues != endValidValues; ++itValidValues) { CObjectLists::ListType ListType = toEnum(itValidValues->first, CObjectLists::ListTypeName, CObjectLists::EMPTY_LIST); std::vector<const CDataObject * > Tmp = CObjectLists::getListOfConstObjects(ListType, pModel); ValidObjects.insert(ValidObjects.end(), Tmp.begin(), Tmp.end()); } std::vector< const CDataObject * > NewSelection = CCopasiSelectionDialog::getObjectVector(this, ValidObjects, &Selection); // Modify group parameters; mpParameterGroupDM->beginResetModel(); group.clear(); std::vector< const CDataObject * >::const_iterator itNew = NewSelection.begin(); std::vector< const CDataObject * >::const_iterator endNew = NewSelection.end(); for (; itNew != endNew; ++itNew) { group.addParameter("Reaction", CCopasiParameter::Type::CN, (*itNew)->getCN()); } mpParameterGroupDM->endResetModel(); }