Пример #1
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;
}
Пример #2
0
bool CQBaseDataModel::removeRow(int position)
{
  if (0 <= position && position < rowCount() && !isDefaultRow(index(position, 0)))
    return removeRows(position, 1);
  else
    return false;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
bool CQSpecieDM::setData(const QModelIndex &index, const QVariant &value,
                         int role)
{
  //change is only accepted if the new value is different from the old value and also the old value is not equal to "New Species" for the 'name' column
  // in that case no new species will be created!
  if (index.data() == value)
    return false;

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

  if (index.column() == COL_COMPARTMENT && value == "")
    return false;

  bool defaultRow = isDefaultRow(index);

  if (defaultRow)
    {
      mpUndoStack->push(new InsertSpecieRowsCommand(rowCount(), 1, this, index, value));
    }
  else
    {
      mpUndoStack->push(new SpecieDataChangeCommand(mpSpecies, value, index.data(), index.column(), this));
    }

  return true;
}
Пример #6
0
QVariant CQUnitDM::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  if (index.row() >= rowCount())
    return QVariant();

  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
    return QColor(Qt::darkGray);

  if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(QString(""));

              case COL_NAME_UNITS:
                return QVariant(QString("New Unit"));

              case COL_SYMBOL_UNITS:
                return QVariant(QString(""));

              case COL_EXPRESSION_UNITS:
                return QVariant(QString(""));

              default:
                return QVariant(QString(""));
            }
        }
      else
        {
          const CUnitDefinition * pUnitDef = &CCopasiRootContainer::getUnitList()->operator[](index.row());

          if (pUnitDef == NULL)
            return QVariant();

          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

              case COL_NAME_UNITS:
                return QVariant(QString(FROM_UTF8(pUnitDef->getObjectName())));

              case COL_SYMBOL_UNITS:
                return QVariant(QString(FROM_UTF8(pUnitDef->getSymbol())));

              case COL_EXPRESSION_UNITS:
                return QVariant(QString(FROM_UTF8(pUnitDef->getExpression())));
            }
        }
    }

  return QVariant();
}
Пример #7
0
QVariant CQFunctionDM::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  if (index.row() >= rowCount())
    return QVariant();

  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
    return QColor(Qt::darkGray);

  if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(QString(""));

              case COL_NAME_FUNCTIONS:
                return QVariant(QString("New Function"));

              case COL_TYPE_FUNCTIONS:
                return QVariant(QString(FROM_UTF8(CEvaluationTree::TypeName[4])));

              default:
                return QVariant(QString(""));
            }
        }
      else
        {
          const CEvaluationTree *pFunc = &CRootContainer::getFunctionList()->loadedFunctions()[index.row()];

          if (pFunc == NULL)
            return QVariant();

          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

              case COL_NAME_FUNCTIONS:
                return QVariant(QString(FROM_UTF8(pFunc->getObjectName())));

              case COL_TYPE_FUNCTIONS:
                return QVariant(QString(FROM_UTF8(CEvaluationTree::TypeName[pFunc->getType()])));

              case COL_MATH_DESC_FUNCTIONS:
                return QVariant(QString(FROM_UTF8(pFunc->getInfix())));

              case COL_SBML_ID_FUNCTIONS:
                return QVariant();
            }
        }
    }

  return QVariant();
}
Пример #8
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;
}
Пример #9
0
Qt::ItemFlags CQUnitDM::flags(const QModelIndex &index) const
{
  if (!index.isValid())
    return Qt::ItemIsEnabled;

  if (!isDefaultRow(index))
    return QAbstractItemModel::flags(index);

  if (index.column() == COL_SYMBOL_UNITS)
    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
  else
    return QAbstractItemModel::flags(index);
}
Пример #10
0
Qt::ItemFlags CQFunctionDM::flags(const QModelIndex &index) const
{
  if (!index.isValid())
    return Qt::ItemIsEnabled;

  if (!isDefaultRow(index) && isFunctionReadOnly(index))
    return QAbstractItemModel::flags(index);

  if (index.column() == COL_NAME_FUNCTIONS)
    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
  else
    return QAbstractItemModel::flags(index);
}
Пример #11
0
bool CQUnitDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = &CCopasiRootContainer::getDatamodelList()->operator[](0);
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return false;

  // Build the list of pointers to items to be deleted
  // before actually deleting any item.

  QList <CUnitDefinition *> pUnitDefQList;
  QModelIndexList::const_iterator i;
  CUnitDefinition * pUnitDef;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) &&
          (pUnitDef = &CCopasiRootContainer::getUnitList()->operator[](i->row())) != NULL &&
          pModel->getUnitSymbolUsage(pUnitDef->getSymbol()).empty() &&
          !pUnitDef->isReadOnly())//Don't delete built-ins or used units
        pUnitDefQList.append(&CCopasiRootContainer::getUnitList()->operator[](i->row()));
    }

  for (QList <CUnitDefinition *>::const_iterator j = pUnitDefQList.begin(); j != pUnitDefQList.end(); ++j)
    {
      size_t delRow =
        CCopasiRootContainer::getUnitList()->CCopasiVector< CUnitDefinition >::getIndex(*j);

      if (delRow != C_INVALID_INDEX)
        {
          CCopasiObject::DataObjectSet DeletedObjects;
          DeletedObjects.insert(*j);

          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "unit",
                                        FROM_UTF8((*j)->getObjectName()),
                                        DeletedObjects);

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}
Пример #12
0
bool CQCompartmentDM::setData(const QModelIndex &index,
                              const QVariant &value,
                              int role)
{
  QVariant data = index.data();

  if (data == value)
    return false;

  if (isDefaultRow(index) && data != value)
    {
      insertNewRows(rowCount(), 1, index.column(), value);
    }
  else if (role == Qt::EditRole)
    {
      CCompartment & Compartment = mpCompartments->operator[](index.row());

      CData OldData = Compartment.toData();

      switch (index.column())
        {
          case COL_NAME_COMPARTMENTS:
            if (mpCompartments->getIndex(TO_UTF8(value.toString())) == C_INVALID_INDEX)
              {
                Compartment.setObjectName(TO_UTF8(value.toString()));
              }

            break;

          case COL_TYPE_COMPARTMENTS:
            Compartment.setStatus(CModelEntity::StatusName.toEnum(TO_UTF8(value.toString())));
            break;

          case COL_IVOLUME:
            Compartment.setInitialValue(value.toDouble());
            break;
        }

      CUndoData UndoData;
      Compartment.createUndoData(UndoData, CUndoData::Type::CHANGE, OldData, (CCore::Framework) mFramework);

      if (!UndoData.empty())
        {
          ListViews::addUndoMetaData(this, UndoData);
          emit signalNotifyChanges(mpDataModel->recordData(UndoData));
        }
    }

  return true;
}
Пример #13
0
bool CQReportDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
    if (rows.isEmpty())
        return false;

    assert(mpDataModel != NULL);

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

    if (pReportList == NULL)
        return false;

    QList< CReportDefinition * > Reports;

    QModelIndexList::const_iterator i;

    for (i = rows.begin(); i != rows.end(); ++i)
    {
        if (!isDefaultRow(*i) && &pReportList->operator[](i->row()))
            Reports.append(&pReportList->operator[](i->row()));
    }

    QList< CReportDefinition * >::const_iterator j;

    for (j = Reports.begin(); j != Reports.end(); ++j)
    {
        CReportDefinition * pReport = *j;

        size_t delRow = pReportList->getIndex(pReport);

        if (delRow != C_INVALID_INDEX)
        {
            std::set< const CCopasiObject * > DeletedObjects;
            DeletedObjects.insert(pReport);

            QMessageBox::StandardButton choice =
                CQMessageBox::confirmDelete(NULL, "report",
                                            FROM_UTF8(pReport->getObjectName()),
                                            DeletedObjects);

            if (choice == QMessageBox::Ok)
            {
                removeRow((int) delRow);
            }
        }
    }

    return true;
}
Пример #14
0
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;
}
Пример #15
0
bool CQSpecieDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
  CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();

  if (pModel == NULL)
    return false;

