COPASI API  4.16.103
CQEFMReactionDM.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQEFMReactionDM.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 "CQEFMReactionDM.h"
20 #include "qtUtilities.h"
21 
25 #include "model/CReaction.h"
26 
28  CQBaseDataModel(parent),
29  mpTask(NULL),
30  mBeginModes(),
31  mModesSize(0),
32  mBeginReactions(),
33  mReactionsSize(0)
34 {}
35 
36 int CQEFMReactionDM::rowCount(const QModelIndex & C_UNUSED(parent)) const
37 {
38  if (mpTask == NULL)
39  return 0;
40 
41  return (int) mModesSize;
42 }
43 
44 int CQEFMReactionDM::columnCount(const QModelIndex & C_UNUSED(parent)) const
45 {
46  if (mpTask == NULL)
47  return 0;
48 
49  return (int)(mReactionsSize + 1); // For flux mode number
50 }
51 
52 Qt::ItemFlags CQEFMReactionDM::flags(const QModelIndex &index) const
53 {
54  if (!index.isValid())
55  return Qt::ItemIsEnabled;
56 
57  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
58 }
59 
60 QVariant CQEFMReactionDM::data(const QModelIndex &index, int role) const
61 {
62  if (!index.isValid())
63  return QVariant();
64 
65  if (index.row() >= rowCount())
66  return QVariant();
67 
68  if (role == Qt::DisplayRole || role == Qt::EditRole)
69  {
70  //std::vector< CFluxMode >::const_iterator itMode = mBeginModes + index.row();
71 
72  switch (index.column())
73  {
74  case COL_ROW_NUMBER:
75  return QVariant(index.row() + 1);
76  break;
77 
78  default:
79  return QVariant((mBeginModes + index.row())->getMultiplier(index.column() - 1));
80  }
81  }
82 
83  return QVariant();
84 }
85 
86 QVariant CQEFMReactionDM::headerData(int section, Qt::Orientation orientation,
87  int role) const
88 {
89  if (role != Qt::DisplayRole)
90  return QVariant();
91 
92  if (orientation == Qt::Horizontal)
93  {
94  switch (section)
95  {
96  case COL_ROW_NUMBER:
97  return QVariant(QString("#"));
98  break;
99 
100  default:
101  return QVariant(QString(FROM_UTF8((*(mBeginReactions + section - 1))->getObjectName())));
102  break;
103  }
104  }
105 
106  //Vertical header
107  return QString("%1").arg(section + 1);
108 }
109 
111 {
112  mpTask = pTask;
113 
114  if (mpTask != NULL)
115  {
116  mBeginModes = mpTask->getFluxModes().begin();
117  mModesSize = mpTask->getFluxModes().size();
118 
119  mBeginReactions = static_cast< const CEFMProblem * >(mpTask->getProblem())->getReorderedReactions().begin();
120  mReactionsSize = static_cast< const CEFMProblem * >(mpTask->getProblem())->getReorderedReactions().size();
121  }
122  else
123  {
124  mModesSize = 0;
125  mReactionsSize = 0;
126  }
127 }
128 
129 bool CQEFMReactionDM::setData(const QModelIndex & /* index */, const QVariant & /* value */, int /* role */)
130 {
131  return false;
132 }
133 
134 // virtual
135 bool CQEFMReactionDM::insertRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
136 {
137  return false;
138 }
139 
140 // virtual
141 bool CQEFMReactionDM::removeRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
142 {
143  return false;
144 }
145 
146 // virtual
147 bool CQEFMReactionDM::isDefaultRow(const QModelIndex& /* i */) const
148 {
149  return false;
150 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())
const std::vector< CFluxMode > & getFluxModes() const
Definition: CEFMTask.cpp:183
#define C_UNUSED(p)
Definition: copasi.h:220
CTSSATask * pTask
CQEFMReactionDM(QObject *parent=0)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
const CEFMTask * mpTask
std::vector< CFluxMode >::const_iterator mBeginModes
virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())
Qt::ItemFlags flags(const QModelIndex &index) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual bool isDefaultRow(const QModelIndex &i) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
std::vector< const CReaction * >::const_iterator mBeginReactions
void setTask(const CEFMTask *pTask)
QVariant data(const QModelIndex &index, int role) const
#define COL_ROW_NUMBER