COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CQCompartmentDM Class Reference

#include <CQCompartmentDM.h>

Inheritance diagram for CQCompartmentDM:
Inheritance graph
[legend]
Collaboration diagram for CQCompartmentDM:
Collaboration graph
[legend]

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQCompartmentDM (QObject *parent=0)
 
virtual QVariant data (const QModelIndex &index, int role) const
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
const std::vector< unsigned
C_INT32 > & 
getItemToType ()
 
const QStringList & getTypes ()
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
bool removeRows (QModelIndexList rows, const QModelIndex &index=QModelIndex())
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
- Public Member Functions inherited from CQBaseDataModel
virtual bool clear ()
 
 CQBaseDataModel (QObject *parent=0)
 
QString createNewName (const QString name, const int nameCol)
 
bool insertRow ()
 
virtual bool isDefaultRow (const QModelIndex &i) const
 
bool removeRow (int position)
 

Protected Member Functions

bool insertRows (int position, int rows, const QModelIndex &index=QModelIndex())
 
bool removeRows (int position, int rows, const QModelIndex &index=QModelIndex())
 

Protected Attributes

std::vector< unsigned C_INT32mItemToType
 
QStringList mTypes
 

Additional Inherited Members

- Signals inherited from CQBaseDataModel
void notifyGUI (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Detailed Description

Definition at line 35 of file CQCompartmentDM.h.

Constructor & Destructor Documentation

CQCompartmentDM::CQCompartmentDM ( QObject *  parent = 0)

Definition at line 26 of file CQCompartmentDM.cpp.

References CModelEntity::ASSIGNMENT, CModelEntity::FIXED, FROM_UTF8, mItemToType, mTypes, CModelEntity::ODE, and CModelEntity::StatusName.

27  : CQBaseDataModel(parent)
28 
29 {
33 
34  mItemToType.push_back(CModelEntity::FIXED);
35  mItemToType.push_back(CModelEntity::ASSIGNMENT);
36  mItemToType.push_back(CModelEntity::ODE);
37 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
std::vector< unsigned C_INT32 > mItemToType
CQBaseDataModel(QObject *parent=0)
QStringList mTypes

Member Function Documentation

int CQCompartmentDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 53 of file CQCompartmentDM.cpp.

References TOTAL_COLS_COMPARTMENTS.

Referenced by CQCompartmentsWidget::keyPressEvent().

54 {
56 }
#define TOTAL_COLS_COMPARTMENTS
QVariant CQCompartmentDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 76 of file CQCompartmentDM.cpp.

References COL_EXPRESSION_COMPARTMENTS, COL_IEXPRESSION_COMPARTMENTS, COL_IVOLUME, COL_NAME_COMPARTMENTS, COL_RATE_COMPARTMENTS, COL_ROW_NUMBER, COL_TYPE_COMPARTMENTS, COL_VOLUME, flags(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CExpression::getDisplayString(), CModelEntity::getExpressionPtr(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getInitialValue(), CCopasiObject::getObjectName(), CModelEntity::getRate(), CModelEntity::getStatus(), CModelEntity::getValue(), CQBaseDataModel::isDefaultRow(), mItemToType, rowCount(), and CModelEntity::StatusName.

Referenced by flags(), and setData().

77 {
78  if (!index.isValid())
79  return QVariant();
80 
81  if (index.row() >= rowCount())
82  return QVariant();
83 
84  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
85  return QColor(Qt::darkGray);
86 
87  if (role == Qt::DisplayRole || role == Qt::EditRole)
88  {
89  if (isDefaultRow(index))
90  {
91  switch (index.column())
92  {
93  case COL_ROW_NUMBER:
94  return QVariant(QString(""));
95 
97  return QVariant(QString("New Compartment"));
98 
100  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[0]])));
101 
102  case COL_IVOLUME:
103  return QVariant(QString::number(1.0, 'g', 10));
104 
105  default:
106  return QVariant(QString(""));
107  }
108  }
109  else
110  {
111  CCompartment *pComp = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[index.row()];
112  const CExpression * pExpression = NULL;
113 
114  switch (index.column())
115  {
116  case COL_ROW_NUMBER:
117  return QVariant(index.row() + 1);
118 
120  return QVariant(QString(FROM_UTF8(pComp->getObjectName())));
121 
123  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[pComp->getStatus()])));
124 
125  case COL_IVOLUME:
126 
127  if (role == Qt::EditRole)
128  return QVariant(QString::number(pComp->getInitialValue(), 'g', 10));
129  else
130  return QVariant(pComp->getInitialValue());
131 
132  case COL_VOLUME:
133  return QVariant(pComp->getValue());
134 
136  return QVariant(pComp->getRate());
137 
139  {
140  pExpression = pComp->getInitialExpressionPtr();
141 
142  if (pExpression != NULL)
143  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
144  else
145  return QVariant();
146  }
147 
149  {
150  pExpression = pComp->getExpressionPtr();
151 
152  if (pExpression != NULL)
153  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
154  else
155  return QVariant();
156  }
157  }
158  }
159  }
160 
161  return QVariant();
162 }
const CExpression * getExpressionPtr() const
#define COL_VOLUME
virtual Qt::ItemFlags flags(const QModelIndex &index) const
#define COL_NAME_COMPARTMENTS
#define COL_TYPE_COMPARTMENTS
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
const C_FLOAT64 & getRate() const
const std::string & getObjectName() const
std::vector< unsigned C_INT32 > mItemToType
const std::string & getDisplayString() const
#define COL_IEXPRESSION_COMPARTMENTS
#define COL_IVOLUME
const C_FLOAT64 & getInitialValue() const
#define COL_EXPRESSION_COMPARTMENTS
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const C_FLOAT64 & getValue() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
#define COL_RATE_COMPARTMENTS
const CModelEntity::Status & getStatus() const
virtual bool isDefaultRow(const QModelIndex &i) const
const CExpression * getInitialExpressionPtr() const
#define COL_ROW_NUMBER
Qt::ItemFlags CQCompartmentDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 58 of file CQCompartmentDM.cpp.

