COPASI API  4.16.103
CQTaskMethodWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include "CQTaskMethodWidget.h"
7 #include "qtUtilities.h"
8 
9 #include "copasi.h"
10 
11 #include "utilities/CCopasiTask.h"
13 #include "utilities/utility.h"
14 
15 CQTaskMethodWidget::CQTaskMethodWidget(QWidget* parent, Qt::WindowFlags f):
16  QWidget(parent, f),
17  mpTask(NULL),
18  mpMethod(NULL),
19  mpActiveMethod(NULL),
20  mMethodHistory(),
21  mShowMethods(false),
22  mShowMethodParameters(false)
23 {
24  setupUi(this);
25 
26  mpTableParameter->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
27  mpTableParameter->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
28  mpTableParameter->horizontalHeader()->hide();
29 
30  mpLblMethod->hide();
31  mpBoxMethod->hide();
32 
33  mpLblParameter->hide();
34  mpTableParameter->hide();
35 }
36 
38 {
39  clearHistory();
40 }
41 
42 void CQTaskMethodWidget::changeMethod(int /* index */)
43 {
44  if (mpTask == NULL)
45  return;
46 
47  // We update the active methods parameters
49  {
50  unsigned C_INT32 i;
51  QString Value;
52 
53  for (i = 0; i < mpActiveMethod->size(); i++)
54  {
55  if (!mpTableParameter->item(i, 0))
56  continue;
57 
58  Value = mpTableParameter->item(i, 0)->text();
60  }
61  }
62 
64  toEnum(TO_UTF8(mpBoxMethod->currentText()), CCopasiMethod::SubTypeName, CCopasiMethod::unset);
65 
66  setActiveMethod(Type);
67  loadMethod();
68 
69  return;
70 }
71 
73 {
74  mpTask = pTask;
75 
76  if (mpTask != NULL)
77  {
79 
80  if (mpMethod != NULL)
81  {
84  }
85  }
86  else
87  {
88  mpMethod = NULL;
89  mpActiveMethod = NULL;
90  }
91 }
92 
93 void CQTaskMethodWidget::setValidMethods(const unsigned int * validMethods)
94 {
95  unsigned C_INT32 i;
96 
97  for (i = 0; validMethods[i] != CCopasiMethod::unset; i++)
98  mpBoxMethod->insertItem(mpBoxMethod->count(), FROM_UTF8(CCopasiMethod::SubTypeName[validMethods[i]]));
99 
100  if (i > 0)
101  {
102  mShowMethods = true;
103  mpLblMethod->show();
104  mpBoxMethod->show();
105 
106  connect(mpBoxMethod, SIGNAL(activated(int)), this, SLOT(changeMethod(int)));
107  }
108  else
109  {
110  mShowMethods = false;
111  mpLblMethod->hide();
112  mpBoxMethod->hide();
113 
114  disconnect(mpBoxMethod, SIGNAL(activated(int)), this, SLOT(changeMethod(int)));
115  }
116 }
117 
119 {
120  mShowMethodParameters = show;
121 
123  {
124  mpLblParameter->show();
125  mpTableParameter->show();
126  }
127  else
128  {
129  mpLblParameter->hide();
130  mpTableParameter->hide();
131  }
132 }
133 
135 {
136  if (!mpTask) return false;
137 
138  if (!mpActiveMethod) return false;
139 
140  if (mShowMethods)
141  {
142  mpBoxMethod->setCurrentIndex(mpBoxMethod->findText(FROM_UTF8(CCopasiMethod::SubTypeName[mpActiveMethod->getSubType()])));
143  }
144 
146  {
147  QString Value;
148 
149  mpTableParameter->setRowCount((int) mpActiveMethod->size());
150 
151  unsigned C_INT32 i;
153 
154  for (i = 0; i < mpActiveMethod->size(); i++)
155  {
156  // create item of the current row and give it a name
157  mpTableParameter->setVerticalHeaderItem(i, new QTableWidgetItem());
158  mpTableParameter->verticalHeaderItem(i)->setText(FROM_UTF8(mpActiveMethod->getName(i)));
159 
160  Value = getParameterValue(mpActiveMethod, i, &Type);
161 
162  QTableWidgetItem *pValueItem = new QTableWidgetItem();
163  pValueItem->setData(Qt::EditRole, QVariant(Value));
164  pValueItem->setTextAlignment(Qt::AlignRight);
165  mpTableParameter->setItem(i, 0, pValueItem);
166  }
167  }
168 
169  mpTableParameter->resizeColumnsToContents();
170 
171  return true;
172 }
173 
175 {
176  if (!mpTask) return false;
177 
178  const CCopasiMethod * pMethod = mpTask->getMethod();
179 
180  if (!pMethod) return false;
181 
182  bool changed = false;
183 
184  if (mShowMethods)
185  {
186  if (pMethod->getSubType() != mpActiveMethod->getSubType())
187  {
190 
191  changed = true;
192  }
193  }
194 
196  {
197  unsigned C_INT32 i;
198  QString Value;
200 
201  for (i = 0; i < mpActiveMethod->size(); i++)
202  {
203  if (!mpTableParameter->item(i, 0))
204  continue;
205 
206  Value = mpTableParameter->item(i, 0)->text();
207 
208  if (Value != getParameterValue(mpActiveMethod, i, &Type))
209  {
211  changed = true;
212  }
213  }
214  }
215 
216  if (changed)
217  {
219  }
220 
221  return changed;
222 }
223 
225 {
226  if (pMethod == NULL)
227  {
228  return;
229  }
230 
231  std::map< CCopasiMethod::SubType, CCopasiMethod * >::iterator found = mMethodHistory.find(pMethod->getSubType());
232 
233  if (found != mMethodHistory.end())
234  {
235  if (found->second != pMethod)
236  {
237  delete found->second;
238  found->second = pMethod;
239  }
240 
241  return;
242  }
243 
244  mMethodHistory[pMethod->getSubType()] = pMethod;
245 }
246 
248 {
249  if (pMethod == NULL)
250  {
251  return;
252  }
253 
254  std::map< CCopasiMethod::SubType, CCopasiMethod * >::iterator found = mMethodHistory.find(pMethod->getSubType());
255 
256  if (found != mMethodHistory.end())
257  {
258  mMethodHistory.erase(found);
259  }
260 }
261 
263 {
264  std::map< CCopasiMethod::SubType, CCopasiMethod * >::const_iterator found = mMethodHistory.find(Type);
265 
266  if (found != mMethodHistory.end())
267  {
268  return found->second;
269  }
270 
271  return NULL;
272 }
273 
275 {
277 
278  if (mpActiveMethod == NULL)
279  {
282  }
283 
284  assert(mpActiveMethod != NULL);
285 
286  return;
287 }
288 
290 {
291  std::map< CCopasiMethod::SubType, CCopasiMethod * >::iterator it = mMethodHistory.begin();
292  std::map< CCopasiMethod::SubType, CCopasiMethod * >::iterator end = mMethodHistory.end();
293 
294  for (; it != end; ++it)
295  {
296  delete it->second;
297  }
298 
299  mMethodHistory.clear();
300 }
virtual const std::string & getName(const size_t &index) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiMethod * mpActiveMethod
bool setParameterValue(CCopasiParameterGroup *group, const size_t &index, const QString &value)
Definition: qtUtilities.cpp:94
void setActiveMethod(const CCopasiMethod::SubType &Type)
void addToHistory(CCopasiMethod *pMethod)
const CCopasiMethod::SubType & getSubType() const
#define C_INT32
Definition: copasi.h:90
CCopasiMethod * mpMethod
CTSSATask * pTask
void removeFromHistory(CCopasiMethod *pMethod)
void setTask(CCopasiTask *pTask)
QString getParameterValue(const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
Definition: qtUtilities.cpp:28
void showMethodParameters(const bool &show)
virtual bool setMethodType(const int &type)
CType toEnum(const char *attribute, const char **enumNames, const CType &enumDefault)
Definition: utility.h:107
CCopasiMethod * getMethod()
CQTaskMethodWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static const std::string SubTypeName[]
Definition: CCopasiMethod.h:95
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual CCopasiMethod * createMethod(const int &type) const
CCopasiMethod * getFromHistory(const CCopasiMethod::SubType &Type) const
void setValidMethods(const unsigned int *validMethods)
std::map< CCopasiMethod::SubType, CCopasiMethod * > mMethodHistory