void CQSpecieDM::deleteSpecieRow(UndoSpeciesData *pSpecieData) { GET_MODEL_OR_RETURN(pModel); switchToWidget(CCopasiUndoCommand::SPECIES); CMetab * pSpecies = dynamic_cast< CMetab * >(pSpecieData->getObject(pModel)); if (pSpecies == NULL) return; size_t Index = pModel->getMetabolites().getIndex(pSpecies); removeRow((int) Index); if (!pSpecieData->getCreatedCompartment()) return; Index = pModel->getCompartments().getIndex(pSpecieData->getCompartment()); if (Index == C_INVALID_INDEX) return; CCompartment* pComp = &pModel->getCompartments()[Index]; if (pComp == NULL) return; std::string key = pComp->getKey(); pModel->removeCompartment(Index); emit notifyGUI(ListViews::COMPARTMENT, ListViews::DELETE, key); }
bool CQGlobalQuantityDM::insertGlobalQuantityRows(QList <UndoGlobalQuantityData *>& pData) { //reinsert all the GlobalQuantities QList <UndoGlobalQuantityData *>::const_iterator i; for (i = pData.begin(); i != pData.end(); ++i) { UndoGlobalQuantityData * data = *i; if (mpGlobalQuantities->getIndex(data->getName()) != C_INVALID_INDEX) continue; beginInsertRows(QModelIndex(), 1, 1); CModelValue *pGlobalQuantity = data->restoreObjectIn(mpDataModel->getModel()); if (pGlobalQuantity != NULL) emit notifyGUI(ListViews::MODELVALUE, ListViews::ADD, pGlobalQuantity->getKey()); endInsertRows(); } switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); return true; }
void WidgetStackControlListener::slotValueChanged(double v) { if (v > 0.0) { emit(switchToWidget()); } else { emit(hideWidget()); } }
void CQCompartment::deleteCompartment() { if (mpCompartment == NULL) return; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(this, "compartment", FROM_UTF8(mpCompartment->getObjectName()), mpCompartment->getDeletedObjects()); switch (choice) { case QMessageBox::Ok: { CModel * pModel = mpCompartment->getModel(); assert(pModel != NULL); pModel->removeCompartment(mKey); protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, mKey); protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, ""); //Refresh all as there may be dependencies. break; } default: break; } switchToWidget(CCopasiUndoCommand::COMPARTMENTS); }
void CQCompartment::addCompartment(UndoCompartmentData *pData) { //reinsert all the Compartments CModel * pModel = mpCompartment->getModel(); assert(pModel != NULL); pData->restoreObjectIn(pModel); protectedNotify(ListViews::COMPARTMENT, ListViews::ADD, pData->getKey()); switchToWidget(C_INVALID_INDEX, pData->getKey()); }
void CQGlobalQuantityDM::deleteGlobalQuantityRow(UndoGlobalQuantityData *pGlobalQuantityData) { switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); size_t index = mpGlobalQuantities->getIndex(pGlobalQuantityData->getName()); if (index == C_INVALID_INDEX) return; removeRow((int) index); }
void CQGlobalQuantityDM::addGlobalQuantityRow(UndoGlobalQuantityData *pGlobalQuantityData) { switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); beginInsertRows(QModelIndex(), 1, 1); CModelValue *pGlobalQuantity = pGlobalQuantityData->restoreObjectIn(mpDataModel->getModel()); if (pGlobalQuantity != NULL) emit notifyGUI(ListViews::MODELVALUE, ListViews::ADD, pGlobalQuantity->getKey()); endInsertRows(); }
void CQGlobalQuantityDM::deleteGlobalQuantityRows(QList <UndoGlobalQuantityData *>& pData) { switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); QList <UndoGlobalQuantityData *>::const_iterator j; for (j = pData.begin(); j != pData.end(); ++j) { UndoGlobalQuantityData * data = *j; size_t index = mpGlobalQuantities->getIndex(data->getName()); removeRow((int) index); } }
void WWidgetStack::addWidgetWithControl(QWidget* pWidget, ControlObject* pControl) { int index = addWidget(pWidget); if (pControl) { WidgetStackControlListener* pListener = new WidgetStackControlListener( this, pControl, index); connect(pListener, SIGNAL(switchToWidget()), &m_mapper, SLOT(map())); connect(this, SIGNAL(currentChanged(int)), pListener, SLOT(onCurrentWidgetChanged(int))); m_mapper.setMapping(pListener, index); pListener->onCurrentWidgetChanged(currentIndex()); } }
void CQSpecieDM::addSpecieRow(UndoSpeciesData *pSpecieData) { GET_MODEL_OR_RETURN(pModel); switchToWidget(CCopasiUndoCommand::SPECIES); CMetab *species = pSpecieData->restoreObjectIn(pModel); if (species == NULL) return; beginInsertRows(QModelIndex(), 1, 1); emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, species->getKey()); endInsertRows(); }
void CQSpeciesDetail::deleteSpecies(UndoSpeciesData *pSData) { GET_MODEL_OR_RETURN(pModel); switchToWidget(CCopasiUndoCommand::SPECIES); CMetab * pSpecies = dynamic_cast< CMetab * >(pSData->getObject(pModel)); if (pSpecies == NULL) return; std::string key = pSpecies->getKey(); pModel->removeMetabolite(key); #undef DELETE protectedNotify(ListViews::METABOLITE, ListViews::DELETE, key); //mKey); protectedNotify(ListViews::METABOLITE, ListViews::DELETE, "");//Refresh all as there may be dependencies. }
bool CQGlobalQuantityDM::globalQuantityDataChange(const QModelIndex &index, const QVariant &value, int role) { assert((size_t)index.row() < mpGlobalQuantities->size()); if (!index.isValid() || role != Qt::EditRole) return false; bool defaultRow = isDefaultRow(index); if (defaultRow) { if (index.column() == COL_TYPE_GQ) { if (index.data().toString() != QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]]))) insertRow(rowCount(), index); else return false; } else if (index.data() != value) insertRow(rowCount(), index); else return false; } switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); CModelValue & GQ = mpGlobalQuantities->operator [](index.row()); if (index.column() == COL_NAME_GQ) GQ.setObjectName(TO_UTF8(value.toString())); else if (index.column() == COL_TYPE_GQ) GQ.setStatus((CModelEntity::Status) mItemToType[value.toInt()]); else if (index.column() == COL_INITIAL_GQ) GQ.setInitialValue(value.toDouble()); if (defaultRow && this->index(index.row(), COL_NAME_GQ).data().toString() == "quantity") GQ.setObjectName(TO_UTF8(createNewName("quantity", COL_NAME_GQ))); emit dataChanged(index, index); emit notifyGUI(ListViews::MODELVALUE, ListViews::CHANGE, GQ.getKey()); return true; }
void CQCompartment::deleteCompartment(UndoCompartmentData *pCompartmentData) { switchToWidget(CCopasiUndoCommand::COMPARTMENTS); CModel * pModel = mpCompartment->getModel(); assert(pModel != NULL); CCompartment* pComp = &pModel->getCompartments()[pCompartmentData->getName()]; if (pComp == NULL) return; std::string key = pComp->getKey(); pModel->removeCompartment(key); mpCompartment = NULL; #undef DELETE protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, key); protectedNotify(ListViews::COMPARTMENT, ListViews::DELETE, "");//Refresh all as there may be dependencies. }
bool CQSpecieDM::removeSpecieRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; GET_MODEL_OR(pModel, return false); switchToWidget(CCopasiUndoCommand::SPECIES); //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CMetab *> pSpecies; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &pModel->getMetabolites()[i->row()]) pSpecies.append(&pModel->getMetabolites()[i->row()]); } QList <CMetab *>::const_iterator j; for (j = pSpecies.begin(); j != pSpecies.end(); ++j) { CMetab * pSpecie = *j; size_t delRow = pModel->getMetabolites().CCopasiVector< CMetab >::getIndex(pSpecie); if (delRow == C_INVALID_INDEX) continue; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "species", FROM_UTF8(pSpecie->getObjectName()), pSpecie->getDeletedObjects()); if (choice == QMessageBox::Ok) removeRow((int) delRow); } return true; }
bool CQGlobalQuantityDM::removeGlobalQuantityRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CModelValue *> pGlobalQuantities; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &mpGlobalQuantities->operator [](i->row())) pGlobalQuantities.append(&mpGlobalQuantities->operator [](i->row())); } QList <CModelValue *>::const_iterator j; for (j = pGlobalQuantities.begin(); j != pGlobalQuantities.end(); ++j) { CModelValue * pGQ = *j; size_t delRow = mpGlobalQuantities->CCopasiVector< CModelValue >::getIndex(pGQ); if (delRow == C_INVALID_INDEX) continue; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "quantity", FROM_UTF8(pGQ->getObjectName()), pGQ->getDeletedObjects()); if (choice == QMessageBox::Ok) removeRow((int) delRow); } return true; }
void WWidgetStack::addWidgetWithControl(QWidget* pWidget, ControlObject* pControl) { int index = addWidget(pWidget); if (pControl) { WidgetStackControlListener* pListener = new WidgetStackControlListener( this, pControl, index); m_showMapper.setMapping(pListener, index); m_hideMapper.setMapping(pListener, index); if (pControl->get() > 0) { setCurrentIndex(count()-1); } pListener->onCurrentWidgetChanged(currentIndex()); connect(pListener, SIGNAL(switchToWidget()), &m_showMapper, SLOT(map())); connect(pListener, SIGNAL(hideWidget()), &m_hideMapper, SLOT(map())); connect(this, SIGNAL(currentChanged(int)), pListener, SLOT(onCurrentWidgetChanged(int))); } if (m_currentPageControl.get() == index) { setCurrentIndex(index); } }
bool CQCompartment::changeValue(const std::string& key, CCopasiUndoCommand::Type type, const QVariant& newValue, double iValue, UndoCompartmentData* pUndoData) { if (!mIgnoreUpdates) { mKey = key; mpObject = CCopasiRootContainer::getKeyFactory()->get(key); mpCompartment = dynamic_cast<CCompartment*>(mpObject); load(); switchToWidget(C_INVALID_INDEX, mKey); } switch (type) { case CCopasiUndoCommand::COMPARTMENT_EXPRESSION_CHANGE: mpCompartment->setExpression(TO_UTF8(newValue.toString())); break; case CCopasiUndoCommand::COMPARTMENT_INITIAL_EXPRESSION_CHANGE: mpCompartment->setInitialExpression(TO_UTF8(newValue.toString())); if (newValue.toString().isEmpty()) { mpCompartment->setInitialValue(iValue); } break; case CCopasiUndoCommand::COMPARTMENT_INITIAL_VOLUME_CHANGE: mpCompartment->setInitialValue(newValue.toDouble()); if (pUndoData != NULL) { CModel * pModel = mpCompartment->getModel(); assert(pModel != NULL); pUndoData->fillDependentObjects(pModel); } break; case CCopasiUndoCommand::COMPARTMENT_SIMULATION_TYPE_CHANGE: mpCompartment->setStatus((CModelEntity::Status)newValue.toInt()); break; case CCopasiUndoCommand::COMPARTMENT_SPATIAL_DIMENSION_CHANGE: mpCompartment->setDimensionality(newValue.toInt()); break; case CCopasiUndoCommand::COMPARTMENT_ADD_NOISE_CHANGE: mpCompartment->setAddNoise(newValue.toBool()); break; case CCopasiUndoCommand::COMPARTMENT_NOISE_EXPRESSION_CHANGE: mpCompartment->setNoiseExpression(TO_UTF8(newValue.toString())); break; default: return false; } if (mIgnoreUpdates) return true; assert(mpDataModel != NULL); mpDataModel->changed(); protectedNotify(ListViews::COMPARTMENT, ListViews::CHANGE, mKey); load(); return true; }
bool CQSpecieDM::specieDataChange( UndoSpeciesData *pUndoSpeciesData, const QVariant &value, int column) { switchToWidget(CCopasiUndoCommand::SPECIES); GET_MODEL_OR(pModel, return false); mpSpecies = dynamic_cast<CMetab*>(pUndoSpeciesData->getObject(pModel)); if (mpSpecies == NULL) return false; const CCompartment * pCompartment = NULL; if (column == COL_COMPARTMENT || column == COL_ICONCENTRATION || column == COL_INUMBER) { try { pCompartment = mpSpecies->getCompartment(); } catch (...) {} } if (column == COL_NAME_SPECIES) { mpSpecies->setObjectName(TO_UTF8(value.toString())); pUndoSpeciesData->setCN(mpSpecies->getCN()); } else if (column == COL_COMPARTMENT) { // This must be set first for setInitialConcentration and // setInitialNumber to work correctly. std::string Compartment(TO_UTF8(value.toString())); if (Compartment != pCompartment->getObjectName()) { std::string CompartmentToRemove = mpSpecies->getCompartment()->getObjectName(); if (!(pModel->getCompartments()[Compartment].addMetabolite(mpSpecies))) { QString msg; msg = "Unable to move species '" + FROM_UTF8(mpSpecies->getObjectName()) + "'\n" + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + FROM_UTF8(Compartment) + "'\n" + "since a species with that name already exist in the target compartment."; CQMessageBox::information(NULL, "Unable to move Species", msg, QMessageBox::Ok, QMessageBox::Ok); return false; } else { pModel->getCompartments()[CompartmentToRemove].getMetabolites().remove(mpSpecies->getObjectName()); pModel->setCompileFlag(); pModel->initializeMetabolites(); if (mpSpecies && pCompartment) { C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue(); Factor *= pCompartment->getInitialValue(); mpSpecies->setInitialValue(Factor * pUndoSpeciesData->getINumber()); mpSpecies->setValue(Factor * mpSpecies->getValue()); } emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, mpSpecies->getKey()); emit notifyGUI(ListViews::COMPARTMENT, ListViews::CHANGE, pCompartment->getKey()); } } } else if (column == COL_TYPE_SPECIES) mpSpecies->setStatus((CModelEntity::Status) mItemToType[value.toInt()]); else if (column == COL_ICONCENTRATION) { if (mFlagConc) mpSpecies->setInitialConcentration(value.toDouble()); if (mpSpecies && pCompartment) { const C_FLOAT64 initialValue = CMetab::convertToNumber(pUndoSpeciesData->getIConc(), *pCompartment, *pModel); mpSpecies->setInitialValue(initialValue); } } else if (column == COL_INUMBER) { if (!mFlagConc) mpSpecies->setInitialValue(value.toDouble()); if (mpSpecies && pCompartment) { mpSpecies->setInitialConcentration( CMetab::convertToConcentration(pUndoSpeciesData->getINumber(), *pCompartment, *pModel) ); } } //Save Key std::string key = mpSpecies->getKey(); // ask for refresh this may change the key! QModelIndex index = getIndexFor(mpSpecies, column); emit dataChanged(index, index); if (column == COL_NAME_SPECIES) { emit notifyGUI(ListViews::METABOLITE, ListViews::RENAME, key); } else { emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, key); } return true; }