References CModelEntity::ASSIGNMENT, COL_IVOLUME, COL_NAME_COMPARTMENTS, COL_TYPE_COMPARTMENTS, data(), FROM_UTF8, and CModelEntity::StatusName.

Referenced by data().

59 {
60  if (!index.isValid())
61  return Qt::ItemIsEnabled;
62 
63  if (index.column() == COL_NAME_COMPARTMENTS || index.column() == COL_TYPE_COMPARTMENTS)
64  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
65  else if (index.column() == COL_IVOLUME)
66  {
67  if (this->index(index.row(), COL_TYPE_COMPARTMENTS).data() == QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT])))
68  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEnabled;
69  else
70  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
71  }
72  else
73  return QAbstractItemModel::flags(index);
74 }
#define COL_NAME_COMPARTMENTS
#define COL_TYPE_COMPARTMENTS
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
virtual QVariant data(const QModelIndex &index, int role) const
#define COL_IVOLUME
const std::vector< unsigned C_INT32 > & CQCompartmentDM::getItemToType ( )

Definition at line 44 of file CQCompartmentDM.cpp.

References mItemToType.

45 {
46  return mItemToType;
47 }
std::vector< unsigned C_INT32 > mItemToType
const QStringList & CQCompartmentDM::getTypes ( )

Definition at line 39 of file CQCompartmentDM.cpp.

References mTypes.

Referenced by CQCompartmentsWidget::CQCompartmentsWidget().

40 {
41  return mTypes;
42 }
QStringList mTypes
QVariant CQCompartmentDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 164 of file CQCompartmentDM.cpp.

References COL_EXPRESSION_COMPARTMENTS, COL_IEXPRESSION_COMPARTMENTS, COL_IVOLUME, COL_NAME_COMPARTMENTS, COL_RATE_COMPARTMENTS, COL_ROW_NUMBER, COL_TYPE_COMPARTMENTS, COL_VOLUME, FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CModel::getVolumeRateUnitsDisplayString(), and CModel::getVolumeUnitsDisplayString().

