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

#include <CQSpecieDM.h>

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

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQSpecieDM (QObject *parent=0)
 
QVariant data (const QModelIndex &index, int role) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
const std::vector< unsigned
C_INT32 > & 
getItemToType ()
 
const QStringList & getTypes ()
 
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
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
void setFlagConc (bool flag)
 
- 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

bool mFlagConc
 
std::vector< unsigned C_INT32mItemToType
 
bool mNotify
 
CMetabmpSpecies
 
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 39 of file CQSpecieDM.h.

Constructor & Destructor Documentation

CQSpecieDM::CQSpecieDM ( QObject *  parent = 0)

Definition at line 22 of file CQSpecieDM.cpp.

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

22  :
23  CQBaseDataModel(parent),
24  mFlagConc(true),
25  mpSpecies(NULL),
26  mNotify(true)
27 {
32 
33  mItemToType.push_back(CModelEntity::REACTIONS);
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
bool mFlagConc
Definition: CQSpecieDM.h:59
CMetab * mpSpecies
Definition: CQSpecieDM.h:70
QStringList mTypes
Definition: CQSpecieDM.h:60
CQBaseDataModel(QObject *parent=0)
bool mNotify
Definition: CQSpecieDM.h:72
std::vector< unsigned C_INT32 > mItemToType
Definition: CQSpecieDM.h:65

Member Function Documentation

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

Definition at line 59 of file CQSpecieDM.cpp.

References TOTAL_COLS_SPECIES.

Referenced by CQSpeciesWidget::keyPressEvent().

60 {
61  return TOTAL_COLS_SPECIES;
62 }
#define TOTAL_COLS_SPECIES
Definition: CQSpecieDM.h:37
QVariant CQSpecieDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 111 of file CQSpecieDM.cpp.

References COL_COMPARTMENT, COL_CONCENTRATION, COL_CRATE, COL_EXPRESSION_SPECIES, COL_ICONCENTRATION, COL_IEXPRESSION_SPECIES, COL_INUMBER, COL_NAME_SPECIES, COL_NRATE, COL_NUMBER, COL_ROW_NUMBER, COL_TYPE_SPECIES, flags(), FROM_UTF8, CMetab::getCompartment(), CMetab::getConcentration(), CMetab::getConcentrationRate(), CCopasiRootContainer::getDatamodelList(), CExpression::getDisplayString(), CModelEntity::getExpressionPtr(), CMetab::getInitialConcentration(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getInitialValue(), CCopasiObject::getObjectName(), CModelEntity::getRate(), CModelEntity::getStatus(), CModelEntity::getValue(), CQBaseDataModel::isDefaultRow(), mFlagConc, mItemToType, mpSpecies, rowCount(), CCopasiVector< T >::size(), and CModelEntity::StatusName.

Referenced by flags(), and setData().

112 {
113  if (!index.isValid())
114  return QVariant();
115 
116  if (index.row() >= rowCount())
117  return QVariant();
118 
119  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
120  return QColor(Qt::darkGray);
121 
122  if (role == Qt::DisplayRole || role == Qt::EditRole)
123  {
124  if (isDefaultRow(index))
125  {
126  switch (index.column())
127  {
128  case COL_ROW_NUMBER:
129  return QVariant(QString(""));
130 
131  case COL_NAME_SPECIES:
132  return QVariant(QString("New Species"));
133 
134  case COL_COMPARTMENT:
135  {
136  const CCopasiVector < CCompartment > & compartments =
137  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments();
138 
139  if (compartments.size())
140  return QVariant(QString(FROM_UTF8(compartments[0]->getObjectName())));
141  else
142  return QVariant(QString(""));
143  }
144 
145  case COL_TYPE_SPECIES:
146  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[0]])));
147 
148  case COL_ICONCENTRATION:
149  {
150  if (mFlagConc)
151  return QVariant(QString::number(1.0, 'g', 10));
152  else
153  return QVariant(QString(""));
154  }
155 
156  case COL_INUMBER:
157  {
158  if (mFlagConc)
159  return QVariant(QString(""));
160  else
161  return QVariant(QString::number(100.0, 'g', 10));
162  }
163 
164  default:
165  return QVariant(QString(""));
166  }
167  }
168  else
169  {
170  mpSpecies = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites()[index.row()];
171 
172  switch (index.column())
173  {
174  case COL_ROW_NUMBER:
175  return QVariant(index.row() + 1);
176 
177  case COL_NAME_SPECIES:
178  return QVariant(QString(FROM_UTF8(mpSpecies->getObjectName())));
179 
180  case COL_COMPARTMENT:
181  return QVariant(QString(FROM_UTF8(mpSpecies->getCompartment()->getObjectName())));
182 
183  case COL_TYPE_SPECIES:
184  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[mpSpecies->getStatus()])));
185 
186  case COL_ICONCENTRATION:
187  {
188  if (role == Qt::EditRole)
189  return QVariant(QString::number(mpSpecies->getInitialConcentration(), 'g', 10));
190  else
191  return QVariant(mpSpecies->getInitialConcentration());
192  }
193 
194  case COL_INUMBER:
195  {
196  if (role == Qt::EditRole)
197  return QVariant(QString::number(mpSpecies->getInitialValue(), 'g', 10));
198  else
199  return QVariant(mpSpecies->getInitialValue());
200  }
201 
202  case COL_CONCENTRATION:
203  return QVariant(mpSpecies->getConcentration());
204 
205  case COL_NUMBER:
206  return QVariant(mpSpecies->getValue());
207 
208  case COL_CRATE:
209  return QVariant(mpSpecies->getConcentrationRate());
210 
211  case COL_NRATE:
212  return QVariant(mpSpecies->getRate());
213 
215  {
216  const CExpression * pExpression = NULL;
217 
218  if (mpSpecies->getInitialExpression() != "")
219  {
220  pExpression = mpSpecies->getInitialExpressionPtr();
221 
222  if (pExpression != NULL)
223  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
224  }
225 
226  return QVariant(QString(""));
227  }
228 
230  {
231  const CExpression * pExpression = mpSpecies->getExpressionPtr();
232 
233  if (pExpression != NULL)
234  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
235  else
236  return QVariant(QString(""));
237  }
238  }
239  }
240  }
241 
242  return QVariant();
243 }
const CExpression * getExpressionPtr() const
#define COL_NAME_SPECIES
Definition: CQSpecieDM.h:26
#define COL_IEXPRESSION_SPECIES
Definition: CQSpecieDM.h:35
#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
virtual size_t size() const
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: CQSpecieDM.cpp:64
bool mFlagConc
Definition: CQSpecieDM.h:59
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQSpecieDM.cpp:54
#define COL_TYPE_SPECIES
Definition: CQSpecieDM.h:28
const std::string & getDisplayString() const
#define COL_CONCENTRATION
Definition: CQSpecieDM.h:31
CMetab * mpSpecies
Definition: CQSpecieDM.h:70
#define COL_NRATE
Definition: CQSpecieDM.h:34
#define COL_EXPRESSION_SPECIES
Definition: CQSpecieDM.h:36
const C_FLOAT64 & getInitialValue() const
#define COL_INUMBER
Definition: CQSpecieDM.h:30
#define COL_COMPARTMENT
Definition: CQSpecieDM.h:27
#define COL_NUMBER
std::string getInitialExpression() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const C_FLOAT64 & getValue() const
const C_FLOAT64 & getConcentration() const
Definition: CMetab.cpp:218
const CModelEntity::Status & getStatus() const
virtual bool isDefaultRow(const QModelIndex &i) const
C_FLOAT64 getConcentrationRate() const
Definition: CMetab.cpp:870
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
#define COL_CRATE
Definition: CQSpecieDM.h:33
const CExpression * getInitialExpressionPtr() const
#define COL_ICONCENTRATION
Definition: CQSpecieDM.h:29
#define COL_ROW_NUMBER
std::vector< unsigned C_INT32 > mItemToType
Definition: CQSpecieDM.h:65
Qt::ItemFlags CQSpecieDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 64 of file CQSpecieDM.cpp.

