COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
CQModelValue Class Reference

#include <CQModelValue.h>

Inheritance diagram for CQModelValue:
Inheritance graph
[legend]
Collaboration diagram for CQModelValue:
Collaboration graph
[legend]

Public Member Functions

 CQModelValue (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQModelValue ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
virtual void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 

Protected Member Functions

virtual bool enterProtected ()
 

Private Slots

void slotBtnCopy ()
 
void slotBtnDelete ()
 
void slotBtnNew ()
 Slot to create a new quantity; activated whenever the New button is clicked. More...
 
void slotExpressionValid (bool valid)
 
void slotInitialExpressionValid (bool valid)
 
void slotInitialTypeChanged (bool useInitialAssignment)
 
void slotTypeChanged (int type)
 

Private Member Functions

void destroy ()
 
void init ()
 
void load ()
 
void save ()
 

Private Attributes

bool mChanged
 
bool mExpressionValid
 
bool mInitialExpressionValid
 
std::vector< int > mItemToType
 
std::string mKeyToCopy
 
CModelValuempModelValue
 

Additional Inherited Members

- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 
- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Detailed Description

Definition at line 28 of file CQModelValue.h.

Constructor & Destructor Documentation

CQModelValue::CQModelValue ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 32 of file CQModelValue.cpp.

References init().

33  : CopasiWidget(parent, name),
34  mKeyToCopy("")
35 {
36  setupUi(this);
37 
38  init();
39 }
std::string mKeyToCopy
Definition: CQModelValue.h:55
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
CQModelValue::~CQModelValue ( )

Definition at line 44 of file CQModelValue.cpp.

References destroy().

45 {
46  destroy();
47  // no need to delete child widgets, Qt does it all for us
48 }

Member Function Documentation

void CQModelValue::destroy ( )
private

Definition at line 201 of file CQModelValue.cpp.

Referenced by ~CQModelValue().

202 {}
bool CQModelValue::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 267 of file CQModelValue.cpp.

References CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), load(), mKeyToCopy, CopasiWidget::mpListView, mpModelValue, CopasiWidget::mpObject, and ListViews::switchToOtherWidget().

268 {
269  mpModelValue = NULL;
270 
271  if (mKeyToCopy != "")
272  {
274  mKeyToCopy = "";
275  }
276  else
277  {
278  mpModelValue = dynamic_cast<CModelValue *>(mpObject);
279  }
280 
281  if (!mpModelValue)
282  {
284  return false;
285  }
286 
287  load();
288 
289  mpModelValue = dynamic_cast<CModelValue *>(mpObject);
290 
291  return true;
292 }
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
CCopasiObject * get(const std::string &key)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
std::string mKeyToCopy
Definition: CQModelValue.h:55
CModelValue * mpModelValue
Definition: CQModelValue.h:46
ListViews * mpListView
Definition: copasiWidget.h:62
static CKeyFactory * getKeyFactory()
void CQModelValue::init ( )
private

Definition at line 184 of file CQModelValue.cpp.

References CModelEntity::ASSIGNMENT, CModelEntity::FIXED, FROM_UTF8, CQExpressionWidget::InitialExpression, mExpressionValid, mInitialExpressionValid, mItemToType, CModelEntity::ODE, CModelEntity::StatusName, and CQExpressionWidget::TransientExpression.

Referenced by CQModelValue().

185 {
186  mpComboBoxType->insertItem(mpComboBoxType->count(), FROM_UTF8(CModelEntity::StatusName[CModelEntity::FIXED]));
187  mpComboBoxType->insertItem(mpComboBoxType->count(), FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT]));
188  mpComboBoxType->insertItem(mpComboBoxType->count(), FROM_UTF8(CModelEntity::StatusName[CModelEntity::ODE]));
189 
190  mItemToType.push_back(CModelEntity::FIXED);
192  mItemToType.push_back(CModelEntity::ODE);
193 
194  mExpressionValid = false;
195  mpExpressionEMW->mpExpressionWidget->setExpressionType(CQExpressionWidget::TransientExpression);
196 
197  mInitialExpressionValid = false;
198  mpInitialExpressionEMW->mpExpressionWidget->setExpressionType(CQExpressionWidget::InitialExpression);
199 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
std::vector< int > mItemToType
Definition: CQModelValue.h:45
static const std::string StatusName[]
Definition: CModelValue.h:67
bool mInitialExpressionValid
Definition: CQModelValue.h:49
bool mExpressionValid
Definition: CQModelValue.h:48
bool CQModelValue::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 248 of file CQModelValue.cpp.

