COPASI API  4.16.103
CQFittingItemWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "CQFittingItemWidget.h"
16 
17 #include <QtGui/QApplication>
18 #include <QtGui/QPalette>
19 #include <QtGui/QHeaderView>
20 
21 #include "CCopasiSelectionDialog.h"
22 #include "CQValidator.h"
23 #include "CQExperimentSelection.h"
24 #include "CQStartValueReset.h"
25 #include "qtUtilities.h"
26 
28 
30 #include "report/CKeyFactory.h"
35 #include "utilities/utility.h"
37 
38 #include <QtCore/QtDebug>
39 
40 /*
41  * Constructs a CQFittingItemWidget as a child of 'parent', with the
42  * name 'name' and widget flags set to 'f'.
43  */
44 CQFittingItemWidget::CQFittingItemWidget(QWidget* parent, Qt::WindowFlags fl)
45  : QWidget(parent, fl)
46 {
47  setupUi(this);
48 
50 
52 
53  mpBtnUpperEdit->setIcon(CQIconResource::icon(CQIconResource::copasi));
54  mpBtnLowerEdit->setIcon(CQIconResource::icon(CQIconResource::copasi));
55  mpBtnObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
56 
58 
60 
62 
63  mpBtnReset->setIcon(CQIconResource::icon(CQIconResource::tool));
64  mpBtnExperiments->setIcon(CQIconResource::icon(CQIconResource::tool));
65  mpBtnCrossValidations->setIcon(CQIconResource::icon(CQIconResource::tool));
66 
67  init();
68 }
69 
70 /*
71  * Destroys the object and frees any allocated resources
72  */
74 {
75  destroy();
76  // no need to delete child widgets, Qt does it all for us
77 }
78 
80 {
81  mppExperimentSet = NULL;
82  mppCrossValidationSet = NULL;
83 
84  mpItemsCopy = new std::vector<COptItem *>;
86 
88 
89  mLowerInfChanged = false;
90  mUpperInfChanged = false;
91 
92  mpTable->horizontalHeader()->hide();
93  mpTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
94  mpTable->setAlternatingRowColors(true);
95  mpTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
96  mpTable->setSelectionBehavior(QAbstractItemView::SelectRows);
97 
98  int h, s, v;
99 
100  mSavedColor = palette().color(backgroundRole());
101  mSavedColor.getHsv(&h, &s, &v);
102 
103  if (s < 20) s = 20;
104 
105  mChangedColor.setHsv(240, s, v);
106 
107  mpObjectValidator = new CQValidatorNotEmpty(mpEditObject);
108  mpEditObject->setValidator(mpObjectValidator);
110 
111  mpLowerValidator = new CQValidatorBound(mpEditLower, "-");
112  mpEditLower->setValidator(mpLowerValidator);
114 
115  mpUpperValidator = new CQValidatorBound(mpEditUpper, "+");
116  mpEditUpper->setValidator(mpUpperValidator);
118 
119  mpBtnCrossValidations->hide();
120  mpCheckCrossValidationsAll->hide();
121  mpBoxCrossValidations->hide();
122  mpLblCrossValidations->hide();
123 }
124 
126 {
127  std::vector< COptItem * >::iterator it = mpItemsCopy->begin();
128  std::vector< COptItem * >::iterator end = mpItemsCopy->end();
129 
130  for (; it != end; ++it)
131  pdelete(*it);
132 
134 }
135 
137 {
138  mpEditLower->setEnabled(!checked);
139 
141 
142  if (mLowerInfChanged)
143  {
144  mpCheckLowerInf->setStyleSheet(QString(mpCheckLowerInf->metaObject()->className()) + " {background-color:" + mChangedColor.name() + ";}");
145 
146  if (mpEditLower->isEnabled()) mpLowerValidator->revalidate();
147  }
148  else
149  {
150  mpCheckLowerInf->setStyleSheet(QString(mpCheckLowerInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
151  }
152 
153  std::string Number;
154 
155  if (checked)
156  Number = "-inf";
157  else if (isNumber(TO_UTF8(mpEditLower->text())))
158  Number = TO_UTF8(mpEditLower->text());
159  else if (mpLowerObject)
160  Number = mpLowerObject->getCN();
161  else return;
162 
163  std::set< size_t >::const_iterator it = mSelection.begin();
164  std::set< size_t >::const_iterator end = mSelection.end();
165 
166  for (; it != end; ++it)
167  {
168  (*mpItemsCopy)[*it]->setLowerBound(Number);
169  setTableText((int) *it, (*mpItemsCopy)[*it]);
170  }
171 }
172 
174 {
175  mpEditUpper->setEnabled(!checked);
176 
178 
179  if (mUpperInfChanged)
180  {
181  mpCheckUpperInf->setStyleSheet(QString(mpCheckUpperInf->metaObject()->className()) + " {background-color:" + mChangedColor.name() + ";}");
182 
183  if (mpEditUpper->isEnabled()) mpUpperValidator->revalidate();
184  }
185  else
186  {
187  mpCheckUpperInf->setStyleSheet(QString(mpCheckUpperInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
188  }
189 
190  std::string Number;
191 
192  if (checked)
193  Number = "inf";
194  else if (isNumber(TO_UTF8(mpEditUpper->text())))
195  Number = TO_UTF8(mpEditUpper->text());
196  else if (mpUpperObject)
197  Number = mpUpperObject->getCN();
198  else return;
199 
200  std::set< size_t >::const_iterator it = mSelection.begin();
201  std::set< size_t >::const_iterator end = mSelection.end();
202 
203  for (; it != end; ++it)
204  {
205  (*mpItemsCopy)[*it]->setUpperBound(Number);
206  setTableText((int) *it, (*mpItemsCopy)[*it]);
207  }
208 }
209 
211 {
213 
214  switch (mItemType)
215  {
216  case OPT_ITEM:
217  case FIT_ITEM:
218  Classes =
222  break;
223 
224  case OPT_CONSTRAINT:
225  case FIT_CONSTRAINT:
226  Classes =
233  break;
234  }
235 
236  const CCopasiObject * pObject =
238 
239  if (pObject)
240  {
241  mpCheckLowerInf->setChecked(false);
242  mpEditLower->setEnabled(true);
243 
244  if (!mSelection.size())
245  slotNew();
246 
247  std::set< size_t >::const_iterator it = mSelection.begin();
248  std::set< size_t >::const_iterator end = mSelection.end();
249 
250  mpLowerObject = pObject;
252 
253  for (; it != end; ++it)
254  {
255  (*mpItemsCopy)[*it]->setLowerBound(CN);
256  setTableText((int) *it, (*mpItemsCopy)[*it]);
257  }
258 
259  QString Value = FROM_UTF8(pObject->getObjectDisplayName());
260  mpLowerValidator->force(Value);
261  mpEditLower->setText(Value);
262  }
263 }
264 
266 {
268 
269  switch (mItemType)
270  {
271  case OPT_ITEM:
272  case FIT_ITEM:
273  Classes =
277  break;
278 
279  case OPT_CONSTRAINT:
280  case FIT_CONSTRAINT:
281  Classes =
288  break;
289  }
290 
291  const CCopasiObject * pObject =
293 
294  if (pObject)
295  {
296  mpCheckUpperInf->setChecked(false);
297  mpEditUpper->setEnabled(true);
298 
299  if (!mSelection.size())
300  slotNew();
301 
302  std::set< size_t >::const_iterator it = mSelection.begin();
303  std::set< size_t >::const_iterator end = mSelection.end();
304 
305  mpUpperObject = pObject;
307 
308  for (; it != end; ++it)
309  {
310  (*mpItemsCopy)[*it]->setUpperBound(CN);
311  setTableText((int) *it, (*mpItemsCopy)[*it]);
312  }
313 
314  QString Value = FROM_UTF8(pObject->getObjectDisplayName());
315  mpUpperValidator->force(Value);
316  mpEditUpper->setText(Value);
317  }
318 }
319 
321 {
322  std::vector< const CCopasiObject * > Selection;
323 
325 
326  switch (mItemType)
327  {
328  case OPT_ITEM:
329  case FIT_ITEM:
330  Classes =
333  break;
334 
335  case OPT_CONSTRAINT:
336  case FIT_CONSTRAINT:
337  Classes =
343  break;
344  }
345 
346  if (mSelection.size() > 1)
347  {
348  const CCopasiObject * pObject =
350 
351  if (pObject)
352  Selection.push_back(pObject);
353  }
354  else
355  Selection =
357 
358  if (Selection.size() != 0)
359  {
360  // We need to loop through the selection.
361  size_t current = currentRow();
362 
363  // We must not trigger slotSelectionChanged!
364  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
365 
366  // If no item is selected create one.
367  if (!mSelection.size())
368  {
369  COptItem * pItem;
370 
371  switch (mItemType)
372  {
373  case OPT_ITEM:
374  case OPT_CONSTRAINT:
375  pItem = new COptItem(mpDataModel);
376  break;
377 
378  case FIT_ITEM:
379  pItem = new CFitItem(mpDataModel);
380  break;
381 
382  case FIT_CONSTRAINT:
383  pItem = new CFitConstraint(mpDataModel);
384  break;
385  }
386 
387  mpItemsCopy->push_back(pItem);
388  current = mpTable->rowCount();
389  mSelection.insert(current);
390  mpTable->insertRow((int) current);
391  setTableText((int) current, pItem);
392  }
393 
394  // Update the selected items
395  std::set< size_t >::const_iterator it = mSelection.begin();
396  std::set< size_t >::const_iterator end = mSelection.end();
397 
398  for (; it != end; ++it)
399  {
400  (*mpItemsCopy)[*it]->setObjectCN(Selection[0]->getCN());
401  setTableText((int) *it, (*mpItemsCopy)[*it]);
402  }
403 
404  saveSelection();
405 
406  // If one item is selected we may have no several objects
407  // and must create the appropriate items
408  size_t i, imax = Selection.size();
409 
410  COptItem * pSrc = (*mpItemsCopy)[*mSelection.begin()];
411 
412  for (i = 1; i != imax; i++)
413  {
414  COptItem * pItem;
415 
416  switch (mItemType)
417  {
418  case OPT_ITEM:
419  case OPT_CONSTRAINT:
420  pItem = new COptItem(*pSrc);
421  break;
422 
423  case FIT_ITEM:
424  pItem = new CFitItem(*pSrc);
425  break;
426 
427  case FIT_CONSTRAINT:
428  pItem = new CFitConstraint(*pSrc);
429  break;
430  }
431 
432  pItem->setObjectCN(Selection[i]->getCN());
433 
434  // Add the new item to the list.
435  mpItemsCopy->insert(mpItemsCopy->begin() + current + i, pItem);
436 
437  // Update the table
438  mpTable->insertRow((int)(current + i));
439  setTableText((int)(current + i), pItem);
440  }
441 
442  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
443 
444  // Update the selection;
445  if (current != C_INVALID_INDEX)
446  selectRow(current);
447  else
448  loadSelection();
449 
450  emit numberChanged((int) mpItemsCopy->size());
451  }
452 }
453 
455 {
457  {
458  CQExperimentSelection * pDialog = new CQExperimentSelection(this);
459  pDialog->load(mpBoxExperiments, * mppExperimentSet);
460 
461  if (pDialog->exec() == QDialog::Accepted)
462  {
463  if (!mSelection.size())
464  slotNew();
465 
466  std::set< size_t >::const_iterator it = mSelection.begin();
467  std::set< size_t >::const_iterator end = mSelection.end();
468 
469  for (; it != end; ++it)
470  {
471  (*mpItemsCopy)[*it]->getGroup("Affected Experiments")->clear();
472  size_t i, imax = mpBoxExperiments->count();
473 
474  for (i = 0; i < imax && imax < (*mppExperimentSet)->getExperimentCount(); i++)
475  static_cast<CFitItem *>((*mpItemsCopy)[*it])->addExperiment((*mppExperimentSet)->getExperiment(TO_UTF8(mpBoxExperiments->itemText((int) i)))->CCopasiParameter::getKey());
476 
477  setTableText((int) *it, (*mpItemsCopy)[*it]);
478  }
479  }
480 
481  loadSelection();
482 
483  delete pDialog;
484  }
485 }
486 
488  CCopasiParameterGroup * pItems,
489  const std::map<std::string, std::string> * pExperimentMap,
490  const std::map<std::string, std::string> * pCrossValidationMap)
491 {
492  mpDataModel = pDataModel;
493 
494  mpItems = pItems;
495  mSelection.clear();
496 
497  std::vector< COptItem * >::iterator it = mpItemsCopy->begin();
498  std::vector< COptItem * >::iterator end = mpItemsCopy->end();
499 
500  for (; it != end; ++it)
501  pdelete(*it);
502 
503  // We must not trigger slotSelectionChanged!
504  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
505  mpTable->setRowCount((int) mpItems->size());
506  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
508 
509  mpItemsCopy->resize(mpItems->size());
510 
511  it = mpItemsCopy->begin();
512  end = mpItemsCopy->end();
513 
514  std::vector< COptItem * >::const_iterator src =
515  static_cast<std::vector< COptItem * > *>(mpItems->CCopasiParameter::getValue().pVOID)->begin();
516 
517  size_t i;
518 
519  for (i = 0; it != end; ++it, ++src, ++i)
520  {
521  switch (mItemType)
522  {
523  case OPT_ITEM:
524  case OPT_CONSTRAINT:
525  *it = new COptItem(**src);
526  break;
527 
528  case FIT_ITEM:
529  *it = new CFitItem(**src);
530  break;
531 
532  case FIT_CONSTRAINT:
533  *it = new CFitConstraint(**src);
534  break;
535  }
536 
538  {
539  if (!pExperimentMap) return false;
540 
541  CFitItem *fitItem = static_cast<CFitItem *>(*it);
542 
543  // Change the key to reflect the local copy *mppExperimentSet
544  size_t j, jmax = fitItem->getExperimentCount();
545 
546  for (j = 0; j < jmax; j++)
547  {
548  std::string & Key =
549  *const_cast<std::string *>(&fitItem->getExperiment(j));
550 
551  if (Key.empty())
552  {
553  CCopasiMessage(CCopasiMessage::ERROR, "Could not find experiment for fit item '%s'.", fitItem->getObjectCN().c_str());
554  continue;
555  }
556 
557  Key = pExperimentMap->find(Key)->second;
558  }
559 
560  if (!pCrossValidationMap) return false;
561 
562  // Change the key to reflect the local copy *mppCrossValidationSet
563  jmax = fitItem->getCrossValidationCount();
564 
565  for (j = 0; j < jmax; j++)
566  {
567  std::string & Key =
568  *const_cast<std::string *>(&fitItem->getCrossValidation(j));
569 
570  if (Key.empty())
571  {
572  CCopasiMessage(CCopasiMessage::ERROR, "Could not find cross validation set for fit item '%s'.", fitItem->getObjectCN().c_str());
573  continue;
574  }
575 
576  Key = pCrossValidationMap->find(Key)->second;
577  }
578  }
579 
580  setTableText((int) i, *it);
581  }
582 
583  if (mpItemsCopy->size())
584  selectRow(0);
585  else
587 
588  emit numberChanged((int) mpItemsCopy->size());
589  mpTable->resizeRowsToContents();
590 
591  return true;
592 }
593 
594 bool CQFittingItemWidget::save(const std::map<std::string, std::string> * pExperimentMap,
595  const std::map<std::string, std::string> * pCrossValidationMap)
596 {
597  // Make sure that the current items is saved.
598  saveSelection();
599 
600  bool changed = false;
601 
602  std::vector< COptItem * >::const_iterator it = mpItemsCopy->begin();
603  std::vector< COptItem * >::const_iterator end = mpItemsCopy->end();
604 
605  std::vector< COptItem * >::iterator target =
606  static_cast<std::vector< COptItem * > *>(mpItems->CCopasiParameter::getValue().pVOID)->begin();
607  std::vector< COptItem * >::iterator targetEnd =
608  static_cast<std::vector< COptItem * > *>(mpItems->CCopasiParameter::getValue().pVOID)->end();
609 
610  size_t i;
611  size_t imax = std::max<size_t>(mpItemsCopy->size(), mpItems->size());
612 
613  for (i = 0; it != end && target != targetEnd; ++it, ++target, ++i)
614  {
615  if ((*target)->getObjectCN() != (*it)->getObjectCN())
616  {
617  changed = true;
618 
619  if (!(*target)->setObjectCN((*it)->getObjectCN()))
620  (*target)->setValue("ObjectCN", (*it)->getObjectCN());
621  }
622 
623  if ((*target)->getLowerBound() != (*it)->getLowerBound())
624  {
625  changed = true;
626  (*target)->setLowerBound((*it)->getLowerBound());
627  }
628 
629  if ((*target)->getUpperBound() != (*it)->getUpperBound())
630  {
631  changed = true;
632  (*target)->setUpperBound((*it)->getUpperBound());
633  }
634 
635  if ((*target)->getStartValue() != (*it)->getStartValue())
636  {
637  changed = true;
638  (*target)->setStartValue((*it)->getStartValue());
639  }
640 
642  {
643  if (pExperimentMap == NULL) return false;
644 
645  size_t j, jmax =
646  std::min(static_cast<CFitItem *>(*it)->getExperimentCount(),
647  static_cast<CFitItem *>(*target)->getExperimentCount());
648 
649  // Compare and assign common experiments
650  for (j = 0; j < jmax; j++)
651  {
652  std::string & Target =
653  *const_cast<std::string *>(&static_cast<CFitItem *>(*target)->getExperiment(j));
654  const std::string &Key = static_cast<CFitItem *>(*it)->getExperiment(j);
655 
656  if (Key.empty())
657  {
658  continue;
659  }
660 
661  std::map<std::string, std::string>::const_iterator found = pExperimentMap->find(Key);
662 
663  if (found == pExperimentMap->end())
664  {
665  continue;
666  }
667 
668  if (Target != found->second)
669  {
670  changed = true;
671  Target = found->second;
672  }
673  }
674 
675  // Remove exceeding experiments starting from the last
676  for (jmax = static_cast<CFitItem *>(*target)->getExperimentCount() - 1;
677  j <= jmax && jmax != C_INVALID_INDEX; jmax--)
678  {
679  changed = true;
680  static_cast<CFitItem *>(*target)->removeExperiment(jmax);
681  }
682 
683  // Add missing experiments
684  for (jmax = static_cast<CFitItem *>(*it)->getExperimentCount(); j < jmax; j++)
685  {
686  changed = true;
687 
688  const std::string & Source =
689  pExperimentMap->find(static_cast<CFitItem *>(*it)->getExperiment(j))->second;
690 
691  static_cast<CFitItem *>(*target)->addExperiment(Source);
692  }
693 
694  if (pCrossValidationMap == NULL) return false;
695 
696  jmax =
697  std::min(static_cast<CFitItem *>(*it)->getCrossValidationCount(),
698  static_cast<CFitItem *>(*target)->getCrossValidationCount());
699 
700  // Compare and assign common cross validations
701  for (j = 0; j < jmax; j++)
702  {
703  std::string & Target =
704  *const_cast<std::string *>(&static_cast<CFitItem *>(*target)->getCrossValidation(j));
705  const std::string &Key = static_cast<CFitItem *>(*it)->getCrossValidation(j);
706 
707  if (Key.empty())
708  {
709  continue;
710  }
711 
712  std::map<std::string, std::string>::const_iterator found = pCrossValidationMap->find(Key);
713 
714  if (found == pCrossValidationMap->end())
715  {
716  continue;
717  }
718 
719  if (Target != found->second)
720  {
721  changed = true;
722  Target = found->second;
723  }
724  }
725 
726  // Remove exceeding cross validations starting from the last
727  for (jmax = static_cast<CFitItem *>(*target)->getCrossValidationCount() - 1;
728  j <= jmax && jmax != C_INVALID_INDEX; jmax--)
729  {
730  changed = true;
731  static_cast<CFitItem *>(*target)->removeCrossValidation(jmax);
732  }
733 
734  // Add missing cross validations
735  for (jmax = static_cast<CFitItem *>(*it)->getCrossValidationCount(); j < jmax; j++)
736  {
737  changed = true;
738 
739  const std::string & Source =
740  pCrossValidationMap->find(static_cast<CFitItem *>(*it)->getCrossValidation(j))->second;
741 
742  static_cast<CFitItem *>(*target)->addCrossValidation(Source);
743  }
744  }
745  }
746 
747  // Remove exceeding items starting from the last.
748  for (imax--; i <= imax && imax != C_INVALID_INDEX; imax--)
749  {
750  changed = true;
751  mpItems->removeParameter(imax);
752  }
753 
754  // Add missing items
755  for (; it != end; ++it)
756  {
757  changed = true;
758 
759  COptItem * pItem = NULL;
760 
761  switch (mItemType)
762  {
763  case OPT_ITEM:
764  case OPT_CONSTRAINT:
765  pItem = new COptItem(**it);
766  break;
767 
768  case FIT_ITEM:
769  pItem = new CFitItem(**it);
770  break;
771 
772  case FIT_CONSTRAINT:
773  pItem = new CFitConstraint(**it);
774  break;
775  }
776 
778  {
779  if (pExperimentMap == NULL) return false;
780 
781  size_t j, jmax =
782  static_cast<CFitItem *>(pItem)->getExperimentCount();
783 
784  // Remap the experiment keys
785  for (j = 0; j < jmax; j++)
786  {
787  std::string & Target =
788  *const_cast<std::string *>(&static_cast<CFitItem *>(pItem)->getExperiment(j));
789  const std::string & Source =
790  pExperimentMap->find(static_cast<CFitItem *>(*it)->getExperiment(j))->second;
791 
792  Target = Source;
793  }
794  }
795 
796  mpItems->addParameter(pItem);
797  }
798 
799  return changed;
800 }
801 
803 {
804  mItemType = type;
805 
807  {
808  mpLblExperiments->show();
809  mpCheckAll->show();
810  mpBoxExperiments->show();
811  mpBtnExperiments->show();
812  mpBtnPerExperiment->show();
813 
814  mpLblCrossValidations->show();
815  mpCheckCrossValidationsAll->show();
816  mpBoxCrossValidations->show();
817  mpBtnCrossValidations->show();
818  }
819  else
820  {
821  mpLblExperiments->hide();
822  mpCheckAll->hide();
823  mpBoxExperiments->hide();
824  mpBtnExperiments->hide();
825  mpBtnPerExperiment->hide();
826 
827  mpLblCrossValidations->hide();
828  mpCheckCrossValidationsAll->hide();
829  mpBoxCrossValidations->hide();
830  mpBtnCrossValidations->hide();
831  }
832 
834  {
835  mpLblStart->hide();
836  mpEditStart->hide();
837  mpBtnReset->hide();
838  }
839  else
840  {
841  mpLblStart->show();
842  mpEditStart->show();
843  mpBtnReset->show();
844  }
845 
846  qApp->processEvents();
847 }
848 
850 {
851  // This slot is triggered when an experiment is deleted or changed,
852  // but before new experiments are created.
853 
854  if (mItemType == OPT_ITEM || mItemType == OPT_CONSTRAINT) return;
855 
856  // Remove all references to deleted experiments.
857  std::vector< COptItem * >::iterator it = mpItemsCopy->begin();
858  std::vector< COptItem * >::iterator end = mpItemsCopy->end();
859 
860  size_t i, imax;
861  size_t Row;
862 
863  for (Row = 0; it != end; ++it, ++Row)
864  {
865  for (i = 0, imax = static_cast<CFitItem *>(*it)->getExperimentCount(); i < imax; ++i)
866  if (!CCopasiRootContainer::getKeyFactory()->get(static_cast<CFitItem *>(*it)->getExperiment(i)))
867  static_cast<CFitItem *>(*it)->removeExperiment(i);
868 
869  setTableText((int) Row, *it);
870  }
871 
872  // Reload the current item.
873  loadSelection();
874 
875  return;
876 }
877 
879 {mppExperimentSet = &pExperimentSet;}
880 
882 {
883  size_t row = mCurrentRow;
884 
885  COptItem * pItem;
886 
887  std::set< size_t >::const_iterator it = mSelection.begin();
888  std::set< size_t >::const_iterator end = mSelection.end();
889 
890  // We must not trigger slotSelectionChanged!
891  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
892 
893  size_t Deleted = 0;
894 
895  for (; it != end; ++it, ++Deleted)
896  {
897  row = *it - Deleted;
898 
899  pItem = (*mpItemsCopy)[row];
900 
901  // Erase the item from the vector.
902  mpItemsCopy->erase(mpItemsCopy->begin() + row);
903  // Update the table
904  mpTable->removeRow((int) row);
905  pdelete(pItem);
906  }
907 
908  mpTable->clearSelection();
909  mSelection.clear();
910 
911  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
912 
913  // Change the selection
914  if (row >= mpItemsCopy->size())
915  row = mpItemsCopy->size() - 1;
916 
917  selectRow(row);
918 
919  emit numberChanged((int) mpItemsCopy->size());
920 }
921 
923 {
924  if (!mSelection.size())
925  {
926  // We have nothing to copy, therefore we create a new item.
927  slotNew();
928  return;
929  }
930 
931  // Save the changes to the current items
932  saveSelection();
933 
934  // Create the new item.
935  COptItem * pItem;
936  COptItem * pSrc = (*mpItemsCopy)[*mSelection.begin()];
937 
938  switch (mItemType)
939  {
940  case OPT_ITEM:
941  case OPT_CONSTRAINT:
942  pItem = new COptItem(*pSrc);
943  break;
944 
945  case FIT_ITEM:
946  pItem = new CFitItem(*pSrc);
947  break;
948 
949  case FIT_CONSTRAINT:
950  pItem = new CFitConstraint(*pSrc);
951  break;
952  }
953 
954  size_t row = mCurrentRow + 1;
955  mpItemsCopy->insert(mpItemsCopy->begin() + row, pItem);
956 
957  // Update the table
958  // We must not trigger slotSelectionChanged!
959  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
960 // mpTable->insertRows(row);
961  mpTable->insertRow((int) row);
962  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
963 
964  setTableText((int) row, pItem);
965 
966  // Update the selection
967  selectRow(row);
968 
969  emit numberChanged((int) mpItemsCopy->size());
970 }
971 
973 {
974  if (!mSelection.size()) return; // Nothing to move.
975 
976  saveSelection();
977 
978  std::set< size_t > NewSelection;
979  std::set< size_t >::const_iterator it = mSelection.begin();
980  std::set< size_t >::const_iterator end = mSelection.end();
981  COptItem * pItem;
982 
983  if (*it == 0) ++it; // The first row can not be moved up.
984 
985  for (; it != end; ++it)
986  {
987  NewSelection.insert(*it - 1);
988 
989  // Swap the items
990  pItem = (*mpItemsCopy)[*it];
991  (*mpItemsCopy)[*it] = (*mpItemsCopy)[*it - 1];
992  (*mpItemsCopy)[*it - 1] = pItem;
993 
994  // Swap the table rows
995  QTableWidgetItem *item1 = mpTable->takeItem((int)(*it - 1), 0);
996  QTableWidgetItem *item2 = mpTable->takeItem((int) * it, 0);
997  mpTable->setItem((int) *it, 0, item1);
998  mpTable->setItem((int)(*it - 1), 0, item2);
999  }
1000 
1001  setItemSelection(NewSelection);
1002  loadSelection();
1003 }
1004 
1006 {
1007  if (!mSelection.size()) return; // Nothing to move.
1008 
1009  saveSelection();
1010 
1011  std::set< size_t > NewSelection;
1012  std::set< size_t >::reverse_iterator it = mSelection.rbegin();
1013  std::set< size_t >::reverse_iterator end = mSelection.rend();
1014  COptItem * pItem;
1015 
1016  if ((int) *it == (mpTable->rowCount() - 1))
1017  ++it; // The last row can not be moved down.
1018 
1019  for (; it != end; ++it)
1020  {
1021  NewSelection.insert(*it + 1);
1022 
1023  // Swap the items
1024  pItem = (*mpItemsCopy)[*it];
1025  (*mpItemsCopy)[*it] = (*mpItemsCopy)[*it + 1];
1026  (*mpItemsCopy)[*it + 1] = pItem;
1027 
1028  // Swap the table rows
1029  QTableWidgetItem *item1 = mpTable->takeItem((int)(*it + 1), 0);
1030  QTableWidgetItem *item2 = mpTable->takeItem((int) * it, 0);
1031  mpTable->setItem((int) *it, 0, item1);
1032  mpTable->setItem((int)(*it + 1), 0, item2);
1033  }
1034 
1035  setItemSelection(NewSelection);
1036  loadSelection();
1037 }
1038 
1040 {
1041  if (mItemType == OPT_ITEM || mItemType == OPT_CONSTRAINT) return;
1042 
1043  // Save the changes to the current items
1044  saveSelection();
1045 
1046  if (!mSelection.size())
1047  slotNew();
1048 
1049  size_t row = mCurrentRow + 1;
1050  size_t i, imax =
1051  static_cast<CFitItem *>((*mpItemsCopy)[*mSelection.begin()])->getExperimentCount();
1052 
1053  CFitItem * pItem = NULL, * pTemplate = NULL;
1054 
1055  // We must not trigger slotSelectionChanged!
1056  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1057 
1058  if (imax)
1059  {
1060  // We have a list of experiments
1061  switch (mItemType)
1062  {
1063  case FIT_ITEM:
1064  pTemplate = new CFitItem(*(*mpItemsCopy)[*mSelection.begin()]);
1065  break;
1066 
1067  case FIT_CONSTRAINT:
1068  pTemplate = new CFitConstraint(*(*mpItemsCopy)[*mSelection.begin()]);
1069  break;
1070 
1071  default:
1072  break;
1073  }
1074 
1075  // Remove all experiments from the template
1076  for (i = imax - 1; i != C_INVALID_INDEX; i--)
1077  pTemplate->removeExperiment(i);
1078 
1079  // Create imax - 1 copies
1080  for (i = imax - 1; i != 0; i--)
1081  {
1082  switch (mItemType)
1083  {
1084  case FIT_ITEM:
1085  pItem = new CFitItem(*pTemplate);
1086  break;
1087 
1088  case FIT_CONSTRAINT:
1089  pItem = new CFitConstraint(*pTemplate);
1090  break;
1091 
1092  default:
1093  break;
1094  }
1095 
1096  pItem->addExperiment(static_cast<CFitItem *>((*mpItemsCopy)[*mSelection.begin()])->getExperiment(i));
1097 
1098  static_cast<CFitItem *>((*mpItemsCopy)[*mSelection.begin()])->removeExperiment(i);
1099 
1100  mpItemsCopy->insert(mpItemsCopy->begin() + row, pItem);
1101 
1102  // Update the table
1103  mpTable->insertRow((int) row);
1104  setTableText((int) row, pItem);
1105  }
1106  }
1107  else
1108  {
1109  // We have ALL
1110  imax = (*mppExperimentSet)->getExperimentCount();
1111 
1112  if (imax > 0)
1113  {
1114  // Create imax - 1 copies
1115  for (i = imax - 1; i != 0; i--)
1116  {
1117  pItem = new CFitItem(*(*mpItemsCopy)[*mSelection.begin()]);
1118  pItem->addExperiment((*mppExperimentSet)->getExperiment(i)->CCopasiParameter::getKey());
1119 
1120  mpItemsCopy->insert(mpItemsCopy->begin() + row, pItem);
1121 
1122  // Update the table
1123  mpTable->insertRow((int) row);
1124  setTableText((int) row, pItem);
1125  }
1126  }
1127 
1128  // Update the current item only when we have more than one experiment.
1129  if (imax > 1)
1130  static_cast<CFitItem *>((*mpItemsCopy)[*mSelection.begin()])->addExperiment((*mppExperimentSet)->getExperiment(0)->CCopasiParameter::getKey());
1131  }
1132 
1133  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1134 
1135  // Update the current item
1136  setTableText((int)(row - 1), (*mpItemsCopy)[*mSelection.begin()]);
1137 
1138  // Update the selection
1139  selectRow(row - 1);
1140 
1141  emit numberChanged((int) mpItemsCopy->size());
1142 }
1143 
1145 {
1146  // Save the changes to the current items
1147  saveSelection();
1148 
1149  // Create the new item.
1150  COptItem * pItem;
1151 
1152  switch (mItemType)
1153  {
1154  case OPT_ITEM:
1155  case OPT_CONSTRAINT:
1156  pItem = new COptItem(mpDataModel);
1157  break;
1158 
1159  case FIT_ITEM:
1160  pItem = new CFitItem(mpDataModel);
1161  break;
1162 
1163  case FIT_CONSTRAINT:
1164  pItem = new CFitConstraint(mpDataModel);
1165  break;
1166  }
1167 
1168  mpItemsCopy->push_back(pItem);
1169 
1170  size_t row = mpTable->rowCount();
1171 
1172  // Update the table
1173  // We must not trigger slotSelectionChanged!
1174  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1175  // mpTable->insertRows(row);
1176  mpTable->insertRow((int) row);
1177  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1178 
1179  setTableText((int) row, pItem);
1180 
1181  // Update the selection
1182  selectRow(row);
1183 
1184  emit numberChanged((int) mpItemsCopy->size());
1185 }
1186 
1187 void CQFittingItemWidget::setTableText(const int & row, const COptItem * pItem)
1188 {
1189  QString Item = " ";
1190  const CCopasiObject *pObject;
1191 
1192  if (pItem->getLowerBound() == "-inf" ||
1193  isNumber(pItem->getLowerBound()))
1194  Item += FROM_UTF8(pItem->getLowerBound());
1195  else if ((pObject = mpDataModel->getDataObject(pItem->getLowerBound())))
1196  Item += FROM_UTF8(pObject->getObjectDisplayName());
1197  else
1198  Item += "Not found: " + FROM_UTF8(pItem->getLowerBound());
1199 
1200  // Insert less than character
1201  Item += FROM_UTF8(std::string(" \xe2\x89\xa4 "));
1202 
1203  pObject = mpDataModel->getDataObject(pItem->getObjectCN());
1204 
1205  if (pObject)
1206  Item += FROM_UTF8(pObject->getObjectDisplayName());
1207  else
1208  Item += "Not found: " + FROM_UTF8(pItem->getObjectCN());
1209 
1211  {
1212  QString Experiments =
1213  FROM_UTF8(static_cast<const CFitItem *>(pItem)->getExperiments());
1214 
1215  if (Experiments != "")
1216  Item += "; {" + Experiments + "}";
1217  }
1218 
1219  // Insert less than character
1220  Item += FROM_UTF8(std::string(" \xe2\x89\xa4 "));
1221 
1222  if (pItem->getUpperBound() == "inf" ||
1223  isNumber(pItem->getUpperBound()))
1224  Item += FROM_UTF8(pItem->getUpperBound());
1225  else if ((pObject = mpDataModel->getDataObject(pItem->getUpperBound())))
1226  Item += FROM_UTF8(pObject->getObjectDisplayName());
1227  else
1228  Item += "Not found: " + FROM_UTF8(pItem->getUpperBound());
1229 
1230  if (mItemType == OPT_ITEM || mItemType == FIT_ITEM)
1231  {
1232  Item += "; Start Value = " + QString::number(pItem->getStartValue());
1233  }
1234 
1235  QTableWidgetItem *itemValue = new QTableWidgetItem(Item);
1236  itemValue->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1237  itemValue->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
1238  mpTable->setItem(row, 0, itemValue);
1239 
1240  mpTable->resizeRowToContents(row);
1241 }
1242 
1244 {
1245  if (mSelection.size() != 1)
1246  return C_INVALID_INDEX;
1247 
1248  return *mSelection.begin();
1249 }
1250 
1252 {
1253  saveSelection();
1254 
1255  size_t i, imax = mpTable->rowCount();
1256 
1257  // Update mSelection;
1258  for (i = 0; i != imax; i++)
1259 
1260  if (mpTable->item((int) i, 0)->isSelected())
1261  mSelection.insert(i);
1262  else
1263  mSelection.erase(i);
1264 
1265  mCurrentRow = currentRow();
1266 
1267  loadSelection();
1268 }
1269 
1271 {
1272  bool Enabled = (mSelection.size() <= 1);
1273 
1274  mpBtnCopy->setEnabled(Enabled);
1275  mpBtnPerExperiment->setEnabled(Enabled);
1276 
1277  std::set< size_t >::const_iterator it = mSelection.begin();
1278  std::set< size_t >::const_iterator end = mSelection.end();
1279 
1280  if (it == end)
1281  {
1282  mpEditObject->setText("");
1283 
1284  mpEditLower->setText(QString::number(1e-06));
1285  mpCheckLowerInf->setChecked(false);
1286  mpLowerObject = NULL;
1287 
1288  mpEditUpper->setText(QString::number(1e+06));
1289  mpCheckUpperInf->setChecked(false);
1290  mpUpperObject = NULL;
1291 
1292  mpEditStart->setText("");
1293 
1294  mpCheckAll->setChecked(true);
1295  mpBoxExperiments->setEnabled(false);
1296 
1297  mpCheckCrossValidationsAll->setChecked(true);
1298  mpBoxCrossValidations->setEnabled(false);
1299 
1300  QString Empty("");
1301  int Pos = 0;
1302  mpObjectValidator->validate(Empty, Pos);
1303  }
1304  else
1305  {
1306  disconnect(mpCheckAll, SIGNAL(toggled(bool)), this, SLOT(slotCheckAllExperiments(bool)));
1307  disconnect(mpCheckCrossValidationsAll, SIGNAL(toggled(bool)), this, SLOT(slotCheckAllCrossValidations(bool)));
1308  QString Value;
1309 
1310  COptItem * pItem = (*mpItemsCopy)[*it];
1311 
1312  const CCopasiObject *pObject = mpDataModel->getDataObject(pItem->getObjectCN());
1313 
1314  if (pObject)
1315  {
1316  Value = FROM_UTF8(pObject->getObjectDisplayName());
1317  mpEditObject->setText(Value);
1319  }
1320  else
1321  {
1322  if (pItem->getObjectCN() != "")
1323  Value = "Not found: " + FROM_UTF8(pItem->getObjectCN());
1324  else
1325  Value = "";
1326 
1327  mpEditObject->setText(Value);
1328 
1329  int Pos = 0;
1330  mpObjectValidator->validate(Value, Pos);
1331  }
1332 
1333  mpLowerObject = NULL;
1334 
1335  if (pItem->getLowerBound() == "-inf" ||
1336  isNumber(pItem->getLowerBound()))
1337  Value = FROM_UTF8(pItem->getLowerBound());
1338  else if ((mpLowerObject = mpDataModel->getDataObject(pItem->getLowerBound())))
1340  else
1341  Value = "Not found: " + FROM_UTF8(pItem->getLowerBound());
1342 
1343  mpEditLower->setText(Value);
1344  mpCheckLowerInf->setChecked(Value == "-inf");
1345 
1346  mpUpperObject = NULL;
1347 
1348  if (pItem->getUpperBound() == "inf" ||
1349  isNumber(pItem->getUpperBound()))
1350  Value = FROM_UTF8(pItem->getUpperBound());
1351  else if ((mpUpperObject = mpDataModel->getDataObject(pItem->getUpperBound())))
1353  else
1354  Value = "Not found: " + FROM_UTF8(pItem->getUpperBound());
1355 
1356  mpEditUpper->setText(Value);
1357  mpCheckUpperInf->setChecked(Value == "inf");
1358 
1359  mpEditStart->setText(QString::number(pItem->getStartValue()));
1360 
1361  std::string Experiments;
1362  std::string CrossValidations;
1363 
1365  {
1366  Experiments = static_cast<CFitItem *>(pItem)->getExperiments();
1367 
1368  mpBoxExperiments->clear();
1369 
1370  size_t i, imax = static_cast<CFitItem *>(pItem)->getExperimentCount();
1371 
1372  for (i = 0; i < imax; i++)
1373  {
1374  const CCopasiObject * pObject =
1375  CCopasiRootContainer::getKeyFactory()->get(static_cast<CFitItem *>(pItem)->getExperiment(i));
1376 
1377  if (pObject)
1378  mpBoxExperiments->insertItem(mpBoxExperiments->count(), FROM_UTF8(pObject->getObjectName()));
1379  }
1380 
1381  mpCheckAll->setChecked(imax == 0);
1382  mpBoxExperiments->setEnabled(imax != 0);
1383 
1384  CrossValidations = static_cast<CFitItem *>(pItem)->getCrossValidations();
1385 
1386  mpBoxCrossValidations->clear();
1387 
1388  imax = static_cast<CFitItem *>(pItem)->getCrossValidationCount();
1389 
1390  for (i = 0; i < imax; i++)
1391  {
1392  const CCopasiObject * pObject =
1393  CCopasiRootContainer::getKeyFactory()->get(static_cast<CFitItem *>(pItem)->getCrossValidation(i));
1394 
1395  if (pObject)
1396  mpBoxCrossValidations->insertItem(0, FROM_UTF8(pObject->getObjectName()));
1397  }
1398 
1399  mpCheckCrossValidationsAll->setChecked(imax == 0);
1400  mpBoxCrossValidations->setEnabled(imax != 0);
1401  }
1402 
1403  for (++it; it != end; ++it)
1404  {
1405  pItem = (*mpItemsCopy)[*it];
1406 
1407  const CCopasiObject *pObject = mpDataModel->getDataObject(pItem->getObjectCN());
1408 
1409  if (pObject)
1410  Value = FROM_UTF8(pObject->getObjectDisplayName());
1411  else
1412  {
1413  if (pItem->getObjectCN() != "")
1414  Value = "Not found: " + FROM_UTF8(pItem->getObjectCN());
1415  else
1416  Value = "";
1417  }
1418 
1419  if (Value != mpEditObject->text())
1420  {
1421  mpEditObject->setText("");
1423  }
1424 
1425  if (pItem->getLowerBound() == "-inf" ||
1426  isNumber(pItem->getLowerBound()))
1427  Value = FROM_UTF8(pItem->getLowerBound());
1428  else if ((pObject = mpDataModel->getDataObject(pItem->getLowerBound())))
1429  Value = FROM_UTF8(pObject->getObjectDisplayName());
1430  else
1431  Value = "Not found: " + FROM_UTF8(pItem->getLowerBound());
1432 
1433  if (Value != mpEditLower->text())
1434  {
1435  mpEditLower->setText("");
1436  mpCheckLowerInf->setChecked(false);
1437  }
1438 
1439  if (pItem->getUpperBound() == "inf" ||
1440  isNumber(pItem->getUpperBound()))
1441  Value = FROM_UTF8(pItem->getUpperBound());
1442  else if ((pObject = mpDataModel->getDataObject(pItem->getUpperBound())))
1443  Value = FROM_UTF8(pObject->getObjectDisplayName());
1444  else
1445  Value = "Not found: " + FROM_UTF8(pItem->getUpperBound());
1446 
1447  if (Value != mpEditUpper->text())
1448  {
1449  mpEditUpper->setText("");
1450  mpCheckUpperInf->setChecked(false);
1451  }
1452 
1453  if (QString::number(pItem->getStartValue()) != mpEditStart->text())
1454  mpEditStart->setText("");
1455 
1456  if ((mItemType == FIT_ITEM || mItemType == FIT_CONSTRAINT) &&
1457  Experiments != static_cast<CFitItem *>(pItem)->getExperiments())
1458  {
1459  mpCheckAll->setChecked(false);
1460  mpBoxExperiments->setEnabled(false);
1461  }
1462 
1463  if ((mItemType == FIT_ITEM || mItemType == FIT_CONSTRAINT) &&
1464  CrossValidations != static_cast<CFitItem *>(pItem)->getCrossValidations())
1465  {
1466  mpCheckCrossValidationsAll->setChecked(false);
1467  mpBoxCrossValidations->setEnabled(false);
1468  }
1469  }
1470 
1471  connect(mpCheckAll, SIGNAL(toggled(bool)), this, SLOT(slotCheckAllExperiments(bool)));
1472  connect(mpCheckCrossValidationsAll, SIGNAL(toggled(bool)), this, SLOT(slotCheckAllCrossValidations(bool)));
1473  }
1474 
1477 
1478  mpCheckLowerInf->setStyleSheet(QString(mpCheckLowerInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
1479  mLowerInfChanged = false;
1480 
1481  mpCheckUpperInf->setStyleSheet(QString(mpCheckUpperInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
1482  mUpperInfChanged = false;
1483 }
1484 
1486 {
1487  std::set< size_t >::const_iterator it = mSelection.begin();
1488  std::set< size_t >::const_iterator end = mSelection.end();
1489 
1490  COptItem * pItem;
1491 
1492  for (; it != end; ++it)
1493  {
1494  pItem = (*mpItemsCopy)[*it];
1495 
1496  if (mpCheckLowerInf->isChecked())
1497  pItem->setLowerBound(CCopasiObjectName("-inf"));
1498  else if (isNumber(TO_UTF8(mpEditLower->text())))
1499  pItem->setLowerBound(CCopasiObjectName(TO_UTF8(mpEditLower->text())));
1500 
1501  if (mpCheckUpperInf->isChecked())
1502  pItem->setUpperBound(CCopasiObjectName("inf"));
1503  else if (isNumber(TO_UTF8(mpEditUpper->text())))
1504  pItem->setUpperBound(CCopasiObjectName(TO_UTF8(mpEditUpper->text())));
1505 
1506  if (isNumber(TO_UTF8(mpEditStart->text())))
1507  pItem->setStartValue(mpEditStart->text().toDouble());
1508 
1509  mpCheckLowerInf->setStyleSheet(QString(mpCheckLowerInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
1510  mLowerInfChanged = false;
1511 
1512  mpCheckUpperInf->setStyleSheet(QString(mpCheckUpperInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}");
1513  mUpperInfChanged = false;
1517 
1518  setTableText((int) *it, pItem);
1519  }
1520 }
1521 
1522 void CQFittingItemWidget::selectRow(const size_t & row)
1523 {
1524  if (row == C_INVALID_INDEX)
1525  {
1526  mSelection.clear();
1527  return loadSelection();
1528  }
1529 
1530  // This sets the focus and creates a selection
1531  mpTable->setCurrentCell((int) row, 0);
1532 
1533  // We must not trigger slotSelectionChanged!
1534  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1535  mpTable->clearSelection();
1536  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1537 
1538  mpTable->selectRow((int) row);
1539 }
1540 
1541 void CQFittingItemWidget::setItemSelection(const std::set< size_t > & selection)
1542 {
1543  mSelection = selection;
1544 
1545  std::set< size_t >::const_iterator it = selection.begin();
1546  std::set< size_t >::const_iterator end = selection.end();
1547 
1548  // We must not trigger slotSelectionChanged!
1549  disconnect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1550 
1551  // This sets the focus and creates a selection
1552  if (it != end)
1553  mpTable->setCurrentCell((int) *it, 0);
1554  else
1555  mpTable->setCurrentCell(-1, 0);
1556 
1557  // Update selection
1558  for (; it != end; ++it)
1559  mpTable->item((int) *it, 0)->setSelected(true);
1560 
1561  connect(mpTable, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
1562 }
1563 
1565 {
1566  std::string Number = TO_UTF8(mpEditLower->text());
1567 
1568  if (!isNumber(Number) &&
1569  !(Number[0] == '-' &&
1570  Number[Number.length() - 1] == '%' &&
1571  isNumber(Number.substr(1, Number.length() - 2)))) return;
1572 
1573  mpLowerObject = NULL;
1574 
1575  bool first = true;
1576  std::string NewValue = "";
1577 
1578  std::set< size_t >::const_iterator it = mSelection.begin();
1579  std::set< size_t >::const_iterator end = mSelection.end();
1580 
1581  for (; it != end; ++it)
1582  {
1583  (*mpItemsCopy)[*it]->setLowerBound(Number);
1584 
1585  if (first)
1586  {
1587  NewValue = (*mpItemsCopy)[*it]->getLowerBound();
1588  first = false;
1589  }
1590  else if (NewValue != (*mpItemsCopy)[*it]->getLowerBound())
1591  NewValue = "";
1592 
1593  setTableText((int) *it, (*mpItemsCopy)[*it]);
1594  }
1595 
1596  mpEditLower->setText(FROM_UTF8(NewValue));
1597 }
1598 
1600 {
1601  std::string Number = TO_UTF8(mpEditUpper->text());
1602 
1603  if (!isNumber(Number) &&
1604  !(Number[0] == '+' &&
1605  Number[Number.length() - 1] == '%' &&
1606  isNumber(Number.substr(1, Number.length() - 2)))) return;
1607 
1608  mpUpperObject = NULL;
1609 
1610  std::set< size_t >::const_iterator it = mSelection.begin();
1611  std::set< size_t >::const_iterator end = mSelection.end();
1612 
1613  bool first = true;
1614  std::string NewValue = "";
1615 
1616  for (; it != end; ++it)
1617  {
1618  (*mpItemsCopy)[*it]->setUpperBound(Number);
1619 
1620  if (first)
1621  {
1622  NewValue = (*mpItemsCopy)[*it]->getUpperBound();
1623  first = false;
1624  }
1625  else if (NewValue != (*mpItemsCopy)[*it]->getUpperBound())
1626  NewValue = "";
1627 
1628  setTableText((int) *it, (*mpItemsCopy)[*it]);
1629  }
1630 
1631  mpEditUpper->setText(FROM_UTF8(NewValue));
1632 }
1633 
1635 {
1636  CQStartValueReset * pDialog = new CQStartValueReset(this);
1637  pDialog->exec();
1638 
1639  std::set< size_t >::const_iterator it = mSelection.begin();
1640  std::set< size_t >::const_iterator end = mSelection.end();
1641 
1642  switch (pDialog->result())
1643  {
1644  case QDialog::Rejected:
1645  break;
1646 
1648 
1649  for (; it != end; ++it)
1650  {
1651  (*mpItemsCopy)[*it]->setStartValue(std::numeric_limits<C_FLOAT64>::quiet_NaN());
1652  mpEditStart->setText(QString::number((*mpItemsCopy)[*it]->getStartValue()));
1653  setTableText((int) *it, (*mpItemsCopy)[*it]);
1654  }
1655 
1656  break;
1657 
1659 
1660  for (; it != end; ++it)
1661  {
1662  (*mpItemsCopy)[*it]->setStartValue((*mpItemsCopy)[*it]->getRandomValue());
1663  mpEditStart->setText(QString::number((*mpItemsCopy)[*it]->getStartValue()));
1664  setTableText((int) *it, (*mpItemsCopy)[*it]);
1665  }
1666 
1667  break;
1668 
1670  {
1671  COptProblem * pProblem = dynamic_cast< COptProblem * >(mpItems->getObjectParent());
1672  const CVector< C_FLOAT64 > & Solution = pProblem->getSolutionVariables();
1673 
1674  if (Solution.size() == mpItems->size())
1675  for (; it != end; ++it)
1676  {
1677  (*mpItemsCopy)[*it]->setStartValue(Solution[*it]);
1678  mpEditStart->setText(QString::number((*mpItemsCopy)[*it]->getStartValue()));
1679  setTableText((int) *it, (*mpItemsCopy)[*it]);
1680  }
1681  }
1682  break;
1683  }
1684 
1685  pdelete(pDialog);
1686 
1687  loadSelection();
1688 }
1689 
1691 {
1692  if (!isNumber(TO_UTF8(mpEditStart->text()))) return;
1693 
1694  C_FLOAT64 Number = mpEditStart->text().toDouble();
1695 
1696  std::set< size_t >::const_iterator it = mSelection.begin();
1697  std::set< size_t >::const_iterator end = mSelection.end();
1698 
1699  for (; it != end; ++it)
1700  {
1701  (*mpItemsCopy)[*it]->setStartValue(Number);
1702  setTableText((int) *it, (*mpItemsCopy)[*it]);
1703  }
1704 }
1705 
1707 {
1709  {
1710  CQExperimentSelection * pDialog = new CQExperimentSelection(this);
1711  pDialog->load(mpBoxCrossValidations, * mppCrossValidationSet);
1712 
1713  if (pDialog->exec() == QDialog::Accepted)
1714  {
1715  if (!mSelection.size())
1716  slotNew();
1717 
1718  std::set< size_t >::const_iterator it = mSelection.begin();
1719  std::set< size_t >::const_iterator end = mSelection.end();
1720 
1721  for (; it != end; ++it)
1722  {
1723  (*mpItemsCopy)[*it]->getGroup("Affected Cross Validation Experiments")->clear();
1724  size_t i, imax = mpBoxCrossValidations->count();
1725 
1726  for (i = 0; i < imax && imax < (*mppCrossValidationSet)->getExperimentCount(); i++)
1727  static_cast<CFitItem *>((*mpItemsCopy)[*it])->addCrossValidation((*mppCrossValidationSet)->getExperiment(TO_UTF8(mpBoxCrossValidations->itemText(i)))->CCopasiParameter::getKey());
1728 
1729  setTableText(*it, (*mpItemsCopy)[*it]);
1730  }
1731  }
1732 
1733  loadSelection();
1734 
1735  delete pDialog;
1736  }
1737 }
1738 
1740 {
1741  // This slot is triggered when an experiment is deleted or changed,
1742  // but before new experiments are created.
1743 
1744  if (mItemType == OPT_ITEM || mItemType == OPT_CONSTRAINT) return;
1745 
1746  // Remove all references to deleted experiments.
1747  std::vector< COptItem * >::iterator it = mpItemsCopy->begin();
1748  std::vector< COptItem * >::iterator end = mpItemsCopy->end();
1749 
1750  size_t i, imax;
1751  size_t Row;
1752 
1753  for (Row = 0; it != end; ++it, ++Row)
1754  {
1755  for (i = 0, imax = static_cast<CFitItem *>(*it)->getCrossValidationCount(); i < imax; ++i)
1756  if (!CCopasiRootContainer::getKeyFactory()->get(static_cast<CFitItem *>(*it)->getCrossValidation(i)))
1757  static_cast<CFitItem *>(*it)->removeCrossValidation(i);
1758 
1759  setTableText(Row, *it);
1760  }
1761 
1762  // Reload the current item.
1763  loadSelection();
1764 
1765  // Enable/disable the interface to affected cross validations.
1767 
1768  return;
1769 }
1770 
1772 {
1773  mppCrossValidationSet = &pCrossValidationSet;
1774 
1775  bool Enabled = (*mppCrossValidationSet)->getExperimentCount() != 0;
1776 
1777  mpBtnCrossValidations->setEnabled(Enabled);
1778  mpCheckCrossValidationsAll->setEnabled(Enabled);
1779  mpBoxCrossValidations->setEnabled(Enabled && !mpCheckCrossValidationsAll->isChecked());
1780  mpLblCrossValidations->setEnabled(Enabled);
1781 }
1782 
1784 {
1785  if (mItemType == OPT_ITEM || mItemType == OPT_CONSTRAINT) return;
1786 
1787  if (!checked && mpBoxCrossValidations->count() == 0)
1789  else if (checked)
1790  {
1791  std::set< size_t >::const_iterator it = mSelection.begin();
1792  std::set< size_t >::const_iterator end = mSelection.end();
1793 
1794  for (; it != end; ++it)
1795  {
1796  (*mpItemsCopy)[*it]->getGroup("Affected Cross Validation Experiments")->clear();
1797  setTableText((int) *it, (*mpItemsCopy)[*it]);
1798  }
1799  }
1800 
1801  loadSelection();
1802 }
1803 
1805 {
1806  if (mItemType == OPT_ITEM || mItemType == OPT_CONSTRAINT) return;
1807 
1808  if (!checked && mpBoxExperiments->count() == 0)
1809  slotExperiments();
1810  else if (checked)
1811  {
1812  std::set< size_t >::const_iterator it = mSelection.begin();
1813  std::set< size_t >::const_iterator end = mSelection.end();
1814 
1815  for (; it != end; ++it)
1816  {
1817  (*mpItemsCopy)[*it]->getGroup("Affected Experiments")->clear();
1818  setTableText((int) *it, (*mpItemsCopy)[*it]);
1819  }
1820  }
1821 
1822  loadSelection();
1823 }
const std::string & getExperiment(const size_t &index) const
Definition: CFitItem.cpp:194
void setItemType(const ItemType &type)
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
void numberChanged(int)
#define pdelete(p)
Definition: copasi.h:215
bool isNumber(const std::string &str)
Definition: utility.cpp:75
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const CCopasiObjectName getObjectCN() const
Definition: COptItem.cpp:131
std::set< size_t > mSelection
void setExperimentSet(const CExperimentSet *&pExperimentSet)
virtual CCopasiObjectName getCN() const
const std::string & getObjectName() const
bool setLowerBound(const CCopasiObjectName &lowerBound)
Definition: COptItem.cpp:142
std::vector< COptItem * > * mpItemsCopy
CCopasiObject * get(const std::string &key)
const std::string getUpperBound() const
Definition: COptItem.cpp:189
virtual bool save(const std::map< std::string, std::string > *pExperimentMap, const std::map< std::string, std::string > *pCrossValidationMap)
static std::vector< const CCopasiObject * > getObjectVector(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const std::vector< const CCopasiObject * > *pCurrentSelection=NULL)
CQValidatorBound * mpLowerValidator
void setTableText(const int &row, const COptItem *pItem)
const CCopasiObject * mpUpperObject
bool removeCrossValidation(const size_t &index)
Definition: CFitItem.cpp:254
CQValidatorBound * mpUpperValidator
bool setObjectCN(const CCopasiObjectName &objectCN)
Definition: COptItem.cpp:111
#define C_INVALID_INDEX
Definition: copasi.h:222
void slotCheckLowerInf(bool checked)
bool addExperiment(const std::string &key)
Definition: CFitItem.cpp:184
const CCopasiObject * mpLowerObject
bool setUpperBound(const CCopasiObjectName &upperBound)
Definition: COptItem.cpp:167
void slotCheckUpperInf(bool checked)
void setItemSelection(const std::set< size_t > &selection)
bool removeParameter(const std::string &name)
void slotCheckAllCrossValidations(bool checked)
virtual void force(const QString &input) const
Definition: CQValidator.cpp:59
const CExperimentSet ** mppExperimentSet
virtual void saved() const
Definition: CQValidator.h:71
virtual State revalidate()
Definition: CQValidator.h:63
CQFittingItemWidget(QWidget *parent=0, Qt::WindowFlags f=0)
const CCrossValidationSet ** mppCrossValidationSet
static const QIcon & icon(const IconID &id)
const CVector< C_FLOAT64 > & getSolutionVariables() const
const CCopasiDataModel * mpDataModel
bool setStartValue(const C_FLOAT64 &value)
Definition: COptItem.cpp:192
void selectRow(const size_t &row)
virtual void load(QComboBox *pBox, const CExperimentSet *pExperimentSet)
virtual bool load(CCopasiDataModel *pDataModel, CCopasiParameterGroup *pItems, const std::map< std::string, std::string > *pExperimentMap, const std::map< std::string, std::string > *pCrossValidationMap)
size_t size() const
Definition: CVector.h:100
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
size_t getCrossValidationCount() const
Definition: CFitItem.cpp:257
static CKeyFactory * getKeyFactory()
const std::string getLowerBound() const
Definition: COptItem.cpp:164
#define C_FLOAT64
Definition: copasi.h:92
CCopasiParameterGroup * mpItems
CQValidatorNotEmpty * mpObjectValidator
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
bool addParameter(const CCopasiParameter &parameter)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
void slotCheckAllExperiments(bool checked)
bool removeExperiment(const size_t &index)
Definition: CFitItem.cpp:204
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:25
void setCrossValidationSet(const CCrossValidationSet *&pCrossValidationSet)
#define min(a, b)
Definition: f2c.h:175
size_t getExperimentCount() const
const std::string & getCrossValidation(const size_t &index) const
Definition: CFitItem.cpp:244
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
size_t getExperimentCount() const
Definition: CFitItem.cpp:207
CCopasiContainer * getObjectParent() const
bool addCrossValidation(const std::string &key)
Definition: CFitItem.cpp:234