COPASI API  4.16.103
CQEFMSpeciesDM.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQEFMSpeciesDM.cpp,v $
3 // $Revision: 1.6 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/10 16:03:10 $
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 "CQEFMSpeciesDM.h"
20 #include "qtUtilities.h"
21 
25 #include "model/CModel.h"
28 
30  CQBaseDataModel(parent),
31  mpTask(NULL),
32  mBeginModes(),
33  mModesSize(0),
34  mpModel(NULL),
35  mBeginSpecies(),
36  mSpeciesSize(0)
37 {}
38 
39 int CQEFMSpeciesDM::rowCount(const QModelIndex & C_UNUSED(parent)) const
40 {
41  if (mpTask == NULL)
42  return 0;
43 
44  return (int) mModesSize;
45 }
46 
47 int CQEFMSpeciesDM::columnCount(const QModelIndex & C_UNUSED(parent)) const
48 {
49  if (mpTask == NULL)
50  return 0;
51 
52  return (int)(mSpeciesSize + 1); // For flux mode number
53 }
54 
55 Qt::ItemFlags CQEFMSpeciesDM::flags(const QModelIndex &index) const
56 {
57  if (!index.isValid())
58  return Qt::ItemIsEnabled;
59 
60  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
61 }
62 
63 QVariant CQEFMSpeciesDM::data(const QModelIndex &index, int role) const
64 {
65  if (!index.isValid())
66  return QVariant();
67 
68  if (index.row() >= rowCount())
69  return QVariant();
70 
71  if (role == Qt::DisplayRole || role == Qt::EditRole)
72  {
73  //std::vector< CFluxMode >::const_iterator itMode = mBeginModes + index.row();
74 
75  switch (index.column())
76  {
77  case COL_ROW_NUMBER:
78  return QVariant(index.row() + 1);
79  break;
80 
81  default:
82  {
83  std::pair< C_FLOAT64, C_FLOAT64 > Changes =
84  mpTask->getSpeciesChanges(*(mBeginModes + index.row()), **(mBeginSpecies + index.column() - 1));
85 
86  if (Changes.first > 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() ||
87  Changes.second > 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
88  {
89  return QVariant(QString("-" + QString::number(Changes.first) + " | +" + QString::number(Changes.second)));
90  }
91 
92  return QVariant();
93  }
94  }
95  }
96 
97  return QVariant();
98 }
99 
100 QVariant CQEFMSpeciesDM::headerData(int section, Qt::Orientation orientation,
101  int role) const
102 {
103  if (role != Qt::DisplayRole)
104  return QVariant();
105 
106  if (orientation == Qt::Horizontal)
107  {
108  switch (section)
109  {
110  case COL_ROW_NUMBER:
111  return QVariant(QString("#"));
112  break;
113 
114  default:
115  return QVariant(QString(FROM_UTF8(CMetabNameInterface::getDisplayName(mpModel, **(mBeginSpecies + section - 1), false))));
116  break;
117  }
118  }
119 
120  return QString("%1").arg(section + 1);
121 }
122 
124 {
125  mpTask = pTask;
126 
127  if (mpTask != NULL)
128  {
129  mBeginModes = mpTask->getFluxModes().begin();
130  mModesSize = mpTask->getFluxModes().size();
131 
133 
134  if (mpModel != NULL)
135  {
138  }
139  else
140  {
141  mSpeciesSize = 0;
142  }
143  }
144  else
145  {
146  mModesSize = 0;
147  mpModel = NULL;
148  mSpeciesSize = 0;
149  }
150 }
151 
152 bool CQEFMSpeciesDM::setData(const QModelIndex & /* index */, const QVariant & /* value */, int /* role */)
153 {
154  return false;
155 }
156 
157 // virtual
158 bool CQEFMSpeciesDM::insertRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
159 {
160  return false;
161 }
162 
163 // virtual
164 bool CQEFMSpeciesDM::removeRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
165 {
166  return false;
167 }
168 
169 // virtual
170 bool CQEFMSpeciesDM::isDefaultRow(const QModelIndex& /* i */) const
171 {
172  return false;
173 }
virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
std::pair< C_FLOAT64, C_FLOAT64 > getSpeciesChanges(const CFluxMode &fluxMode, const CMetab &metab) const
Definition: CEFMTask.cpp:216
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
void setTask(const CEFMTask *pTask)
std::vector< CFluxMode >::const_iterator mBeginModes
std::vector< CMetab * >::const_iterator mBeginSpecies
virtual size_t size() const
iterator begin()
const std::vector< CFluxMode > & getFluxModes() const
Definition: CEFMTask.cpp:183
#define C_UNUSED(p)
Definition: copasi.h:220
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
CTSSATask * pTask
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
const CEFMTask * mpTask
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual bool isDefaultRow(const QModelIndex &i) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
CModel * getModel() const
const CModel * mpModel
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())
#define COL_ROW_NUMBER
CQEFMSpeciesDM(QObject *parent=0)