示例#1
0
bool FunctionWidget1::loadParameterTable()
{
  QColor subsColor(255, 210, 210);
  QColor prodColor(210, 255, 210);
  QColor modiColor(250, 250, 190);
  QColor paraColor(210, 210, 255);
  QColor volColor(210, 210, 255);
  QColor timeColor(210, 210, 210);
  QColor color;

  size_t i, j;
  CFunctionParameters & params = mpFunction->getVariables();

  // list of usages for combobox
  QStringList Usages;

  for (i = 0; CFunctionParameter::RoleNameDisplay[i] != ""; i++)
    {
      if (dynamic_cast<CKinFunction *>(mpFunction) &&
          CFunctionParameter::VARIABLE == (CFunctionParameter::Role) i) continue;

      Usages += (FROM_UTF8(CFunctionParameter::RoleNameDisplay[i]));
    }

  //create list of data types (for combobox)
  QStringList functionType;

  for (i = 0; CFunctionParameter::DataTypeName[i] != ""; i++)
    functionType += (FROM_UTF8(CFunctionParameter::DataTypeName[i]));

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

  CFindDimensions ddd(mpFunction, pModel->getQuantityUnitEnum() == CModel::dimensionlessQuantity,
                      pModel->getVolumeUnitEnum() == CModel::dimensionlessVolume,
                      pModel->getTimeUnitEnum() == CModel::dimensionlessTime,
                      pModel->getAreaUnitEnum() == CModel::dimensionlessArea,
                      pModel->getLengthUnitEnum() == CModel::dimensionlessLength
                     );

  ddd.setUseHeuristics(true);
  std::vector<std::string> units = ddd.findDimensionsBoth(pModel);

  CFunctionParameter::Role usage;
  QString qUsage;

  //C_INT32 noOffunctParams = functParam.size();
  Table1->setRowCount((int) params.size());

  for (j = 0; j < params.size(); j++)
    {
      usage = params[j]->getUsage();

      if (usage == CFunctionParameter::VARIABLE &&
          dynamic_cast<CKinFunction *>(mpFunction))
        {
          usage = CFunctionParameter::PARAMETER;
          params[j]->setUsage(usage);
        }

      qUsage = FROM_UTF8(CFunctionParameter::RoleNameDisplay[usage]);

      switch (usage)
        {
          case CFunctionParameter::SUBSTRATE:
            color = subsColor;
            break;

          case CFunctionParameter::PRODUCT:
            color = prodColor;
            break;

          case CFunctionParameter::MODIFIER:
            color = modiColor;
            break;

          case CFunctionParameter::PARAMETER:
            color = paraColor;
            break;

          case CFunctionParameter::VOLUME:
            color = volColor;
            break;

          case CFunctionParameter::TIME:
            color = timeColor;
            break;

          case CFunctionParameter::VARIABLE:
            color = QColor(250, 250, 250);
            break;

          default :
            qUsage = "unknown";
            color = QColor(255, 20, 20);
            break;
        }

      // col. 0 (name)
      QString Name = FROM_UTF8(params[j]->getObjectName());

      if (!params[j]->isUsed())
        Name += " (unused)";

      if (Table1->item((int) j, COL_NAME) == NULL)
        {
          QTableWidgetItem *newItem = new QTableWidgetItem(Name);
          newItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
          Table1->setItem((int) j, COL_NAME, newItem);
        }
      else
        Table1->item((int) j, COL_NAME)->setText(Name);

      Table1->item((int) j, COL_NAME)->setBackground(QBrush(color));

      // col. 1 (description)
      QTableWidgetItem *newItem2 = new QTableWidgetItem();
      newItem2->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
      Table1->setItem((int) j, COL_USAGE, newItem2);
      Table1->item((int) j, COL_USAGE)->setBackground(QBrush(color));

      QComboBox *comboItem = new QComboBox(Table1);
      comboItem->addItems(Usages);
      comboItem->setCurrentIndex(comboItem->findText(qUsage));
      comboItem->setDisabled(mReadOnly);

      Table1->setCellWidget((int) j, COL_USAGE, comboItem);

      // connection between comboItem and its parent, Table1
      connect(comboItem, SIGNAL(activated(const QString &)), this, SLOT(slotTableValueChanged(const QString &)));
      comboItem->setObjectName(QString::number(j));  // just need to save the row index

      //col. 2 (units)
      QString strUnit = FROM_UTF8(units[j]);

      if (Table1->item((int) j, COL_UNIT) == NULL)
        {
          QTableWidgetItem *newItem = new QTableWidgetItem(strUnit);
          newItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
          Table1->setItem((int) j, COL_UNIT, newItem);
        }
      else
        Table1->item((int) j, COL_UNIT)->setText(strUnit);

      Table1->item((int) j, COL_UNIT)->setBackground(QBrush(color));
    }

  Table1->horizontalHeader()->setStretchLastSection(true);
  Table1->resizeColumnsToContents();
  Table1->resizeRowsToContents();

  /*
  Table1->setFixedSize(Table1->horizontalHeader()->length() + 10,
                       Table1->verticalHeader()->length() + 30);
  */

  return true;
}
示例#2
0
void ParameterTable::updateTable(const CReactionInterface & ri, const CReaction * pReaction)
{
  blockSignals(true); // So cellChanged doesn't fire when items are set.

  setRowCount(0);

  if (pReaction == NULL) return;

  CModel * pModel = dynamic_cast< CModel * >(pReaction->getObjectAncestor("Model"));

  //first get the units strings
  CFindDimensions units(ri.getFunction(), pModel->getQuantityUnit().isDimensionless(),
                        pModel->getVolumeUnit().isDimensionless(),
                        pModel->getTimeUnit().isDimensionless(),
                        pModel->getAreaUnit().isDimensionless(),
                        pModel->getLengthUnit().isDimensionless()
                       );
  units.setUseHeuristics(true);
  units.setMolecularitiesForMassAction(ri.getChemEqInterface().getMolecularity(CFunctionParameter::SUBSTRATE),
                                       ri.getChemEqInterface().getMolecularity(CFunctionParameter::PRODUCT));
  units.findDimensions(ri.isMulticompartment());

  CFunctionParameter::Role usage;

  // Load the comboDelegate lists
  mGlobalParameters.clear();
  mGlobalParameters = getListOfAllGlobalParameterNames(*pModel);

  if (mGlobalParameters.indexOf("--local--") != -1) // in case someone names a parameter "--local--"
    mGlobalParameters.replace(mGlobalParameters.indexOf("--local--"), "\"--local--\"");

  mGlobalParameters.push_front("--local--");

  std::vector<std::string>::const_iterator it;

  mSubstrates.clear();
  usage = CFunctionParameter::SUBSTRATE;

  for (it = ri.getListOfMetabs(usage).begin(); it != ri.getListOfMetabs(usage).end(); ++it)
    mSubstrates += FROM_UTF8(CMetabNameInterface::unQuote(*it));

  mProducts.clear();
  usage = CFunctionParameter::PRODUCT;

  for (it = ri.getListOfMetabs(usage).begin(); it != ri.getListOfMetabs(usage).end(); ++it)
    mProducts += FROM_UTF8(CMetabNameInterface::unQuote(*it));

  mModifiers.clear();  // Get all metabs; modifiers are never locked
  vectorOfStrings2QStringList(getListOfAllMetabNames(*pModel, ri), mModifiers);

  mVolumes.clear();
  mVolumes = getListOfAllCompartmentNames(*pModel);

  size_t i, imax = ri.size();
  size_t j, jmax;
  size_t rowCounter = 0;

  QTableWidgetItem *pItem = NULL;

  QColor subsColor(255, 210, 210);
  QColor prodColor(210, 255, 210);
  QColor modiColor(250, 250, 190);
  QColor paraColor(210, 210, 255);
  QColor volColor(210, 210, 255);
  QColor timeColor(210, 210, 210);

  QString qUsage;
  bool locked = false;
  QColor color;
  const std::vector<std::string> * metabNames;

  mIndex2Line.resize(imax);
  mLine2Index.clear();

  setRowCount((int) imax);

  for (i = 0; i < imax; ++i)
    {
      mIndex2Line[i] = rowCounter;

      // set the stuff that is different for the specific usages
      usage = ri.getUsage(i);
      qUsage = FROM_UTF8(CFunctionParameter::RoleNameDisplay[usage]);
      locked = ri.isLocked(i);

      switch (usage)
        {
          case CFunctionParameter::SUBSTRATE:
            color = subsColor;
            break;

          case CFunctionParameter::PRODUCT:
            color = prodColor;
            break;

          case CFunctionParameter::MODIFIER:
            color = modiColor;
            break;

          case CFunctionParameter::PARAMETER:
            color = paraColor;
            break;

          case CFunctionParameter::VOLUME:
            color = volColor;
            break;

          case CFunctionParameter::TIME:
            color = timeColor;
            break;

          case CFunctionParameter::VARIABLE:
            color = QColor(255, 20, 20);
            break;

          default :
            qUsage = "unknown";
            color = QColor(255, 20, 20);
            break;
        }

      // add first column
      pItem = new QTableWidgetItem(qUsage);
      pItem->setBackground(color);

      if (usage == CFunctionParameter::SUBSTRATE)
        pItem->setIcon(CQIconResource::icon(CQIconResource::reactionSubstrate));
      else if (usage == CFunctionParameter::PRODUCT)
        pItem->setIcon(CQIconResource::icon(CQIconResource::reactionProduct));
      else if (usage == CFunctionParameter::MODIFIER)
        pItem->setIcon(CQIconResource::icon(CQIconResource::reactionModifier));

      pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
      setItem((int) rowCounter, 0, pItem);

      // add second column
      pItem = new QTableWidgetItem(FROM_UTF8(ri.getParameterName(i)));
      pItem->setBackground(color);

      if ((usage != CFunctionParameter::PARAMETER)
          && (usage != CFunctionParameter::VOLUME)
          && (usage != CFunctionParameter::TIME))
        {
          if (locked)
            pItem->setIcon(CQIconResource::icon(CQIconResource::locked));
          else
            pItem->setIcon(CQIconResource::icon(CQIconResource::unlocked));
        }

      pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
      setItem((int) rowCounter, 1, pItem);

      // add units column
      const CCopasiDataModel* pDataModel = pModel->getObjectDataModel();

      if (pDataModel == NULL) return;

      QString theseUnits = FROM_UTF8(" " + units.getDimensions()[i].getDisplayString(pModel));
      pItem = new QTableWidgetItem(theseUnits);
      pItem->setBackgroundColor(color);
      pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
      setItem((int) rowCounter, 4, pItem);

      // Create and color Value column
      pItem = new QTableWidgetItem("");
      pItem->setBackground(QColor(color));
      pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
      setItem((int) rowCounter, 3, pItem);

      // add fourth (Mapping) column (col index = 3)
      pItem = new QTableWidgetItem("");
      pItem->setBackground(color);
      setItem((int) rowCounter, 2, pItem);

      // if line is for a metabolite Parameter . . .
      if ((usage == CFunctionParameter::SUBSTRATE)
          || (usage == CFunctionParameter::PRODUCT)
          || (usage == CFunctionParameter::MODIFIER))
        {

          metabNames = &(ri.getMappings(i));

          if (locked)
            {
              pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
              closePersistentEditor(pItem);
            }
          else
            {
              if (usage == CFunctionParameter::SUBSTRATE)
                mpComboDelegate->setItems(rowCounter, &mSubstrates);
              else if (usage == CFunctionParameter::PRODUCT)
                mpComboDelegate->setItems(rowCounter, &mProducts);
              else   // must be MODIFIER
                {
                  mpComboDelegate->setItems(rowCounter, &mModifiers);
                }

              openPersistentEditor(pItem);
            }

          if (!ri.isVector(i))
            pItem->setText(FROM_UTF8(CMetabNameInterface::unQuote((*metabNames)[0])));
          else
            {
              if (locked)
                pItem->setText("");
              else  // this should not happen
                pItem->setText("add species");

              // add lines for vector parameters
              jmax = metabNames->size();
              setRowCount(rowCount() + (int)(jmax - 1));

              item((int) rowCounter, 2)->setText(FROM_UTF8((*metabNames)[0]));

              for (j = 1; j < jmax; ++j)
                {
                  ++rowCounter;

                  for (int k = 0; k < 5; k++)
                    {
                      pItem = new QTableWidgetItem("");
                      pItem->setFlags(pItem->flags() & (~Qt::ItemIsEditable));
                      pItem->setBackgroundColor(color);
                      setItem((int) rowCounter, k, pItem);
                    }

                  item((int) rowCounter, 2)->setText(FROM_UTF8((*metabNames)[j]));
                  item((int) rowCounter, 4)->setText(theseUnits);
                }
            }
        }
      // if line is for a kinetic parameter . . .
      else if (usage == CFunctionParameter::PARAMETER)
        {
          mpComboDelegate->setItems(rowCounter, &mGlobalParameters);

          if (ri.isLocalValue(i))
            {
              pItem->setText("--local--");
            }
          else //global parameter
            {
              QString paramText = FROM_UTF8(ri.getMapping(i));

              if (paramText == "--local--")
                paramText = "\"--local--\"";

              pItem->setText(paramText);
            }

          openPersistentEditor(pItem);

          // add item to Value column
          pItem = item((int) rowCounter, 3);

          if (ri.isLocalValue(i))
            {
              pItem->setText(QString::number(ri.getLocalValue(i)));
              pItem->setFlags(pItem->flags() | (Qt::ItemIsEditable));
            }
          else
            {
              const std::vector<std::string> &mapping = pReaction->getParameterMapping(i);

              if (mapping.size() > 0)
                {
                  std::string Key = mapping[0];

                  const CModelValue * pParamObject =
                    dynamic_cast<const CModelValue *>(CCopasiRootContainer::getKeyFactory()->get(Key));

                  if (pParamObject != NULL &&
                      pParamObject->getStatus() == CModelEntity::FIXED)
                    {
                      pItem->setText(QString::number(pParamObject->getInitialValue()));
                      pItem->setTextColor(QColor(Qt::darkGray));
                    }
                }
            }
        }

      // if line is for a volume . . .
      else if (usage == CFunctionParameter::VOLUME)
        {
          mpComboDelegate->setItems(rowCounter, &mVolumes);
          pItem->setText(FROM_UTF8(ri.getMapping(i)));
          openPersistentEditor(pItem);
        }
      // if line is for time . . .
      else if (usage == CFunctionParameter::TIME)
        {
          pItem->setText("");
        }
      // if line is for an unknown role . . .
      else
        {
          pItem->setText(QString::number(ri.getLocalValue(i)));
        }

      resizeRowToContents((int) rowCounter);

      ++rowCounter;
    }

  resizeColumnsToContents();

  blockSignals(false);
}
示例#3
0
void ParameterTable::updateTable(const CReactionInterface & ri, const CModel & model)
{
  //first get the units strings
  CFindDimensions units(ri.getFunction(), model.getQuantityUnitEnum() == CModel::dimensionlessQuantity,
                        model.getVolumeUnitEnum() == CModel::dimensionlessVolume,
                        model.getTimeUnitEnum() == CModel::dimensionlessTime,
                        model.getAreaUnitEnum() == CModel::dimensionlessArea,
                        model.getLengthUnitEnum() == CModel::dimensionlessLength
                       );
  units.setUseHeuristics(true);
  units.setMolecularitiesForMassAction(ri.getChemEqInterface().getMolecularity(CFunctionParameter::SUBSTRATE),
                                       ri.getChemEqInterface().getMolecularity(CFunctionParameter::PRODUCT));
  units.findDimensions(ri.isMulticompartment());

  size_t i, imax = ri.size();
  size_t j, jmax;
  size_t rowCounter = 0;

  QStringList qsl;

  QColor subsColor(255, 210, 210);
  QColor prodColor(210, 255, 210);
  QColor modiColor(250, 250, 190);
  QColor paraColor(210, 210, 255);
  QColor volColor(210, 210, 255);
  QColor timeColor(210, 210, 210);

  CFunctionParameter::Role usage;
  QString qUsage;
  QColor color;
  const std::vector<std::string> * metabNames;

  mIndex2Line.resize(imax);
  mLine2Index.clear();

  this->setRowCount(0);
  this->setRowCount((int)(imax * 2));

  for (i = 0; i < imax; ++i)
    {
      rowCounter++;
      mIndex2Line[i] = rowCounter;

      // set the stuff that is different for the specific usages
      usage = ri.getUsage(i);
      qUsage = FROM_UTF8(CFunctionParameter::RoleNameDisplay[usage]);

      switch (usage)
        {
          case CFunctionParameter::SUBSTRATE:
            color = subsColor;
            break;

          case CFunctionParameter::PRODUCT:
            color = prodColor;
            break;

          case CFunctionParameter::MODIFIER:
            color = modiColor;
            break;

          case CFunctionParameter::PARAMETER:
            color = paraColor;
            break;

          case CFunctionParameter::VOLUME:
            color = volColor;
            break;

          case CFunctionParameter::TIME:
            color = timeColor;
            break;

          case CFunctionParameter::VARIABLE:
            color = QColor(255, 20, 20);
            break;

          default:
            qUsage = "unknown";
            color = QColor(255, 20, 20);
            break;
        }

      // add first column
      QTableWidgetItem * pItem = new ColorTableItem(color, qUsage);

      if (usage == CFunctionParameter::SUBSTRATE) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionSubstrate));

      if (usage == CFunctionParameter::PRODUCT) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionProduct));

      if (usage == CFunctionParameter::MODIFIER) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionModifier));

      setItem((int) rowCounter, 0, pItem);

      // add second column
      pItem = new ColorTableItem(color, FROM_UTF8(ri.getParameterName(i)));

      if ((usage != CFunctionParameter::PARAMETER)
          && (usage != CFunctionParameter::VOLUME)
          && (usage != CFunctionParameter::TIME))
        {
          if (ri.isLocked(i))
            pItem->setIcon(CQIconResource::icon(CQIconResource::locked));
          else
            pItem->setIcon(CQIconResource::icon(CQIconResource::unlocked));
        }

      setItem((int) rowCounter, 1, pItem);

      // add third column
      pItem = new ColorTableItem(color, "");

      if (usage == CFunctionParameter::PARAMETER)
        {
          pItem->setFlags(pItem->flags() | Qt::ItemIsUserCheckable);
          pItem->setCheckState(ri.isLocalValue(i) ? Qt::Unchecked : Qt::Checked);
        }

      setItem((int) rowCounter, 2, pItem);

      // add units column
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
      assert(pDataModel != NULL);
      pItem = new ColorTableItem(color, FROM_UTF8(" " + units.getDimensions()[i].getDisplayString(pDataModel)));
      setItem((int) rowCounter, 4, pItem);

      // add a line for a metabolite Parameter
      if ((usage == CFunctionParameter::SUBSTRATE)
          || (usage == CFunctionParameter::PRODUCT)
          || (usage == CFunctionParameter::MODIFIER))
        {
          // get the list of possible metabs (for the combo box)
          if (usage == CFunctionParameter::MODIFIER) //get all metabs; modifiers are never locked
            vectorOfStrings2QStringList(getListOfAllMetabNames(model, ri), qsl);
          else //only get the modifiers from the ChemEq
            {
              if (!ri.isLocked(i))
                vectorOfStrings2QStringList(ri.getListOfMetabs(usage), qsl);
            }

          metabNames = &(ri.getMappings(i));

          if (!ri.isVector(i))
            {
              if (ri.isLocked(i))
                {
                  pItem = new ColorTableItem(color, FROM_UTF8((*metabNames)[0]));
                  setItem((int) rowCounter, 3, pItem);
                }
              else
                {
                  QComboBox * pComboBox = new QComboBox();
                  pComboBox->addItems(qsl);
                  pComboBox->setBackgroundColor(color);
                  pComboBox->setCurrentText(FROM_UTF8(unQuote((*metabNames)[0])));

                  setCellWidget((int) rowCounter, 3, pComboBox);
                }
            }
          else
            {
              if (ri.isLocked(i))
                {
                  pItem = new ColorTableItem(color, "");
                  setItem((int) rowCounter, 3, pItem);
                }
              else // this should not happen
                {
                  QComboBox * pComboBox = new QComboBox();
                  pComboBox->addItems(qsl);
                  pComboBox->setBackgroundColor(color);
                  pComboBox->setCurrentText("add species");

                  setCellWidget((int) rowCounter, 3, pComboBox);
                }

              // add lines for vector parameters
              jmax = metabNames->size();
              setRowCount(rowCount() + (int) jmax);

              for (j = 0; j < jmax; ++j)
                {
                  ++rowCounter;
                  pItem = new ColorTableItem(color, FROM_UTF8((*metabNames)[j]));
                  setItem((int) rowCounter, 3, pItem);
                }
            }
        }
      // add a line for a kinetic parameter
      else if (usage == CFunctionParameter::PARAMETER)
        {
          if (ri.isLocalValue(i))
            {
              pItem = new ColorTableItem(color, QString::number(ri.getLocalValue(i)));
              setItem((int) rowCounter, 3, pItem);
            }
          else //global parameter
            {
              QComboBox * pComboBox = new QComboBox();
              pComboBox->addItems(getListOfAllGlobalParameterNames(model));
              pComboBox->setBackgroundColor(color);
              pComboBox->setCurrentText(FROM_UTF8(ri.getMapping(i)));

              setCellWidget((int) rowCounter, 3, pComboBox);
            }
        }
      // add a line for a kinetic parameter
      else if (usage == CFunctionParameter::VOLUME)
        {
          QComboBox * pComboBox = new QComboBox();
          pComboBox->addItems(getListOfAllCompartmentNames(model));
          pComboBox->setBackgroundColor(color);
          pComboBox->setCurrentText(FROM_UTF8(ri.getMapping(i)));

          setCellWidget((int) rowCounter, 3, pComboBox);
        }
      // add a line for time
      else if (usage == CFunctionParameter::TIME)
        {
          pItem = new ColorTableItem(color, "");
          setItem((int) rowCounter, 3, pItem);
        }
      // add a line for an unknown role
      else
        {
          pItem = new ColorTableItem(color, QString::number(ri.getLocalValue(i)));
          setItem((int) rowCounter, 3, pItem);
        }

      resizeRowToContents((int) rowCounter);

      //mLine2Index

      ++rowCounter;
    }

  this->resizeColumnsToContents();
}