//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)
        {
          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "species",
                                        FROM_UTF8(pSpecie->getObjectName()),
                                        pSpecie->getDeletedObjects());

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}
Пример #16
0
Qt::ItemFlags CQSpecieDM::flags(const QModelIndex &index) const
{
  if (!index.isValid())
    return Qt::ItemIsEnabled;

  if (isDefaultRow(index))
    {
      if (index.column() == COL_NAME_SPECIES || index.column() == COL_COMPARTMENT ||
          index.column() == COL_TYPE_SPECIES || index.column() == COL_ICONCENTRATION ||
          index.column() == COL_INUMBER)
        return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
      else
        return QAbstractItemModel::flags(index);
    }

  if (index.column() == COL_NAME_SPECIES || index.column() == COL_COMPARTMENT ||
      index.column() == COL_TYPE_SPECIES)
    {
      return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
    }
  else if (index.column() == COL_ICONCENTRATION)
    {
      mpSpecies = &CCopasiRootContainer::getDatamodelList()->operator[](0).getModel()->getMetabolites()[index.row()];

      if (this->index(index.row(), COL_TYPE_SPECIES).data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT]))
          || !(this->index(index.row(), COL_IEXPRESSION_SPECIES).data().toString().isEmpty()))
        return QAbstractItemModel::flags(index) & ~Qt::ItemIsEnabled;
      else
        {
          if (mpSpecies->isInitialConcentrationChangeAllowed())
            return QAbstractItemModel::flags(index)  | Qt::ItemIsEditable | Qt::ItemIsEnabled;
          else
            return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled;
        }
    }
  else if (index.column() == COL_INUMBER)
    {
      if (this->index(index.row(), COL_TYPE_SPECIES).data() == QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT]))
          || !(this->index(index.row(), COL_IEXPRESSION_SPECIES).data().toString().isEmpty()))
        return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled;
      else
        return QAbstractItemModel::flags(index)  | Qt::ItemIsEditable | Qt::ItemIsEnabled;
    }
  else
    return QAbstractItemModel::flags(index);
}
Пример #17
0
QVariant CQReportDM::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= rowCount())
        return QVariant();

    if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
        return QColor(Qt::darkGray);

    if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
        if (isDefaultRow(index))
        {
            switch (index.column())
            {
            case COL_ROW_NUMBER:
                return QVariant(QString(""));

            case COL_NAME_REPORTS:
                return QVariant(QString("New Report"));

            default:
                return QVariant(QString(""));
            }
        }
        else
        {
            CReportDefinition *pRepDef = &mpDataModel->getReportDefinitionList()->operator[](index.row());

            switch (index.column())
            {
            case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

            case COL_NAME_REPORTS:
                return QVariant(QString(FROM_UTF8(pRepDef->getObjectName())));
            }
        }
    }

    return QVariant();
}
Пример #18
0
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;
}
Пример #19
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;
}
Пример #20
0
QVariant CQModifiedDM::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= rowCount())
        return QVariant();

    if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
        if (isDefaultRow(index))
        {
            if (index.column() == COL_ROW_NUMBER)
                return QVariant(QString(""));
            else if (index.column() == COL_DATE_MODIFIED)
            {
                if (role == Qt::DisplayRole)
                    return QVariant(QDateTime());
                else
                    return QVariant(QDateTime::currentDateTime());
            }
            else
                return QVariant(QString(""));
        }
        else
        {
            switch (index.column())
            {
            case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

            case COL_DATE_MODIFIED:
                QDateTime dt(QDateTime::fromString(FROM_UTF8(mpMIRIAMInfo->getModifications()[index.row()].getDate()), Qt::ISODate));

                if (dt.isValid())
                    return QVariant(dt);
            }
        }
    }

    return QVariant();
}
Пример #21
0
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;
}
Пример #22
0
QVariant CQReferenceDM::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  if (index.row() >= rowCount())
    return QVariant();

  if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          if (index.column() == COL_RESOURCE_REFERENCE)
            return QVariant(QString("-- select --"));
          else if (index.column() == COL_ROW_NUMBER)
            return QVariant(QString(""));
          else
            return QVariant(QString(""));
        }
      else
        {
          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

              case COL_RESOURCE_REFERENCE:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getReferences()[index.row()].getResource())));

              case COL_ID_REFERENCE:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getReferences()[index.row()].getId())));

              case COL_DESCRIPTION:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getReferences()[index.row()].getDescription())));
            }
        }
    }

  return QVariant();
}
Пример #23
0
bool CQGlobalQuantityDM::setData(const QModelIndex &index, const QVariant &value,
                                 int role)
{
  if (index.data() == value)
    return false;

  if (index.column() == COL_TYPE_GQ && index.data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
    return false;

  bool defaultRow = isDefaultRow(index);

  if (defaultRow)
    {
      mpUndoStack->push(new InsertGlobalQuantityRowsCommand(rowCount(), 1, this, index, value));
    }
  else
    {
      mpUndoStack->push(new GlobalQuantityDataChangeCommand(index, value, role, this));
    }

  return true;
}
Пример #24
0
QVariant CQCreatorDM::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  if (index.row() >= rowCount())
    return QVariant();

  if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          if (index.column() == COL_ROW_NUMBER)
            return QVariant(QString(""));
          else
            return QVariant(QString(""));
        }
      else
        {
          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);
              case COL_FAMILY_NAME:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getFamilyName())));
              case COL_GIVEN_NAME:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getGivenName())));
              case COL_EMAIL:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getEmail())));
              case COL_ORG:
                return QVariant(QString(FROM_UTF8(mpMIRIAMInfo->getCreators()[index.row()]->getORG())));
            }
        }
    }

  return QVariant();
}
Пример #25
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;
}
Пример #26
0
bool CQCompartmentDM::removeRows(QModelIndexList rows, const QModelIndex& index)
{
  if (rows.isEmpty())
    return false;

  // Build the list of pointers to items to be deleted
  // before actually deleting any item.
  QList <CCompartment *> Compartments;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    if (!isDefaultRow(*i) &&
        &mpCompartments->operator[](i->row()) != NULL)
      {
        Compartments.append(&mpCompartments->operator[](i->row()));
      }

  QList< CCompartment * >::const_iterator j;

  for (j = Compartments.begin(); j != Compartments.end(); ++j)
    {
      CCompartment * pCompartment = *j;

      QMessageBox::StandardButton choice =
        CQMessageBox::confirmDelete(NULL, "compartment",
                                    FROM_UTF8(pCompartment->getObjectName()),
                                    pCompartment);

      if (choice == QMessageBox::Ok)
        {
          removeRows(mpCompartments->getIndex(pCompartment->getObjectName()), 1);
        }
    }

  return true;
}
Пример #27
0
bool CQCreatorDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

