示例#1
0
void SliderDialog::addSlider(CSlider* pSlider)
{
  if (mpParentWindow == NULL)
    return;

  // check if there already is a slider for this  object
  CCopasiDataModel * pDataModel = pSlider->getObjectDataModel();
  assert(pDataModel != NULL);
  SCopasiXMLGUI* pGUI = pDataModel->getGUI();
  assert(pGUI);

  if (!equivalentSliderExists(pSlider))
    {
      CObjectInterface::ContainerList listOfContainers;
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      listOfContainers.push_back(pDataModel->getModel());
      pSlider->compile(listOfContainers);
      pGUI->getSliderList()->add(pSlider, true);
    }

  CopasiSlider* tmp = findCopasiSliderForCSlider(pSlider);

  if (!tmp)
    {
      setCurrentSlider(new CopasiSlider(pSlider, mpParentWindow->getDataModel(), mpSliderBox));
      mpCurrSlider->installEventFilter(this);
      mpCurrSlider->setHidden(true);
      mpCurrSlider->updateSliderData();
      // make sure the slider points to the correct object
      // for the currently set framework
      this->setCorrectSliderObject(this->mpCurrSlider);
      mSliderMap[mCurrentFolderId].push_back(mpCurrSlider);
      QBoxLayout* layout = static_cast<QBoxLayout*>(mpSliderBox->layout());
      int childCount = layout->count() - 1;
      layout->insertWidget(childCount, mpCurrSlider);
      connect(mpCurrSlider, SIGNAL(valueChanged(double)), this , SLOT(sliderValueChanged()));
      connect(mpCurrSlider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased()));
      connect(mpCurrSlider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
      connect(mpCurrSlider, SIGNAL(closeClicked(CopasiSlider*)), this, SLOT(removeSlider(CopasiSlider*)));
      connect(mpCurrSlider, SIGNAL(editClicked(CopasiSlider*)), this, SLOT(editSlider(CopasiSlider*)));
      mpCurrSlider->setHidden(false);
      mChanged = true;
    }
示例#2
0
void SliderDialog::createNewSlider()
{
  // allow the user to create more than one slider
  std::vector<const CCopasiObject*> objects = CCopasiSelectionDialog::getObjectVector(this,
      CQSimpleSelectionTree::InitialTime |
      CQSimpleSelectionTree::Parameters);
  std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId();
  std::vector<const CCopasiObject*>::const_iterator it = objects.begin(), endit = objects.end();
  bool yesToAll = false;
  bool noToAll = false;
  // create the sliders for all the selected objects

  // first we need the task object because we need it later to associate the
  // later with the correct task
  CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId);

  if (!object) return;

  CCopasiObject* pTmpObject = NULL;

  while (it != endit)
    {
      // create a new slider
      assert((*it) != NULL);
      pTmpObject = const_cast<CCopasiObject*>(determineCorrectObjectForSlider(*it));

      CSlider* pCSlider = new CSlider("slider", (*CCopasiRootContainer::getDatamodelList())[0]);

      if (pCSlider)
        {
          pCSlider->setSliderObject(pTmpObject);
          pCSlider->setAssociatedEntityKey(object->getKey());
          // check if a slider for that object already exists and if so, prompt
          // the user what to do
          CSlider* pEquivalentSlider = equivalentSliderExists(pCSlider);

          if (pEquivalentSlider != NULL)
            {
              CopasiSlider* pCopasiSlider = NULL;

              // if the user has specified yesToAll, we reset the ranges of all
              // duplicate sliders
              if (yesToAll)
                {
                  pEquivalentSlider->resetRange();
                  // update the slider widget
                  pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider);
                  assert(pCopasiSlider != NULL);

                  if (pCopasiSlider != NULL)
                    {
                      pCopasiSlider->updateSliderData();
                    }
                }
              // if the user has not specified noToAll, we need to prompt
              else if (!noToAll)
                {
                  QMessageBox::StandardButton result = CQMessageBox::information(NULL, "Slider Exists",
                                                       "A slider for this object already exists.\n\nDo you want to reset the range of the slider?",
                                                       QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll, QMessageBox::No);

                  // check the answer and maybe set some flags
                  switch (result)
                    {
                      case QMessageBox::YesToAll:
                        // set the flag
                        yesToAll = true;

                      case QMessageBox::Yes:
                        // reset the range
                        pEquivalentSlider->resetRange();
                        // update the slider widget
                        pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider);
                        assert(pCopasiSlider != NULL);

                        if (pCopasiSlider != NULL)
                          {
                            pCopasiSlider->updateSliderData();
                          }

                        break;

                      case QMessageBox::NoToAll:
                        // set the flag
                        noToAll = true;
                        break;

                      case QMessageBox::No:
                        // do nothing else
                        break;

                      default:
                        // do nothing
                        break;
                    }
                }

              delete pCSlider;
            }
          else
            {
              std::vector<CCopasiContainer*> listOfContainers;
              assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
              listOfContainers.push_back((*CCopasiRootContainer::getDatamodelList())[0]->getModel());
              pCSlider->compile(listOfContainers);
              pCSlider->resetRange();
              addSlider(pCSlider);
              mChanged = true;
            }
        }

      ++it;
    }

  delete pVector;
}