COPASI API  4.16.103
CQCurrentValueTable.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "CQCurrentValueTable.h"
12 
13 #include <QtGui/QHeaderView>
14 #include <QtGui/QTableWidget>
15 #include <QtGui/QTableWidgetItem>
16 #include <QtGui/QPushButton>
17 #include <QtGui/QLayout>
18 #include <QtGui/QHBoxLayout>
19 #include <QtGui/QVBoxLayout>
20 #include <QtGui/QButtonGroup>
21 
22 #include <iostream>
23 
24 #include "copasi/UI/qtUtilities.h"
26 
28  : QWidget(parent)
29 {
30  init();
31  this->show();
32 }
33 
35 {
36  QVBoxLayout* pLayout = new QVBoxLayout(this);
37  this->mpTable = new QTableWidget(this);
38  pLayout->addWidget(this->mpTable);
39  this->mpTable->setRowCount(1);
40  this->mpTable->setColumnCount(2);
41  // set default entry
42  QHeaderView *header = this->mpTable->horizontalHeader();
43  this->mpTable->setHorizontalHeaderLabels(QStringList() << "Metabolite" << "Concentration");
44  header = this->verticalHeader();
45  header->hide();
46  QTableWidgetItem* pItem = new QTableWidgetItem("*** no time series load ***");
47  this->mpTable->setItem(0, 0, pItem);
48  pItem = new QTableWidgetItem("NaN");
49  this->mpTable->setItem(0, 1, pItem);
50  this->mpTable->item(0, 0)->setFlags(this->mpTable->item(0, 0)->flags() & ~Qt::ItemIsEditable);
51  QHBoxLayout *hLayout = new QHBoxLayout();
52  this->mpCheckAllButton = new QPushButton("Check all", this);
53  this->mpUncheckAllButton = new QPushButton("Uncheck all", this);
54  hLayout->addWidget(mpCheckAllButton);
55  hLayout->addWidget(mpUncheckAllButton);
56  pLayout->addLayout(hLayout);
57  connect(this->mpTable, SIGNAL(cellChanged(int, int)), this, SLOT(tableValueChanged(int, int)));
58  connect(this->mpCheckAllButton, SIGNAL(clicked()), this, SLOT(slotCheckAllClicked()));
59  connect(this->mpUncheckAllButton, SIGNAL(clicked()), this, SLOT(slotUncheckAllClicked()));
60  resize(QSize(202, 153).expandedTo(minimumSizeHint()));
61 }
62 
64 {}
65 
66 // sets complete row: 1. name of reactant 2. concentration (or number of particles) value
67 void CQCurrentValueTable::setRowInTable(int row, std::string key, std::string s, C_FLOAT64 val)
68 {
69  QTableWidgetItem * pCheckItem = new QTableWidgetItem(FROM_UTF8(s));
70  // make the item a check item and make it non editable
71  pCheckItem->setFlags((pCheckItem->flags() & ~Qt::ItemIsEditable) | Qt::ItemIsUserCheckable);
72  this->mpTable->setItem(row, 0, pCheckItem);
73  pCheckItem->setCheckState(Qt::Checked); // initially checked
74  pCheckItem = new QTableWidgetItem(QString::number(val));
75  this->mpTable->setItem(row, 1, pCheckItem);
76  this->setKeyIndex(key, row); // remember which node key is in which row
77 }
78 
79 // changes the value in a given row (value in second column is replaced)
81 {
82  if (this->mpTable->item(row, 1) == NULL)
83  {
84  this->mpTable->setItem(row, 1, new QTableWidgetItem(QString::number(val)));
85  }
86  else
87  {
88  this->mpTable->item(row, 1)->setText(QString::number(val));
89  }
90 }
91 
92 // sets (numerical) value as text into the second column of the corresponding reactant (given by row index)
93 // TODO this method does exactly the same thing as the one above, so we could
94 // TODO get rid of one of them
96 {
97  this->updateRowInTable(row, val);
98 }
99 
101 {
102  int i;
103 
104  for (i = 0; i < this->mpTable->rowCount(); i++)
105  {
106  QTableWidgetItem *pCell = this->mpTable->item(i, 0);
107  assert(pCell != NULL);
108 
109  if (pCell->flags() & Qt::ItemIsUserCheckable)
110  {
111  // is cell a QCheckTableItem?
112  pCell->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
113  CQLayoutMainWindow * pTmp = dynamic_cast<CQLayoutMainWindow *>(parentWidget()->parentWidget()->parentWidget()->parentWidget());
114  assert(pTmp);
115 
116  if (pTmp)
117  {
118  if (checked == true)
119  {
120  pTmp->addItemInAnimation(this->getKeyForRow(i));
121  }
122  else
123  {
124  pTmp->removeItemInAnimation(this->getKeyForRow(i));
125  }
126  }
127  }
128  }
129 }
130 
132 {
133  this->setAllBoxesChecked(false);
134 }
135 
136 //store row index for every node key
137 void CQCurrentValueTable::setKeyIndex(std::string key, int row)
138 {
139  this->mIndexMap.insert(std::pair<int, std::string>
140  (row,
141  key));
142 }
143 
144 std::string CQCurrentValueTable::getKeyForRow(int row) const
145 {
146  std::string s = "";
147 
148  std::map<int, std::string>::const_iterator itIndexObj = this->mIndexMap.find(row);
149 
150  if (itIndexObj != this->mIndexMap.end())
151  {
152  s = (*itIndexObj).second;
153  }
154 
155  return s;
156 }
157 
159 {
160  QTableWidgetItem *pCell = this->mpTable->item(row, 0);
161  assert(pCell != NULL);
162  return pCell->checkState() == Qt::Checked;
163 }
164 
166 {
167  this->setAllBoxesChecked();
168 }
169 
171 {
172  this->setAllBoxesUnchecked();
173 }
174 
176 {
177  this->mpTable->setRowCount(rows);
178 }
179 
181 {
182  this->mpTable->setColumnCount(columns);
183 }
184 
186 {
187  return this->mpTable->rowCount();
188 }
189 
191 {
192  return this->mpTable->verticalHeader();
193 }
194 
195 /**
196  * This slot is caled whenever a value in the table changes, i.e. whenever
197  * a species is activated or deactived by it's checkbox.
198  * This information is broadcasted by emitting another signal which contains the row number.
199  */
200 void CQCurrentValueTable::tableValueChanged(int row, int /*column*/)
201 {
202  emit valueChanged(row);
203 }
std::string getKeyForRow(int row) const
QHeaderView * verticalHeader()
void setValue(int row, C_FLOAT64 val)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
QPushButton * mpUncheckAllButton
bool getValueForRow(int row) const
CQCurrentValueTable(QWidget *parent=0)
void valueChanged(int row)
void removeItemInAnimation(std::string s)
void setAllBoxesChecked(bool checked=true)
std::map< int, std::string > mIndexMap
void setRowInTable(int row, std::string key, std::string s, C_FLOAT64 val)
void tableValueChanged(int row, int column)
#define C_FLOAT64
Definition: copasi.h:92
void setKeyIndex(std::string key, int row)
void addItemInAnimation(std::string s)
QPushButton * mpCheckAllButton
void setNumCols(int columns)
void updateRowInTable(int row, C_FLOAT64 val)