//Build the list of pointers to items to be deleted
//before actually deleting any item.
  QList <CCreator *> pCreators;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) && mpMIRIAMInfo->getCreators()[(*i).row()])
        pCreators.append(mpMIRIAMInfo->getCreators()[(*i).row()]);
    }

  bool retVal = false, askEveryItem = true;
  QMessageBox::StandardButton choice = QMessageBox::NoToAll;
  QList <CCreator *>::const_iterator j;

  for (j = pCreators.begin(); j != pCreators.end(); ++j)
    {
      CCreator * pCreator = *j;

      size_t delRow =
        mpMIRIAMInfo->getCreators().CCopasiVector< CCreator >::getIndex(pCreator);

      if (delRow != C_INVALID_INDEX)
        {
          if (askEveryItem)
            {
              QString givenName = data(this->index((int) delRow, COL_GIVEN_NAME), Qt::DisplayRole).toString();
              QString familyName = data(this->index((int) delRow, COL_FAMILY_NAME), Qt::DisplayRole).toString();
              QString msg = "Do you want to delete author '";

              if (!givenName.isNull())
                {
                  msg.append(givenName);
                }

              if (!familyName.isNull())
                {
                  msg.append(" ");
                  msg.append(familyName);
                }

              msg.append("'?");

              choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg,
                                              QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll,
                                              QMessageBox::No);
            }

          if (choice == QMessageBox::NoToAll)
            {return retVal;}
          else if (choice == QMessageBox::Yes)
            {retVal = removeRow((int) delRow);}
          else if (choice == QMessageBox::YesToAll)
            {
              askEveryItem = false;
              retVal = removeRow((int) delRow);
            }
        }
    }

  return true;
}
Пример #28
0
bool CQReferenceDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

