COPASI API  4.16.103
Public Member Functions | Public Attributes | Protected Slots | Protected Attributes | Private Slots | Private Member Functions | List of all members
CQMergingData Class Reference

#include <CQMergingData.h>

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

Public Member Functions

 CQMergingData (QWidget *parent=0, Qt::WindowFlags fl=0, bool simple=false)
 
 ~CQMergingData ()
 

Public Attributes

std::map< QTreeWidgetItem
*, CCopasiObject * > 
mItemMap1
 
std::map< QTreeWidgetItem
*, CCopasiObject * > 
mItemMap2
 

Protected Slots

void treeSelectionChanged ()
 

Protected Attributes

CModelmpModel
 

Private Slots

void slotBtnCancel ()
 
void slotBtnMerge ()
 

Private Member Functions

void fillTree (QTreeWidget *pW, const CModel *pModel, std::map< QTreeWidgetItem *, CCopasiObject * > &itemMap, bool flagGlobalQuantities, bool flagReactions, const std::set< CCopasiObject * > &added, bool highlightInvolved)
 
void load ()
 

Detailed Description

Definition at line 24 of file CQMergingData.h.

Constructor & Destructor Documentation

CQMergingData::CQMergingData ( QWidget *  parent = 0,
Qt::WindowFlags  fl = 0,
bool  simple = false 
)

Definition at line 44 of file CQMergingData.cpp.

References load(), and treeSelectionChanged().

45  : QDialog(parent, fl)
46 {
47  setupUi(this);
48  connect(mpTree1, SIGNAL(currentItemChanged(QTreeWidgetItem * , QTreeWidgetItem *)), this, SLOT(treeSelectionChanged()));
49  connect(mpTree2, SIGNAL(currentItemChanged(QTreeWidgetItem * , QTreeWidgetItem *)), this, SLOT(treeSelectionChanged()));
50 
51  load();
52 }
void treeSelectionChanged()
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
CQMergingData::~CQMergingData ( )

Definition at line 57 of file CQMergingData.cpp.

58 {
59  // no need to delete child widgets, Qt does it all for us
60 }

Member Function Documentation

void CQMergingData::fillTree ( QTreeWidget *  pW,
const CModel pModel,
std::map< QTreeWidgetItem *, CCopasiObject * > &  itemMap,
bool  flagGlobalQuantities,
bool  flagReactions,
const std::set< CCopasiObject * > &  added,
bool  highlightInvolved 
)
private

fills a tree widget with the items of the model. All tree items are mapped to the model items in itemMap. const std::set<CCopasiObject*> & added : contains the model elements that were added by the latest model adding operation. They will be highlighted. If highlightInvolved is true, items that are actually referred to in other parts of the model are highlighted (these are the items that it is useful to replace)

Definition at line 62 of file CQMergingData.cpp.

References CModelExpansion::existDependentEntities(), FROM_UTF8, CChemEqInterface::getChemEqString(), CModel::getCompartments(), CModel::getModelValues(), CCopasiObject::getObjectName(), CModel::getReactions(), and CCopasiVector< T >::size().

Referenced by load().

66 {
67  itemMap.clear();
68  pW->clear();
69  CModelExpansion mex(const_cast<CModel*>(pModel));
70 
71  //create an italic font for highlighting new model elements
72  QFont tmpFont = pW->font();
73  tmpFont.setItalic(true);
74 
75  //add the compartments
76  size_t i, imax = pModel->getCompartments().size();
77  for(i=0; i<imax; ++i)
78  {
79  CCopasiObject * pObj = pModel->getCompartments()[i];
80  QTreeWidgetItem * pItem = new QTreeWidgetItem((QTreeWidget*)NULL, 1000);
81  pItem->setText(0, FROM_UTF8(pObj->getObjectName()));
82 
83  //highlight new objects
84  std::set<CCopasiObject*>::const_iterator it = added.find(pObj);
85  if (it != added.end())
86  {
87  pItem->setFont(0, tmpFont);
88  //pItem->setBackgroundColor(0, QColor(200,200,250));
89  }
90 
91  //highlight objects that are referred to by others
92  if (highlightInvolved)
93  {
94  if (!mex.existDependentEntities(pObj))
95  pItem->setTextColor(0, QColor(130,130,130));
96  }
97 
98  itemMap[pItem] = pObj;
99  pW->addTopLevelItem(pItem);
100  pW->setFirstItemColumnSpanned(pItem, true);
101 
102  //add species
103  //QTreeWidgetItem * pChild;
104  size_t j, jmax = pModel->getCompartments()[i]->getMetabolites().size();
105  for(j=0; j<jmax; ++j)
106  {
107  pObj = pModel->getCompartments()[i]->getMetabolites()[j];
108  QTreeWidgetItem * pChild = new QTreeWidgetItem(pItem, 1001);
109  pChild->setText(0, FROM_UTF8(pObj->getObjectName()));
110  pW->setFirstItemColumnSpanned(pChild, true);
111 
112  //highlight new objects
113  std::set<CCopasiObject*>::const_iterator it = added.find(pObj);
114  if (it != added.end())
115  {
116  pChild->setFont(0, tmpFont);
117  //pChild->setBackgroundColor(0, QColor(200,200,250));
118  }
119  //highlight objects that are referred to by others
120  if (highlightInvolved)
121  {
122  if (!mex.existDependentEntities(pObj))
123  pChild->setTextColor(0, QColor(130,130,130));
124  }
125 
126  itemMap[pChild]=pObj;
127  }
128  pItem->setExpanded(true);
129 
130  }
131 
132  if (flagGlobalQuantities && pModel->getModelValues().size())
133  {
134  QTreeWidgetItem * pItem = new QTreeWidgetItem((QTreeWidget*)NULL, 1000);
135  pItem->setText(0, "Global Quantities");
136  pW->addTopLevelItem(pItem);
137  pW->setFirstItemColumnSpanned(pItem, true);
138 
139 
140  //QTreeWidgetItem * pChild;
141  size_t j, jmax = pModel->getModelValues().size();
142  for(j=0; j<jmax; ++j)
143  {
144  CCopasiObject * pObj = pModel->getModelValues()[j];
145  QTreeWidgetItem * pChild = new QTreeWidgetItem(pItem, 1001);
146  pChild->setText(0, FROM_UTF8(pObj->getObjectName()));
147  pW->setFirstItemColumnSpanned(pChild, true);
148 
149  //highlight new objects
150  std::set<CCopasiObject*>::const_iterator it = added.find(pObj);
151  if (it != added.end())
152  {
153  pChild->setFont(0, tmpFont);
154  //pChild->setBackgroundColor(0, QColor(200,200,250));
155  }
156  //highlight objects that are referred to by others
157  if (highlightInvolved)
158  {
159  if (!mex.existDependentEntities(pObj))
160  pChild->setTextColor(0, QColor(130,130,130));
161  }
162 
163  itemMap[pChild]=pObj;
164  }
165  }
166  if (flagReactions && pModel->getReactions().size())
167  {
168  pW->setColumnCount(2);
169 
170  QTreeWidgetItem * pItem = new QTreeWidgetItem((QTreeWidget*)NULL, 1000);
171  pItem->setText(0, "Reactions");
172  pW->addTopLevelItem(pItem);
173  pW->setFirstItemColumnSpanned(pItem, true);
174 
175  QFont tmpFontSmall = pItem->font(0);
176  tmpFontSmall.setPointSize(tmpFontSmall.pointSize()-2);
177 
178  //QTreeWidgetItem * pChild;
179  size_t j, jmax = pModel->getReactions().size();
180  for(j=0; j<jmax; ++j)
181  {
182  CCopasiObject * pObj = pModel->getReactions()[j];
183  QTreeWidgetItem * pChild = new QTreeWidgetItem(pItem, 1001);
184  pChild->setText(0, FROM_UTF8(pObj->getObjectName()));
185  pW->setFirstItemColumnSpanned(pChild, false);
186 
187  //add the chemical equation (with a smaller font)
188  const CReaction * pReaction = dynamic_cast<const CReaction*>(pObj);
189  if (pReaction)
190  pChild->setText(1, FROM_UTF8(CChemEqInterface::getChemEqString(const_cast<CModel*>(pModel), *pReaction, false) ) );
191  pChild->setFont(1, tmpFontSmall);
192 
193  //highlight new objects
194  std::set<CCopasiObject*>::const_iterator it = added.find(pObj);
195  if (it != added.end())
196  {
197  pChild->setFont(0, tmpFont);
198  //pChild->setBackgroundColor(0, QColor(200,200,250));
199  }
200  //highlight objects that are referred to by others
201  if (highlightInvolved)
202  {
203  if (!mex.existDependentEntities(pObj))
204  pChild->setTextColor(0, QColor(130,130,130));
205  pChild->setTextColor(1, QColor(130,130,130));
206  }
207 
208  itemMap[pChild]=pObj;
209  }
210  //pW->setCo
211  }
212 
213 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
std::string getChemEqString(bool expanded) const
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
void CQMergingData::load ( )
private

Definition at line 233 of file CQMergingData.cpp.

References fillTree(), CCopasiRootContainer::getDatamodelList(), mItemMap1, mItemMap2, mpModel, and treeSelectionChanged().

Referenced by CQMergingData(), and slotBtnMerge().

234 {
235 
236  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
237 
238 
239  mpModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
240 
241  fillTree(mpTree1, mpModel, mItemMap1, true, true, (*CCopasiRootContainer::getDatamodelList())[0]->mLastAddedObjects, true);
242  fillTree(mpTree2, mpModel, mItemMap2, true, true, (*CCopasiRootContainer::getDatamodelList())[0]->mLastAddedObjects, false);
243 
245  }
void treeSelectionChanged()
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap2
Definition: CQMergingData.h:33
CModel * mpModel
Definition: CQMergingData.h:36
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void fillTree(QTreeWidget *pW, const CModel *pModel, std::map< QTreeWidgetItem *, CCopasiObject * > &itemMap, bool flagGlobalQuantities, bool flagReactions, const std::set< CCopasiObject * > &added, bool highlightInvolved)
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap1
Definition: CQMergingData.h:32
void CQMergingData::slotBtnCancel ( )
privateslot

Definition at line 298 of file CQMergingData.cpp.

299 {
300  //this is actually not "Cancel", but "Done"
301  accept();
302 }
void CQMergingData::slotBtnMerge ( )
privateslot

Definition at line 247 of file CQMergingData.cpp.

References CModelExpansion::ElementsMap::add(), CCopasiObject::getObjectType(), if(), load(), mItemMap1, mItemMap2, mpModel, and CModelExpansion::replaceInModel().

248 {
249  //simple, preliminary
250  CCopasiObject* p1=NULL;
251  CCopasiObject* p2=NULL;
252 
253  std::map<QTreeWidgetItem*, CCopasiObject*>::const_iterator it;
254  it = mItemMap1.find(mpTree1->currentItem());
255  if (it != mItemMap1.end())
256  p1 = it->second;
257  it = mItemMap2.find(mpTree2->currentItem());
258  if (it != mItemMap2.end())
259  p2 = it->second;
260 
261 /* for (it=mItemMap1.begin(); it != mItemMap1.end(); ++it)
262  {
263  if (it->first->checkState(0)==Qt::Checked)
264  {
265  p1=it->second;
266  break;
267  }
268  }
269  for (it=mItemMap2.begin(); it != mItemMap2.end(); ++it)
270  {
271  if (it->first->checkState(0)==Qt::Checked)
272  {
273  p2=it->second;
274  break;
275  }
276  }*/
277 
278  //check if the replacement matches in type
279  if (!p1 || !p2 || p1->getObjectType()!=p2->getObjectType())
280  return;
281  //TODO it would be better to check this constantly and disable the merge button accordingly
282 
283  //pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
284  CModelExpansion expa(mpModel);
286  emap.add(p1, p2);
287  expa.replaceInModel(emap, true); //true means remove replaced items
288 
289  //CModelMerging merging(pModel);
290  //merging.simpleCall(mColumnKey, mObjectKey);
291 
292  load();
293 
294  //accept();
295 }
const std::string & getObjectType() const
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap2
Definition: CQMergingData.h:33
void add(const CCopasiObject *source, CCopasiObject *copy)
add a source->duplicate mapping
CModel * mpModel
Definition: CQMergingData.h:36
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap1
Definition: CQMergingData.h:32
if(!yymsg) yymsg
void CQMergingData::treeSelectionChanged ( )
protectedslot

Definition at line 215 of file CQMergingData.cpp.

References CCopasiObject::getObjectType(), if(), mItemMap1, and mItemMap2.

Referenced by CQMergingData(), and load().

216 {
217  // only enable the merging button if the selected items match and are not identical
218  CCopasiObject* p1=NULL;
219  CCopasiObject* p2=NULL;
220  std::map<QTreeWidgetItem*, CCopasiObject*>::const_iterator it;
221  it = mItemMap1.find(mpTree1->currentItem());
222  if (it != mItemMap1.end())
223  p1 = it->second;
224  it = mItemMap2.find(mpTree2->currentItem());
225  if (it != mItemMap2.end())
226  p2 = it->second;
227  if (!p1 || !p2 || p1->getObjectType()!=p2->getObjectType() || p1==p2)
228  mpBtnMerge->setEnabled(false);
229  else
230  mpBtnMerge->setEnabled(true);
231 }
const std::string & getObjectType() const
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap2
Definition: CQMergingData.h:33
std::map< QTreeWidgetItem *, CCopasiObject * > mItemMap1
Definition: CQMergingData.h:32
if(!yymsg) yymsg

Member Data Documentation

std::map<QTreeWidgetItem*, CCopasiObject*> CQMergingData::mItemMap1

Definition at line 32 of file CQMergingData.h.

Referenced by load(), slotBtnMerge(), and treeSelectionChanged().

std::map<QTreeWidgetItem*, CCopasiObject*> CQMergingData::mItemMap2

Definition at line 33 of file CQMergingData.h.

Referenced by load(), slotBtnMerge(), and treeSelectionChanged().

CModel* CQMergingData::mpModel
protected

Definition at line 36 of file CQMergingData.h.

Referenced by load(), and slotBtnMerge().


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