COPASI API  4.16.103
Classes | Public Types | Public Member Functions | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CQBrowserPaneDM Class Reference

#include <CQBrowserPaneDM.h>

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

Classes

class  CNode
 
class  SData
 

Public Types

enum  Type { Model = 0x01, Tasks = 0x02, Output = 0x04, FunctionDB = 0x08 }
 

Public Member Functions

void add (const size_t &id, const std::string &key, const QString &displayRole, const size_t &parentId=C_INVALID_INDEX)
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
 CQBrowserPaneDM (QObject *parent=0)
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
CNodefindNodeFromId (const size_t &id) const
 
CNodefindNodeFromKey (const std::string &key) const
 
size_t getIdFromIndex (const QModelIndex &index) const
 
std::string getKeyFromIndex (const QModelIndex &index) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
QModelIndex index (const size_t &id, const std::string &key) const
 
void load ()
 
void load (const size_t &id)
 
virtual QModelIndex parent (const QModelIndex &index) const
 
void remove (const std::string &key)
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 
void rename (const std::string &key, const QString &displayRole)
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
void setCopasiDM (const CCopasiDataModel *pDataModel)
 
void setGuiDM (const DataModelGUI *pDataModel)
 
virtual ~CQBrowserPaneDM ()
 

Private Slots

bool slotNotify (ListViews::ObjectType objectType, ListViews::Action action, std::string key="")
 

Private Member Functions

void clear ()
 
void createStaticDM ()
 
QModelIndex index (CNode *pNode) const
 

Static Private Member Functions

static CNodenodeFromIndex (const QModelIndex &index)
 

Private Attributes

bool mEmitDataChanged
 
int mFlags
 
const CCopasiDataModelmpCopasiDM
 
const DataModelGUImpGuiDM
 
CNodempRoot
 

Detailed Description

Definition at line 26 of file CQBrowserPaneDM.h.

Member Enumeration Documentation

Enumerator
Model 
Tasks 
Output 
FunctionDB 

Definition at line 72 of file CQBrowserPaneDM.h.

Constructor & Destructor Documentation

CQBrowserPaneDM::CQBrowserPaneDM ( QObject *  parent = 0)

Definition at line 25 of file CQBrowserPaneDM.cpp.

References createStaticDM().

25  :
26  QAbstractItemModel(pParent),
27  mpRoot(NULL),
28  mpCopasiDM(NULL),
29  mpGuiDM(NULL),
30  mEmitDataChanged(true),
32 {
33  // setSortRole(Qt::EditRole);
35 }
const CCopasiDataModel * mpCopasiDM
const DataModelGUI * mpGuiDM
CQBrowserPaneDM::~CQBrowserPaneDM ( )
virtual

Definition at line 38 of file CQBrowserPaneDM.cpp.

References mpRoot, and pdelete.

39 {
40  pdelete(mpRoot);
41 }
#define pdelete(p)
Definition: copasi.h:215

Member Function Documentation

void CQBrowserPaneDM::add ( const size_t &  id,
const std::string &  key,
const QString &  displayRole,
const size_t &  parentId = C_INVALID_INDEX 
)

Definition at line 254 of file CQBrowserPaneDM.cpp.

References findNodeFromId(), CCopasiNode< _Data >::getNumChildren(), and index().

Referenced by slotNotify().