References CModelEntity::FIXED, mItemToType, and save().

Referenced by slotBtnNew().

249 {
250  if ((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()] != CModelEntity::FIXED)
251  {
252  // -- Expression --
253  mpExpressionEMW->updateWidget();
254  }
255 
256  if (mpBoxUseInitialExpression->isChecked())
257  {
258  // -- Initial Expression --
259  mpInitialExpressionEMW->updateWidget();
260  }
261 
262  save();
263 
264  return true;
265 }
std::vector< int > mItemToType
Definition: CQModelValue.h:45
void CQModelValue::load ( )
private

Load any saved values to the screen

Definition at line 297 of file CQModelValue.cpp.

References CModelEntity::ASSIGNMENT, FROM_UTF8, CModelEntity::getExpression(), CModelEntity::getInitialExpression(), CModelEntity::getInitialValue(), CModelEntity::getRate(), CModelEntity::getStatus(), CModelEntity::getValue(), mChanged, mpModelValue, slotTypeChanged(), and CModelEntity::StatusName.

Referenced by enterProtected(), and update().

298 {
299  if (mpModelValue == NULL) return;
300 
301  // Type
302  mpComboBoxType->setCurrentIndex(mpComboBoxType->findText(FROM_UTF8(CModelEntity::StatusName[mpModelValue->getStatus()])));
303 
304  // Initial Value
305  mpEditInitialValue->setText(QString::number(mpModelValue->getInitialValue(), 'g', 10));
306 
307  // Current Value
308  mpEditCurrentValue->setText(QString::number(mpModelValue->getValue(), 'g', 10));
309 
310  // Rate
311  mpEditRate->setText(QString::number(mpModelValue->getRate(), 'g', 10));
312 
313  // Expression
314  mpExpressionEMW->mpExpressionWidget->setExpression(mpModelValue->getExpression());
315 
316  // Update Expression Widget
317  mpExpressionEMW->updateWidget();
318 
319  // Initial Expression
320  mpInitialExpressionEMW->mpExpressionWidget->setExpression(mpModelValue->getInitialExpression());
321 
322  // Update Initial Expression Widget
323  mpInitialExpressionEMW->updateWidget();
324 
325  // Type dependent display of values
326  slotTypeChanged(mpComboBoxType->currentIndex());
327 
328  // Use Initial Expression
331  {
332  mpBoxUseInitialExpression->setChecked(false);
333  // slotInitialTypeChanged(false);
334  }
335  else
336  {
337  mpBoxUseInitialExpression->setChecked(true);
338  // slotInitialTypeChanged(true);
339  }
340 
341  mChanged = false;
342 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
const C_FLOAT64 & getRate() const
std::string getExpression() const
void slotTypeChanged(int type)
const C_FLOAT64 & getInitialValue() const
CModelValue * mpModelValue
Definition: CQModelValue.h:46
std::string getInitialExpression() const
const C_FLOAT64 & getValue() const
const CModelEntity::Status & getStatus() const
void CQModelValue::save ( )
private

Save any inputs and set them as initial setting values

Definition at line 347 of file CQModelValue.cpp.

References CModelEntity::ASSIGNMENT, ListViews::CHANGE, CCopasiRootContainer::getDatamodelList(), CModelEntity::getExpression(), CModelEntity::getInitialExpression(), CModelEntity::getInitialValue(), CModelEntity::getStatus(), mChanged, mItemToType, CopasiWidget::mKey, ListViews::MODELVALUE, mpModelValue, CopasiWidget::protectedNotify(), CModelEntity::setExpression(), CModelEntity::setInitialExpression(), CModelEntity::setInitialValue(), and CModelEntity::setStatus().

Referenced by leave().

348 {
349  if (mpModelValue == NULL) return;
350 
351  // set status
352  if (mpModelValue->getStatus() != (CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()])
353  {
354  mpModelValue->setStatus((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()]);
355  mChanged = true;
356  }
357 
358  // set initial value
359  if (QString::number(mpModelValue->getInitialValue(), 'g', 10) != mpEditInitialValue->text() &&
361  {
362  mpModelValue->setInitialValue(mpEditInitialValue->text().toDouble());
363  mChanged = true;
364  }
365 
366  // set expression
367  if (mpModelValue->getExpression() != mpExpressionEMW->mpExpressionWidget->getExpression())
368  {
369  // mpModelValue->setExpression(((CQExpressionWidget *)mpEditExpression->widget(0))->getExpression());
370  mpModelValue->setExpression(mpExpressionEMW->mpExpressionWidget->getExpression());
371  mChanged = true;
372  }
373 
374  // set initial expression
375  if ((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()] != CModelEntity::ASSIGNMENT)
376  {
377  if (mpBoxUseInitialExpression->isChecked() &&
378  mpModelValue->getInitialExpression() != mpInitialExpressionEMW->mpExpressionWidget->getExpression())
379  {
380  mpModelValue->setInitialExpression(mpInitialExpressionEMW->mpExpressionWidget->getExpression());
381  mChanged = true;
382  }
383  else if (!mpBoxUseInitialExpression->isChecked() &&
385  {
387  mChanged = true;
388  }
389  }
390 
391  if (mChanged)
392  {
393  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
394  (*CCopasiRootContainer::getDatamodelList())[0]->changed();
396  }
397 
398  mChanged = false;
399 }
std::vector< int > mItemToType
Definition: CQModelValue.h:45
bool setInitialExpression(const std::string &expression)
std::string getExpression() const
const C_FLOAT64 & getInitialValue() const
CModelValue * mpModelValue
Definition: CQModelValue.h:46
virtual void setStatus(const CModelEntity::Status &status)
std::string getInitialExpression() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void setInitialValue(const C_FLOAT64 &initialValue)
const CModelEntity::Status & getStatus() const
bool setExpression(const std::string &expression)
std::string mKey
Definition: copasiWidget.h:63
void CQModelValue::slotBtnCopy ( )
privateslot

Definition at line 76 of file CQModelValue.cpp.

References CopasiWidget::mKey, and mKeyToCopy.

77 {
78  mKeyToCopy = mKey;
79 }
std::string mKeyToCopy
Definition: CQModelValue.h:55
std::string mKey
Definition: copasiWidget.h:63
void CQModelValue::slotBtnDelete ( )
privateslot

Definition at line 81 of file CQModelValue.cpp.

References CQMessageBox::confirmDelete(), ListViews::DELETE, FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CModelEntity::getDeletedObjects(), CCopasiDataModel::getModel(), CCopasiObject::getObjectName(), CopasiWidget::mKey, ListViews::MODELVALUE, mpModelValue, CopasiWidget::protectedNotify(), and CModel::removeModelValue().

82 {
83  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
85  assert(pDataModel != NULL);
86  CModel * pModel = pDataModel->getModel();
87 
88  if (pModel == NULL)
89  return;
90 
91  if (mpModelValue == NULL)
92  return;
93 
94  QMessageBox::StandardButton choice =
95  CQMessageBox::confirmDelete(this, "quantity",
98 
99  switch (choice)
100  {
101  case QMessageBox::Ok:
102  {
103  pDataModel->getModel()->removeModelValue(mKey);
104  mpModelValue = NULL;
105 
106 #undef DELETE
108  protectedNotify(ListViews::MODELVALUE, ListViews::DELETE, "");//Refresh all as there may be dependencies.
109  break;
110  }
111 
112  default:
113  break;
114  }
115 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
bool removeModelValue(const CModelValue *pModelValue, const bool &recursive=true)
Definition: CModel.cpp:2903
CModelValue * mpModelValue
Definition: CQModelValue.h:46
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual std::set< const CCopasiObject * > getDeletedObjects() const
Definition: CModel.h:50
std::string mKey
Definition: copasiWidget.h:63
void CQModelValue::slotBtnNew ( )
privateslot

Slot to create a new quantity; activated whenever the New button is clicked.

Definition at line 51 of file CQModelValue.cpp.

References ListViews::ADD, C_INVALID_INDEX, CCopasiRootContainer::getDatamodelList(), CModelEntity::getKey(), leave(), ListViews::MODELVALUE, CopasiWidget::mpListView, mpModelValue, CopasiWidget::protectedNotify(), ListViews::switchToOtherWidget(), and TO_UTF8.

52 {
53  // save the current setting values
54  leave();
55 
56  // standard name
57  std::string name = "quantity_1";
58 
59  // if the standard name already exists then creating the new event will fail
60  // thus, a growing index will automatically be added to the standard name
61  int i = 1;
62  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
63 
64  while (!(mpModelValue = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->createModelValue(name)))
65  {
66  i++;
67  name = "quantity_";
68  name += TO_UTF8(QString::number(i));
69  }
70 
71  std::string key = mpModelValue->getKey();
74 }
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
#define C_INVALID_INDEX
Definition: copasi.h:222
CModelValue * mpModelValue
Definition: CQModelValue.h:46
ListViews * mpListView
Definition: copasiWidget.h:62
virtual const std::string & getKey() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual bool leave()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
void CQModelValue::slotExpressionValid ( bool  valid)
privateslot

This function is used in case of not FIXED type

Definition at line 174 of file CQModelValue.cpp.

References mExpressionValid.

175 {
176  mExpressionValid = valid;
177 }
bool mExpressionValid
Definition: CQModelValue.h:48
void CQModelValue::slotInitialExpressionValid ( bool  valid)
privateslot

Definition at line 179 of file CQModelValue.cpp.

References mInitialExpressionValid.

180 {
181  mInitialExpressionValid = valid;
182 }
bool mInitialExpressionValid
Definition: CQModelValue.h:49
void CQModelValue::slotInitialTypeChanged ( bool  useInitialAssignment)
privateslot

If the initial expression is chosen to be used by checking the mpBoxUseInitialExpression check box being represented by the boolean parameter useInitialAssignment (true if checked; false otherwise), COPASI will show the Initial Expression Widget with its correct push buttons. Otherwise, the widget and its buttons will be hidden.

Definition at line 406 of file CQModelValue.cpp.

References CModelEntity::ASSIGNMENT, and mItemToType.

Referenced by slotTypeChanged().

407 {
408  if (useInitialAssignment) // use Initial Expression (ie. the mpBoxUseInitialExpression is checked)
409  {
410  // show label, widget, and the correct buttons
411  mpLblInitialExpression->show(); // show the label
412  mpInitialExpressionEMW->show(); // show the widget
413 
414  // enable the option of use Initial Value
415  mpEditInitialValue->setEnabled(false);
416 
417  // update the Initial Expression Widget
418  mpInitialExpressionEMW->updateWidget();
419  }
420  else // mpBoxUseInitialExpression is not checked
421  {
422  // hide label, widget, and all buttons
423  mpLblInitialExpression->hide();
424  mpInitialExpressionEMW->hide();
425 
426  // enable the option of use Initial Value
427  mpEditInitialValue->setEnabled((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()] != CModelEntity::ASSIGNMENT);
428 
429  // we don't need to update the Initial Expression Widget
430  }
431 }
std::vector< int > mItemToType
Definition: CQModelValue.h:45
void CQModelValue::slotTypeChanged ( int  type)
privateslot

If the simulation type is changed then COPASI will automatically adjust its appearance, especially correlating to the Expression Widget and its buttons.

Definition at line 121 of file CQModelValue.cpp.

References CModelEntity::ASSIGNMENT, CModelEntity::FIXED, mItemToType, CModelEntity::ODE, and slotInitialTypeChanged().

Referenced by load().

122 {
123  switch ((CModelEntity::Status) mItemToType[type])
124  {
125  case CModelEntity::FIXED:
126  // hide label, widget, and all buttons
127  mpLblExpression->hide();
128  mpExpressionEMW->hide();
129 
130  // enable the option of use Initial Expression
131  mpBoxUseInitialExpression->setEnabled(true);
132  slotInitialTypeChanged(mpBoxUseInitialExpression->isChecked());
133 
134  // we don't need to update the expression widget as it is already hidden
135 
136  break;
137 
139  // show label, widget, and correct buttons
140  mpLblExpression->show(); // show the label
141  mpExpressionEMW->show(); // show the widget
142 
143  // disable the option of use Initial Expression
144  mpBoxUseInitialExpression->setEnabled(false);
145  slotInitialTypeChanged(false);
146 
147  // update the expression widget
148  mpExpressionEMW->updateWidget();
149 
150  break;
151 
152  case CModelEntity::ODE:
153  // show label, widget, and correct buttons
154  mpLblExpression->show(); // show the label
155  mpExpressionEMW->show(); // show the widget
156 
157  // enable the option of use Initial Expression
158  mpBoxUseInitialExpression->setEnabled(true);
159  slotInitialTypeChanged(mpBoxUseInitialExpression->isChecked());
160 
161  // update the expression widget
162  mpExpressionEMW->updateWidget();
163 
164  break;
165 
166  default:
167  break;
168  }
169 }
std::vector< int > mItemToType
Definition: CQModelValue.h:45
void slotInitialTypeChanged(bool useInitialAssignment)
bool CQModelValue::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 204 of file CQModelValue.cpp.

References ListViews::ADD, ListViews::DELETE, load(), CopasiWidget::mIgnoreUpdates, CopasiWidget::mKey, ListViews::MODEL, ListViews::MODELVALUE, mpModelValue, CopasiWidget::mpObject, and ListViews::STATE.

207 {
208  switch (objectType)
209  {
210  case ListViews::MODEL:
211 
212  // For a new model we need to remove references to no longer existing metabolites
213  if (action == ListViews::ADD)
214  {
215  mKey = "";
216  mpObject = NULL;
217  mpModelValue = NULL;
218  }
219 
220  break;
221 
223 
224  // If the currently displayed metabolite is deleted we need to remove its references.
225  if (action == ListViews::DELETE && mKey == key)
226  {
227  mKey = "";
228  mpObject = NULL;
229  mpModelValue = NULL;
230  }
231 
232  break;
233 
234  case ListViews::STATE:
235  break;
236 
237  default:
238  return true;
239  break;
240  }
241 
242  if (isVisible() && !mIgnoreUpdates)
243  load();
244 
245  return true;
246 }
objectType
CCopasiObject * mpObject
Definition: copasiWidget.h:64
bool mIgnoreUpdates
Definition: copasiWidget.h:67
CModelValue * mpModelValue
Definition: CQModelValue.h:46
std::string mKey
Definition: copasiWidget.h:63

Member Data Documentation

bool CQModelValue::mChanged
private

Definition at line 47 of file CQModelValue.h.

Referenced by load(), and save().

bool CQModelValue::mExpressionValid
private

Definition at line 48 of file CQModelValue.h.

Referenced by init(), and slotExpressionValid().

bool CQModelValue::mInitialExpressionValid
private

Definition at line 49 of file CQModelValue.h.

Referenced by init(), and slotInitialExpressionValid().

std::vector< int > CQModelValue::mItemToType
private

Definition at line 45 of file CQModelValue.h.

Referenced by init(), leave(), save(), slotInitialTypeChanged(), and slotTypeChanged().

std::string CQModelValue::mKeyToCopy
private

Definition at line 55 of file CQModelValue.h.

Referenced by enterProtected(), and slotBtnCopy().

CModelValue* CQModelValue::mpModelValue
private

Definition at line 46 of file CQModelValue.h.

Referenced by enterProtected(), load(), save(), slotBtnDelete(), slotBtnNew(), and update().


The documentation for this class was generated from the following files: