COPASI API  4.16.103
CQRDFTreeView.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "CQRDFTreeView.h"
12 #include "CQRDFTreeViewItem.h"
13 
14 #include "UI/CQMessageBox.h"
15 #include "UI/qtUtilities.h"
16 
17 #include "MIRIAM/CRDFGraph.h"
18 #include "MIRIAM/CRDFParser.h"
19 // #include "MIRIAM/CRDFWriter.h"
20 #include "MIRIAM/CRDFSubject.h"
21 
22 // #include "CopasiDataModel/CCopasiDataModel.h"
23 // #include "report/CKeyFactory.h"
24 // #include "model/CModel.h"
25 #include "model/CModelValue.h"
26 #include "model/CEvent.h"
27 #include "model/CReaction.h"
28 #include "function/CFunction.h"
29 // #include "utilities/CCopasiMessage.h"
31 
32 #define COL_SUBJECT 0
33 #define COL_PREDICATE 1
34 #define COL_OBJECT 2
35 
36 CQRDFTreeView::CQRDFTreeView(QWidget* parent, const char* name) :
37  CopasiWidget(parent, name),
38  mNode2Item(),
39  mpGraph(NULL)
40 {
41  setupUi(this);
42 }
43 
45 {
46  clear();
47 }
48 
50  ListViews::Action /* action */,
51  const std::string & /* key */)
52 {
53  return true;
54 }
55 
57 {
58  clear();
59 
61 
62  if (pObject != NULL)
63  {
64  CModelEntity * pEntity = NULL;
65  CEvent * pEvent = NULL;
66  CReaction * pReaction = NULL;
67  CFunction * pFunction = NULL;
68  const std::string * pMiriamAnnotation = NULL;
69 
70  if ((pEntity = dynamic_cast< CModelEntity * >(pObject)) != NULL)
71  pMiriamAnnotation = &pEntity->getMiriamAnnotation();
72  else if ((pEvent = dynamic_cast< CEvent * >(pObject)) != NULL)
73  pMiriamAnnotation = &pEvent->getMiriamAnnotation();
74  else if ((pReaction = dynamic_cast< CReaction * >(pObject)) != NULL)
75  pMiriamAnnotation = &pReaction->getMiriamAnnotation();
76  else if ((pFunction = dynamic_cast< CFunction * >(pObject)) != NULL)
77  pMiriamAnnotation = &pFunction->getMiriamAnnotation();
78 
79  if (pMiriamAnnotation && *pMiriamAnnotation != "")
80  mpGraph = CRDFParser::graphFromXml(*pMiriamAnnotation);
81  }
82 
84 
85  if (CCopasiMessage::size() != 0)
86  {
88  CQMessageBox::warning(this, QString("RDF Warning"), Message,
89  QMessageBox::Ok, QMessageBox::Ok);
90  }
91 
92  if (mpGraph == NULL)
93  mpGraph = new CRDFGraph;
94 
95  // We make sure that we always have an about node.
97 
98  // We iterate of all triplets
99  std::set< CRDFTriplet >::const_iterator it = mpGraph->getTriplets().begin();
100  std::set< CRDFTriplet >::const_iterator end = mpGraph->getTriplets().end();
101 
102  for (; it != end; ++it)
103  {
104  CQRDFTreeViewItem * pSubjectItem = find(it->pSubject);
105 
106  if (pSubjectItem == NULL)
107  {
108  pSubjectItem = new CQRDFTreeViewItem(mpTreeWidget, NULL);
109  insert(it->pSubject, pSubjectItem);
110  // Display the subject information
111 
112  const CRDFSubject & Subject = it->pSubject->getSubject();
113 
114  switch (Subject.getType())
115  {
117  pSubjectItem->setText(COL_SUBJECT, FROM_UTF8(Subject.getResource()));
118  break;
119 
121  pSubjectItem->setText(COL_SUBJECT, FROM_UTF8(Subject.getBlankNodeID()));
122  break;
123  }
124  }
125 
126  CQRDFTreeViewItem * pObjectItem = NULL;
127 
128  if (it->Predicate.getURI() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject")
129  {
130  pObjectItem = new CQRDFTreeViewItem(pSubjectItem, NULL);
131  insert(it->pObject, pObjectItem);
132  }
133  else
134  pObjectItem = find(it->pObject);
135 
136  if (pObjectItem == NULL)
137  {
138  pObjectItem = new CQRDFTreeViewItem(pSubjectItem, NULL);
139  insert(it->pObject, pObjectItem);
140  }
141  else
142  {
143  QTreeWidgetItem * pParent = pObjectItem->parent();
144 
145  if (pParent == NULL)
146  {
147  mpTreeWidget->invisibleRootItem()->removeChild(pObjectItem);
148  pSubjectItem->addChild(pObjectItem);
149  }
150  else
151  {
152  pParent->removeChild(pObjectItem);
153  pSubjectItem->addChild(pObjectItem);
154  }
155  }
156 
157  pObjectItem->setTriplet(*it);
158  }
159 
160  mpTreeWidget->setFocus();
161 
162  return true;
163 }
164 
166 {
167  mNode2Item.clear();
168  pdelete(mpGraph);
169  mpTreeWidget->clear();
170 }
171 
173 {
174  std::map< const CRDFNode *, CQRDFTreeViewItem * >::iterator it = mNode2Item.find(pNode);
175 
176  if (it != mNode2Item.end())
177  return it->second;
178 
179  return NULL;
180 }
181 
183 {
184  mNode2Item[pNode] = pItem;
185 }
Definition: CEvent.h:152
CRDFNode * createAboutNode(const std::string &key)
Definition: CRDFGraph.cpp:416
#define pdelete(p)
Definition: copasi.h:215
Header file of class CModelEntity and CModelValue.
const std::string & getResource() const
Definition: CRDFSubject.cpp:82
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiObject * get(const std::string &key)
const std::string & getBlankNodeID() const
Definition: CRDFSubject.cpp:91
static std::string getAllMessageText(const bool &chronological=true)
virtual bool enterProtected()
virtual void clear()
const std::string & getMiriamAnnotation() const
static void clearDeque()
std::map< const CRDFNode *, CQRDFTreeViewItem * > mNode2Item
Definition: CQRDFTreeView.h:72
CQRDFTreeView(QWidget *parent=0, const char *name=0)
void insert(const CRDFNode *pNode, CQRDFTreeViewItem *pItem)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
const std::set< CRDFTriplet > & getTriplets() const
Definition: CRDFGraph.cpp:434
static size_t size()
#define COL_SUBJECT
CQRDFTreeViewItem * find(const CRDFNode *pNode)
static CKeyFactory * getKeyFactory()
void setTriplet(const CRDFTriplet &triplet)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
Header file of class CEvent.
CRDFGraph * mpGraph
Definition: CQRDFTreeView.h:77
static CRDFGraph * graphFromXml(const std::string &xml)
Definition: CRDFParser.cpp:30
std::string mKey
Definition: copasiWidget.h:63
virtual ~CQRDFTreeView()
const eSubjectType & getType() const
Definition: CRDFSubject.cpp:73