References CModelEntity::ASSIGNMENT, COL_COMPARTMENT, COL_ICONCENTRATION, COL_IEXPRESSION_SPECIES, COL_INUMBER, COL_NAME_SPECIES, COL_TYPE_SPECIES, data(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CQBaseDataModel::isDefaultRow(), CMetab::isInitialConcentrationChangeAllowed(), mpSpecies, and CModelEntity::StatusName.

Referenced by data().

65 {
66  if (!index.isValid())
67  return Qt::ItemIsEnabled;
68 
69  if (isDefaultRow(index))
70  {
71  if (index.column() == COL_NAME_SPECIES || index.column() == COL_COMPARTMENT ||
72  index.column() == COL_TYPE_SPECIES || index.column() == COL_ICONCENTRATION ||
73  index.column() == COL_INUMBER)
74  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
75  else
76  return QAbstractItemModel::flags(index);
77  }
78 
79  if (index.column() == COL_NAME_SPECIES || index.column() == COL_COMPARTMENT ||
80  index.column() == COL_TYPE_SPECIES)
81  {
82  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
83  }
84  else if (index.column() == COL_ICONCENTRATION)
85  {
86  mpSpecies = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites()[index.row()];
87 
88  if (this->index(index.row(), COL_TYPE_SPECIES).data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT]))
89  || !(this->index(index.row(), COL_IEXPRESSION_SPECIES).data().toString().isEmpty()))
90  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEnabled;
91  else
92  {
94  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
95  else
96  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled;
97  }
98  }
99  else if (index.column() == COL_INUMBER)
100  {
101  if (this->index(index.row(), COL_TYPE_SPECIES).data() == QString(FROM_UTF8(CModelEntity::StatusName[CModelEntity::ASSIGNMENT]))
102  || !(this->index(index.row(), COL_IEXPRESSION_SPECIES).data().toString().isEmpty()))
103  return QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable & ~Qt::ItemIsEnabled;
104  else
105  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
106  }
107  else
108  return QAbstractItemModel::flags(index);
109 }
#define COL_NAME_SPECIES
Definition: CQSpecieDM.h:26
#define COL_IEXPRESSION_SPECIES
Definition: CQSpecieDM.h:35
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
#define COL_TYPE_SPECIES
Definition: CQSpecieDM.h:28
CMetab * mpSpecies
Definition: CQSpecieDM.h:70
QVariant data(const QModelIndex &index, int role) const
Definition: CQSpecieDM.cpp:111
#define COL_INUMBER
Definition: CQSpecieDM.h:30
const bool & isInitialConcentrationChangeAllowed() const
Definition: CMetab.cpp:664
#define COL_COMPARTMENT
Definition: CQSpecieDM.h:27
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_ICONCENTRATION
Definition: CQSpecieDM.h:29
const std::vector< unsigned C_INT32 > & CQSpecieDM::getItemToType ( )

