Ejemplo n.º 1
0
CLRenderInformationBase* updateRenderInformationList(QComboBox* list, CCopasiDataModel* dataModel, CLayout* layout)
{

  if (list == NULL || dataModel == NULL) return NULL;

  bool skipGlobal = list->count() > 0;
  CLRenderInformationBase* result = NULL;

  // remove oldItems
  if (skipGlobal)
    {
      for (size_t i = list->count(); i > 0; --i)
        {
          QString current = list->itemText(i - 1);
          int type = list->itemData(i - 1).toInt();

          if (type == RENDERINFORMATION_TYPE_LOCAL)
            list->removeItem(i - 1);
        }
    }

  // add local information
  if (layout != NULL)
    {
      CCopasiVector<CLLocalRenderInformation> & render = layout->getListOfLocalRenderInformationObjects();
      CCopasiVector<CLLocalRenderInformation>::iterator it = render.begin();

      while (it != render.end())
        {
          CLLocalRenderInformation* current = *it;

          if (result == NULL) result = current;

          if (current->getName().empty())
            list->insertItem(0, current->getKey().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_LOCAL));
          else
            list->insertItem(0, current->getName().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_LOCAL));

          ++it;
        }
    }

  // bail
  if (skipGlobal)
    {
      if (result == NULL && dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects().size() > 0)
        result = dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects()[0];

      if (result == NULL && getNumDefaultStyles() > 0)
        result = getDefaultStyle(0);

      return result;
    }

  // add global ones
  {
    CCopasiVector<CLGlobalRenderInformation> & render = dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects();
    CCopasiVector<CLGlobalRenderInformation>::const_iterator it = render.begin();

    while (it != render.end())
      {
        CLGlobalRenderInformation* current = *it;

        if (result == NULL) result = current;

        if (current->getName().empty())
          list->addItem(current->getKey().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_GLOBAL));
        else
          list->addItem(current->getName().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_GLOBAL));

        ++it;
      }

    // add default ones
    {
      size_t i, iMax = getNumDefaultStyles();
      CLRenderInformationBase* current = NULL;

      for (i = 0; i < iMax; ++i)
        {
          current = getDefaultStyle(i);

          if (result == NULL) result = current;

          std::string text = current->getKey();

          if (!current->getName().empty())
            {
              text = current->getName();
            }

          list->addItem(text.c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_DEFAULT));
        }
    }
  }

  return result;
}