166 {
167  if (role != Qt::DisplayRole)
168  return QVariant();
169 
170  if (orientation == Qt::Horizontal)
171  {
172  QString ValueUnits, RateUnits, ExpressionUnits;
173  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
174  const CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
175 
176  if (pModel)
177  {
178  ValueUnits = FROM_UTF8(pModel->getVolumeUnitsDisplayString());
179 
180  if (!ValueUnits.isEmpty())
181  ValueUnits = "\n(" + ValueUnits + ")";
182 
183  RateUnits = FROM_UTF8(pModel->getVolumeRateUnitsDisplayString());
184 
185  if (!RateUnits.isEmpty())
186  RateUnits = "\n(" + RateUnits + ")";
187 
188  if (!ValueUnits.isEmpty() && !RateUnits.isEmpty())
189  {
190  if (ValueUnits == RateUnits)
191  ExpressionUnits = ValueUnits;
192  else
193  ExpressionUnits = "\n(" + FROM_UTF8(pModel->getVolumeUnitsDisplayString()) + " or " + FROM_UTF8(pModel->getVolumeRateUnitsDisplayString()) + ")";
194  }
195  else if (!ValueUnits.isEmpty())
196  ExpressionUnits = "\n(" + FROM_UTF8(pModel->getVolumeUnitsDisplayString()) + " or 1)";
197  else if (!RateUnits.isEmpty())
198  ExpressionUnits = "\n(1 or " + FROM_UTF8(pModel->getVolumeRateUnitsDisplayString()) + ")";
199  }
200 
201  switch (section)
202  {
203  case COL_ROW_NUMBER:
204  return QVariant(QString("#"));
205 
207  return QVariant(QString("Name"));
208 
210  return QVariant(QString(" Type "));
211 
212  case COL_IVOLUME:
213  return QVariant("Initial Volume" + ValueUnits);
214 
215  case COL_VOLUME:
216  return QVariant("Volume" + ValueUnits);
217 
219  return QVariant("Rate" + RateUnits);
220 
222  return QVariant("Initial Expression" + ValueUnits);
223 
225  return QVariant("Expression" + ExpressionUnits);
226 
227  default:
228  return QVariant();
229  }
230  }
231  else //Vertical header
232  return QString("%1").arg(section + 1);
233 }
#define COL_VOLUME
#define COL_NAME_COMPARTMENTS
#define COL_TYPE_COMPARTMENTS
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
std::string getVolumeRateUnitsDisplayString() const
Definition: CModel.cpp:4571
#define COL_IEXPRESSION_COMPARTMENTS
#define COL_IVOLUME
std::string getVolumeUnitsDisplayString() const
Definition: CModel.cpp:4547
#define COL_EXPRESSION_COMPARTMENTS
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
#define COL_RATE_COMPARTMENTS
Definition: CModel.h:50
#define COL_ROW_NUMBER
bool CQCompartmentDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 277 of file CQCompartmentDM.cpp.

References ListViews::ADD, COL_NAME_COMPARTMENTS, ListViews::COMPARTMENT, CQBaseDataModel::createNewName(), CCopasiRootContainer::getDatamodelList(), CModelEntity::getKey(), CQBaseDataModel::notifyGUI(), and TO_UTF8.

278 {
279  beginInsertRows(QModelIndex(), position, position + rows - 1);
280 
281  for (int row = 0; row < rows; ++row)
282  {
283  CCompartment * pComp = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->createCompartment(TO_UTF8(createNewName("compartment", COL_NAME_COMPARTMENTS)));
285  }
286 
287  endInsertRows();
288 
289  return true;
290 }
#define COL_NAME_COMPARTMENTS
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual const std::string & getKey() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool CQCompartmentDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 327 of file CQCompartmentDM.cpp.

References C_INVALID_INDEX, CQMessageBox::confirmDelete(), FROM_UTF8, CModel::getCompartments(), CCopasiRootContainer::getDatamodelList(), CCompartment::getDeletedObjects(), CCopasiDataModel::getModel(), CCopasiObject::getObjectName(), CQBaseDataModel::isDefaultRow(), and CQBaseDataModel::removeRow().

Referenced by CQCompartmentsWidget::deleteSelectedCompartments().

