COPASI API  4.16.103
CScanWidgetScan.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CScanWidgetScan.cpp,v $
3 // $Revision: 1.18 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/03/21 15:41:54 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "copasi.h"
20 
21 #include "CScanWidgetScan.h"
22 
23 #include <QtGui/QValidator>
24 
25 #include "UI/qtUtilities.h"
28 
31 
32 
33 /*
34  * Constructs a CScanWidgetScan as a child of 'parent', with the
35  * name 'name' and widget flags set to 'f'.
36  */
38  QWidget(parent),
39  CScanItemData(CScanProblem::SCAN_LINEAR)
40 {
41  setupUi(this);
42 
43  buttonObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
44 
45  init();
46 }
47 
48 CScanWidgetScan::CScanWidgetScan(const CScanWidgetScan & src, QWidget * parent) :
49  QWidget(parent),
50  CScanItemData(src)
51 {
52  setupUi(this);
53 
54  buttonObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
55 
56  init();
57  load(mpData);
58 }
59 
60 /*
61  * Destroys the object and frees any allocated resources
62  */
64 {
65  // no need to delete child widgets, Qt does it all for us
66 }
67 
69 {
70  lineEditObject->setReadOnly(true);
71 
72  lineEditNumber->setValidator(new QIntValidator(lineEditNumber));
73  lineEditMin->setValidator(new QDoubleValidator(lineEditMin));
74  lineEditMax->setValidator(new QDoubleValidator(lineEditMax));
75 
76  mpObject = NULL;
77 }
78 
80 {
81  const CCopasiObject * pObject =
85  mpObject);
86 
87  if (mpObject != pObject) // Object selection changed.
88  initFromObject(pObject);
89 }
90 
92 {
93  mpObject = obj;
94 
95  if (obj)
96  {
97  lineEditObject->setText(FROM_UTF8(obj->getObjectDisplayName()));
98 
99  if (obj->isValueDbl())
100  {
101  C_FLOAT64 value = *(C_FLOAT64*)obj->getValuePointer();
102  lineEditNumber->setText("10");
103  lineEditMin->setText(QString::number(value*0.5));
104  lineEditMax->setText(QString::number(value*2));
105  }
106  }
107  else
108  {
109  lineEditObject->setText("");
110  lineEditNumber->setText("");
111  lineEditMin->setText("");
112  lineEditMax->setText("");
113  }
114 }
115 
116 // virtual
118 {
119  if (pItem == NULL) return;
120 
121  *mpData = *pItem;
122 
123  void * tmp;
124 
125  if (!(tmp = mpData->getValue("Type").pVOID)) return;
126 
128 
129  if (type != CScanProblem::SCAN_LINEAR)
130  return;
131 
132  if (!(tmp = mpData->getValue("Number of steps").pVOID)) return;
133 
134  lineEditNumber->setText(QString::number(*(C_INT32*)tmp));
135 
136  if (!(tmp = mpData->getValue("Object").pVOID)) return;
137 
138  std::string tmpString = *(std::string*)tmp;
139 
140  if (tmpString == "")
141  mpObject = NULL;
142  else
143  {
144  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
146  assert(pDataModel != NULL);
147  mpObject = pDataModel->getDataObject(tmpString);
148  }
149 
150  if (mpObject)
151  lineEditObject->setText(FROM_UTF8(mpObject->getObjectDisplayName()));
152  else
153  lineEditObject->setText("");
154 
155  if (!(tmp = mpData->getValue("Minimum").pVOID)) return;
156 
157  lineEditMin->setText(QString::number(*(C_FLOAT64*)tmp));
158 
159  if (!(tmp = mpData->getValue("Maximum").pVOID)) return;
160 
161  lineEditMax->setText(QString::number(*(C_FLOAT64*)tmp));
162 
163  if (!(tmp = mpData->getValue("log").pVOID)) return;
164 
165  checkBoxLog->setChecked(*(bool*)tmp);
166 
167  return;
168 }
169 
170 // virtual
172 {
173  mpData->setValue("Number of steps", lineEditNumber->text().toUInt());
174  mpData->setValue("Minimum", lineEditMin->text().toDouble());
175  mpData->setValue("Maximum", lineEditMax->text().toDouble());
176  mpData->setValue("log", checkBoxLog->isChecked());
177 
178  if (mpObject != NULL)
179  {
180  mpData->setValue("Object", mpObject->getCN());
181  }
182  else
183  {
184  mpData->setValue("Object", std::string(""));
185  }
186 
187  if (pItem != NULL)
188  {
189  if (*mpData == *pItem) return false;
190 
191  *pItem = *mpData;
192  return true;
193  }
194 
195  return false;
196 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual ~CScanWidgetScan()
virtual CCopasiObjectName getCN() const
const CCopasiObject * mpObject
CScanWidgetScan(QWidget *parent=0)
#define C_INT32
Definition: copasi.h:90
static const QIcon & icon(const IconID &id)
CCopasiParameterGroup * mpData
Definition: CScanItemData.h:42
bool setValue(const std::string &name, const CType &value)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
#define C_FLOAT64
Definition: copasi.h:92
virtual void slotChooseObject()
virtual void load(const CCopasiParameterGroup *pItem)
bool isValueDbl() const
const CCopasiParameter::Value & getValue(const std::string &name) const
virtual void * getValuePointer() const
virtual bool save(CCopasiParameterGroup *pItem) const
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
void initFromObject(const CCopasiObject *obj)