Definition at line 49 of file CQSpecieDM.cpp.

References mItemToType.

50 {
51  return mItemToType;
52 }
std::vector< unsigned C_INT32 > mItemToType
Definition: CQSpecieDM.h:65
const QStringList & CQSpecieDM::getTypes ( )

Definition at line 39 of file CQSpecieDM.cpp.

References mTypes.

Referenced by CQSpeciesWidget::CQSpeciesWidget().

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

Implements CQBaseDataModel.

Definition at line 245 of file CQSpecieDM.cpp.

References COL_COMPARTMENT, COL_CONCENTRATION, COL_CRATE, COL_EXPRESSION_SPECIES, COL_ICONCENTRATION, COL_IEXPRESSION_SPECIES, COL_INUMBER, COL_NAME_SPECIES, COL_NRATE, COL_NUMBER, COL_ROW_NUMBER, COL_TYPE_SPECIES, FROM_UTF8, CModel::getConcentrationRateUnitsDisplayString(), CModel::getConcentrationUnitsDisplayString(), CCopasiRootContainer::getDatamodelList(), and CModel::getFrequencyUnitsDisplayString().

247 {
248  if (role != Qt::DisplayRole)
249  return QVariant();
250 
251  if (orientation == Qt::Horizontal)
252  {
253  const CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
254 
255  if (pModel == NULL) return QVariant();
256 
257  QString ValueUnits, RateUnits, FrequencyUnits, ExpressionUnits;
258 
259  if (pModel)
260  ValueUnits = FROM_UTF8(pModel->getConcentrationUnitsDisplayString());
261 
262  if (!ValueUnits.isEmpty())
263  ValueUnits = "\n(" + ValueUnits + ")";
264 
265  if (pModel)
266  RateUnits = FROM_UTF8(pModel->getConcentrationRateUnitsDisplayString());
267 
268  if (!RateUnits.isEmpty())
269  RateUnits = "\n(" + RateUnits + ")";
270 
271  if (pModel)
272  FrequencyUnits = FROM_UTF8(pModel->getFrequencyUnitsDisplayString());
273 
274  if (!FrequencyUnits.isEmpty())
275  FrequencyUnits = "\n(" + FrequencyUnits + ")";
276 
277  if (!ValueUnits.isEmpty() && !RateUnits.isEmpty())
278  {
279  if (ValueUnits == RateUnits)
280  ExpressionUnits = ValueUnits;
281  else
282  ExpressionUnits = "\n(" + FROM_UTF8(pModel->getConcentrationUnitsDisplayString())
283  + " or " + FROM_UTF8(pModel->getConcentrationRateUnitsDisplayString()) + ")";
284  }
285  else if (!ValueUnits.isEmpty())
286  ExpressionUnits = "\n(" + FROM_UTF8(pModel->getConcentrationUnitsDisplayString()) + " or 1)";
287  else if (!RateUnits.isEmpty())
288  ExpressionUnits = "\n(1 or " + FROM_UTF8(pModel->getConcentrationRateUnitsDisplayString()) + ")";
289 
290  switch (section)
291  {
292  case COL_ROW_NUMBER:
293  return QVariant(QString("#"));
294 
295  case COL_NAME_SPECIES:
296  return QVariant(QString("Name"));
297 
298  case COL_COMPARTMENT:
299  return QVariant(QString("Compartment"));
300 
301  case COL_TYPE_SPECIES:
302  return QVariant(QString(" Type "));
303 
304  case COL_ICONCENTRATION:
305  return QVariant("Initial Concentration" + ValueUnits);
306 
307  case COL_INUMBER:
308  return QVariant(QString("Initial Number"));
309 
310  case COL_CONCENTRATION:
311  return QVariant("Concentration" + ValueUnits);
312 
313  case COL_NUMBER:
314  return QVariant(QString("Number"));
315 
316  case COL_CRATE:
317  return QVariant("Rate" + RateUnits);
318 
319  case COL_NRATE:
320  return QVariant("Number Rate" + FrequencyUnits);
321 
323  return QVariant("Initial Expression" + ValueUnits);
324 
326  return QVariant("Expression" + ExpressionUnits);
327 
328  default:
329  return QVariant();
330  }
331  }
332  else
333  return QString("%1").arg(section + 1);
334 }
#define COL_NAME_SPECIES
Definition: CQSpecieDM.h:26
#define COL_IEXPRESSION_SPECIES
Definition: CQSpecieDM.h:35
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
std::string getConcentrationRateUnitsDisplayString() const
Definition: CModel.cpp:4607
std::string getFrequencyUnitsDisplayString() const
Definition: CModel.cpp:4539
#define COL_TYPE_SPECIES
Definition: CQSpecieDM.h:28
#define COL_CONCENTRATION
Definition: CQSpecieDM.h:31
#define COL_NRATE
Definition: CQSpecieDM.h:34
#define COL_EXPRESSION_SPECIES
Definition: CQSpecieDM.h:36
#define COL_INUMBER
Definition: CQSpecieDM.h:30
#define COL_COMPARTMENT
Definition: CQSpecieDM.h:27
#define COL_NUMBER
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
std::string getConcentrationUnitsDisplayString() const
Definition: CModel.cpp:4587
Definition: CModel.h:50
#define COL_CRATE
Definition: CQSpecieDM.h:33
#define COL_ICONCENTRATION
Definition: CQSpecieDM.h:29
#define COL_ROW_NUMBER
bool CQSpecieDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 479 of file CQSpecieDM.cpp.