328 {
329  if (rows.isEmpty())
330  return false;
331 
332  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
334  assert(pDataModel != NULL);
335  CModel * pModel = pDataModel->getModel();
336 
337  if (pModel == NULL)
338  return false;
339 
340 //Build the list of pointers to items to be deleted
341 //before actually deleting any item.
342  QList <CCompartment *> pCompartments;
343  QModelIndexList::const_iterator i;
344 
345  for (i = rows.begin(); i != rows.end(); ++i)
346  {
347  if (!isDefaultRow(*i) && pModel->getCompartments()[(*i).row()])
348  pCompartments.append(pModel->getCompartments()[(*i).row()]);
349  }
350 
351  QList <CCompartment *>::const_iterator j;
352 
353  for (j = pCompartments.begin(); j != pCompartments.end(); ++j)
354  {
355  CCompartment * pCompartment = *j;
356 
357  size_t delRow =
358  pModel->getCompartments().CCopasiVector< CCompartment >::getIndex(pCompartment);
359 
360  if (delRow != C_INVALID_INDEX)
361  {
362  QMessageBox::StandardButton choice =
363  CQMessageBox::confirmDelete(NULL, "compartment",
364  FROM_UTF8(pCompartment->getObjectName()),
365  pCompartment->getDeletedObjects());
366 
367  if (choice == QMessageBox::Ok)
368  removeRow((int) delRow);
369  }
370  }
371 
372  return true;
373 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual std::set< const CCopasiObject * > getDeletedObjects() const
bool removeRow(int position)
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQCompartmentDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 292 of file CQCompartmentDM.cpp.

References CCopasiVector< T >::begin(), ListViews::COMPARTMENT, ListViews::DELETE, CModel::getCompartments(), CCopasiRootContainer::getDatamodelList(), ListViews::METABOLITE, and CQBaseDataModel::notifyGUI().

293 {
294  if (rows <= 0)
295  return true;
296 
297  beginRemoveRows(QModelIndex(), position, position + rows - 1);
298 
299  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
300 
301  std::vector< std::string > DeletedKeys;
302  DeletedKeys.resize(rows);
303 
304  std::vector< std::string >::iterator itDeletedKey;
305  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();
306 
308 
309  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow)
310  {
311  *itDeletedKey = (*itRow)->getKey();
312  }
313 
314  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey)
315  {
316  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->removeCompartment(*itDeletedKey);
317  emit notifyGUI(ListViews::COMPARTMENT, ListViews::DELETE, *itDeletedKey);
319  emit notifyGUI(ListViews::METABOLITE, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
320  }
321 
322  endRemoveRows();
323 
324  return true;
325 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
iterator begin()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
Definition: CModel.h:50
int CQCompartmentDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 49 of file CQCompartmentDM.cpp.

References CCopasiRootContainer::getDatamodelList().

Referenced by data(), and CQCompartmentsWidget::deleteSelectedCompartments().

50 {
51  return (int)(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments().size() + 1;
52 }
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool CQCompartmentDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 235 of file CQCompartmentDM.cpp.

References ListViews::CHANGE, COL_IVOLUME, COL_NAME_COMPARTMENTS, COL_TYPE_COMPARTMENTS, ListViews::COMPARTMENT, CQBaseDataModel::createNewName(), data(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CModelEntity::getKey(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), mItemToType, CQBaseDataModel::notifyGUI(), CModelEntity::setInitialValue(), CCopasiObject::setObjectName(), CModelEntity::setStatus(), CModelEntity::StatusName, and TO_UTF8.

237 {
238  if (index.isValid() && role == Qt::EditRole)
239  {
240  bool defaultRow = isDefaultRow(index);
241 
242  if (defaultRow)
243  {
244  if (index.column() == COL_TYPE_COMPARTMENTS)
245  {
246  if (index.data().toString() != QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
247  insertRow();
248  else
249  return false;
250  }
251  else if (index.data() != value)
252  insertRow();
253  else
254  return false;
255  }
256 
257  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
258  CCompartment *pComp = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[index.row()];
259 
260  if (index.column() == COL_NAME_COMPARTMENTS)
261  pComp->setObjectName(TO_UTF8(value.toString()));
262  else if (index.column() == COL_TYPE_COMPARTMENTS)
263  pComp->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
264  else if (index.column() == COL_IVOLUME)
265  pComp->setInitialValue(value.toDouble());
266 
267  if (defaultRow && this->index(index.row(), COL_NAME_COMPARTMENTS).data().toString() == "compartment")
268  pComp->setObjectName(TO_UTF8(createNewName("compartment", COL_NAME_COMPARTMENTS)));
269 
270  emit dataChanged(index, index);
272  }
273 
274  return true;
275 }
#define COL_NAME_COMPARTMENTS
#define COL_TYPE_COMPARTMENTS
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
std::vector< unsigned C_INT32 > mItemToType
virtual QVariant data(const QModelIndex &index, int role) const
#define COL_IVOLUME
virtual const std::string & getKey() const
virtual void setStatus(const CModelEntity::Status &status)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual void setInitialValue(const C_FLOAT64 &initialValue)
virtual bool isDefaultRow(const QModelIndex &i) const
bool setObjectName(const std::string &name)

Member Data Documentation

std::vector< unsigned C_INT32 > CQCompartmentDM::mItemToType
protected

A vector mapping the item index to a model valu type

Definition at line 58 of file CQCompartmentDM.h.

Referenced by CQCompartmentDM(), data(), getItemToType(), and setData().

QStringList CQCompartmentDM::mTypes
protected

Definition at line 54 of file CQCompartmentDM.h.

Referenced by CQCompartmentDM(), and getTypes().


The documentation for this class was generated from the following files: