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

#include <CQGlobalQuantityDM.h>

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

Public Member Functions

virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQGlobalQuantityDM (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)
 
- 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 34 of file CQGlobalQuantityDM.h.

Constructor & Destructor Documentation

CQGlobalQuantityDM::CQGlobalQuantityDM ( QObject *  parent = 0)

Definition at line 22 of file CQGlobalQuantityDM.cpp.

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

23  : CQBaseDataModel(parent)
24 
25 {
29 
30  mItemToType.push_back(CModelEntity::FIXED);
31  mItemToType.push_back(CModelEntity::ASSIGNMENT);
32  mItemToType.push_back(CModelEntity::ODE);
33 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
CQBaseDataModel(QObject *parent=0)
std::vector< unsigned C_INT32 > mItemToType

Member Function Documentation

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

Definition at line 49 of file CQGlobalQuantityDM.cpp.

References TOTAL_COLS_GQ.

Referenced by CQGlobalQuantitiesWidget::keyPressEvent().

50 {
51  return TOTAL_COLS_GQ;
52 }
#define TOTAL_COLS_GQ
QVariant CQGlobalQuantityDM::data ( const QModelIndex &  index,
int  role 
) const
virtual

Implements CQBaseDataModel.

Definition at line 72 of file CQGlobalQuantityDM.cpp.

References COL_EXPRESSION_GQ, COL_IEXPRESSION_GQ, COL_INITIAL_GQ, COL_NAME_GQ, COL_RATE_GQ, COL_ROW_NUMBER, COL_TRANSIENT_GQ, COL_TYPE_GQ, flags(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CExpression::getDisplayString(), CModelEntity::getExpressionPtr(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getInitialValue(), CCopasiObject::getObjectName(), CModelEntity::getRate(), CModelEntity::getStatus(), CModelEntity::getValue(), CQBaseDataModel::isDefaultRow(), mItemToType, rowCount(), and CModelEntity::StatusName.

Referenced by flags(), and setData().

73 {
74  if (!index.isValid())
75  return QVariant();
76 
77  if (index.row() >= rowCount())
78  return QVariant();
79 
80  if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable))
81  return QColor(Qt::darkGray);
82 
83  if (role == Qt::DisplayRole || role == Qt::EditRole)
84  {
85  if (isDefaultRow(index))
86  {
87  switch (index.column())
88  {
89  case COL_ROW_NUMBER:
90  return QVariant(QString(""));
91 
92  case COL_NAME_GQ:
93  return QVariant(QString("New Quantity"));
94 
95  case COL_TYPE_GQ:
96  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[0]])));
97 
98  case COL_INITIAL_GQ:
99  return QVariant(QString::number(0.0, 'g', 10));
100 
101  default:
102  return QVariant(QString(""));
103  }
104  }
105  else
106  {
107  CModelValue *pGQ = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getModelValues()[index.row()];
108  const CExpression * pExpression = NULL;
109 
110  switch (index.column())
111  {
112  case COL_ROW_NUMBER:
113  return QVariant(index.row() + 1);
114 
115  case COL_NAME_GQ:
116  return QVariant(QString(FROM_UTF8(pGQ->getObjectName())));
117 
118  case COL_TYPE_GQ:
119  return QVariant(QString(FROM_UTF8(CModelEntity::StatusName[pGQ->getStatus()])));
120 
121  case COL_INITIAL_GQ:
122 
123  if (role == Qt::EditRole)
124  return QVariant(QString::number(pGQ->getInitialValue(), 'g', 10));
125  else
126  return QVariant(pGQ->getInitialValue());
127 
128  case COL_TRANSIENT_GQ:
129  return QVariant(pGQ->getValue());
130 
131  case COL_RATE_GQ:
132  return QVariant(pGQ->getRate());
133 
134  case COL_IEXPRESSION_GQ:
135 
136  if (pGQ->getInitialExpression() != "")
137  {
138  pExpression = pGQ->getInitialExpressionPtr();
139 
140  if (pExpression != NULL)
141  return QVariant(QString(FROM_UTF8(pExpression->getDisplayString())));
142  else
143  return QVariant();
144  }
145 
146  break;
147 
148  case COL_EXPRESSION_GQ:
149  {
150  pExpression = pGQ->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_EXPRESSION_GQ
#define COL_NAME_GQ
#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 int rowCount(const QModelIndex &parent=QModelIndex()) const
const std::string & getDisplayString() const
#define COL_INITIAL_GQ
const C_FLOAT64 & getInitialValue() const
#define COL_RATE_GQ
std::string getInitialExpression() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const C_FLOAT64 & getValue() const
#define COL_TYPE_GQ
Qt::ItemFlags flags(const QModelIndex &index) const
#define COL_IEXPRESSION_GQ
const CModelEntity::Status & getStatus() const
std::vector< unsigned C_INT32 > mItemToType
virtual bool isDefaultRow(const QModelIndex &i) const
#define COL_TRANSIENT_GQ
const CExpression * getInitialExpressionPtr() const
#define COL_ROW_NUMBER
Qt::ItemFlags CQGlobalQuantityDM::flags ( const QModelIndex &  index) const
virtual

Reimplemented from CQBaseDataModel.

Definition at line 54 of file CQGlobalQuantityDM.cpp.

References CModelEntity::ASSIGNMENT, COL_INITIAL_GQ, COL_NAME_GQ, COL_TYPE_GQ, data(), FROM_UTF8, and CModelEntity::StatusName.

Referenced by data().

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

Definition at line 40 of file CQGlobalQuantityDM.cpp.

References mItemToType.

41 {
42  return mItemToType;
43 }
std::vector< unsigned C_INT32 > mItemToType
const QStringList & CQGlobalQuantityDM::getTypes ( )

Definition at line 35 of file CQGlobalQuantityDM.cpp.

References mTypes.

Referenced by CQGlobalQuantitiesWidget::CQGlobalQuantitiesWidget().

36 {
37  return mTypes;
38 }
QVariant CQGlobalQuantityDM::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Implements CQBaseDataModel.

Definition at line 164 of file CQGlobalQuantityDM.cpp.

References COL_EXPRESSION_GQ, COL_IEXPRESSION_GQ, COL_INITIAL_GQ, COL_NAME_GQ, COL_RATE_GQ, COL_ROW_NUMBER, COL_TRANSIENT_GQ, and COL_TYPE_GQ.

166 {
167  if (role != Qt::DisplayRole)
168  return QVariant();
169 
170  if (orientation == Qt::Horizontal)
171  {
172  switch (section)
173  {
174  case COL_ROW_NUMBER:
175  return QVariant(QString("#"));
176 
177  case COL_NAME_GQ:
178  return QVariant(QString("Name"));
179 
180  case COL_TYPE_GQ:
181  return QVariant(QString(" Type "));
182 
183  case COL_INITIAL_GQ:
184  return QVariant("Initial Value");
185 
186  case COL_TRANSIENT_GQ:
187  return QVariant("Transient Value");
188 
189  case COL_RATE_GQ:
190  return QVariant("Rate");
191 
192  case COL_IEXPRESSION_GQ:
193  return QVariant("Initial Expression");
194 
195  case COL_EXPRESSION_GQ:
196  return QVariant("Expression");
197 
198  default:
199  return QVariant();
200  }
201  }
202  else //Vertical header
203  return QString("%1").arg(section + 1);
204 }
#define COL_EXPRESSION_GQ
#define COL_NAME_GQ
#define COL_INITIAL_GQ
#define COL_RATE_GQ
#define COL_TYPE_GQ
#define COL_IEXPRESSION_GQ
#define COL_TRANSIENT_GQ
#define COL_ROW_NUMBER
bool CQGlobalQuantityDM::insertRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 248 of file CQGlobalQuantityDM.cpp.

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

249 {
250  beginInsertRows(QModelIndex(), position, position + rows - 1);
251 
252  for (int row = 0; row < rows; ++row)
253  {
254  CModelValue *pGQ = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->createModelValue(TO_UTF8(createNewName("quantity", COL_NAME_GQ)));
256  }
257 
258  endInsertRows();
259 
260  return true;
261 }
#define COL_NAME_GQ
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 CQGlobalQuantityDM::removeRows ( QModelIndexList  rows,
const QModelIndex &  index = QModelIndex() 
)

Definition at line 297 of file CQGlobalQuantityDM.cpp.

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

Referenced by CQGlobalQuantitiesWidget::deleteSelectedGlobalQuantities().

298 {
299  if (rows.isEmpty())
300  return false;
301 
302  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
304  assert(pDataModel != NULL);
305  CModel * pModel = pDataModel->getModel();
306 
307  if (pModel == NULL)
308  return false;
309 
310 //Build the list of pointers to items to be deleted
311 //before actually deleting any item.
312  QList <CModelValue *> pGlobalQuantities;
313  QModelIndexList::const_iterator i;
314 
315  for (i = rows.begin(); i != rows.end(); ++i)
316  {
317  if (!isDefaultRow(*i) && pModel->getModelValues()[(*i).row()])
318  pGlobalQuantities.append(pModel->getModelValues()[(*i).row()]);
319  }
320 
321  QList <CModelValue *>::const_iterator j;
322 
323  for (j = pGlobalQuantities.begin(); j != pGlobalQuantities.end(); ++j)
324  {
325  CModelValue * pGQ = *j;
326 
327  size_t delRow =
328  pModel->getModelValues().CCopasiVector< CModelValue >::getIndex(pGQ);
329 
330  if (delRow != C_INVALID_INDEX)
331  {
332  QMessageBox::StandardButton choice =
333  CQMessageBox::confirmDelete(NULL, "quantity",
334  FROM_UTF8(pGQ->getObjectName()),
335  pGQ->getDeletedObjects());
336 
337  if (choice == QMessageBox::Ok)
338  removeRow((int) delRow);
339  }
340  }
341 
342  return true;
343 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
#define C_INVALID_INDEX
Definition: copasi.h:222
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()
virtual std::set< const CCopasiObject * > getDeletedObjects() const
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
bool CQGlobalQuantityDM::removeRows ( int  position,
int  rows,
const QModelIndex &  index = QModelIndex() 
)
protectedvirtual

Implements CQBaseDataModel.

Definition at line 263 of file CQGlobalQuantityDM.cpp.

References CCopasiVector< T >::begin(), ListViews::DELETE, CCopasiRootContainer::getDatamodelList(), CModel::getModelValues(), ListViews::MODELVALUE, CQBaseDataModel::notifyGUI(), and CModel::removeModelValue().

264 {
265  if (rows <= 0)
266  return true;
267 
268  beginRemoveRows(QModelIndex(), position, position + rows - 1);
269 
270  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
271 
272  std::vector< std::string > DeletedKeys;
273  DeletedKeys.resize(rows);
274 
275  std::vector< std::string >::iterator itDeletedKey;
276  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();
277 
279 
280  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow)
281  {
282  *itDeletedKey = (*itRow)->getKey();
283  }
284 
285  for (itDeletedKey = DeletedKeys.begin(); itDeletedKey != endDeletedKey; ++itDeletedKey)
286  {
287  pModel->removeModelValue(*itDeletedKey);
288  emit notifyGUI(ListViews::MODELVALUE, ListViews::DELETE, *itDeletedKey);
289  emit notifyGUI(ListViews::MODELVALUE, ListViews::DELETE, ""); //Refresh all as there may be dependencies.
290  }
291 
292  endRemoveRows();
293 
294  return true;
295 }
void notifyGUI(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
iterator begin()
bool removeModelValue(const CModelValue *pModelValue, const bool &recursive=true)
Definition: CModel.cpp:2903
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
Definition: CModel.h:50
int CQGlobalQuantityDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 45 of file CQGlobalQuantityDM.cpp.

References CCopasiRootContainer::getDatamodelList().

Referenced by data(), and CQGlobalQuantitiesWidget::deleteSelectedGlobalQuantities().

46 {
47  return (int)(*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getModelValues().size() + 1;
48 }
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool CQGlobalQuantityDM::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Implements CQBaseDataModel.

Definition at line 206 of file CQGlobalQuantityDM.cpp.

References ListViews::CHANGE, COL_INITIAL_GQ, COL_NAME_GQ, COL_TYPE_GQ, CQBaseDataModel::createNewName(), data(), FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CModelEntity::getKey(), CQBaseDataModel::insertRow(), CQBaseDataModel::isDefaultRow(), mItemToType, ListViews::MODELVALUE, CQBaseDataModel::notifyGUI(), CModelEntity::setInitialValue(), CCopasiObject::setObjectName(), CModelEntity::setStatus(), CModelEntity::StatusName, and TO_UTF8.

208 {
209  if (index.isValid() && role == Qt::EditRole)
210  {
211  bool defaultRow = isDefaultRow(index);
212 
213  if (defaultRow)
214  {
215  if (index.column() == COL_TYPE_GQ)
216  {
217  if (index.data().toString() != QString(FROM_UTF8(CModelEntity::StatusName[mItemToType[value.toInt()]])))
218  insertRow();
219  else
220  return false;
221  }
222  else if (index.data() != value)
223  insertRow();
224  else
225  return false;
226  }
227 
228  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
229  CModelValue *pGQ = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getModelValues()[index.row()];
230 
231  if (index.column() == COL_NAME_GQ)
232  pGQ->setObjectName(TO_UTF8(value.toString()));
233  else if (index.column() == COL_TYPE_GQ)
234  pGQ->setStatus((CModelEntity::Status) mItemToType[value.toInt()]);
235  else if (index.column() == COL_INITIAL_GQ)
236  pGQ->setInitialValue(value.toDouble());
237 
238  if (defaultRow && this->index(index.row(), COL_NAME_GQ).data().toString() == "quantity")
239  pGQ->setObjectName(TO_UTF8(createNewName("quantity", COL_NAME_GQ)));
240 
241  emit dataChanged(index, index);
243  }
244 
245  return true;
246 }
#define COL_NAME_GQ
#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="")
#define COL_INITIAL_GQ
QVariant data(const QModelIndex &index, int role) const
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 COL_TYPE_GQ
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
virtual void setInitialValue(const C_FLOAT64 &initialValue)
std::vector< unsigned C_INT32 > mItemToType
virtual bool isDefaultRow(const QModelIndex &i) const
bool setObjectName(const std::string &name)

Member Data Documentation

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

A vector mapping the item index to a model valu type

Definition at line 57 of file CQGlobalQuantityDM.h.

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

QStringList CQGlobalQuantityDM::mTypes
protected

Definition at line 53 of file CQGlobalQuantityDM.h.

Referenced by CQGlobalQuantityDM(), and getTypes().


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