References ListViews::ADD, COL_NAME_SPECIES, ListViews::COMPARTMENT, CModel::createCompartment(), CModel::createMetabolite(), CQBaseDataModel::createNewName(), CModel::getCompartments(), CCopasiRootContainer::getDatamodelList(), CModelEntity::getKey(), CCopasiObject::getKey(), CCopasiDataModel::getModel(), ListViews::METABOLITE, mNotify, mpSpecies, CQBaseDataModel::notifyGUI(), CModelEntity::REACTIONS, CCopasiVector< T >::size(), and TO_UTF8.

480 {
482 
483  if (pDataModel->getModel()->getCompartments().size() == 0)
484  {
485  pDataModel->getModel()->createCompartment("compartment");
487  }
488 
489  beginInsertRows(QModelIndex(), position, position + rows - 1);
490 
491  for (int row = 0; row < rows; ++row)
492  {
493  mpSpecies =
495 
496  if (mNotify)
497  {
499  }
500  }
501 
502  endInsertRows();
503 
504  return true;
505 }
#define COL_NAME_SPECIES
Definition: CQSpecieDM.h:26
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual size_t size() const
CMetab * mpSpecies
Definition: CQSpecieDM.h:70
virtual const std::string & getKey() const
virtual const std::string & getKey() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
bool mNotify
Definition: CQSpecieDM.h:72
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CCompartment * createCompartment(const std::string &name, const C_FLOAT64 &volume=1.0)
Definition: CModel.cpp:2698
CMetab * createMetabolite(const std::string &name, const std::string &compartment, const C_FLOAT64 &iconc=1.0, const CModelEntity::Status &status=CModelEntity::REACTIONS)
Definition: CModel.cpp:2622
bool CQSpecieDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 541 of file CQSpecieDM.cpp.

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

