COPASI API  4.16.103
qtUtilities.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 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <QtCore/QString>
16 #include <QtCore/QFileInfo>
17 
18 #include "copasi.h"
19 #include "qtUtilities.h"
20 #include "CQMessageBox.h"
22 #include "utilities/CDirEntry.h"
23 
24 #ifdef DEBUG_UI
25 #include <QtCore/QtDebug>
26 #endif
27 
29  const size_t & index,
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 }
88 
90  const std::string & name,
92 {return getParameterValue(group, group->getIndex(name), type);}
93 
95  const size_t & index,
96  const QString & value)
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 }
173 
175  const std::string & name,
176  const QString & value)
177 {return setParameterValue(group, group->getIndex(name), value);}
178 
179 C_INT32 checkSelection(const QString & file)
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 }
204 
205 void vectorOfStrings2QStringList(std::vector<std::string> vs, QStringList & qsl)
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 }
virtual const std::string & getName(const size_t &index) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
size_t getIndex(const std::string &name) const
CCopasiParameter::Type getType(const std::string &name) const
bool setParameterValue(CCopasiParameterGroup *group, const size_t &index, const QString &value)
Definition: qtUtilities.cpp:94
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define C_INT32
Definition: copasi.h:90
CRegisteredObjectName * pCN
void vectorOfStrings2QStringList(std::vector< std::string > vs, QStringList &qsl)
C_INT32 checkSelection(const QString &file)
bool setValue(const std::string &name, const CType &value)
static bool isWritable(const std::string &path)
Definition: CDirEntry.cpp:95
unsigned C_INT32 * pUINT
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
const CCopasiParameter::Value & getValue(const std::string &name) const
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)