COPASI API  4.16.103
Functions
qtUtilities.cpp File Reference
#include <QtCore/QString>
#include <QtCore/QFileInfo>
#include "copasi.h"
#include "qtUtilities.h"
#include "CQMessageBox.h"
#include "utilities/CCopasiParameterGroup.h"
#include "utilities/CDirEntry.h"
Include dependency graph for qtUtilities.cpp:

Go to the source code of this file.

Functions

C_INT32 checkSelection (const QString &file)
 
QString getParameterValue (const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
 
QString getParameterValue (const CCopasiParameterGroup *group, const std::string &name, CCopasiParameter::Type *type)
 
bool setParameterValue (CCopasiParameterGroup *group, const size_t &index, const QString &value)
 
bool setParameterValue (CCopasiParameterGroup *group, const std::string &name, const QString &value)
 
void vectorOfStrings2QStringList (std::vector< std::string > vs, QStringList &qsl)
 

Function Documentation

C_INT32 checkSelection ( const QString &  file)

Checks whether the file exists. If the file exist the user is prompted whether to overwrite the file. The return value is one of QMessageBox::Yes, QMessageBox::No, or QMessageBox::Cancel. If the file does not exist QMessageBox::Yes is returned. param const QString & file

Returns
C_INT32 overwrite

Definition at line 179 of file qtUtilities.cpp.

References CQMessageBox::information(), CDirEntry::isWritable(), CQMessageBox::question(), and TO_UTF8.

Referenced by PlotWindow::printAsImage(), CQTSSAResultSubWidget::saveDataToFile(), CQBarChart::saveDataToFile(), CQLyapResultWidget::saveToFile(), CQSensResultWidget::saveToFile(), CQParameterOverviewWidget::slotBtnSaveToFile(), CopasiUI3Window::slotCapture(), CopasiUI3Window::slotExportMathModel(), CopasiUI3Window::slotExportSBML(), CopasiUI3Window::slotFileSaveAs(), CopasiUI3Window::slotFunctionDBSave(), CQDifferentialEquations::slotSave(), CQSteadyStateResult::slotSave(), CQTimeSeriesWidget::slotSave(), CQMoietiesTaskResult::slotSave(), CQOptimizationResult::slotSave(), CMCAResultSubwidget::slotSave(), CLNAResultSubwidget::slotSave(), CQFittingResult::slotSave(), CQEFMResultWidget::slotSave(), PlotWindow::slotSaveData(), and CQExpressionMmlStackedWidget::slotSaveExpression().

180 {
181 
182 #ifdef DEBUG_UI
183  qDebug() << "Filename on checkSelection = " << file;
184 #endif
185 
186  if (QFileInfo(file).exists())
187  {
188  if (CDirEntry::isWritable(TO_UTF8(file)))
189  return CQMessageBox::question(NULL, "File exists!",
190  "Overwrite existing file " + file + "?",
191  QMessageBox::Ok | QMessageBox::Cancel,
192  QMessageBox::Cancel);
193  else
194  {
195  CQMessageBox::information(NULL, "File read-only",
196  "The file is read-only. Please select another file!",
197  QMessageBox::Ok, QMessageBox::Ok);
198  return QMessageBox::Cancel;
199  }
200  }
201  else
202  return QMessageBox::Ok;
203 }
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static bool isWritable(const std::string &path)
Definition: CDirEntry.cpp:95
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
QString getParameterValue ( const CCopasiParameterGroup group,
const size_t &  index,
CCopasiParameter::Type type = NULL 
)

Retrieve a parameter from a parameter group and convert it to a QString.

Parameters
constCCopasiParameterGroup * group
constsize_t & index
CCopasiParameter::Type* type (default: NULL)
Returns
QString value

Definition at line 28 of file qtUtilities.cpp.

References CCopasiParameter::BOOL, CCopasiParameter::CN, CCopasiParameter::DOUBLE, FROM_UTF8, CCopasiParameterGroup::getName(), CCopasiParameterGroup::getType(), CCopasiParameterGroup::getValue(), CCopasiParameter::GROUP, CCopasiParameter::INT, CCopasiParameter::INVALID, CCopasiParameter::KEY, CCopasiParameter::Value::pBOOL, CCopasiParameter::Value::pCN, CCopasiParameter::Value::pDOUBLE, CCopasiParameter::Value::pINT, CCopasiParameter::Value::pKEY, CCopasiParameter::Value::pSTRING, CCopasiParameter::Value::pUINT, CCopasiParameterGroup::size(), CCopasiParameter::STRING, CCopasiParameter::UDOUBLE, and CCopasiParameter::UINT.

Referenced by getParameterValue(), CScanWidgetRandom::load(), CQTaskMethodWidget::loadMethod(), CQLNAWidget::loadParameterTable(), CQMCAWidget::loadParameterTable(), CQTaskMethodWidget::saveMethod(), CQMCAWidget::saveParameterTable(), CQLNAWidget::saveParameterTable(), and setParameterValue().

31 {
32  if (index >= group->size())
33  return QString::fromLatin1("INVALID");
34 
35  if (type) *type = group->getType(index);
36 
37  switch (group->getType(index))
38  {
40  return QString::number(* group->getValue(index).pDOUBLE);
41  break;
42 
44  return QString::number(* group->getValue(index).pDOUBLE);
45  break;
46 
48  return QString::number(* group->getValue(index).pINT);
49  break;
50 
52  return QString::number(* group->getValue(index).pUINT);
53  break;
54 
56  return QString::number(* group->getValue(index).pBOOL);
57  break;
58 
60  return
61  FROM_UTF8(* group->getValue(index).pSTRING);
62  break;
63 
65  return
66  FROM_UTF8(* group->getValue(index).pKEY);
67  break;
68 
70  return
71  FROM_UTF8(* group->getValue(index).pCN);
72  break;
73 
75  return FROM_UTF8((group->getName(index)));
76  break;
77 
79  return QString::fromUtf8("INVALID");
80  break;
81 
82  default:
83  break;
84  }
85 
86  return QString::fromLatin1("INVALID");
87 }
virtual const std::string & getName(const size_t &index) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiParameter::Type getType(const std::string &name) const
CRegisteredObjectName * pCN
unsigned C_INT32 * pUINT
const CCopasiParameter::Value & getValue(const std::string &name) const
QString getParameterValue ( const CCopasiParameterGroup group,
const std::string &  name,
CCopasiParameter::Type type = NULL 
)

Retrieve a parameter from a parameter group and convert it to a QString.

Parameters
constCCopasiParameterGroup * group
conststd::string & name
CCopasiParameter::Type* type (default: NULL)
Returns
QString value

Definition at line 89 of file qtUtilities.cpp.

References CCopasiParameterGroup::getIndex(), and getParameterValue().

92 {return getParameterValue(group, group->getIndex(name), type);}
size_t getIndex(const std::string &name) const
QString getParameterValue(const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
Definition: qtUtilities.cpp:28
bool setParameterValue ( CCopasiParameterGroup group,
const size_t &  index,
const QString &  value 
)

Set a parameter of a parameter group from a value given as a QString. Success = true is returned when the set operation was succesful, i.e., value == getParameterValue.

Parameters
CCopasiParameterGroup* group
constsize_t & index
constQString & value
Returns
bool success.

Definition at line 94 of file qtUtilities.cpp.

References CCopasiParameter::BOOL, C_FLOAT64, C_INT32, CCopasiParameter::CN, CCopasiParameter::DOUBLE, getParameterValue(), CCopasiParameterGroup::getType(), CCopasiParameter::GROUP, CCopasiParameter::INT, CCopasiParameter::INVALID, CCopasiParameter::KEY, CCopasiParameterGroup::setValue(), CCopasiParameterGroup::size(), CCopasiParameter::STRING, TO_UTF8, CCopasiParameter::UDOUBLE, and CCopasiParameter::UINT.

Referenced by CQTaskMethodWidget::changeMethod(), CQTaskMethodWidget::saveMethod(), CQMCAWidget::saveParameterTable(), CQLNAWidget::saveParameterTable(), and setParameterValue().

97 {
98  if (index >= group->size())
99  return false;
100 
101  if (getParameterValue(group, index) == value) return true;
102 
103  bool ok;
104 
105  C_FLOAT64 DOUBLE;
106  C_INT32 INT;
107  unsigned C_INT32 UINT;
108  bool BOOL;
109  std::string STRING;
111 
112  switch (group->getType(index))
113  {
116  DOUBLE = value.toDouble(&ok);
117 
118  if (!ok) return false;
119 
120  return group->setValue(index, DOUBLE);
121  break;
122 
124  INT = value.toInt(&ok);
125 
126  if (!ok) return false;
127 
128  return group->setValue(index, INT);
129  break;
130 
132  UINT = value.toUInt(&ok);
133 
134  if (!ok) return false;
135 
136  return group->setValue(index, UINT);
137  break;
138 
140  UINT = value.toUShort(&ok);
141 
142  if (!ok) return false;
143 
144  if (UINT == 1) BOOL = true;
145  else if (UINT == 0) BOOL = false;
146  else return false;
147 
148  return group->setValue(index, BOOL);
149  break;
150 
153  STRING = TO_UTF8(value);
154  return group->setValue(index, STRING);
155  break;
156 
158  CN = std::string(TO_UTF8(value));
159  return group->setValue(index, CN);
160  break;
161 
164  return false;
165  break;
166 
167  default:
168  break;
169  }
170 
171  return false;
172 }
CCopasiParameter::Type getType(const std::string &name) const
#define C_INT32
Definition: copasi.h:90
bool setValue(const std::string &name, const CType &value)
QString getParameterValue(const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
Definition: qtUtilities.cpp:28
#define C_FLOAT64
Definition: copasi.h:92
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool setParameterValue ( CCopasiParameterGroup group,
const std::string &  name,
const QString &  value 
)

Set a parameter of a parameter group from a value given as a QString. Success = true is returned when the set operation was succesful, i.e., value == getParameterValue.

Parameters
CCopasiParameterGroup* group
conststd::string & name
constQString & value
Returns
bool success.

Definition at line 174 of file qtUtilities.cpp.

References CCopasiParameterGroup::getIndex(), and setParameterValue().

177 {return setParameterValue(group, group->getIndex(name), value);}
size_t getIndex(const std::string &name) const
bool setParameterValue(CCopasiParameterGroup *group, const size_t &index, const QString &value)
Definition: qtUtilities.cpp:94
void vectorOfStrings2QStringList ( std::vector< std::string >  vs,
QStringList &  qsl 
)

This converts a std::vector<std::string> into a QStringList

Definition at line 205 of file qtUtilities.cpp.

References FROM_UTF8.

Referenced by ReactionsWidget1::FillWidgetFromRI(), CQArrayAnnotationsWidget::initSelectionTable(), and ParameterTable::updateTable().

206 {
207  qsl.clear();
208  size_t i, imax = vs.size();
209 
210  for (i = 0; i < imax; ++i) qsl += FROM_UTF8(vs[i]);
211 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73