258 {
259  CNode * pParent = findNodeFromId(parentId);
260  int row = 0;
261 
262  if (pParent != NULL)
263  {
264  row = pParent->getNumChildren();
265  }
266 
267  beginInsertRows(index(pParent), row, row);
268  new CNode(id, key, displayRole, pParent);
269  endInsertRows();
270 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
CNode * findNodeFromId(const size_t &id) const
void CQBrowserPaneDM::clear ( )
private

Definition at line 722 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::deleteChildren(), and findNodeFromId().

Referenced by setCopasiDM().

723 {
724  findNodeFromId(111)->deleteChildren(); // Compartment
725  findNodeFromId(112)->deleteChildren(); // Species
726  findNodeFromId(114)->deleteChildren(); // Reactions
727  findNodeFromId(115)->deleteChildren(); // Global Quantities
728  findNodeFromId(116)->deleteChildren(); // Events
729  findNodeFromId(119)->deleteChildren(); // Model Parameter Sets
730  findNodeFromId(42)->deleteChildren(); // Plot Specifications
731  findNodeFromId(43)->deleteChildren(); // Report Specifications
732  findNodeFromId(5)->deleteChildren(); // Functions
733 }
CNode * findNodeFromId(const size_t &id) const
bool deleteChildren()
Definition: CCopasiNode.h:199
int CQBrowserPaneDM::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 44 of file CQBrowserPaneDM.cpp.

45 {
46  return 1;
47 }
void CQBrowserPaneDM::createStaticDM ( )
private

Definition at line 653 of file CQBrowserPaneDM.cpp.

References data(), DataModeltxt, findNodeFromId(), FROM_UTF8, FunctionDB, mFlags, Model, mpRoot, Output, and Tasks.

Referenced by CQBrowserPaneDM().

654 {
655  mpRoot = new CNode(0, "", "COPASI", NULL);
656 
657  std::stringstream in;
658  in.str(DataModeltxt);
659 
660  std::string str1;
661  std::string delimiter("\x0a\x0d");
662  char c;
663 
664  while (!in.eof())
665  {
666  str1 = "";
667 
668  while (!in.fail())
669  {
670  in.get(c);
671 
672  if (delimiter.find(c) != std::string::npos) break;
673 
674  str1 += c;
675  }
676 
677  if (str1 == "") break;
678 
679  QString data(FROM_UTF8(str1));
680 
681  int first = data.indexOf(':');
682  int second = data.indexOf(':', first + 1);
683  int parentId = data.mid(0, first).toInt();
684  int myId = data.mid(first + 1, second - first - 1).toInt();
685  QString str = data.mid(second + 1, data.length() - second - 1);
686 
687  CNode * pParent = NULL;
688 
689  if (parentId == 0)
690  {
691  switch (myId)
692  {
693  case 1:
694  pParent = (mFlags & Model) ? mpRoot : NULL;
695  break;
696 
697  case 2:
698  pParent = (mFlags & Tasks) ? mpRoot : NULL;
699  break;
700 
701  case 4:
702  pParent = (mFlags & Output) ? mpRoot : NULL;
703  break;
704 
705  case 5:
706  pParent = (mFlags & FunctionDB) ? mpRoot : NULL;
707  break;
708  }
709  }
710  else
711  {
712  pParent = this->findNodeFromId(parentId);
713  }
714 
715  if (pParent != NULL)
716  {
717  new CNode(myId, "", str, pParent);
718  }
719  }
720 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CNode * findNodeFromId(const size_t &id) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
static char DataModeltxt[]
Definition: DataModel.txt.h:15
QVariant CQBrowserPaneDM::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 50 of file CQBrowserPaneDM.cpp.

References CQBrowserPaneDM::CNode::getDisplayRole(), CQBrowserPaneDM::CNode::getId(), CCopasiNode< _Data >::getNumChildren(), CQBrowserPaneDM::CNode::getSortRole(), and nodeFromIndex().

Referenced by createStaticDM().

51 {
52  CNode * pNode = nodeFromIndex(index);
53 
54  if (pNode == NULL) return QVariant();
55 
56  switch (role)
57  {
58  case Qt::DisplayRole:
59 
60  // We need to add the number of children to some nodes.
61  switch (pNode->getId())
62  {
63  case 5:
64  case 42:
65  case 43:
66  case 111:
67  case 112:
68  case 114:
69  case 115:
70  case 116:
71  case 119:
72  return QVariant(pNode->getDisplayRole() + " (" + QString::number(pNode->getNumChildren()) + ")");
73  break;
74 
75  default:
76  return QVariant(pNode->getDisplayRole());
77  break;
78  }
79 
80  break;
81 
82  case Qt::EditRole:
83  return QVariant(pNode->getSortRole());
84  break;
85  }
86 
87  return QVariant();
88 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
static CNode * nodeFromIndex(const QModelIndex &index)
CQBrowserPaneDM::CNode * CQBrowserPaneDM::findNodeFromId ( const size_t &  id) const

Definition at line 171 of file CQBrowserPaneDM.cpp.

References mpRoot.

Referenced by add(), clear(), createStaticDM(), index(), and load().

172 {
175 
176  for (; it != end; ++it)
177  {
178  if (it->getData().mId == id)
179  {
180  return &*it;
181  }
182  }
183 
184  return NULL;
185 }
CQBrowserPaneDM::CNode * CQBrowserPaneDM::findNodeFromKey ( const std::string &  key) const

Definition at line 187 of file CQBrowserPaneDM.cpp.

References mpRoot.

Referenced by index(), remove(), and rename().

188 {
191 
192  for (; it != end; ++it)
193  {
194  if (it->getData().mKey == key)
195  {
196  return &*it;
197  }
198  }
199 
200  return NULL;
201 }
size_t CQBrowserPaneDM::getIdFromIndex ( const QModelIndex &  index) const

Definition at line 203 of file CQBrowserPaneDM.cpp.

References C_INVALID_INDEX, CQBrowserPaneDM::CNode::getId(), and nodeFromIndex().

Referenced by ListViews::findWidgetFromIndex(), and ListViews::getCurrentItemId().

204 {
205  CNode * pNode = nodeFromIndex(index);
206 
207  if (pNode == NULL) return C_INVALID_INDEX;
208 
209  return pNode->getId();
210 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
#define C_INVALID_INDEX
Definition: copasi.h:222
static CNode * nodeFromIndex(const QModelIndex &index)
std::string CQBrowserPaneDM::getKeyFromIndex ( const QModelIndex &  index) const

Definition at line 212 of file CQBrowserPaneDM.cpp.

References CQBrowserPaneDM::CNode::getKey(), and nodeFromIndex().

Referenced by ListViews::slotFolderChanged().

213 {
214  CNode * pNode = nodeFromIndex(index);
215 
216  if (pNode == NULL) return "";
217 
218  return pNode->getKey();
219 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
static CNode * nodeFromIndex(const QModelIndex &index)
QModelIndex CQBrowserPaneDM::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Definition at line 91 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::getChild(), mpRoot, and nodeFromIndex().

Referenced by add(), index(), load(), nodeFromIndex(), remove(), rename(), setCopasiDM(), ListViews::setDataModel(), and ListViews::switchToOtherWidget().

92 {
93  CNode * pParent = nodeFromIndex(parent);
94 
95  if (pParent == NULL) return createIndex(row, column, mpRoot);
96 
97  CNode * pNode = static_cast< CNode * >(pParent->getChild(row));
98 
99  if (pNode)
100  return createIndex(row, column, pNode);
101  else
102  return QModelIndex();
103 }
virtual QModelIndex parent(const QModelIndex &index) const
static CNode * nodeFromIndex(const QModelIndex &index)
QModelIndex CQBrowserPaneDM::index ( const size_t &  id,
const std::string &  key 
) const

Definition at line 121 of file CQBrowserPaneDM.cpp.

References C_INVALID_INDEX, findNodeFromId(), findNodeFromKey(), and index().

122 {
123  CNode * pNode = NULL;
124 
125  if (id != C_INVALID_INDEX)
126  {
127  pNode = findNodeFromId(id);
128  }
129  else if (key != "")
130  {
131  pNode = findNodeFromKey(key);
132  }
133 
134  return index(pNode);
135 }
CNode * findNodeFromKey(const std::string &key) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
#define C_INVALID_INDEX
Definition: copasi.h:222
CNode * findNodeFromId(const size_t &id) const
QModelIndex CQBrowserPaneDM::index ( CQBrowserPaneDM::CNode pNode) const
private

Definition at line 620 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::getParent(), CQBrowserPaneDM::CNode::getRow(), index(), and mpRoot.

621 {
622  if (pNode == NULL)
623  {
624  return QModelIndex();
625  }
626 
627  if (pNode == mpRoot)
628  {
629  return index(0, 0, QModelIndex());
630  }
631 
632  QModelIndex Parent = index(static_cast< CNode * >(pNode->getParent()));
633 
634  return index(pNode->getRow(), 0, Parent);
635 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
CCopasiNode< Data > * getParent()
Definition: CCopasiNode.h:139
void CQBrowserPaneDM::load ( )

Definition at line 306 of file CQBrowserPaneDM.cpp.

References findNodeFromId(), COutputDefinitionVector::getKey(), CModelParameterSet::getKey(), CReportDefinitionVector::getKey(), CModel::getKey(), CCopasiDataModel::getModel(), CModel::getModelParameterSet(), CCopasiDataModel::getPlotDefinitionList(), CCopasiDataModel::getReportDefinitionList(), CCopasiDataModel::getTaskList(), index(), mpCopasiDM, and CQBrowserPaneDM::CNode::setKey().

Referenced by setCopasiDM(), and slotNotify().

307 {
309 
310  load(111); // Compartment
311  load(112); // Species
312  load(114); // Reactions
313  load(115); // Global Quantities
314  load(116); // Events
315 
316  findNodeFromId(118)->setKey(mpCopasiDM->getModel()->getModelParameterSet().getKey()); // Parameter Set
318  load(119); // Model Parameter Sets
319 
320  findNodeFromId(21)->setKey((*mpCopasiDM->getTaskList())["Steady-State"]->getKey());
321  findNodeFromId(221)->setKey((*mpCopasiDM->getTaskList())["Elementary Flux Modes"]->getKey());
322  findNodeFromId(222)->setKey((*mpCopasiDM->getTaskList())["Moieties"]->getKey());
323  findNodeFromId(2221)->setKey((*mpCopasiDM->getTaskList())["Moieties"]->getKey());
324  findNodeFromId(23)->setKey((*mpCopasiDM->getTaskList())["Time-Course"]->getKey());
325  findNodeFromId(24)->setKey((*mpCopasiDM->getTaskList())["Metabolic Control Analysis"]->getKey());
326  findNodeFromId(27)->setKey((*mpCopasiDM->getTaskList())["Time Scale Separation Analysis"]->getKey());
327  findNodeFromId(26)->setKey((*mpCopasiDM->getTaskList())["Lyapunov Exponents"]->getKey());
328  findNodeFromId(28)->setKey((*mpCopasiDM->getTaskList())["Cross Section"]->getKey());
329  findNodeFromId(31)->setKey((*mpCopasiDM->getTaskList())["Scan"]->getKey());
330  findNodeFromId(32)->setKey((*mpCopasiDM->getTaskList())["Optimization"]->getKey());
331  findNodeFromId(33)->setKey((*mpCopasiDM->getTaskList())["Parameter Estimation"]->getKey());
332  findNodeFromId(34)->setKey((*mpCopasiDM->getTaskList())["Sensitivities"]->getKey());
333  findNodeFromId(35)->setKey((*mpCopasiDM->getTaskList())["Linear Noise Approximation"]->getKey());
334 
336  load(42); // Plot Specifications
337 
339  load(43); // Report Specifications
340 
341  load(5); // Functions
342 
343  dataChanged(index(0, 0), index(0, 0));
344 }
const CModelParameterSet & getModelParameterSet() const
Definition: CModel.cpp:1072
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
CNode * findNodeFromId(const size_t &id) const
const CCopasiDataModel * mpCopasiDM
virtual const std::string & getKey() const
const CReportDefinitionVector * getReportDefinitionList() const
const std::string & getKey() const
virtual const std::string & getKey() const
CCopasiVectorN< CCopasiTask > * getTaskList()
void setKey(const std::string &key)
const std::string & getKey() const
Definition: CModel.cpp:1142
const COutputDefinitionVector * getPlotDefinitionList() const
void CQBrowserPaneDM::load ( const size_t &  id)

Definition at line 346 of file CQBrowserPaneDM.cpp.

References CCopasiVector< T >::begin(), C_INVALID_INDEX, CCopasiVector< T >::end(), findNodeFromId(), FROM_UTF8, CModel::getCompartments(), CMetabNameInterface::getDisplayName(), CQBrowserPaneDM::CNode::getDisplayRole(), CModel::getEvents(), CCopasiRootContainer::getFunctionList(), CModel::getMetabolites(), CCopasiDataModel::getModel(), CModel::getModelParameterSets(), CModel::getModelValues(), CCopasiNode< _Data >::getNumChildren(), CCopasiDataModel::getPlotDefinitionList(), CModel::getReactions(), CCopasiDataModel::getReportDefinitionList(), CCopasiNode< _Data >::getSibling(), index(), CFunctionDB::loadedFunctions(), mEmitDataChanged, mpCopasiDM, removeRows(), CQBrowserPaneDM::CNode::setDisplayRole(), and CQBrowserPaneDM::CNode::setKey().

347 {
348  bool isSpecies = false;
349  const CModel * pModel = mpCopasiDM->getModel();
350  const CCopasiVector< CCopasiObject > * pVector = NULL;
351 
352  switch (id)
353  {
354  case 111: // Compartment
355  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getCompartments());
356  break;
357 
358  case 112: // Species
359  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getMetabolites());
360  isSpecies = true;
361  break;
362 
363  case 114: // Reactions
364  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getReactions());
365  break;
366 
367  case 115: // Global Quantities
368  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getModelValues());
369  break;
370 
371  case 116: // Events
372  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getEvents());
373  break;
374 
375  case 119: // Parameter Sets
376  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&pModel->getModelParameterSets());
377  break;
378 
379  case 42: // Plot Specifications
380  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(mpCopasiDM->getPlotDefinitionList());
381  break;
382 
383  case 43: // Report Specifications
384  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(mpCopasiDM->getReportDefinitionList());
385  break;
386 
387  case 5: // Functions
388  pVector = reinterpret_cast< const CCopasiVector< CCopasiObject > * >(&CCopasiRootContainer::getFunctionList()->loadedFunctions());
389  break;
390 
391  default:
392  return;
393  break;
394  }
395 
396  // We need to compare the existing nodes with the COPASI data model objects.
397  CNode * pParent = findNodeFromId(id);
398  CCopasiNode< CQBrowserPaneDM::SData > * pChildData = pParent->CCopasiNode< CQBrowserPaneDM::SData >::getChild();
401 
402  bool changed = false;
403 
404  for (; pChildData != NULL && it != end; pChildData = pChildData->getSibling(), ++it)
405  {
406  CNode * pChild = static_cast< CNode *>(pChildData);
407 
408  pChild->setKey((*it)->getKey());
409 
410  QString DisplayRole;
411 
412  if (isSpecies)
413  {
414  DisplayRole = FROM_UTF8(CMetabNameInterface::getDisplayName(pModel, *static_cast<const CMetab *>(*it), false));
415  }
416  else
417  {
418  DisplayRole = FROM_UTF8((*it)->getObjectName());
419  }
420 
421  if (pChild->getDisplayRole() != DisplayRole)
422  {
423  pChild->setDisplayRole(DisplayRole);
424  changed = true;
425  }
426  }
427 
428  // Remove excess nodes
429  if (pChildData != NULL)
430  {
431  int row = static_cast< CNode *>(pChildData)->getRow();
432  int count = 0;
433 
434  while (pChildData != NULL)
435  {
436  count++;
437  pChildData = pChildData->getSibling();
438  }
439 
440  removeRows(row, count, index(pParent));
441  }
442 
443  // Add missing nodes
444  if (it != end)
445  {
446  int first = pParent->getNumChildren();
447  int last = first + (end - it) - 1;
448 
449  beginInsertRows(index(pParent), first, last);
450 
451  for (; it != end; ++it)
452  {
453  QString DisplayRole;
454 
455  if (isSpecies)
456  {
457  DisplayRole = FROM_UTF8(CMetabNameInterface::getDisplayName(pModel, *static_cast<const CMetab *>(*it), false));
458  }
459  else
460  {
461  DisplayRole = FROM_UTF8((*it)->getObjectName());
462  }
463 
464  new CNode(C_INVALID_INDEX, (*it)->getKey(), DisplayRole, pParent);
465  }
466 
467  endInsertRows();
468  }
469 
470  if (changed && mEmitDataChanged)
471  {
472  QModelIndex Parent = index(pParent);
473 
474  emit dataChanged(Parent, Parent);
475  }
476 }
CCopasiVectorN< CFunction > & loadedFunctions()
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
iterator begin()
#define C_INVALID_INDEX
Definition: copasi.h:222
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
CNode * findNodeFromId(const size_t &id) const
const CCopasiDataModel * mpCopasiDM
const CReportDefinitionVector * getReportDefinitionList() const
iterator end()
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
const CCopasiVectorN< CModelParameterSet > & getModelParameterSets() const
Definition: CModel.cpp:1066
static CFunctionDB * getFunctionList()
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
const COutputDefinitionVector * getPlotDefinitionList() const
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
Definition: CModel.h:50
CQBrowserPaneDM::CNode * CQBrowserPaneDM::nodeFromIndex ( const QModelIndex &  index)
staticprivate

