COPASI API  4.16.103
CQModelWidget.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 /*
7  * CQModelWidget.cpp
8  *
9  * Created on: Aug 13, 2010
10  * Author: shoops
11  */
12 
13 #include "CQModelWidget.h"
14 #include "qtUtilities.h"
15 
16 #include "model/CModel.h"
18 
19 CQModelWidget::CQModelWidget(QWidget* parent, const char* name) :
20  CopasiWidget(parent, name),
21  mpModel(NULL)
22 {
23  setupUi(this);
24 
25  QStringList ComboEntries;
26  const char ** pComboEntries;
27 
28  for (pComboEntries = CModel::TimeUnitNames; *pComboEntries != NULL; ++pComboEntries)
29  {
30  ComboEntries.push_front(QString::fromUtf8(*pComboEntries));
31  }
32 
33  mpComboTimeUnit->clear();
34  mpComboTimeUnit->insertItems(0, ComboEntries);
35 
36  ComboEntries.clear();
37 
38  for (pComboEntries = CModel::VolumeUnitNames; *pComboEntries != NULL; ++pComboEntries)
39  {
40  ComboEntries.push_front(QString::fromUtf8(*pComboEntries));
41  }
42 
43  mpComboVolumeUnit->clear();
44  mpComboVolumeUnit->insertItems(0, ComboEntries);
45 
46  ComboEntries.clear();
47 
48  for (pComboEntries = CModel::AreaUnitNames; *pComboEntries != NULL; ++pComboEntries)
49  {
50  ComboEntries.push_front(QString::fromUtf8(*pComboEntries));
51  }
52 
53  mpComboAreaUnit->clear();
54  mpComboAreaUnit->insertItems(0, ComboEntries);
55 
56  ComboEntries.clear();
57 
58  for (pComboEntries = CModel::LengthUnitNames; *pComboEntries != NULL; ++pComboEntries)
59  {
60  ComboEntries.push_front(QString::fromUtf8(*pComboEntries));
61  }
62 
63  mpComboLengthUnit->clear();
64  mpComboLengthUnit->insertItems(0, ComboEntries);
65 
66  ComboEntries.clear();
67 
68  for (pComboEntries = CModel::QuantityUnitNames; *pComboEntries != NULL; ++pComboEntries)
69  {
70  ComboEntries.push_front(QString::fromUtf8(*pComboEntries));
71  }
72 
73  mpComboQuantityUnit->clear();
74  mpComboQuantityUnit->insertItems(0, ComboEntries);
75 
76 #ifndef COPASI_EXTUNIT
77  mpLblAreaUnit->hide();
78  mpComboAreaUnit->hide();
79 
80  mpLblLengthUnit->hide();
81  mpComboLengthUnit->hide();
82 #endif
83 }
84 
86 {}
87 
89 {
90  if (mpModel == NULL)
91  return;
92 
93  mpComboTimeUnit->setCurrentIndex(mpComboTimeUnit->findText(FROM_UTF8(mpModel->getTimeUnitName())));
94  mpComboVolumeUnit->setCurrentIndex(mpComboVolumeUnit->findText(FROM_UTF8(mpModel->getVolumeUnitName())));
95  mpComboQuantityUnit->setCurrentIndex(mpComboQuantityUnit->findText(FROM_UTF8(mpModel->getQuantityUnitName())));
96  mpComboAreaUnit->setCurrentIndex(mpComboAreaUnit->findText(FROM_UTF8(mpModel->getAreaUnitName())));
97  mpComboLengthUnit->setCurrentIndex(mpComboLengthUnit->findText(FROM_UTF8(mpModel->getLengthUnitName())));
98 
99  mpCheckStochasticCorrection->setChecked(mpModel->getModelType() == CModel::deterministic);
100 
101  mpLblInitialTime->setText("Initial Time (" + mpComboTimeUnit->currentText() + ")");
102  mpEditInitialTime->setText(QString::number(mpModel->getInitialTime()));
103  mpEditInitialTime->setReadOnly(mpModel->isAutonomous());
104 
105  mpLblCurrentTime->setText("Time (" + mpComboTimeUnit->currentText() + ")");
106  mpEditCurrentTime->setText(QString::number(mpModel->getTime()));
107 
108  return;
109 }
110 
112 {
113  if (mpModel == NULL)
114  return;
115 
116  bool changed = false;
117 
118  if (TO_UTF8(mpComboTimeUnit->currentText()) != mpModel->getTimeUnitName())
119  {
120  mpModel->setTimeUnit(TO_UTF8(mpComboTimeUnit->currentText()));
121  changed = true;
122  }
123 
124  if (TO_UTF8(mpComboVolumeUnit->currentText()) != mpModel->getVolumeUnitName())
125  {
126  mpModel->setVolumeUnit(TO_UTF8(mpComboVolumeUnit->currentText()));
127  changed = true;
128  }
129 
130  if (TO_UTF8(mpComboAreaUnit->currentText()) != mpModel->getAreaUnitName())
131  {
132  mpModel->setAreaUnit(TO_UTF8(mpComboAreaUnit->currentText()));
133  changed = true;
134  }
135 
136  if (TO_UTF8(mpComboLengthUnit->currentText()) != mpModel->getLengthUnitName())
137  {
138  mpModel->setLengthUnit(TO_UTF8(mpComboLengthUnit->currentText()));
139  changed = true;
140  }
141 
142  if (TO_UTF8(mpComboQuantityUnit->currentText()) != mpModel->getQuantityUnitName())
143  {
144  mpModel->setQuantityUnit(TO_UTF8(mpComboQuantityUnit->currentText()));
145  changed = true;
146  }
147 
148  if (mpCheckStochasticCorrection->isChecked() != (mpModel->getModelType() == CModel::deterministic))
149  {
150  if (mpCheckStochasticCorrection->isChecked())
151  {
153  }
154  else
155  {
157  }
158 
159  changed = true;
160  }
161 
162  if (mpEditInitialTime->text() != QString::number(mpModel->getInitialTime()))
163  {
164  mpModel->setInitialTime(mpEditInitialTime->text().toDouble());
165  changed = true;
166  }
167 
168  if (changed)
169  {
170  if (mpDataModel != NULL)
171  {
172  mpDataModel->changed();
173  }
174 
176  }
177 
178  return;
179 }
180 
182 {
183  load();
184 }
185 
187 {
188  save();
189  load();
190 }
191 
193  ListViews::Action C_UNUSED(action), const std::string & key)
194 {
195  if (mIgnoreUpdates) return true;
196 
197  switch (objectType)
198  {
199  case ListViews::MODEL:
200  enter(key);
201  break;
202 
203  default:
204  break;
205  }
206 
207  return true;
208 }
209 
211 {
212  save();
213 
214  mpNotes->leave();
215 
216  return true;
217 }
218 
220 {
221  if (mpObject != NULL)
222  mpModel = dynamic_cast< CModel * >(mpObject);
223  else
224  mpModel = NULL;
225 
226  load();
227 
228  mpNotes->enter(mKey);
229 
230  return true;
231 }
static const char * LengthUnitNames[]
Definition: CModel.h:81
bool setAreaUnit(const std::string &name)
Definition: CModel.cpp:2182
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
bool setVolumeUnit(const std::string &name)
Definition: CModel.cpp:2159
bool setLengthUnit(const std::string &name)
Definition: CModel.cpp:2204
bool setTimeUnit(const std::string &name)
Definition: CModel.cpp:2227
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
virtual bool leave()
std::string getTimeUnitName() const
Definition: CModel.cpp:2238
CModel * mpModel
Definition: CQModelWidget.h:46
CCopasiObject * mpObject
Definition: copasiWidget.h:64
void changed(const bool &changed=true)
#define C_UNUSED(p)
Definition: copasi.h:220
virtual void slotBtnOKClicked()
CQModelWidget(QWidget *parent=0, const char *name=0)
bool mIgnoreUpdates
Definition: copasiWidget.h:67
void setInitialTime(const C_FLOAT64 &time)
Definition: CModel.cpp:1181
virtual bool enterProtected()
const bool & isAutonomous() const
Definition: CModel.cpp:3956
const C_FLOAT64 & getInitialTime() const
Definition: CModel.cpp:1184
std::string getLengthUnitName() const
Definition: CModel.cpp:2215
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const C_FLOAT64 & getTime() const
Definition: CModel.cpp:1190
static const char * AreaUnitNames[]
Definition: CModel.h:71
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
std::string getAreaUnitName() const
Definition: CModel.cpp:2193
std::string getQuantityUnitName() const
Definition: CModel.cpp:2321
const ModelType & getModelType() const
Definition: CModel.cpp:2339
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool setQuantityUnit(const std::string &name)
Definition: CModel.cpp:2250
Definition: CModel.h:50
std::string getVolumeUnitName() const
Definition: CModel.cpp:2170
static const char * TimeUnitNames[]
Definition: CModel.h:91
virtual void slotBtnRevertClicked()
std::string mKey
Definition: copasiWidget.h:63
void setModelType(const ModelType &modelType)
Definition: CModel.cpp:2336
static const char * QuantityUnitNames[]
Definition: CModel.h:107
static const char * VolumeUnitNames[]
Definition: CModel.h:61
bool enter(const std::string &key)