COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
CQFunctionDM Class Reference

#include <CQFunctionDM.h>

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

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQFunctionDM (QObject *parent=0)
 
QVariant data (const QModelIndex &index, int role) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
bool removeRows (QModelIndexList rows, const QModelIndex &index=QModelIndex())
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
- Public Member Functions inherited from CQBaseDataModel
virtual bool clear ()
 
 CQBaseDataModel (QObject *parent=0)
 
QString createNewName (const QString name, const int nameCol)
 
bool insertRow ()
 
virtual bool isDefaultRow (const QModelIndex &i) const
 
bool removeRow (int position)
 

Protected Member Functions

bool insertRows (int position, int rows, const QModelIndex &index=QModelIndex())
 
bool removeRows (int position, int rows, const QModelIndex &index=QModelIndex())
 

Private Member Functions

bool isFunctionReadOnly (const QModelIndex &index) const
 

Additional Inherited Members

- Signals inherited from CQBaseDataModel
void notifyGUI (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Detailed Description

Definition at line 32 of file CQFunctionDM.h.

Constructor & Destructor Documentation

CQFunctionDM::CQFunctionDM ( QObject *  parent = 0)

Definition at line 22 of file CQFunctionDM.cpp.

23  : CQBaseDataModel(parent)
24 
25 {
26 }
CQBaseDataModel(QObject *parent=0)

Member Function Documentation

int CQFunctionDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 32 of file CQFunctionDM.cpp.

References TOTAL_COLS_FUNCTIONS.

Referenced by CQFunctionsWidget::keyPressEvent().

33 {
34  return TOTAL_COLS_FUNCTIONS;
35 }
#define TOTAL_COLS_FUNCTIONS
Definition: CQFunctionDM.h:30
QVariant CQFunctionDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 72 of file CQFunctionDM.cpp.

References COL_MATH_DESC_FUNCTIONS, COL_NAME_FUNCTIONS, COL_ROW_NUMBER, COL_SBML_ID_FUNCTIONS, COL_TYPE_FUNCTIONS, flags(), FROM_UTF8, CCopasiRootContainer::getFunctionList(), CEvaluationTree::getInfix(), CCopasiObject::getObjectName(), CEvaluationTree::getType(), CQBaseDataModel::isDefaultRow(), CFunctionDB::loadedFunctions(), rowCount(), and CEvaluationTree::TypeName.

Referenced by setData().

73 {
74  if (!index.isValid())
75  return QVariant();
76 
77  if (index.row() >= rowCount())
78  return QVariant();
79 
80  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
81  return QColor(Qt::darkGray);
82 
83  if (role == Qt::DisplayRole || role == Qt::EditRole)
84  {
85  if (isDefaultRow(index))
86  {
87  switch (index.column())
88  {
89  case COL_ROW_NUMBER:
90  return QVariant(QString(""));
91  case COL_NAME_FUNCTIONS:
92  return QVariant(QString("New Function"));
93  case COL_TYPE_FUNCTIONS:
94  return QVariant(QString(FROM_UTF8(CEvaluationTree::TypeName[4])));
95  default:
96  return QVariant(QString(""));
97  }
98  }
99  else
100  {
102 
103  if (pFunc == NULL)
104  return QVariant();
105 
106  switch (index.column())
107  {
108  case COL_ROW_NUMBER:
109  return QVariant(index.row() + 1);
110 
111  case COL_NAME_FUNCTIONS:
112  return QVariant(QString(FROM_UTF8(pFunc->getObjectName())));
113 
114  case COL_TYPE_FUNCTIONS:
115  return QVariant(QString(FROM_UTF8(CEvaluationTree::TypeName[pFunc->getType()])));
116 
118  return QVariant(QString(FROM_UTF8(pFunc->getInfix())));
119 
121  return QVariant();
122  }
123  }
124  }
125 
126  return QVariant();
127 }
CCopasiVectorN< CFunction > & loadedFunctions()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
const CEvaluationTree::Type & getType() const
static const std::string TypeName[]
static CFunctionDB * getFunctionList()
#define COL_SBML_ID_FUNCTIONS
Definition: CQFunctionDM.h:29
#define COL_MATH_DESC_FUNCTIONS
Definition: CQFunctionDM.h:28
#define COL_TYPE_FUNCTIONS
Definition: CQFunctionDM.h:27
#define COL_NAME_FUNCTIONS
Definition: CQFunctionDM.h:26
virtual bool isDefaultRow(const QModelIndex &i) const
Qt::ItemFlags flags(const QModelIndex &index) const
const std::string & getInfix() const
#define COL_ROW_NUMBER
Qt::ItemFlags CQFunctionDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 37 of file CQFunctionDM.cpp.

References COL_NAME_FUNCTIONS, CQBaseDataModel::isDefaultRow(), and isFunctionReadOnly().

Referenced by data().

38 {
39  if (!index.isValid())
40  return Qt::ItemIsEnabled;
41 
42  if (!isDefaultRow(index) && isFunctionReadOnly(index))
43  return QAbstractItemModel::flags(index);
44 
45  if (index.column() == COL_NAME_FUNCTIONS)
46  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
47  else
48  return QAbstractItemModel::flags(index);
49 }
bool isFunctionReadOnly(const QModelIndex &index) const
#define COL_NAME_FUNCTIONS
Definition: CQFunctionDM.h:26
virtual bool isDefaultRow(const QModelIndex &i) const
QVariant CQFunctionDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 129 of file CQFunctionDM.cpp.

References COL_MATH_DESC_FUNCTIONS, COL_NAME_FUNCTIONS, COL_ROW_NUMBER, COL_SBML_ID_FUNCTIONS, and COL_TYPE_FUNCTIONS.

131 {
132  if (role != Qt::DisplayRole)
133  return QVariant();
134 
135  if (orientation == Qt::Horizontal)
136  {
137  switch (section)
138  {
139  case COL_ROW_NUMBER:
140  return QVariant(QString("#"));
141  case COL_NAME_FUNCTIONS:
142  return QVariant(QString("Name"));
143  case COL_TYPE_FUNCTIONS:
144  return QVariant(QString("Type"));
146  return QVariant(QString("Mathematical Description"));
148  return QVariant(QString("SBML ID"));
149  default:
150  return QVariant();
151  }
152  }
153  else
154  return QString("%1").arg(section + 1);
155 }
#define COL_SBML_ID_FUNCTIONS
Definition: CQFunctionDM.h:29
#define COL_MATH_DESC_FUNCTIONS
Definition: CQFunctionDM.h:28
#define COL_TYPE_FUNCTIONS
Definition: CQFunctionDM.h:27
#define COL_NAME_FUNCTIONS
Definition: CQFunctionDM.h:26
#define COL_ROW_NUMBER
bool CQFunctionDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 219 of file CQFunctionDM.cpp.

References CFunctionDB::add(), ListViews::ADD, COL_NAME_FUNCTIONS, CQBaseDataModel::createNewName(), ListViews::FUNCTION, CCopasiRootContainer::getFunctionList(), CFunction::getKey(), CQBaseDataModel::notifyGUI(), and TO_UTF8.

220 {
221  beginInsertRows(QModelIndex(), position, position + rows - 1);
222 
223  for (int row = 0; row < rows; ++row)
224  {
225  CFunction *pFunc;
228  }
229 
230  endInsertRows();
231 
232  return true;
233 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const std::string & getKey() const
Definition: CFunction.cpp:58
QString createNewName(const QString name, const int nameCol)
static CFunctionDB * getFunctionList()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
#define COL_NAME_FUNCTIONS
Definition: CQFunctionDM.h:26
bool add(CFunction *pFunction, const bool &adopt)
bool CQFunctionDM::isFunctionReadOnly ( const QModelIndex &  index) const
private

Definition at line 51 of file CQFunctionDM.cpp.

References CEvaluationTree::Expression, CEvaluationTree::Function, CCopasiRootContainer::getFunctionList(), CEvaluationTree::getType(), CFunctionDB::loadedFunctions(), CEvaluationTree::MassAction, CEvaluationTree::MathExpression, CEvaluationTree::PreDefined, and CEvaluationTree::UserDefined.

Referenced by flags(), and removeRows().

52 {
54 
55  switch (pFunc->getType())
56  {
59  return true;
60  break;
65  return false;
66  break;
67  }
68 
69  return true;
70 }
CCopasiVectorN< CFunction > & loadedFunctions()
const CEvaluationTree::Type & getType() const
static CFunctionDB * getFunctionList()
bool CQFunctionDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 279 of file CQFunctionDM.cpp.

References C_INVALID_INDEX, CQMessageBox::confirmDelete(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CEvaluationTree::getDeletedObjects(), CCopasiRootContainer::getFunctionList(), CCopasiDataModel::getModel(), CCopasiObject::getObjectName(), CQBaseDataModel::isDefaultRow(), CFunctionDB::loadedFunctions(), and CQBaseDataModel::removeRow().

Referenced by CQFunctionsWidget::deleteSelectedFunctions().

280 {
281  if (rows.isEmpty())
282  return false;
283 
284  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
286  assert(pDataModel != NULL);
287  CModel * pModel = pDataModel->getModel();
288 
289  if (pModel == NULL)
290  return false;
291 
292 //Build the list of pointers to items to be deleted
293 //before actually deleting any item.
294  QList <CEvaluationTree *> pFunctions;
295  QModelIndexList::const_iterator i;
296 
297  for (i = rows.begin(); i != rows.end(); ++i)
298  {
300  pFunctions.append(CCopasiRootContainer::getFunctionList()->loadedFunctions()[(*i).row()]);
301  }
302 
303  QList <CEvaluationTree *>::const_iterator j;
304 
305  for (j = pFunctions.begin(); j != pFunctions.end(); ++j)
306  {
307  CEvaluationTree * pFunction = *j;
308 
309  size_t delRow =
310  CCopasiRootContainer::getFunctionList()->loadedFunctions().CCopasiVector< CFunction >::getIndex(pFunction);
311 
312  if (delRow != C_INVALID_INDEX)
313  {
314  QMessageBox::StandardButton choice =
315  CQMessageBox::confirmDelete(NULL, "function",
316  FROM_UTF8(pFunction->getObjectName()),
317  pFunction->getDeletedObjects());
318 
319  if (choice == QMessageBox::Ok)
320  removeRow((int) delRow);
321  }
322  }
323 
324  return true;
325 }
CCopasiVectorN< CFunction > & loadedFunctions()
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
#define C_INVALID_INDEX
Definition: copasi.h:222
bool removeRow(int position)
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiObject::DataObjectSet getDeletedObjects() const
static CFunctionDB * getFunctionList()
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQFunctionDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 235 of file CQFunctionDM.cpp.

References CCopasiVector< T >::begin(), ListViews::DELETE, ListViews::FUNCTION, CCopasiRootContainer::getFunctionList(), isFunctionReadOnly(), CFunctionDB::loadedFunctions(), CQBaseDataModel::notifyGUI(), and CFunctionDB::removeFunction().

236 {
237  if (rows <= 0)
238  return true;
239 
240  std::vector< std::string > DeletedKeys;
241  DeletedKeys.resize(rows);
242 
243  std::vector< std::string >::iterator itDeletedKey;
244  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();
245 
248  int row = 0;
249 
250  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow, ++row)
251  {
252  if (isFunctionReadOnly(this->index(position + row, 0)))
253  {
254  *itDeletedKey = "";
255  }
256  else
257  {
258  *itDeletedKey = (*itRow)->getKey();
259  }
260  }
261 
262  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++row)
263  {
264  if (*itDeletedKey != "")
265  {
266  beginRemoveRows(QModelIndex(), position + row, position + row);
267 
269  emit notifyGUI(ListViews::FUNCTION, ListViews::DELETE, *itDeletedKey);
270  emit notifyGUI(ListViews::FUNCTION, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
271 
272  endRemoveRows();
273  }
274  }
275 
276  return true;
277 }
CCopasiVectorN< CFunction > & loadedFunctions()
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
iterator begin()
bool isFunctionReadOnly(const QModelIndex &index) const
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
static CFunctionDB * getFunctionList()
bool removeFunction(size_t index)
int CQFunctionDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 28 of file CQFunctionDM.cpp.

References CCopasiRootContainer::getFunctionList(), CFunctionDB::loadedFunctions(), and CCopasiVector< T >::size().

Referenced by data(), and CQFunctionsWidget::deleteSelectedFunctions().

29 {
31 }
CCopasiVectorN< CFunction > & loadedFunctions()
virtual size_t size() const
static CFunctionDB * getFunctionList()
bool CQFunctionDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 157 of file CQFunctionDM.cpp.

References ListViews::CHANGE, COL_MATH_DESC_FUNCTIONS, COL_NAME_FUNCTIONS, COL_TYPE_FUNCTIONS, CQBaseDataModel::createNewName(), data(), FROM_UTF8, ListViews::FUNCTION, CCopasiRootContainer::getFunctionList(), CCopasiObject::getKey(), CCopasiObject::getObjectName(), CQMessageBox::information(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), CFunctionDB::loadedFunctions(), CQBaseDataModel::notifyGUI(), CEvaluationTree::setInfix(), CCopasiObject::setObjectName(), and TO_UTF8.

159 {
160  if (index.isValid() && role == Qt::EditRole)
161  {
162  bool defaultRow = isDefaultRow(index);
163 
164  if (defaultRow)
165  {
166  if (index.data() != value)
167  insertRow();
168  else
169  return false;
170  }
171 
173 
174  if (pFunc == NULL)
175  return false;
176 
177  if (index.column() == COL_NAME_FUNCTIONS)
178  pFunc->setObjectName(TO_UTF8(value.toString()));
179  else if (index.column() == COL_TYPE_FUNCTIONS)
180  {
181  if (index.data() != value)
182  {
183  QString msg;
184  msg = "Type must not be changed for '" + FROM_UTF8(pFunc->getObjectName()) + "'.\n";
185 
187  "Unable to change Function Type",
188  msg,
189  QMessageBox::Ok, QMessageBox::Ok);
190  }
191  }
192  else if (index.column() == COL_MATH_DESC_FUNCTIONS)
193  {
194  if (index.data() != value)
195  {
196  if (!pFunc->setInfix(TO_UTF8(value.toString())))
197  {
198  QString msg;
199  msg = "Incorrect mathematical description'" + FROM_UTF8(pFunc->getObjectName()) + "'.\n";
200 
202  "Unable to change mathematical description",
203  msg,
204  QMessageBox::Ok, QMessageBox::Ok);
205  }
206  }
207  }
208 
209  if (defaultRow && this->index(index.row(), COL_NAME_FUNCTIONS).data().toString() == "function")
211 
212  emit dataChanged(index, index);
214  }
215 
216  return true;
217 }
CCopasiVectorN< CFunction > & loadedFunctions()
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const std::string & getObjectName() const
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual const std::string & getKey() const
QVariant data(const QModelIndex &index, int role) const
QString createNewName(const QString name, const int nameCol)
static CFunctionDB * getFunctionList()
#define COL_MATH_DESC_FUNCTIONS
Definition: CQFunctionDM.h:28
#define COL_TYPE_FUNCTIONS
Definition: CQFunctionDM.h:27
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
#define COL_NAME_FUNCTIONS
Definition: CQFunctionDM.h:26
virtual bool isDefaultRow(const QModelIndex &i) const
bool setObjectName(const std::string &name)
virtual bool setInfix(const std::string &infix)

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