Esempio n. 1
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;
}
Esempio n. 2
0
void CQReportDefinition::btnCopyReportClicked()
{
  btnCommitClicked();

  CCopasiDataModel* pDataModel = mpObject->getObjectDataModel();

  if (pDataModel == NULL) return;

  CReportDefinition * pRep = new CReportDefinition(*dynamic_cast<CReportDefinition*>(CCopasiRootContainer::getKeyFactory()->get(mKey)));

  std::string baseName = pRep->getObjectName() + "_copy";
  std::string name = baseName;

  int i = 1;

  while (pDataModel->getReportDefinitionList()->getIndex(name) != C_INVALID_INDEX)
    {
      i++;
      name = baseName + TO_UTF8(QString::number(i));
    }

  pRep->setObjectName(name);

  pDataModel->getReportDefinitionList()->add(pRep, true);

  std::string key = pRep->getKey();
  protectedNotify(ListViews::REPORT, ListViews::ADD, key);
  enter(key);
  mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
void CQReportDefinition::btnNewReportClicked()
{
    btnCommitClicked();

    std::string Name = "report";

    int i = 0;
    CReportDefinition* pRep;
    assert(CCopasiRootContainer::getDatamodelList()->size() > 0);

    while (!(pRep = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->createReportDefinition(Name, "")))
    {
        i++;
        Name = "report_";
        Name += TO_UTF8(QString::number(i));
    }

    std::string key = pRep->getKey();
    protectedNotify(ListViews::REPORT, ListViews::ADD, key);
    enter(key);
    mpListView->switchToOtherWidget(C_INVALID_INDEX, key);
}