COPASI API  4.16.103
CQFluxModeDM.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQFluxModeDM.cpp,v $
3 // $Revision: 1.5 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/07 12:35:52 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "CQFluxModeDM.h"
20 #include "qtUtilities.h"
21 
24 
25 CQFluxModeDM::CQFluxModeDM(QObject *parent):
26  CQBaseDataModel(parent),
27  mpTask(NULL),
28  mBeginModes(),
29  mModesSize(0)
30 {}
31 
32 int CQFluxModeDM::rowCount(const QModelIndex & C_UNUSED(parent)) const
33 {
34  if (mpTask == NULL)
35  return 0;
36 
37  return (int) mModesSize;
38 }
39 
40 int CQFluxModeDM::columnCount(const QModelIndex & C_UNUSED(parent)) const
41 {
42  return FluxModeDM_COLUMNS;
43 }
44 
45 Qt::ItemFlags CQFluxModeDM::flags(const QModelIndex &index) const
46 {
47  if (!index.isValid())
48  return Qt::ItemIsEnabled;
49 
50  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
51 }
52 
53 QVariant CQFluxModeDM::data(const QModelIndex &index, int role) const
54 {
55  if (!index.isValid())
56  return QVariant();
57 
58  if (index.row() >= rowCount())
59  return QVariant();
60 
61  if (role == Qt::DisplayRole || role == Qt::EditRole)
62  {
63  std::vector< CFluxMode >::const_iterator itMode = mBeginModes + index.row();
64 
65  switch (index.column())
66  {
67  case COL_ROW_NUMBER:
68  return QVariant(index.row() + 1);
69  break;
70 
71  case COL_REVERSIBILITY:
72 
73  if (itMode->isReversible() == true)
74  {
75  return QVariant(QString("Reversible"));
76  }
77  else
78  {
79  return QVariant(QString("Irreversible"));
80  }
81 
82  break;
83 
84  case COL_REACTION_NAME:
85  return QVariant(QString(FROM_UTF8(mpTask->getFluxModeDescription(*itMode))));
86  break;
87 
89  {
90  std::string reactionEq = "";
91  std::string separator = "";
92 
93  CFluxMode::const_iterator itReaction = itMode->begin();
94  CFluxMode::const_iterator endReaction = itMode->end();
95 
96  for (; itReaction != endReaction; ++itReaction)
97  {
98  reactionEq += separator;
99  reactionEq += mpTask->getReactionEquation(itReaction);
100  separator = "\n";
101  }
102 
103  return QVariant(QString(FROM_UTF8(reactionEq)));
104  }
105  break;
106  }
107  }
108 
109  return QVariant();
110 }
111 
112 QVariant CQFluxModeDM::headerData(int section, Qt::Orientation orientation,
113  int role) const
114 {
115  if (role != Qt::DisplayRole)
116  return QVariant();
117 
118  if (orientation == Qt::Horizontal)
119  {
120  switch (section)
121  {
122  case COL_ROW_NUMBER:
123  return QVariant(QString("#"));
124  break;
125 
126  case COL_REVERSIBILITY:
127  return QVariant(QString("Reversibility"));
128  break;
129 
130  case COL_REACTION_NAME:
131  return QVariant(QString("Reaction Name"));
132  break;
133 
135  return QVariant(QString("Reaction Equation"));
136  break;
137 
138  default:
139  return QVariant();
140  break;
141  }
142  }
143 
144  //Vertical header
145  return QString("%1").arg(section + 1);
146 }
147 
149 {
150  mpTask = pTask;
151 
152  if (mpTask != NULL)
153  {
154  mBeginModes = mpTask->getFluxModes().begin();
155  mModesSize = mpTask->getFluxModes().size();
156  }
157  else
158  {
159  mModesSize = 0;
160  }
161 }
162 
163 bool CQFluxModeDM::setData(const QModelIndex & /* index */, const QVariant & /* value */,
164  int /* role */)
165 {
166  return false;
167 }
168 
169 // virtual
170 bool CQFluxModeDM::insertRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
171 {
172  return false;
173 }
174 
175 // virtual
176 bool CQFluxModeDM::removeRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
177 {
178  return false;
179 }
180 
181 // virtual
182 bool CQFluxModeDM::isDefaultRow(const QModelIndex& /* i */) const
183 {
184  return false;
185 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
std::string getReactionEquation(const std::map< size_t, C_FLOAT64 >::const_iterator &itReaction) const
Definition: CEFMTask.cpp:188
std::string getFluxModeDescription(const CFluxMode &fluxMode) const
Definition: CEFMTask.cpp:132
virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())
Qt::ItemFlags flags(const QModelIndex &index) const
size_t mModesSize
Definition: CQFluxModeDM.h:61
void setTask(const CEFMTask *pTask)
const std::vector< CFluxMode > & getFluxModes() const
Definition: CEFMTask.cpp:183
#define C_UNUSED(p)
Definition: copasi.h:220
#define COL_REVERSIBILITY
Definition: CQFluxModeDM.h:29
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
CTSSATask * pTask
virtual bool isDefaultRow(const QModelIndex &i) const
const CEFMTask * mpTask
Definition: CQFluxModeDM.h:59
QVariant data(const QModelIndex &index, int role) const
#define COL_REACTION_EQUATION
Definition: CQFluxModeDM.h:31
#define COL_REACTION_NAME
Definition: CQFluxModeDM.h:30
virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())
std::map< size_t, C_FLOAT64 >::const_iterator const_iterator
Definition: CFluxMode.h:43
#define FluxModeDM_COLUMNS
Definition: CQFluxModeDM.h:32
std::vector< CFluxMode >::const_iterator mBeginModes
Definition: CQFluxModeDM.h:60
CQFluxModeDM(QObject *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
#define COL_ROW_NUMBER