Referenced by CQSpeciesWidget::deleteSelectedSpecies().

542 {
543  if (rows.isEmpty())
544  return false;
545 
546  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
548  assert(pDataModel != NULL);
549  CModel * pModel = pDataModel->getModel();
550 
551  if (pModel == NULL)
552  return false;
553 
554 //Build the list of pointers to items to be deleted
555 //before actually deleting any item.
556  QList <CMetab *> pSpecies;
557  QModelIndexList::const_iterator i;
558 
559  for (i = rows.begin(); i != rows.end(); ++i)
560  {
561  if (!isDefaultRow(*i) && pModel->getMetabolites()[(*i).row()])
562  pSpecies.append(pModel->getMetabolites()[(*i).row()]);
563  }
564 
565  QList <CMetab *>::const_iterator j;
566 
567  for (j = pSpecies.begin(); j != pSpecies.end(); ++j)
568  {
569  CMetab * pSpecie = *j;
570 
571  size_t delRow =
572  pModel->getMetabolites().CCopasiVector< CMetab >::getIndex(pSpecie);
573 
574  if (delRow != C_INVALID_INDEX)
575  {
576  QMessageBox::StandardButton choice =
577  CQMessageBox::confirmDelete(NULL, "species",
578  FROM_UTF8(pSpecie->getObjectName()),
579  pSpecie->getDeletedObjects());
580 
581  if (choice == QMessageBox::Ok)
582  removeRow((int) delRow);
583  }
584  }
585 
586  return true;
587 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
#define C_INVALID_INDEX
Definition: copasi.h:222
Definition: CMetab.h:178
virtual DataObjectSet getDeletedObjects() const
Definition: CMetab.cpp:806
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()
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQSpecieDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 507 of file CQSpecieDM.cpp.

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

508 {
509  if (rows <= 0)
510  return true;
511 
512  beginRemoveRows(QModelIndex(), position, position + rows - 1);
513 
514  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
515 
516  std::vector< std::string > DeletedKeys;
517  DeletedKeys.resize(rows);
518 
519  std::vector< std::string >::iterator itDeletedKey;
520  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();
521 
522  CCopasiVector< CMetab >::const_iterator itRow = pModel->getMetabolites().begin() + position;
523 
524  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow)
525  {
526  *itDeletedKey = (*itRow)->getKey();
527  }
528 
529  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey)
530  {
531  pModel->removeMetabolite(*itDeletedKey);
532  emit notifyGUI(ListViews::METABOLITE, ListViews::DELETE, *itDeletedKey);
533  emit notifyGUI(ListViews::METABOLITE, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
534  }
535 
536  endRemoveRows();
537 
538  return true;
539 }
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
bool removeMetabolite(const std::string &key, const bool &recursive=true)
Definition: CModel.cpp:2667
iterator begin()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
Definition: CModel.h:50
int CQSpecieDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 54 of file CQSpecieDM.cpp.