//Build the list of pointers to items to be deleted
//before actually deleting any item.
  QList <CReference *> pReferences;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) && &mpMIRIAMInfo->getReferences()[i->row()])
        pReferences.append(&mpMIRIAMInfo->getReferences()[i->row()]);
    }

  bool retVal = false, askEveryItem = true;
  QMessageBox::StandardButton choice = QMessageBox::NoToAll;
  QList <CReference *>::const_iterator j;

  for (j = pReferences.begin(); j != pReferences.end(); ++j)
    {
      CReference * pReference = *j;

      size_t delRow =
        mpMIRIAMInfo->getReferences().CCopasiVector< CReference >::getIndex(pReference);

      if (delRow != C_INVALID_INDEX)
        {
          if (askEveryItem)
            {
              QString resource = data(this->index((int) delRow, COL_RESOURCE_REFERENCE), Qt::DisplayRole).toString();
              QString Id = data(this->index((int) delRow, COL_ID_REFERENCE), Qt::DisplayRole).toString();
              QString msg = "Do you want to delete Reference '";

              if (!resource.isNull())
                {
                  msg.append(resource);
                }

              if (!Id.isNull())
                {
                  msg.append(":");
                  msg.append(Id);
                }

              msg.append("'?");

              choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg,
                                              QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll,
                                              QMessageBox::No);
            }

          if (choice == QMessageBox::NoToAll)
            {return retVal;}
          else if (choice == QMessageBox::Yes)
            {retVal = removeRow((int) delRow);}
          else if (choice == QMessageBox::YesToAll)
            {
              askEveryItem = false;
              retVal = removeRow((int) delRow);
            }
        }
    }

  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
