コード例 #1
0
ファイル: navigabletableview.cpp プロジェクト: mneumann/tulip
void NavigableTableView::resizeTableRows() {

  if (!model())
    return;

  int top = qMax(0, verticalHeader()->visualIndexAt(0));
  int bottom = verticalHeader()->visualIndexAt(viewport()->height());

  if (bottom == -1 || (bottom+10) >= model()->rowCount()) {
    bottom = model()->rowCount() - 1;
  }
  else {
    bottom += 10;
  }

  int left = qMax(0, horizontalHeader()->visualIndexAt(0));
  int right = horizontalHeader()->visualIndexAt(viewport()->width());

  if (right < 0) right = model()->columnCount();

  for (int i = top ; i <= bottom ; ++i)
    resizeRowToContents(i);

  for (int i = left ; i <= right ; ++i)
    resizeColumnToContents(i);

}
コード例 #2
0
ファイル: kwqtableview.cpp プロジェクト: KDE/kwordquiz
void KWQTableView::adjustRow(int row)
{
  // we want to make the row high enough to display content, but
  // if the user already made it even higher we keep that height
  //int r = currentIndex().row();
  int rh = rowHeight(row);
  resizeRowToContents(row);
  if (rh > rowHeight(row))
    setRowHeight(row, rh);
}
コード例 #3
0
MyTable::MyTable(QWidget* parent)
    : QTableView(/*RowCount, ColumnCount, */ parent)
    , m_header(new MyHeader(Qt::Vertical, this))
    , m_model(new MyTableModel(this))
#ifdef EXCEL
    , excel(new Excel::Application(this))
#endif
{
    setModel(m_model);
    setVerticalHeader(m_header);

    connect(m_model, &MyTableModel::dataChanged, [=](const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/, const QVector<int>& /*roles*/) {
        updatePlot(topLeft.row());
        resizeRowToContents(topLeft.row());
    });

    QAbstractButton* cornerButton = findChild<QAbstractButton*>();
    if (cornerButton) {
        c = new QCheckBox("№", cornerButton);
        c->setGeometry(cornerButton->rect() + QMargins(-5, 0, 100, 0));
        connect(c, &QCheckBox::toggled, [this](bool checked) { m_header->setChecked(checked); });
    }

    connect(m_header, &MyHeader::checkedChanged, m_model, &MyTableModel::setRowsEnabled);

    setColumnHidden(MeasureDeltaCh0, true);
    setColumnHidden(MeasureDeltaCh1, true);

    horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    horizontalHeader()->setSectionResizeMode(MeasureCh0, QHeaderView::Stretch);
    horizontalHeader()->setSectionResizeMode(MeasureCh1, QHeaderView::Stretch);

    setIconSize(QSize(24, 24));
#ifdef EXCEL
    excel->SetVisible(true);
#endif
}
コード例 #4
0
void QCustomTableWidget::editCharacter(int index)
{
    if(pChangeCharacterDial->exec()==QDialog::Accepted)
    {
        QTableWidgetItem *rowHeaderItem = verticalHeaderItem ( index );
        if (rowHeaderItem != NULL)
        {
            rowHeaderItem->setText(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName());
        }
        else
        {
            rowHeaderItem = new QTableWidgetItem(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName());
            setVerticalHeaderItem(index, rowHeaderItem);
        }
        // updating the CharacterList
        if (pCharacters != NULL)
        {
            Character &charact = (*pCharacters)[index];
            charact.setName(pChangeCharacterDial->name().toStdString());
            charact.setPlayerName(pChangeCharacterDial->playerName().toStdString());
        }
    }
    resizeRowToContents(index);
}
コード例 #5
0
ファイル: parametertable.cpp プロジェクト: cpanchal/COPASI
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);
}
コード例 #6
0
void TestInputsWidget::updateResults()
{
    // Ensure we are ready to proceed
    if(_factory == 0)
        return;

    RegexBase *regexp = _factory->regexpEngine(_expression);

    // If it's invalid do nothing
    // NOTE: In the future it would probably make more sense if this cleared
    // the current results
    if(!regexp->isValid())
        return;

    for(int i = 0; i < rowCount(); ++i)
    {
        // If there is no item here, don't segfault, that is generally bad
        if(item(i,0) == 0)
            continue;

        QString input = item(i, 0)->text();
        if(!input.isEmpty())
        {
            bool exact = regexp->exactMatch(input);
            int partial = regexp->indexIn(input);

            if(exact)
            {
                item(i, 1)->setText("Exact Match");
                item(i, 2)->setText("0");
            }

            if(!exact && partial > -1)
            {
                item(i, 1)->setText("Partial Match");
                item(i, 2)->setText(QVariant(partial).toString());
            }

            if(exact || partial > -1)
            {
                // If it's an exact match run it again to make sure we caught
                // everything for the capture groups
                if(exact)
                    regexp->exactMatch(input);

                QStringList matches = regexp->capturedTexts();
                QString matchString = "";
                for(int j = 0; j < matches.length(); ++j)
                {
                    matchString += QString("[") + QVariant(j).toString()
                                + "] " + matches.at(j);
                    if(j != (matches.length()-1))
                        matchString += QString(", \n");
                }
                item(i, 3)->setText(matchString);
            }
            else
            {
                item(i, 1)->setText("No Match");
                item(i, 2)->setText("N/A");
                item(i, 3)->setText("");
            }
        }

        resizeRowToContents(i);
    }

    // Also, if there is text in the last row insert a new one so people
    // can continue to provide test inputs
    if(item(rowCount()-1, 0) != 0)
        setRowCount(rowCount()+1);
}
コード例 #7
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();
}