Definition at line 637 of file CQBrowserPaneDM.cpp.

References index().

Referenced by data(), getIdFromIndex(), getKeyFromIndex(), index(), parent(), removeRows(), and rowCount().

638 {
639  if (!index.isValid()) return NULL;
640 
641  QModelIndex Tmp = index;
642  const QAbstractItemModel *pModel = Tmp.model();
643 
644  while (pModel->inherits("QSortFilterProxyModel"))
645  {
646  Tmp = static_cast< const QSortFilterProxyModel *>(pModel)->mapToSource(index);
647  pModel = Tmp.model();
648  }
649 
650  return static_cast< CNode * >(Tmp.internalPointer());
651 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex CQBrowserPaneDM::parent ( const QModelIndex &  index) const
virtual

Definition at line 106 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::getParent(), CQBrowserPaneDM::CNode::getRow(), mpRoot, and nodeFromIndex().

Referenced by ListViews::findWidgetFromIndex().

107 {
108  CNode * pNode = nodeFromIndex(index);
109 
110  if (pNode == NULL || pNode == mpRoot)
111  {
112  return QModelIndex();
113  }
114 
115  CNode * pParent = static_cast< CNode * >(pNode->getParent());
116  assert(pParent != NULL);
117 
118  return createIndex(pParent->getRow(), 0, pParent);
119 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
static CNode * nodeFromIndex(const QModelIndex &index)
void CQBrowserPaneDM::remove ( const std::string &  key)

Definition at line 221 of file CQBrowserPaneDM.cpp.

References findNodeFromKey(), CCopasiNode< _Data >::getParent(), CQBrowserPaneDM::CNode::getRow(), index(), and removeRows().

222 {
223  CNode * pNode = findNodeFromKey(key);
224 
225  if (pNode == NULL || pNode->getParent() == NULL)
226  {
227  return;
228  }
229 
230  QModelIndex Parent = index(static_cast< CNode * >(pNode->getParent()));
231 
232  removeRows(pNode->getRow(), 1, Parent);
233 }
CNode * findNodeFromKey(const std::string &key) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
bool CQBrowserPaneDM::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtual

Definition at line 149 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), and nodeFromIndex().

Referenced by load(), and remove().

150 {
151  CNode * pParent = nodeFromIndex(parent);
152 
153  if (pParent == NULL) return false;
154 
155  CNode * pNode = static_cast< CNode * >(pParent->getChild(row));
156 
157  beginRemoveRows(parent, row, row + count - 1);
158 
159  for (int i = 0; i < count && pNode != NULL; i++)
160  {
161  CNode * pTmp = pNode;
162  pNode = static_cast< CNode * >(pNode->getSibling());
163  delete pTmp;
164  }
165 
166  endRemoveRows();
167 
168  return true;
169 }
virtual QModelIndex parent(const QModelIndex &index) const
static CNode * nodeFromIndex(const QModelIndex &index)
void CQBrowserPaneDM::rename ( const std::string &  key,
const QString &  displayRole 
)

Definition at line 235 of file CQBrowserPaneDM.cpp.

References findNodeFromKey(), CQBrowserPaneDM::CNode::getDisplayRole(), index(), mEmitDataChanged, and CQBrowserPaneDM::CNode::setDisplayRole().

Referenced by slotNotify().

236 {
237  CNode * pNode = findNodeFromKey(key);
238 
239  if (pNode == NULL) return;
240 
241  if (pNode->getDisplayRole() != displayRole)
242  {
243  pNode->setDisplayRole(displayRole);
244 
245  QModelIndex Index = index(pNode);
246 
247  if (mEmitDataChanged)
248  {
249  emit dataChanged(Index, Index);
250  }
251  }
252 }
CNode * findNodeFromKey(const std::string &key) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
int CQBrowserPaneDM::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 138 of file CQBrowserPaneDM.cpp.

References CCopasiNode< _Data >::getNumChildren(), mpRoot, and nodeFromIndex().

139 {
140  if (!parent.isValid())
141  return (mpRoot != NULL) ? 1 : 0;
142 
143  CNode * pParent = nodeFromIndex(parent);
144 
145  return pParent->getNumChildren();
146 }
virtual QModelIndex parent(const QModelIndex &index) const
static CNode * nodeFromIndex(const QModelIndex &index)
void CQBrowserPaneDM::setCopasiDM ( const CCopasiDataModel pDataModel)

Definition at line 272 of file CQBrowserPaneDM.cpp.

References clear(), index(), load(), mEmitDataChanged, and mpCopasiDM.

Referenced by ListViews::setDataModel().

273 {
274  if (mpCopasiDM != pDataModel)
275  {
276  mpCopasiDM = pDataModel;
277 
278  mEmitDataChanged = false;
279 
280  clear();
281  load();
282 
283  dataChanged(index(0, 0), index(0, 0));
284 
285  mEmitDataChanged = true;
286  }
287 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
const CCopasiDataModel * mpCopasiDM
void CQBrowserPaneDM::setGuiDM ( const DataModelGUI pDataModel)

Definition at line 289 of file CQBrowserPaneDM.cpp.

References mpGuiDM, and slotNotify().

Referenced by ListViews::setDataModel().

290 {
291  if (mpGuiDM)
292  {
293  disconnect(mpGuiDM, SIGNAL(notifyView(ListViews::ObjectType, ListViews::Action, std::string)),
294  this, SLOT(slotNotify(ListViews::ObjectType, ListViews::Action, const std::string &)));
295  }
296 
297  mpGuiDM = pDataModel;
298 
299  if (mpGuiDM)
300  {
301  connect(mpGuiDM, SIGNAL(notifyView(ListViews::ObjectType, ListViews::Action, std::string)),
302  this, SLOT(slotNotify(ListViews::ObjectType, ListViews::Action, std::string)));
303  }
304 }
const DataModelGUI * mpGuiDM
bool slotNotify(ListViews::ObjectType objectType, ListViews::Action action, std::string key="")
bool CQBrowserPaneDM::slotNotify ( ListViews::ObjectType  objectType,
ListViews::Action  action,
std::string  key = "" 
)
privateslot

Definition at line 478 of file CQBrowserPaneDM.cpp.

References add(), ListViews::ADD, C_INVALID_INDEX, ListViews::CHANGE, ListViews::COMPARTMENT, ListViews::DELETE, ListViews::EVENT, FROM_UTF8, ListViews::FUNCTION, CKeyFactory::get(), CMetabNameInterface::getDisplayName(), CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectName(), ListViews::LAYOUT, load(), ListViews::METABOLITE, ListViews::MODEL, ListViews::MODELPARAMETERSET, ListViews::MODELVALUE, ListViews::PLOT, ListViews::REACTION, rename(), ListViews::RENAME, and ListViews::REPORT.

Referenced by setGuiDM().

479 {
480  if (key == "")
481  {
482  // Load is only reporting actual changes.
483  load();
484  return true;
485  }
486 
487  const CCopasiObject * pObject = CCopasiRootContainer::getKeyFactory()->get(key);
488 
489  if (pObject == NULL &&
490  action != ListViews::DELETE)
491  {
492  return false;
493  }
494 
495  QString DisplayRole;
496 
497  if (pObject != NULL)
498  {
499  // We have a key we can there fore determine the display role.
500  DisplayRole = FROM_UTF8(pObject->getObjectName());
501 
502  // Species need to be handled differently
503  const CMetab * pMetab = dynamic_cast< const CMetab *>(pObject);
504 
505  if (pMetab != NULL)
506  {
507  const CModel * pModel = pMetab->getModel();
508 
509  if (pModel != NULL)
510  {
511  DisplayRole = FROM_UTF8(CMetabNameInterface::getDisplayName(pModel, *pMetab, false));
512  }
513  }
514  }
515 
516  switch (action)
517  {
518  case ListViews::RENAME:
519  case ListViews::CHANGE:
520 
521  switch (objectType)
522  {
525  case ListViews::REACTION:
527  case ListViews::EVENT:
528  case ListViews::PLOT:
529  case ListViews::REPORT:
530  case ListViews::FUNCTION:
531  case ListViews::LAYOUT:
533  rename(key, DisplayRole);
534  break;
535 
536  default:
537  break;
538  }
539 
540  break;
541 
542  case ListViews::DELETE:
543 
544  // TODO CRITICAL We need to be smarter when deleting objects
545  switch (objectType)
546  {
549  case ListViews::REACTION:
551  case ListViews::EVENT:
552  case ListViews::PLOT:
553  case ListViews::REPORT:
554  case ListViews::FUNCTION:
555  case ListViews::LAYOUT:
557  remove(key);
558  break;
559 
560  default:
561  break;
562  }
563 
564  break;
565 
566  case ListViews::ADD:
567  {
568  switch (objectType)
569  {
570  case ListViews::MODEL:
571  load();
572  break;
573 
575  add(C_INVALID_INDEX, key, DisplayRole, 111);
576  break;
577 
579  add(C_INVALID_INDEX, key, DisplayRole, 112);
580  break;
581 
582  case ListViews::REACTION:
583  add(C_INVALID_INDEX, key, DisplayRole, 114);
584  break;
585 
587  add(C_INVALID_INDEX, key, DisplayRole, 115);
588  break;
589 
590  case ListViews::EVENT:
591  add(C_INVALID_INDEX, key, DisplayRole, 116);
592  break;
593 
595  add(C_INVALID_INDEX, key, DisplayRole, 119);
596  break;
597 
598  case ListViews::PLOT:
599  add(C_INVALID_INDEX, key, DisplayRole, 42);
600  break;
601 
602  case ListViews::REPORT:
603  add(C_INVALID_INDEX, key, DisplayRole, 43);
604  break;
605 
606  case ListViews::FUNCTION:
607  add(C_INVALID_INDEX, key, DisplayRole, 5);
608  break;
609 
610  default:
611  break;
612  }
613  }
614  break;
615  }
616 
617  return true;
618 }
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
CCopasiObject * get(const std::string &key)
#define C_INVALID_INDEX
Definition: copasi.h:222
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
Definition: CMetab.h:178
void add(const size_t &id, const std::string &key, const QString &displayRole, const size_t &parentId=C_INVALID_INDEX)
void rename(const std::string &key, const QString &displayRole)
static CKeyFactory * getKeyFactory()
Definition: CModel.h:50

Member Data Documentation

bool CQBrowserPaneDM::mEmitDataChanged
private

Definition at line 145 of file CQBrowserPaneDM.h.

Referenced by load(), rename(), and setCopasiDM().

int CQBrowserPaneDM::mFlags
private

Definition at line 147 of file CQBrowserPaneDM.h.

Referenced by createStaticDM().

const CCopasiDataModel* CQBrowserPaneDM::mpCopasiDM
private

Definition at line 141 of file CQBrowserPaneDM.h.

Referenced by load(), and setCopasiDM().

const DataModelGUI* CQBrowserPaneDM::mpGuiDM
private

Definition at line 143 of file CQBrowserPaneDM.h.

Referenced by setGuiDM().

CNode* CQBrowserPaneDM::mpRoot
private

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