示例#1
0
bool CQGlobalQuantityDM::removeRows(int position, int rows)
{
  if (rows <= 0)
    return true;

  beginRemoveRows(QModelIndex(), position, position + rows - 1);

  std::vector< std::string > DeletedKeys;
  DeletedKeys.resize(rows);

  std::vector< std::string >::iterator itDeletedKey;
  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();

  CCopasiVector< CModelValue >::const_iterator itRow = mpGlobalQuantities->begin() + position;

  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow)
    {
      *itDeletedKey = itRow->getKey();
    }

  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey)
    {
      mpDataModel->getModel()->removeModelValue(*itDeletedKey);
      emit notifyGUI(ListViews::MODELVALUE, ListViews::DELETE, *itDeletedKey);
      emit notifyGUI(ListViews::MODELVALUE, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
    }

  endRemoveRows();

  return true;
}
示例#2
0
bool CQSpecieDM::insertRows(int position, int rows, const QModelIndex&)
{
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];

  if (pDataModel->getModel()->getCompartments().size() == 0)
    {
      pDataModel->getModel()->createCompartment("compartment");
      emit notifyGUI(ListViews::COMPARTMENT, ListViews::ADD, pDataModel->getModel()->getCompartments()[0]->getKey());
    }

  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      mpSpecies =
        pDataModel->getModel()->createMetabolite(TO_UTF8(createNewName("species", COL_NAME_SPECIES)), "", 1.0, CModelEntity::REACTIONS);

      if (mNotify)
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, mpSpecies->getKey());
        }
    }

  endInsertRows();

  return true;
}
示例#3
0
bool CQSpecieDM::removeRows(int position, int rows, const QModelIndex&)
{
  if (rows <= 0)
    return true;

  beginRemoveRows(QModelIndex(), position, position + rows - 1);

  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();

  std::vector< std::string > DeletedKeys;
  DeletedKeys.resize(rows);

  std::vector< std::string >::iterator itDeletedKey;
  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();

  CCopasiVector< CMetab >::const_iterator itRow = pModel->getMetabolites().begin() + position;

  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow)
    {
      *itDeletedKey = (*itRow)->getKey();
    }

  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey)
    {
      pModel->removeMetabolite(*itDeletedKey);
      emit notifyGUI(ListViews::METABOLITE, ListViews::DELETE, *itDeletedKey);
      emit notifyGUI(ListViews::METABOLITE, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
    }

  endRemoveRows();

  return true;
}
示例#4
0
QList <UndoSpeciesData *> CQSpecieDM::insertNewSpecieRow(int position, int rows, const QModelIndex&index, const QVariant& value)
{
  QList <UndoSpeciesData *> result;
  GET_MODEL_OR(pModel, return result);

  bool createdCompartment = false;

  if (pModel->getCompartments().size() == 0)
    {
      CCompartment* pComp = pModel->createCompartment("compartment");
      createdCompartment = true;

      if (mNotify)
        {
          emit notifyGUI(ListViews::COMPARTMENT, ListViews::ADD, pComp->getKey());
        }
    }

  beginInsertRows(QModelIndex(), position, position + rows - 1);

  int column = index.column();

  for (int row = 0; row < rows; ++row)
    {
      QString name = createNewName(index.isValid() && column == COL_NAME_SPECIES ? value.toString() : "species", COL_NAME_SPECIES);

      QString compartment = index.isValid() && column == COL_COMPARTMENT ? value.toString() : "";

      double initial = index.isValid() && column == COL_ICONCENTRATION ? value.toDouble() : 1.0;

      CModelEntity::Status status = index.isValid() && column == COL_TYPE_SPECIES ?
                                    (CModelEntity::Status) mItemToType[value.toInt()] : CModelEntity::REACTIONS;

      mpSpecies =
        pModel->createMetabolite(TO_UTF8(name), TO_UTF8(compartment), initial, status);

      if (mpSpecies == NULL)
        continue;

      if (mNotify)
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, mpSpecies->getKey());
        }

      UndoSpeciesData* data = new UndoSpeciesData(mpSpecies);
      data->setCreatedCompartment(row == 0 && createdCompartment);
      result.append(data);
    }

  endInsertRows();
  return result;
}
示例#5
0
bool CQParameterSetsDM::removeRows(int position, int rows, const QModelIndex&)
{
  if (rows <= 0) return true;

  if (mpListOfParameterSets == NULL) return false;

  beginRemoveRows(QModelIndex(), position, position + rows - 1);

  std::vector< CModelParameterSet * > DeletedModelParameterSets;
  DeletedModelParameterSets.resize(rows);

  std::vector< CModelParameterSet * >::iterator itDeletedModelParameterSet;
  std::vector< CModelParameterSet * >::iterator endDeletedModelParameterSet = DeletedModelParameterSets.end();

  CCopasiVectorN< CModelParameterSet >::const_iterator itRow = mpListOfParameterSets->begin() + position;

  for (itDeletedModelParameterSet = DeletedModelParameterSets.begin(); itDeletedModelParameterSet != endDeletedModelParameterSet; ++itDeletedModelParameterSet, ++itRow)
    {
      *itDeletedModelParameterSet = *itRow;
    }

  for (itDeletedModelParameterSet = DeletedModelParameterSets.begin(); itDeletedModelParameterSet != endDeletedModelParameterSet; ++itDeletedModelParameterSet)
    {
      std::string Key = (*itDeletedModelParameterSet)->getKey();

      pdelete(*itDeletedModelParameterSet);

      emit notifyGUI(ListViews::MODELPARAMETERSET, ListViews::DELETE, Key);
    }

  endRemoveRows();

  return true;
}
示例#6
0
bool CQReportDM::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_REPORTS) ? value.toString() : "report";
                insertRow(rowCount(), index);
            }
            else
                return false;
        }

        CReportDefinition *pRepDef = &mpDataModel->getReportDefinitionList()->operator[](index.row());

        if (index.column() == COL_NAME_REPORTS)
            pRepDef->setObjectName(TO_UTF8(value.toString()));

        emit dataChanged(index, index);
        emit notifyGUI(ListViews::REPORT, ListViews::CHANGE, pRepDef->getKey());
    }

    return true;
}
示例#7
0
bool CQModifiedDM::setData(const QModelIndex &index, const QVariant &value,
                           int role)
{
    if (index.isValid() && role == Qt::EditRole)
    {
        if (isDefaultRow(index))
        {
            if (index.data() != value)
                insertRow(rowCount(), index);
            else
                return false;
        }

        switch (index.column())
        {
        case COL_DATE_MODIFIED:
            mpMIRIAMInfo->getModifications()[index.row()].setDate(TO_UTF8(value.toDateTime().toString(Qt::ISODate)));
            break;
        }

        emit dataChanged(index, index);
        emit notifyGUI(ListViews::MIRIAM, ListViews::CHANGE, "");
        return true;
    }

    return false;
}
示例#8
0
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;
}
示例#9
0
void CQGlobalQuantityDM::insertNewGlobalQuantityRow(int position, int rows, const QModelIndex& index, const QVariant& value)
{
  beginInsertRows(QModelIndex(), position, position + rows - 1);

  int column = index.column();

  for (int row = 0; row < rows; ++row)
    {
      QString name = createNewName(index.isValid() && column == COL_NAME_GQ ? value.toString() : "quantity", COL_NAME_GQ);

      double initial = index.isValid() && column == COL_INITIAL_GQ ? value.toDouble() : 0.0;

      CModelValue *pGQ = mpDataModel->getModel()->createModelValue(TO_UTF8(name), initial);

      if (pGQ == NULL) continue;

      if (index.isValid() && column == COL_TYPE_GQ)
        {
          pGQ->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
        }

      emit notifyGUI(ListViews::MODELVALUE, ListViews::ADD, pGQ->getKey());
    }

  endInsertRows();
}
示例#10
0
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);
}
示例#11
0
bool CQReferenceDM::setData(const QModelIndex &index, const QVariant &value,
                            int role)
{
  if (index.isValid() && role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          if (index.data() != value)
            insertRow(rowCount(), index);
          else
            return false;
        }

      switch (index.column())
        {
          case COL_RESOURCE_REFERENCE:
            mpMIRIAMInfo->getReferences()[index.row()].setResource(TO_UTF8(value.toString()));
            break;

          case COL_ID_REFERENCE:
            mpMIRIAMInfo->getReferences()[index.row()].setId(TO_UTF8(value.toString()));
            break;

          case COL_DESCRIPTION:
            mpMIRIAMInfo->getReferences()[index.row()].setDescription(TO_UTF8(value.toString()));
            break;
        }

      emit dataChanged(index, index);
      emit notifyGUI(ListViews::MIRIAM, ListViews::CHANGE, "");
      return true;
    }

  return false;
}
示例#12
0
bool CQUnitDM::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)
            insertRow(rowCount(), index);
          else
            return false;
        }

      CUnitDefinition *pUnitDef = &CCopasiRootContainer::getUnitList()->operator[](index.row());

      if (pUnitDef == NULL)
        return false;

      if (index.column() == COL_NAME_UNITS)
        pUnitDef->setObjectName(TO_UTF8(value.toString()));
      else if (index.column() == COL_SYMBOL_UNITS)
        {
          if (!pUnitDef->setSymbol(TO_UTF8(value.toString())))
            {
              QString msg;
              msg = "Unable set Symbol of Unit '" + FROM_UTF8(pUnitDef->getObjectName()) + "'\n"
                    + "to '" + value.toString() + "' since a Unit with that symbol already exists.\n";

              CQMessageBox::information(NULL,
                                        "Unable set Symbol",
                                        msg,
                                        QMessageBox::Ok, QMessageBox::Ok);
            }
        }
      else if (index.column() == COL_EXPRESSION_UNITS)
        {
          if (index.data() != value)
            {
              QString msg;
              msg = "Expression must not be changed for '" + FROM_UTF8(pUnitDef->getObjectName()) + "'.\n";

              CQMessageBox::information(NULL,
                                        "Unable to change Unit Expression",
                                        msg,
                                        QMessageBox::Ok, QMessageBox::Ok);
            }
        }

      if (defaultRow && this->index(index.row(), COL_SYMBOL_UNITS).data().toString() == "unit")
        pUnitDef->setObjectName(TO_UTF8(createNewName("unit", COL_SYMBOL_UNITS)));

      emit dataChanged(index, index);
      emit notifyGUI(ListViews::UNIT, ListViews::CHANGE, pUnitDef->getKey());
    }

  return true;
}
示例#13
0
bool CQFunctionDM::removeRows(int position, int rows, const QModelIndex & parent)
{
  if (rows <= 0)
    return true;

  std::vector< std::string > DeletedKeys;
  DeletedKeys.resize(rows);

  std::vector< std::string >::iterator itDeletedKey;
  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();

  CDataVector< CFunction >::const_iterator itRow =
    CRootContainer::getFunctionList()->loadedFunctions().begin() + position;
  int row = 0;

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow, ++row)
    {
      if (isFunctionReadOnly(this->index(position + row, 0)))
        {
          *itDeletedKey = "";
        }
      else
        {
          *itDeletedKey = itRow->getCN();
        }
    }

  beginRemoveRows(parent, position, position + row - 1);

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++row)
    {
      if (*itDeletedKey != "")
        {
          CRootContainer::getFunctionList()->removeFunction(*itDeletedKey);
          emit notifyGUI(ListViews::ObjectType::FUNCTION, ListViews::DELETE, *itDeletedKey);
          emit notifyGUI(ListViews::ObjectType::FUNCTION, ListViews::DELETE, std::string()); //Refresh all as there may be dependencies.
        }
    }

  endRemoveRows();

  return true;
}
示例#14
0
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();
}
示例#15
0
bool CQCreatorDM::insertRows(int position, int rows, const QModelIndex&)
{
  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      mpMIRIAMInfo->createCreator("");
    }

  endInsertRows();

  emit notifyGUI(ListViews::MIRIAM, ListViews::ADD, "");
  return true;
}
示例#16
0
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();
}
示例#17
0
bool CQModifiedDM::insertRows(int position, int rows, const QModelIndex&)
{
    beginInsertRows(QModelIndex(), position, position + rows - 1);

    for (int row = 0; row < rows; ++row)
    {
        //mpMIRIAMInfo->createModification(TO_UTF8(QDateTime::currentDateTime().toString(Qt::ISODate)));
        mpMIRIAMInfo->createModification("");
    }

    endInsertRows();

    emit notifyGUI(ListViews::MIRIAM, ListViews::ADD, "");
    return true;
}
示例#18
0
bool CQUnitDM::insertRows(int position, int rows, const QModelIndex&)
{
  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      CUnitDefinition *pUnitDef;
      CCopasiRootContainer::getUnitList()->add(pUnitDef = new CUnitDefinition(TO_UTF8(createNewName("unit", COL_NAME_UNITS)), CCopasiRootContainer::getUnitList()), true);
      emit notifyGUI(ListViews::UNIT, ListViews::ADD, pUnitDef->getKey());
    }

  endInsertRows();

  return true;
}
示例#19
0
bool CQReportDM::removeRows(int position, int rows)
{
    if (rows <= 0)
        return true;

    if (mpDataModel == NULL)
        return false;

    CCopasiVector< CReportDefinition > * pReportList = mpDataModel->getReportDefinitionList();

    if (pReportList == NULL)
        return false;

    beginRemoveRows(QModelIndex(), position, position + rows - 1);

    for (int row = 0; row < rows; ++row)
    {
        CReportDefinition * pReport = &pReportList->operator[](position);

        if (pReport == NULL)
            continue;

        std::set< const CCopasiObject * > Tasks;
        std::set< const CCopasiObject * > DeletedObjects;
        DeletedObjects.insert(pReport);

        if (mpDataModel->appendDependentTasks(DeletedObjects, Tasks))
        {
            std::set< const CCopasiObject * >::iterator it = Tasks.begin();
            std::set< const CCopasiObject * >::iterator end = Tasks.end();

            for (; it != end; ++it)
            {
                const CCopasiTask * pTask = static_cast< const CCopasiTask *>(*it);
                const_cast< CCopasiTask * >(pTask)->getReport().setReportDefinition(NULL);
            }
        }

        std::string deletedKey = pReport->getKey();
        pReportList->remove(pReport);
        emit notifyGUI(ListViews::REPORT, ListViews::DELETE, deletedKey);
    }

    endRemoveRows();

    return true;
}
示例#20
0
bool CQParameterSetsDM::insertRows(int position, int rows, const QModelIndex&)
{
  if (mpListOfParameterSets == NULL) return false;

  if (position + rows > (int) mpListOfParameterSets->size())  return false;

  beginInsertRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      emit notifyGUI(ListViews::LAYOUT, ListViews::ADD, (*mpListOfParameterSets)[position + row]->getKey());
    }

  endInsertRows();

  return true;
}
示例#21
0
bool CQCreatorDM::removeRows(int position, int rows, const QModelIndex&)
{
  if (rows <= 0)
    return true;

  beginRemoveRows(QModelIndex(), position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      mpMIRIAMInfo->removeCreator(position);
    }

  endRemoveRows();

  emit notifyGUI(ListViews::MIRIAM, ListViews::DELETE, "");
  return true;
}
示例#22
0
bool CQReportDM::insertRows(int position, int rows, const QModelIndex & source)
{
    beginInsertRows(QModelIndex(), position, position + rows - 1);

    for (int row = 0; row < rows; ++row)
    {
        QString Name = createNewName(mNewName, COL_NAME_REPORTS);
        CReportDefinition *pRepDef = mpDataModel->getReportDefinitionList()->createReportDefinition(TO_UTF8(Name), "");
        emit notifyGUI(ListViews::REPORT, ListViews::ADD, pRepDef->getKey());
    }

    endInsertRows();

    mNewName = "report";

    return true;
}
示例#23
0
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;
}
示例#24
0
bool CQFunctionDM::insertRows(int position, int rows, const QModelIndex & parent)
{
  beginInsertRows(parent, position, position + rows - 1);

  for (int row = 0; row < rows; ++row)
    {
      CFunction *pFunc;
      QString Name = createNewName(mNewName, COL_NAME_FUNCTIONS);

      CRootContainer::getFunctionList()->add(pFunc = new CKinFunction(TO_UTF8(Name)), true);
      emit notifyGUI(ListViews::ObjectType::FUNCTION, ListViews::ADD, pFunc->getCN());
    }

  endInsertRows();

  mNewName = "function";

  return true;
}
示例#25
0
bool CQUnitDM::removeRows(int position, int rows)
{
  if (rows <= 0)
    return true;

  std::vector< std::string > DeletedKeys;
  DeletedKeys.resize(rows);

  std::vector< std::string >::iterator itDeletedKey;
  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();

  CCopasiVector< CUnitDefinition >::const_iterator itRow =
    CCopasiRootContainer::getUnitList()->begin() + position;
  int row = 0;

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow, ++row)
    {
      *itDeletedKey = itRow->getKey();
    }

  beginRemoveRows(QModelIndex(), position, position + row - 1);

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++row)
    {
      if (*itDeletedKey != "")
        {
          CCopasiObject * pUnitDef = CCopasiRootContainer::getKeyFactory()->get(*itDeletedKey);

          if (pUnitDef != NULL) delete pUnitDef;

          emit notifyGUI(ListViews::UNIT, ListViews::DELETE, *itDeletedKey);
        }
    }

  endRemoveRows();

  return true;
}
示例#26
0
bool CQCreatorDM::setData(const QModelIndex &index, const QVariant &value,
                          int role)
{
  if (index.isValid() && role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          if (index.data() != value)
            insertRow();
          else
            return false;
        }

      switch (index.column())
        {
          case COL_FAMILY_NAME:
            mpMIRIAMInfo->getCreators()[index.row()]->setFamilyName(TO_UTF8(value.toString()));
            break;
          case COL_GIVEN_NAME:
            mpMIRIAMInfo->getCreators()[index.row()]->setGivenName(TO_UTF8(value.toString()));
            break;
          case COL_EMAIL:
            mpMIRIAMInfo->getCreators()[index.row()]->setEmail(TO_UTF8(value.toString()));
            break;
          case COL_ORG:
            mpMIRIAMInfo->getCreators()[index.row()]->setORG(TO_UTF8(value.toString()));
            break;
        }

      emit dataChanged(index, index);
      emit notifyGUI(ListViews::MIRIAM, ListViews::CHANGE, "");
      return true;
    }

  return false;
}
示例#27
0
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;
}
示例#28
0
bool CQSpecieDM::setData(const QModelIndex &index, const QVariant &value,
                         int role)
{
  if (index.isValid() && role == Qt::EditRole)
    {
      bool defaultRow = isDefaultRow(index);

      if (defaultRow)
        {
          if (index.column() == COL_TYPE_SPECIES)
            {
              if (index.data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
                return false;
            }
          else if (index.column() == COL_COMPARTMENT && value == "")
            {
              return false;
            }
          else if (index.data() == value)
            {
              return false;
            }

          mNotify = false;
          insertRow();
          mNotify = true;
        }
      else
        {
          assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
          mpSpecies = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites()[index.row()];
        }

      const CCompartment * pCompartment = NULL;

      if (index.column() == COL_COMPARTMENT ||
          index.column() == COL_ICONCENTRATION ||
          index.column() == COL_INUMBER)
        {
          try
            {
              pCompartment = mpSpecies->getCompartment();
            }
          catch (...) {}
        }

      if (index.column() == COL_NAME_SPECIES)
        mpSpecies->setObjectName(TO_UTF8(value.toString()));
      else if (index.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();
              assert(CCopasiRootContainer::getDatamodelList()->size() > 0);

              if (!(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->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
                {
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[CompartmentToRemove]->getMetabolites().remove(mpSpecies->getObjectName());
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->setCompileFlag();
                  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->initializeMetabolites();

                  if (mpSpecies && pCompartment)
                    {
                      C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue();
                      Factor *= pCompartment->getInitialValue();

                      mpSpecies->setInitialValue(Factor * this->index(index.row(), COL_INUMBER).data().toDouble());
                      mpSpecies->setValue(Factor * this->index(index.row(), COL_NUMBER).data().toDouble());
                    }

                  emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, mpSpecies->getKey());
                  emit notifyGUI(ListViews::COMPARTMENT, ListViews::CHANGE, pCompartment->getKey());
                }
            }
        }
      else if (index.column() == COL_TYPE_SPECIES)
        mpSpecies->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
      else if (index.column() == COL_ICONCENTRATION)
        {
          if (mFlagConc)
            mpSpecies->setInitialConcentration(value.toDouble());

          if (mpSpecies && pCompartment)
            {
              const C_FLOAT64 initialValue =
                CMetab::convertToNumber(this->index(index.row(), COL_ICONCENTRATION).data().toDouble(),
                                        *pCompartment,
                                        *(*CCopasiRootContainer::getDatamodelList())[0]->getModel());
              mpSpecies->setInitialValue(initialValue);
            }
        }
      else if (index.column() == COL_INUMBER)
        {
          if (!mFlagConc)
            mpSpecies->setInitialValue(value.toDouble());

          if (mpSpecies && pCompartment)
            {
              mpSpecies->setInitialConcentration(
                CMetab::convertToConcentration(this->index(index.row(), COL_INUMBER).data().toDouble(),
                                               *pCompartment,
                                               *(*CCopasiRootContainer::getDatamodelList())[0]->getModel())
              );
            }
        }

      if (defaultRow && this->index(index.row(), COL_NAME_SPECIES).data().toString() == "species")
        mpSpecies->setObjectName(TO_UTF8(createNewName("species", COL_NAME_SPECIES)));

      //Save Key
      std::string key = mpSpecies->getKey();
      emit dataChanged(index, index);

      if (defaultRow)
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::ADD, key);
        }
      else
        {
          emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, key);
        }
    }

  return true;
}
示例#29
0
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;
}
示例#30
0
void iozoneThread::run()
{
    callFlag = new QSystemSemaphore("notify", 0, QSystemSemaphore::Create);
    waitFlag = new QSystemSemaphore("wait", 1, QSystemSemaphore::Create);
    shm = NULL;
    int argc = DEFAULT_ARGC;
    int i = 0;
    char *argv[DEFAULT_ARGV];
    for( ; i<DEFAULT_ARGV; ++i)
        argv[i] = new char[DEFAULT_ARG_CHAR];

    /* 格式化设备并挂载 */
    QString qsCommand;
    QStringList args;
    if ( param->bFlagMnt == true )
    {   /* 格式化设备 */
        qsCommand = "mkfs";
        args.append("-t");
        args.append(param->qsFsType);
        args.append(param->qsDevDir);
        QProcess::execute(qsCommand, args);
    }
    if ( param->bFlagMnt == true )
    {   /* 挂载文件系统 */
        qsCommand = "mount";
        args.clear();
        args.append("-t");
        args.append(param->qsFsType);
        args.append(param->qsDevDir);
        args.append(param->qsMntDir);
        QProcess::execute(qsCommand, args);
    }
    if ( param->bFlagShell == true )
    {   /* 执行shell 以"sh ./shell fstype mount"格式 */
        qsCommand = "sh";
        args.clear();
        args << param->qsShellDir << param->qsFsType << "mount";
        QProcess::execute( qsCommand, args );
    }
    sleep(1);/* 给时间完成以上工作 */

    //获取系统时间并设置显示格式
    QDateTime currentDateTime = QDateTime::currentDateTime();
    QString tagDateTime = currentDateTime.toString("yyyyMMddhhmmss");

    /*生成字符串数组argv*/
    i = 0;

    strcpy(argv[i++], "./iozone");

    if(param->bFlaga)
        strcpy(argv[i++], "-a");

    if(param->bFlags) {
        strcpy(argv[i++], "-s");
        sprintf(argv[i++], "%dm", param->iFileSize);
    }
    if(param->bFlagi0){
        strcpy(argv[i++], "-i");
        strcpy(argv[i++], "0");
    }
    if(param->bFlagi1){
        strcpy(argv[i++], "-i");
        strcpy(argv[i++], "1");
    }
    if(param->bFlagi2){
        strcpy(argv[i++], "-i");
        strcpy(argv[i++], "2");
    }
    strcpy(argv[i++], "-f");
    strcpy(argv[i], param->qsFileName.toStdString().c_str() );
    strcat(argv[i++], tagDateTime.toStdString().c_str());

    argc = i;

    iozoneThread *p = this;
    pid_t pid;
    i = 0;
    goFork:
    if((pid = fork())==0){
        /* 子进程 */
        callFlag = new QSystemSemaphore("notify", 0, QSystemSemaphore::Open);
        waitFlag = new QSystemSemaphore("wait", 1, QSystemSemaphore::Open);
        /* 共享内存 */
        shmid = shmget( ftok(".", 1), sizeof(struct shmNotify), 0666|IPC_CREAT);
        if(shmid == -1)
        {
            _exit(EXIT_FAILURE);
        }
        shm = shmat(shmid, (void*)0, 0);
        if(shm == (void*)-1)
        {
            _exit(EXIT_FAILURE);
        }
        qDebug()<<"Child Memory attached at "<<shm<<endl;
        pShmNotify = (struct shmNotify*)shm;
        pShmNotify->notifyFlag = 0;
        /* 调用iozone主函数 */
        iozoneMain(p, argc, argv);
        /* 一轮测试结束 */
        waitFlag->acquire();/* 若父进程等待 */
        pShmNotify->notifyFlag = -1;/* 结束标志 */
        callFlag->release();/* 子进程已发出通知 */

        /* 把共享内存从当前进程中分离 */
        if(shmdt(pShmNotify) == -1)
        {
            qDebug()<<"shmdt failed"<<endl;
            _exit(EXIT_FAILURE);
        }
        _exit(0);
        /*-----子进程结束-----*/
    }
    else if(pid>0){
        /* 父进程中 */
        ++i;
        /* 共享内存 */
        shmid = shmget( ftok(".", 1), sizeof(struct shmNotify), 0666|IPC_CREAT);
        if(shmid == -1)
        {
            exit(EXIT_FAILURE);
        }
        shm = shmat(shmid, (void*)0, 0);
        if(shm == (void*)-1)
        {
            exit(EXIT_FAILURE);
        }
        qDebug()<<"Father Memory attached at "<<shm<<endl;
        pShmNotify = (struct shmNotify*)shm;

        /* 等待处理子进程的通知直到子进程发出结束标志 */
        while(1)
        {
            callFlag->acquire();/* 若子进程已发出通知 */
            if(pShmNotify->notifyFlag == 1)
            {   /* 若子进程通知传数据,父进程创建事件对象传给主窗口 */
                notifyGUI(pShmNotify->type, pShmNotify->kb, pShmNotify->reclen, pShmNotify->speed);
                pShmNotify->notifyFlag = 0;/* 标志位置为已接收 */
                waitFlag->release();/* 父进程等待 */
                continue;
            }
            else if(pShmNotify->notifyFlag == -1)
            {   /* 若子进程通知一轮测试已结束 */
                pShmNotify->notifyFlag = 0;/* 将标志位置为已接收 */
                waitFlag->release();/* 父进程等待 */
                break;
            }
        }

        waitpid(pid, NULL, 0);/* 等待子进程 */

        /* 把共享内存从当前进程分离 */
        if(shmdt(pShmNotify) == -1)
        {
            qDebug()<<"shmdt failed"<<endl;
            exit(EXIT_FAILURE);
        }

        /* 释放对象 */
        delete callFlag;
        delete waitFlag;

        /* 判断测试轮数是否达到要求,没有达到的话再fork一次 */
        if ( i < param->iTestTimes )
        {   /* 下次fork之前恢复初始状态 否则会出错 */
            callFlag = new QSystemSemaphore("notify", 0, QSystemSemaphore::Create);
            waitFlag = new QSystemSemaphore("wait", 1, QSystemSemaphore::Create);
            goto goFork;
        }

        /* 判断是否需要取消挂载 */
        if ( param->bFlagMnt == true )
        {   /* 取消挂载 */
            qsCommand = "umount";
            args.clear();
            args.append(param->qsMntDir);
            QProcess::execute(qsCommand, args);
        }
        if ( param->bFlagShell == true )
        {   /* 执行shell 以"sh ./shell fstype mount"格式 */
            qsCommand = "sh";
            args.clear();
            args << param->qsShellDir << param->qsFsType << "umount";
            QProcess::execute( qsCommand, args );
        }

        /* 测试结束 */
        //*(param->pbFlagRun) = false; 在iozonewidget中修改

        /* 释放内存 */
        for ( i = 0; i < DEFAULT_ARGV; ++i)
        {
                delete argv[i];
        }
        delete this->param;/* 在点击start按钮时getparam()中new的 */
        this->quit();
    }
}