COPASI API  4.16.103
CQTimeSeriesDM.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQTimeSeriesDM.cpp,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/17 18:21:25 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include "CQTimeSeriesDM.h"
15 #include "qtUtilities.h"
16 
17 #include "trajectory/CTimeSeries.h"
18 
20  CQBaseDataModel(parent),
21  mpTimeSeries(NULL),
22  mFramework(0)
23 {}
24 
26 {}
27 
28 // virtual
29 int CQTimeSeriesDM::rowCount(const QModelIndex & /* parent */) const
30 {
31  if (mpTimeSeries == NULL) return 0;
32 
33  return (int) mpTimeSeries->getRecordedSteps();
34 }
35 
36 // virtual
37 int CQTimeSeriesDM::columnCount(const QModelIndex & /* parent */) const
38 {
39  if (mpTimeSeries == NULL) return 0;
40 
41  return (int) mpTimeSeries->getNumVariables();
42 }
43 
44 // virtual
45 Qt::ItemFlags CQTimeSeriesDM::flags(const QModelIndex &index) const
46 {
47  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
48 }
49 
50 // virtual
51 QVariant CQTimeSeriesDM::data(const QModelIndex &index, int role) const
52 {
53  if (mpTimeSeries == NULL || role != Qt::DisplayRole) return QVariant();
54 
55  if (!index.isValid() ||
56  index.row() < 0 || rowCount() <= index.row() ||
57  index.column() < 0 || columnCount() <= index.column()) return QVariant();
58 
59  switch (mFramework)
60  {
61  case 0:
62  return QString::number(mpTimeSeries->getConcentrationData(index.row(), index.column()));
63 
64  case 1:
65  return QString::number(mpTimeSeries->getData(index.row(), index.column()));
66  }
67 
68  return QVariant();
69 }
70 
71 // virtual
72 QVariant CQTimeSeriesDM::headerData(int section, Qt::Orientation orientation,
73  int role) const
74 {
75  if (mpTimeSeries == NULL || role != Qt::DisplayRole) return QVariant();
76 
77  switch (orientation)
78  {
79  case Qt::Horizontal:
80 
81  if (section < 0 || columnCount() <= section) return QVariant();
82 
83  return QString(FROM_UTF8(mpTimeSeries->getTitle(section)));
84 
85  case Qt::Vertical:
86 
87  if (section < 0 || rowCount() <= section) return QVariant();
88 
89  return QString("%1").arg(section + 1);
90  }
91 
92  return QVariant();
93 }
94 
95 void CQTimeSeriesDM::setTimeSeries(const CTimeSeries * pTimeSeries)
96 {
97  mpTimeSeries = pTimeSeries;
98  reset();
99 }
100 
101 void CQTimeSeriesDM::setFramework(int framework)
102 {
103  if (mFramework == framework) return;
104 
105  mFramework = framework;
106  emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
107 }
108 
109 bool CQTimeSeriesDM::setData(const QModelIndex & /* index */, const QVariant & /* value */, int /* role */)
110 {
111  return false;
112 }
113 
114 // virtual
115 bool CQTimeSeriesDM::insertRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
116 {
117  return false;
118 }
119 
120 // virtual
121 bool CQTimeSeriesDM::removeRows(int /* position */, int /* rows */, const QModelIndex & /* index */)
122 {
123  return false;
124 }
125 
126 // virtual
127 bool CQTimeSeriesDM::isDefaultRow(const QModelIndex& /* i */) const
128 {
129  return false;
130 }
131 
132 
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
const size_t & getRecordedSteps() const
C_FLOAT64 getConcentrationData(const size_t &step, const size_t &variable) const
const size_t & getNumVariables() const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CQTimeSeriesDM(QObject *parent=0)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
const std::string & getTitle(const size_t &variable) const
void setFramework(int framework)
virtual bool isDefaultRow(const QModelIndex &i) const
void setTimeSeries(const CTimeSeries *pTimeSeries)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
const C_FLOAT64 & getData(const size_t &step, const size_t &variable) const
virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual ~CQTimeSeriesDM()
virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())
virtual Qt::ItemFlags flags(const QModelIndex &index) const
const CTimeSeries * mpTimeSeries
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const