COPASI API  4.16.103
SliderSettingsDialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 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) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "SliderSettingsDialog.h"
16 
17 #include <QtGui/QValidator>
18 
19 #include <cmath>
20 
21 #include "copasi.h"
22 
23 #include "UI/qtUtilities.h"
25 #include "UI/CQMessageBox.h"
27 
28 #include "utilities/CSlider.h"
30 
32  QDialog(pParent),
33  mChanged(),
34  mMinorTickSize(),
35  mMaxValue(),
36  mMinValue(),
37  mValue(),
38  mOriginalValue(),
39  mMinorMajorFactor(),
40  mNumMinorTicks(),
41  mDefinedSliders(),
42  mpSlider(NULL),
43  mCurrentTaskId(),
44  mpModel(NULL),
45  mScaling()
46 {
47  setupUi(this);
48  this->init();
49 }
50 
52 {
53 }
54 
56 {
57  return mpSlider;
58 }
59 
61 {
62  size_t i;
63  size_t iMax = mDefinedSliders.size();
64  bool found = false;
65 
66  for (i = 0; i < iMax; ++i)
67  {
68  if (mDefinedSliders[i] == slider)
69  {
70  found = true;
71  break;
72  }
73  }
74 
75  if (found)
76  {
77  mpSlider = slider;
78 
79  if (slider->getSliderObject())
80  {
81  mpObjectNameLineEdit->setText(FROM_UTF8(slider->getSliderObject()->getObjectDisplayName()));
82  }
83  else
84  {
85  mpObjectNameLineEdit->setText("Object not avalable!");
86  }
87 
90  }
91  else
92  {
93  mpSlider = NULL;
94  mpObjectNameLineEdit->setText("NULL");
95  mpObjectBrowseButton->show();
97  }
98 }
99 
100 void SliderSettingsDialog::setDefinedSliders(std::vector<CSlider *> sliderVect)
101 {
102  mDefinedSliders = sliderVect;
103 }
104 
106 {
107  if (mpSlider)
108  {
110  mpObjectValueEdit->setText(QString::number(mValue));
111 
113  mpOriginalValueEdit->setText(QString::number(mOriginalValue));
114 
116  mpMinValueEdit->setText(QString::number(mMinValue));
117 
119  mpMaxValueEdit->setText(QString::number(mMaxValue));
120 
122  mpNumMinorTicksEdit->setText(QString::number(mNumMinorTicks));
123 
125  mpMinorMajorFactorEdit->setText(QString::number(mMinorMajorFactor));
126 
128 
130  {
131  mpLogCheckBox->setChecked(true);
132  }
133  else
134  {
135  mpLogCheckBox->setChecked(false);
136  }
137  }
138 }
139 
141 {
142  // if the current slider is NULL, disable all input fields
143  if (mpSlider)
144  {
145  mpObjectNameLineEdit->setEnabled(false);
146  mpMaxValueEdit->setEnabled(true);
147  mpMinValueEdit->setEnabled(true);
148  mpMinorMajorFactorEdit->setEnabled(true);
149  mpMinorTickSizeEdit->setEnabled(true);
150  mpNumMinorTicksEdit->setEnabled(true);
151  mpObjectValueEdit->setEnabled(true);
152  mpLogCheckBox->setEnabled(true);
153  mpOriginalValueEdit->setEnabled(true);
154  }
155  else
156  {
157  mpObjectNameLineEdit->setEnabled(true);
158  mpMaxValueEdit->setEnabled(false);
159  mpMinValueEdit->setEnabled(false);
160  mpMinorMajorFactorEdit->setEnabled(false);
161  mpMinorTickSizeEdit->setEnabled(false);
162  mpNumMinorTicksEdit->setEnabled(false);
163  mpObjectValueEdit->setEnabled(false);
164  mpOriginalValueEdit->setEnabled(false);
165  mpLogCheckBox->setEnabled(false);
166  }
167 }
168 
170 {
171  // disconnect all signal receivers from
172  // the min and max value edit fields
173  // otherwise, they would generate an
174  // uneccesary focusLost signal
175  disconnect(mpMinValueEdit, 0, 0, 0);
176  disconnect(mpMaxValueEdit, 0, 0, 0);
177  // only now change underlying slider
178  updateSlider();
179  // close dialog with positive feedback
180  done(QDialog::Accepted);
181 }
182 
184 {
185  // close dialog, drop input
186  close();
187 }
188 
190 {
191  // adjust numMinorTicks
192  mMinorTickSize = mpMinorTickSizeEdit->text().toDouble();
193 
194  if (mMinorTickSize == 0.0)
195  {
196  mNumMinorTicks = 1;
197  }
198  else
199  {
200  mNumMinorTicks = (unsigned int)floor(((mMaxValue - mMinValue) / mMinorTickSize) + 0.5);
201  }
202 
203  if (mNumMinorTicks == 0)
204  {
205  mNumMinorTicks = 1;
207  mpMinorTickSizeEdit->setText(QString::number(mMinorTickSize));
208  }
209 
210  mpNumMinorTicksEdit->setText(QString::number(mNumMinorTicks));
211  mChanged = NONE;
212 }
213 
215 {
216  // adjust minorTickSize
217  mNumMinorTicks = mpNumMinorTicksEdit->text().toUInt();
218 
219  if (mNumMinorTicks == 1)
220  {
221  mNumMinorTicks = 1;
222  mpNumMinorTicksEdit->setText(QString::number(mNumMinorTicks));
223  }
224 
226  mpMinorTickSizeEdit->setText(QString::number(mMinorTickSize));
227  mChanged = NONE;
228 }
229 
231 {
232  // check if it is smaller than the current value
233  // if not, set it to the current value
234  double value = mpMinValueEdit->text().toDouble();
235 
236  if ((value > mOriginalValue) &&
237  (CQMessageBox::question(this, "Default value out of range.",
238  "The minimum value you set is larger than the default value of the slider. The new default will be set to the minimum. Do you want to procceed?",
239  QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Ok)
240  )
241  {
242  mpMinValueEdit->setText(QString::number(mMinValue));
243  }
244  else
245  {
246  mOriginalValue = value;
247  mpOriginalValueEdit->setText(QString::number(mOriginalValue));
248  mMinValue = value;
249 
250  if (mMinValue > mMaxValue)
251  {
253  mpMaxValueEdit->setText(QString::number(mMaxValue));
254  }
255 
256  if (mMinValue > mValue)
257  {
258  mValue = mMinValue;
259  mpObjectValueEdit->setText(QString::number(mValue));
260  }
261 
263  mpMinorTickSizeEdit->setText(QString::number(mMinorTickSize));
264 
265  if (mMinValue <= 0.0 && mpLogCheckBox->isChecked())
266  {
267  CQMessageBox::information(this, "Incorrect min value",
268  "For logarithmic sliders, the minimum value may not be 0.0 or negative. Please set the minimum value to some (possibly very small) positive number first.",
269  QMessageBox::Ok, QMessageBox::Ok);
270  mpLogCheckBox->setChecked(false);
272  }
273  }
274 
275  mChanged = NONE;
276 }
277 
279 {
280  // check if it is larget then the current value
281  // else set it to the current value
282  double value = mpMaxValueEdit->text().toDouble();
283 
284  if (value < mOriginalValue)
285  {
286  if (CQMessageBox::question(this, "Default value out of range.",
287  "The maximum value you set is smaller than the default value of the slider. The new default will be set to the maximum. Do you want to procceed?",
288  QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Ok)
289  {
290  mpMaxValueEdit->setText(QString::number(mMaxValue));
291  mChanged = NONE;
292  return;
293  }
294 
295  mOriginalValue = value;
296  mpOriginalValueEdit->setText(QString::number(mOriginalValue));
297  }
298 
299  mMaxValue = value;
300 
301  if (mMinValue > mMaxValue)
302  {
304  mpMinValueEdit->setText(QString::number(mMinValue));
305  }
306 
307  if (mMaxValue < mValue)
308  {
309  mValue = mMaxValue;
310  mpObjectValueEdit->setText(QString::number(mValue));
311  }
312 
314  mpMinorTickSizeEdit->setText(QString::number(mMinorTickSize));
315  mChanged = NONE;
316 }
317 
319 {
320  // check if the value is within range, else set a new range
321  // get the value and set it in the current slider
322  mValue = mpObjectValueEdit->text().toDouble();
323 
324  if (mValue > mMaxValue)
325  {
326  mMaxValue = mValue;
327  mpMaxValueEdit->setText(QString::number(mMaxValue));
328  }
329 
330  if (mValue < mMinValue)
331  {
332  mMinValue = mValue;
333  mpMinValueEdit->setText(QString::number(mMinValue));
334  }
335 
336  mChanged = NONE;
337 }
338 
340 {
341  // get the value and set it in the current slider
342  mMinorMajorFactor = mpMinorMajorFactorEdit->text().toUInt();
343  mChanged = NONE;
344 }
345 
347 {
348  mpSlider = NULL;
349  mChanged = NONE;
351  mpObjectBrowseButton->setIcon(CQIconResource::icon(CQIconResource::copasi));
352  mpExtendedOptionsButton->setText("Advanced >>");
354  this->setFixedSize(minimumSizeHint());
355  mpObjectValueEdit->setValidator(new QDoubleValidator(this));
356  mpOriginalValueEdit->setValidator(new QDoubleValidator(this));
357  mpMinValueEdit->setValidator(new QDoubleValidator(this));
358  mpMaxValueEdit->setValidator(new QDoubleValidator(this));
359  mpMinorTickSizeEdit->setValidator(new QDoubleValidator(this));
360  QIntValidator* v = new QIntValidator(this);
361  v->setBottom(0);
362  mpNumMinorTicksEdit->setValidator(v);
363  v = new QIntValidator(this);
364  v->setBottom(0);
365  mpMinorMajorFactorEdit->setValidator(v);
367 }
368 
370 {
371  const CCopasiObject * pObject =
375 
376  if (pObject)
377  {
378  if (!pObject->isValueDbl() && !pObject->isValueInt())
379  {
380  CQMessageBox::information(this, "Invalid Object",
381  "You chose an object that does not correspond to an integer or float value. Please choose an object that corresponds to an integet or float value.",
382  QMessageBox::Ok, QMessageBox::Ok);
383  mpSlider = NULL;
384  mpObjectNameLineEdit->setText("");
385  return;
386  }
387 
388  /* Determine the associated entity key */
389  CCopasiContainer * pAncestor = pObject->getObjectAncestor("Task");
390 
391  if (!pAncestor) pAncestor = pObject->getObjectAncestor("Model");
392 
393  if (!pAncestor)
394  {
395  CQMessageBox::information(this, "Invalid Object",
396  "You chose an object that cannot be used as a slider. Please choose an other object.",
397  QMessageBox::Ok, QMessageBox::Ok);
398  mpSlider = NULL;
399  mpObjectNameLineEdit->setText("");
400  return;
401  }
402 
403  // We do not have a slider therefore we create one.
404  if (mpSlider == NULL)
405  {
406  // temporarily add the slider the the first datamodel
408  mpSlider->setSliderObject(const_cast< CCopasiObject * >(pObject));
409 
410  if (pAncestor)
411  mpSlider->setAssociatedEntityKey(pAncestor->getKey());
412 
413  mpSlider->resetRange();
416 
417  mpObjectNameLineEdit->setText(FROM_UTF8(mpSlider->getSliderObject()->getObjectDisplayName()));
418  return;
419  }
420 
421  // If the object of an existing slider has not changed we have nothing to do
422  if (mpSlider->getSliderObject() == pObject)
423  return;
424 
425  // Check whether a slider with the object already exists
426  size_t i, iMax = mDefinedSliders.size();
427 
428  for (i = 0; i < iMax; ++i)
429  if (mDefinedSliders[i]->getSliderObject() == pObject)
430  break;
431 
432  // A slider with the new object exists we switch to it.
433  if (i != iMax)
435  else // We need to change the object an reinitialize the slider
436  {
437  mpSlider->setSliderObject(const_cast< CCopasiObject * >(pObject));
438 
439  if (pAncestor)
440  mpSlider->setAssociatedEntityKey(pAncestor->getKey());
441 
442  mpSlider->resetRange();
445  }
446 
447  mpObjectNameLineEdit->setText(FROM_UTF8(mpSlider->getSliderObject()->getObjectDisplayName()));
448  }
449 }
450 
452 {
453  mpModel = model;
454 }
455 
457 {
458  mpObjectBrowseButton->setHidden(disableChoosing);
459 }
460 
462 {
464 
465  if (mpSlider)
466  {
467  if (mMinValue < mpSlider->getMaxValue())
468  {
471  }
472  else
473  {
476  }
477 
483  }
484 }
485 
487 {
488  if (mpExtendedOptionsButton->text() == "Advanced >>")
489  {
490  mpExtendedOptionsButton->setText("Advanced <<");
492  this->setFixedSize(minimumSizeHint());
493  }
494  else
495  {
496  mpExtendedOptionsButton->setText("Advanced >>");
498  int heightChange = mpOptionsGridLayout->geometry().height();
499  QSize size = this->size() - QSize(0, heightChange);
500  this->setFixedSize(size);
501  }
502 }
503 
505 {
508 
509  if (on)
510  {
511  // check if the minValue is 0.0 or negative if so, issue an error message and uncheck the checkbox again
512  if (mMinValue <= 0.0)
513  {
514  CQMessageBox::information(this, "Incorrect min value",
515  "For logarithmic sliders, the minimum value may not be 0.0 or negative. Please set the minimum value to some (possibly very small) positive number first.",
516  QMessageBox::Ok, QMessageBox::Ok);
517  mpLogCheckBox->setChecked(false);
519  }
520  else
521  {
523  }
524  }
525  else
526  {
528  }
529 }
530 
532 {
534 }
535 
537 {
538  switch (mChanged)
539  {
540  case VALUE:
542  break;
543  case ORIGVAL:
545  break;
546  case MIN:
547  minValueChanged();
548  break;
549  case MAX:
550  maxValueChanged();
551  break;
552  case TICKFACTOR:
554  break;
555  case TICKSIZE:
557  break;
558  case NUMTICKS:
560  break;
561  default:
562  break;
563  }
564 }
565 
567 {
568  // check if the value is within range, else set it to
569  // set new values for the range
570  mOriginalValue = mpOriginalValueEdit->text().toDouble();
571 
573  {
575  mpMaxValueEdit->setText(QString::number(mMaxValue));
576  }
577 
579  {
581  mpMinValueEdit->setText(QString::number(mMinValue));
582  }
583 
584  mChanged = NONE;
585 }
586 
588 {
589  mChanged = MIN;
590 }
591 
593 {
594  mChanged = MAX;
595 }
596 
598 {
599  mChanged = NUMTICKS;
600 }
601 
603 {
604  mChanged = TICKSIZE;
605 }
606 
608 {
610 }
611 
613 {
614  mChanged = ORIGVAL;
615 }
616 
618 {
619  mChanged = VALUE;
620 }
621 
623 {
624  mpNumMinorTicksLabel->show();
625  mpNumMinorTicksEdit->show();
626  mpMinorTickSizeLabel->show();
627  mpMinorTickSizeEdit->show();
628 
629  mpMinorMajorFactorLabel->show();
630  mpMinorMajorFactorEdit->show();
631  mpOriginalValueLabel->show();
632  mpOriginalValueEdit->show();
633 
634  mpObjectValueLabel->show();
635  mpObjectValueEdit->show();
636 }
637 
639 {
640  mpNumMinorTicksLabel->hide();
641  mpNumMinorTicksEdit->hide();
642  mpMinorTickSizeLabel->hide();
643  mpMinorTickSizeEdit->hide();
644 
645  mpMinorMajorFactorLabel->hide();
646  mpMinorMajorFactorEdit->hide();
647  mpOriginalValueLabel->hide();
648  mpOriginalValueEdit->hide();
649 
650  mpObjectValueLabel->hide();
651  mpObjectValueEdit->hide();
652 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual void numMinorTicksChanged()
bool isValueInt() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
virtual void maxValueTextChanged()
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
bool setScaling(Scale scaling)
Definition: CSlider.cpp:374
virtual void cancelButtonPressed()
virtual void numTicksTextChanged()
bool setSliderObject(CCopasiObject *pObject)
Definition: CSlider.cpp:104
SliderSettingsDialog(QWidget *pParent=NULL)
virtual void tickFactorTextChanged()
bool setOriginalValue(const C_FLOAT64 value)
Definition: CSlider.cpp:191
virtual void setSlider(CSlider *slider)
bool setMaxValue(const C_FLOAT64 maxValue)
Definition: CSlider.cpp:323
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
bool setTickFactor(const unsigned C_INT32 tickFactor)
Definition: CSlider.cpp:360
std::vector< CSlider * > mDefinedSliders
virtual const std::string & getKey() const
virtual void minorTickSizeChanged()
virtual void setDefinedSliders(std::vector< CSlider * > sliderVect)
bool setAssociatedEntityKey(const std::string &associatedEntityKey)
Definition: CSlider.cpp:94
virtual void origValueTextChanged()
static const QIcon & icon(const IconID &id)
const C_FLOAT64 & getSliderValue() const
Definition: CSlider.cpp:290
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual void setModel(CModel *model)
const C_FLOAT64 & getOriginalValue() const
Definition: CSlider.cpp:285
virtual void originalValueChanged()
virtual void browseButtonPressed()
const C_FLOAT64 & getMaxValue() const
Definition: CSlider.cpp:348
bool setTickNumber(const unsigned C_INT32 tickNumber)
Definition: CSlider.cpp:351
virtual void logCheckBoxToggled(bool on)
virtual void minorMajorFactorChanged()
virtual void globalCheckBoxToggled()
virtual void disableObjectChoosing(bool disableChoosing)
bool setMinValue(const C_FLOAT64 minValue)
Definition: CSlider.cpp:295
bool isValueDbl() const
Definition: CModel.h:50
virtual CSlider * getSlider()
unsigned C_INT32 getTickNumber() const
Definition: CSlider.cpp:357
virtual void tickSizeTextChanged()
virtual void minValueTextChanged()
const C_FLOAT64 & getMinValue() const
Definition: CSlider.cpp:320
bool setSliderValue(const C_FLOAT64 value, const bool &writeToObject=true)
Definition: CSlider.cpp:215
virtual void extendedOptionsClicked()
void resetRange()
Definition: CSlider.cpp:159
unsigned C_INT32 getTickFactor() const
Definition: CSlider.cpp:366
Scale getScaling() const
Definition: CSlider.cpp:369
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CCopasiObject * getSliderObject()
Definition: CSlider.cpp:176