References CCopasiRootContainer::getDatamodelList().

Referenced by data(), and CQSpeciesWidget::deleteSelectedSpecies().

55 {
56  return (int)(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites().size() + 1;
57 }
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool CQSpecieDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 336 of file CQSpecieDM.cpp.

References ListViews::ADD, C_FLOAT64, ListViews::CHANGE, COL_COMPARTMENT, COL_ICONCENTRATION, COL_INUMBER, COL_NAME_SPECIES, COL_NUMBER, COL_TYPE_SPECIES, ListViews::COMPARTMENT, CMetab::convertToConcentration(), CMetab::convertToNumber(), CQBaseDataModel::createNewName(), data(), FROM_UTF8, CMetab::getCompartment(), CCopasiRootContainer::getDatamodelList(), CModelEntity::getInitialValue(), CModelEntity::getKey(), CCopasiObject::getObjectName(), CQMessageBox::information(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), ListViews::METABOLITE, mFlagConc, mItemToType, mNotify, mpSpecies, CQBaseDataModel::notifyGUI(), CMetab::setInitialConcentration(), CModelEntity::setInitialValue(), CCopasiObject::setObjectName(), CMetab::setStatus(), CModelEntity::setValue(), CModelEntity::StatusName, and TO_UTF8.

338 {
339  if (index.isValid() && role == Qt::EditRole)
340  {
341  bool defaultRow = isDefaultRow(index);
342 
343  if (defaultRow)
344  {
345  if (index.column() == COL_TYPE_SPECIES)
346  {
347  if (index.data().toString() == QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
348  return false;
349  }
350  else if (index.column() == COL_COMPARTMENT && value == "")
351  {
352  return false;
353  }
354  else if (index.data() == value)
355  {
356  return false;
357  }
358 
359  mNotify = false;
360  insertRow();
361  mNotify = true;
362  }
363  else
364  {
365  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
366  mpSpecies = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getMetabolites()[index.row()];
367  }
368 
369  const CCompartment * pCompartment = NULL;
370 
371  if (index.column() == COL_COMPARTMENT ||
372  index.column() == COL_ICONCENTRATION ||
373  index.column() == COL_INUMBER)
374  {
375  try
376  {
377  pCompartment = mpSpecies->getCompartment();
378  }
379  catch (...) {}
380  }
381 
382  if (index.column() == COL_NAME_SPECIES)
383  mpSpecies->setObjectName(TO_UTF8(value.toString()));
384  else if (index.column() == COL_COMPARTMENT)
385  {
386  // This must be set first for setInitialConcentration and
387  // setInitialNumber to work correctly.
388  std::string Compartment(TO_UTF8(value.toString()));
389 
390  if (Compartment != pCompartment->getObjectName())
391  {
392  std::string CompartmentToRemove = mpSpecies->getCompartment()->getObjectName();
393  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
394 
395  if (!(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[Compartment]->addMetabolite(mpSpecies))
396  {
397  QString msg;
398  msg = "Unable to move species '" + FROM_UTF8(mpSpecies->getObjectName()) + "'\n"
399  + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + FROM_UTF8(Compartment) + "'\n"
400  + "since a species with that name already exist in the target compartment.";
401 
403  "Unable to move Species",
404  msg,
405  QMessageBox::Ok, QMessageBox::Ok);
406  return false;
407  }
408  else
409  {
410  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments()[CompartmentToRemove]->getMetabolites().remove(mpSpecies->getObjectName());
411  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->setCompileFlag();
412  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->initializeMetabolites();
413 
414  if (mpSpecies && pCompartment)
415  {
416  C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue();
417  Factor *= pCompartment->getInitialValue();
418 
419  mpSpecies->setInitialValue(Factor * this->index(index.row(), COL_INUMBER).data().toDouble());
420  mpSpecies->setValue(Factor * this->index(index.row(), COL_NUMBER).data().toDouble());
421  }
422 
425  }
426  }
427  }
428  else if (index.column() == COL_TYPE_SPECIES)
430  else if (index.column() == COL_ICONCENTRATION)
431  {
432  if (mFlagConc)
433  mpSpecies->setInitialConcentration(value.toDouble());
434 
435  if (mpSpecies && pCompartment)
436  {
437  const C_FLOAT64 initialValue =
438  CMetab::convertToNumber(this->index(index.row(), COL_ICONCENTRATION).data().toDouble(),
439  *pCompartment,
440  *(*CCopasiRootContainer::getDatamodelList())[0]->getModel());
441  mpSpecies->setInitialValue(initialValue);
442  }
443  }
444  else if (index.column() == COL_INUMBER)
445  {
446  if (!mFlagConc)
447  mpSpecies->setInitialValue(value.toDouble());
448 
449  if (mpSpecies && pCompartment)
450  {
452  CMetab::convertToConcentration(this->index(index.row(), COL_INUMBER).data().toDouble(),
453  *pCompartment,
454  *(*CCopasiRootContainer::getDatamodelList())[0]->getModel())
455  );
456  }
457  }
458 
459  if (defaultRow && this->index(index.row(), COL_NAME_SPECIES).data().toString() == "species")
461 
462  //Save Key
463  std::string key = mpSpecies->getKey();
464  emit dataChanged(index, index);
465 
466  if (defaultRow)
467  {
469  }
470  else
471  {
473  }
474  }
475 
476  return true;
477 }
#define COL_NAME_SPECIES
Definition: CQSpecieDM.h:26
void setInitialConcentration(const C_FLOAT64 &initialConcentration)
Definition: CMetab.cpp:257
#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="")
const std::string & getObjectName() const
virtual void setStatus(const CModelEntity::Status &status)
Definition: CMetab.cpp:291
bool mFlagConc
Definition: CQSpecieDM.h:59
#define COL_TYPE_SPECIES
Definition: CQSpecieDM.h:28
virtual void setValue(const C_FLOAT64 &value)
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CMetab * mpSpecies
Definition: CQSpecieDM.h:70
QVariant data(const QModelIndex &index, int role) const
Definition: CQSpecieDM.cpp:111
const C_FLOAT64 & getInitialValue() const
#define COL_INUMBER
Definition: CQSpecieDM.h:30
#define COL_COMPARTMENT
Definition: CQSpecieDM.h:27
virtual const std::string & getKey() const
#define COL_NUMBER
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QString createNewName(const QString name, const int nameCol)
static C_FLOAT64 convertToNumber(const C_FLOAT64 &concentration, const CCompartment &compartment, const CModel &model)
Definition: CMetab.cpp:35
#define C_FLOAT64
Definition: copasi.h:92
bool mNotify
Definition: CQSpecieDM.h:72
#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)
static C_FLOAT64 convertToConcentration(const C_FLOAT64 &number, const CCompartment &compartment, const CModel &model)
Definition: CMetab.cpp:41
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
#define COL_ICONCENTRATION
Definition: CQSpecieDM.h:29
std::vector< unsigned C_INT32 > mItemToType
Definition: CQSpecieDM.h:65
void CQSpecieDM::setFlagConc ( bool  flag)

Definition at line 44 of file CQSpecieDM.cpp.

References mFlagConc.

Referenced by CQSpeciesWidget::setFramework().

45 {
46  mFlagConc = flag;
47 }
bool mFlagConc
Definition: CQSpecieDM.h:59
long int flag
Definition: f2c.h:52

Member Data Documentation

bool CQSpecieDM::mFlagConc
protected

Definition at line 59 of file CQSpecieDM.h.

Referenced by data(), setData(), and setFlagConc().

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

A vector mapping the item index to a model value type

Definition at line 65 of file CQSpecieDM.h.

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

bool CQSpecieDM::mNotify
protected

Definition at line 72 of file CQSpecieDM.h.

Referenced by insertRows(), and setData().

CMetab* CQSpecieDM::mpSpecies
mutableprotected

A pointer to the selected species

Definition at line 70 of file CQSpecieDM.h.

Referenced by data(), flags(), insertRows(), and setData().

QStringList CQSpecieDM::mTypes
protected

Definition at line 60 of file CQSpecieDM.h.

Referenced by CQSpecieDM(), and getTypes().


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