QVariant CQCompartmentDM::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  if (index.row() >= rowCount())
    return QVariant();

  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
    return QColor(Qt::darkGray);

  if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
      if (isDefaultRow(index))
        {
          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(QString(""));

              case COL_NAME_COMPARTMENTS:
                return QVariant(QString("New Compartment"));

              case COL_TYPE_COMPARTMENTS:
                return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::Status::FIXED])));

              case COL_IVOLUME:
                return QVariant(convertToQString(1.0));

              default:
                return QVariant(QString(""));
            }
        }
      else
        {
          CCompartment & Compartment = mpCompartments->operator[](index.row());
          const CExpression * pExpression = NULL;

          switch (index.column())
            {
              case COL_ROW_NUMBER:
                return QVariant(index.row() + 1);

              case COL_NAME_COMPARTMENTS:
                return QVariant(QString(FROM_UTF8(Compartment.getObjectName())));

              case COL_TYPE_COMPARTMENTS:
                return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[Compartment.getStatus()])));

              case COL_UNIT_COMPARTMENTS:
                return QVariant(mUnits[Compartment.getDimensionality()]);

              case COL_IVOLUME:

                if (role == Qt::EditRole)
                  return QVariant(convertToQString(Compartment.getInitialValue()));
                else
                  return QVariant(Compartment.getInitialValue());

              case COL_VOLUME:
                return QVariant(Compartment.getValue());

              case COL_RATE_COMPARTMENTS:
                return QVariant(Compartment.getRate());

              case COL_IEXPRESSION_COMPARTMENTS:
              {
                pExpression = Compartment.getInitialExpressionPtr();

                if (pExpression != NULL)
                  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
                else
                  return QVariant();
              }

              case COL_EXPRESSION_COMPARTMENTS:
              {
                pExpression = Compartment.getExpressionPtr();

                if (pExpression != NULL)
                  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
                else
                  return QVariant();
              }

              case COL_NEXPRESSION_COMPARTMENTS:
              {
                pExpression = Compartment.getNoiseExpressionPtr();

                if (Compartment.hasNoise() && pExpression != NULL)
                  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
                else
                  return QVariant();
              }
            }
        }
    }

  return QVariant();
}