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

#include <CQAutolayoutWizard.h>

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

Public Member Functions

 CQSelectionWizardPage (const CModel &model)
 
void fillContainers (std::set< const CCompartment * > &compartments, std::set< const CReaction * > &reactions, std::set< const CMetab * > &species) const
 

Protected Slots

void slotCreateCompartments (int state)
 
void slotItemChanged (QTreeWidgetItem *pItem, int column)
 

Protected Member Functions

void fillTree (const CModel &model)
 

Protected Attributes

bool mCreateCompartmentElements
 
QTreeWidgetItem * mpCompartmentsItem
 
QTreeWidgetItem * mpReactionsItem
 
QTreeWidget * mpSelectionTree
 

Detailed Description

This is the first page of the wizard. It displays a tree where the user can select the objects that should be included in the layout.

Definition at line 82 of file CQAutolayoutWizard.h.

Constructor & Destructor Documentation

CQSelectionWizardPage::CQSelectionWizardPage ( const CModel model)

Definition at line 91 of file CQAutolayoutWizard.cpp.

References fillTree(), mpCompartmentsItem, mpReactionsItem, mpSelectionTree, slotCreateCompartments(), and slotItemChanged().

91  :
92  QWizardPage()
94  , mpSelectionTree(new QTreeWidget)
95  , mpCompartmentsItem(new QTreeWidgetItem((QTreeWidget*)NULL, QStringList(QString(tr("Compartments")))))
96  , mpReactionsItem(new QTreeWidgetItem((QTreeWidget*)NULL, QStringList(QString(tr("Reactions")))))
97 {
98  this->setTitle(tr("Model Element Selection"));
99  this->setSubTitle("Please select the model elements for which you want to create layout elements.\nPlease Note the the \"All ...\" elements only turn their immediate children on or off.");
100  QVBoxLayout* pLayout = new QVBoxLayout;
101  this->setLayout(pLayout);
102  pLayout->addWidget(this->mpSelectionTree);
103  this->fillTree(model);
104  QCheckBox* pCheckBox = new QCheckBox("create compartment elements");
105  pCheckBox->setChecked(false);
106  connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotCreateCompartments(int)));
107  pLayout->addWidget(pCheckBox);
108  this->mpSelectionTree->setColumnCount(1);
109  this->mpSelectionTree->setHeaderLabel(tr("Elements"));
110  // add a top level element for the compartments
111  // add a top level element for the reactions
112  QList<QTreeWidgetItem*> items;
113  items.append(this->mpCompartmentsItem);
114  items.append(this->mpReactionsItem);
115  this->mpSelectionTree->insertTopLevelItems(0, items);
116  connect(this->mpSelectionTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotItemChanged(QTreeWidgetItem*, int)));
117 }
void slotCreateCompartments(int state)
QTreeWidgetItem * mpReactionsItem
QTreeWidgetItem * mpCompartmentsItem
void fillTree(const CModel &model)
void slotItemChanged(QTreeWidgetItem *pItem, int column)

Member Function Documentation

void CQSelectionWizardPage::fillContainers ( std::set< const CCompartment * > &  compartments,
std::set< const CReaction * > &  reactions,
std::set< const CMetab * > &  species 
) const

Checks which elements have been selected in the tree and fills the containers that are passed in with those elements.

Definition at line 495 of file CQAutolayoutWizard.cpp.

References CQModelElementTreeWidgetItem::getObject(), mpCompartmentsItem, and mpReactionsItem.

496 {
497  // clear all containers
498  compartments.clear();
499  reactions.clear();
500  species.clear();
501 
502  if (this->mpCompartmentsItem->childCount() > 0)
503  {
504  QTreeWidgetItem* pItem = this->mpCompartmentsItem->child(0);
505  unsigned int i = 0, iMax = pItem->childCount();
506  unsigned int j, jMax;
507  const CMetab* pMetab = NULL;
508  QTreeWidgetItem *pItem2 = NULL, *pChild = NULL, *pChild2 = NULL;
509  const CCompartment* pCompartment = NULL;
510  CQModelElementTreeWidgetItem* pModelItem = NULL;
511 
512  while (i < iMax)
513  {
514  pChild = pItem->child(i);
515  assert(pChild != NULL);
516 
517  if ((pChild->flags() & Qt::ItemIsUserCheckable) && pChild->checkState(0) == Qt::Checked)
518  {
519  pModelItem = dynamic_cast<CQModelElementTreeWidgetItem*>(pItem->child(i));
520  assert(pModelItem != NULL);
521  pCompartment = dynamic_cast<const CCompartment*>(pModelItem->getObject());
522  assert(pCompartment != NULL);
523  compartments.insert(pCompartment);
524  }
525 
526  pItem2 = pChild->child(0);
527 
528  // get the All species item
529  if (pItem2 == NULL)
530  {
531  ++i;
532  continue;
533  }
534 
535  j = 0;
536  jMax = pItem2->childCount();
537 
538  while (j < jMax)
539  {
540  pChild2 = pItem2->child(j);
541 
542  if ((pChild2->flags() & Qt::ItemIsUserCheckable) && pChild2->checkState(0) == Qt::Checked)
543  {
544  pModelItem = dynamic_cast<CQModelElementTreeWidgetItem*>(pItem2->child(j));
545  assert(pModelItem != NULL);
546  pMetab = dynamic_cast<const CMetab*>(pModelItem->getObject());
547  assert(pMetab != NULL);
548  species.insert(pMetab);
549  }
550 
551  ++j;
552  }
553 
554  ++i;
555  }
556 
557  // now we add the reactions
558  }
559 
560  if (this->mpReactionsItem->childCount() > 0)
561  {
562  // there should be only one child (All reactions)
563  assert(this->mpReactionsItem->childCount() == 1);
564  QTreeWidgetItem* pItem = this->mpReactionsItem->child(0), *pChild = NULL;
565  CQModelElementTreeWidgetItem* pModelItem = NULL;
566  unsigned int i = 0, iMax;
567  iMax = pItem->childCount();
568  const CReaction* pReaction = NULL;
569 
570  while (i < iMax)
571  {
572  pChild = pItem->child(i);
573 
574  if ((pChild->flags() & Qt::ItemIsUserCheckable) && pChild->checkState(0) == Qt::Checked)
575  {
576  pModelItem = dynamic_cast<CQModelElementTreeWidgetItem*>(pChild);
577  assert(pModelItem != NULL);
578  pReaction = dynamic_cast<const CReaction*>(pModelItem->getObject());
579  assert(pReaction != NULL);
580  reactions.insert(pReaction);
581  }
582 
583  ++i;
584  }
585  }
586 }
Definition: CMetab.h:178
QTreeWidgetItem * mpReactionsItem
QTreeWidgetItem * mpCompartmentsItem
CCopasiObject * getObject() const
void CQSelectionWizardPage::fillTree ( const CModel model)
protected

Definition at line 392 of file CQAutolayoutWizard.cpp.

References CModel::getCompartments(), CModelEntity::getKey(), CReaction::getKey(), CCompartment::getMetabolites(), CModel::getMetabolites(), CReaction::getObjectDisplayName(), CMetab::getObjectDisplayName(), CCopasiObject::getObjectDisplayName(), CModel::getReactions(), mpCompartmentsItem, mpReactionsItem, and CCopasiVector< T >::size().

Referenced by CQSelectionWizardPage().

393 {
394  const CCopasiVectorNS < CCompartment >& compartments = model.getCompartments();
395  const CCopasiVector< CMetab >& metabs = model.getMetabolites();
396  const CCopasiVectorNS < CReaction >& reactions = model.getReactions();
397 
398  if (compartments.size() > 0 && metabs.size() > 0)
399  {
400  // make all items checkable but the ones for the compartments
401  // and the ones for All compartments
402  // check all checkable items
403 
404  // add the compartments
405  // first we have to add two items to the top level items that we can use to
406  // specify that we want to select all children in a list
407  QTreeWidgetItem* pItem = new QTreeWidgetItem(QStringList(QString(tr("All Compartments"))));
408  pItem->setFlags(pItem->flags() & (!Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
409  this->mpCompartmentsItem->addChild(pItem);
410  // add all compartments to the item
411  QList<QTreeWidgetItem*> children, children2;
412  unsigned int i = 0, iMax = compartments.size();
413  QTreeWidgetItem *pChild1;
414  const CCompartment* pCompartment = NULL;
415  QTreeWidgetItem *pItem2 = NULL, *pItem3 = NULL;
416  const CCopasiVectorNS<CMetab>* pMetabs = NULL;
417  unsigned int j, jMax;
418  const CMetab* pMetab = NULL;
419 
420  while (i < iMax)
421  {
422  pCompartment = compartments[i];
423  assert(pCompartment != NULL);
424  pChild1 = new CQModelElementTreeWidgetItem(QStringList(QString(pCompartment->getObjectDisplayName().c_str())), pCompartment->getKey());
425  pChild1->setFlags(pChild1->flags() & (!Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
426  // add an item to select all children
427  pMetabs = &pCompartment->getMetabolites();
428  assert(pMetabs != NULL);
429 
430  if (pMetabs->size() > 0)
431  {
432  pItem2 = new QTreeWidgetItem(QStringList(QString(tr("All Metabolites in Compartment"))));
433  pItem2->setFlags(pItem2->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
434  pItem2->setCheckState(0, Qt::Checked);
435  pChild1->addChild(pItem2);
436  // now we add all metabolites
437  j = 0;
438  jMax = pMetabs->size();
439 
440  while (j < jMax)
441  {
442  pMetab = (*pMetabs)[j];
443  assert(pMetab != NULL);
444  pItem3 = new CQModelElementTreeWidgetItem(QStringList(QString(pMetab->getObjectDisplayName().c_str())), pMetab->getKey());
445  pItem3->setFlags(pItem3->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
446  pItem3->setCheckState(0, Qt::Checked);
447  children2.append(pItem3);
448  ++j;
449  }
450 
451  pItem2->addChildren(children2);
452  children2.clear();
453  }
454 
455  children.append(pChild1);
456  ++i;
457  }
458 
459  pItem->addChildren(children);
460 
461  if (reactions.size() > 0)
462  {
463  // top level item to select all reactions
464  pItem = new QTreeWidgetItem(QStringList(QString(tr("All Reactions"))));
465  pItem->setFlags(pItem->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
466  pItem->setCheckState(0, Qt::Checked);
467  this->mpReactionsItem->addChild(pItem);
468  // now we add all reactions
469  i = 0;
470  iMax = reactions.size();
471  const CReaction* pReaction = NULL;
472 
473  while (i < iMax)
474  {
475  pReaction = reactions[i];
476  assert(pReaction != NULL);
477  pChild1 = new CQModelElementTreeWidgetItem(QStringList(QString(pReaction->getObjectDisplayName().c_str())), pReaction->getKey());
478  pChild1->setFlags(pChild1->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
479  pChild1->setCheckState(0, Qt::Checked);
480  // TODO add the substrates and products to the reactions
481  children2.append(pChild1);
482  ++i;
483  }
484 
485  pItem->addChildren(children2);
486  }
487  }
488 }
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
CCopasiVectorNS< CMetab > & getMetabolites()
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
virtual size_t size() const
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
Definition: CReaction.cpp:1688
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
Definition: CMetab.cpp:974
Definition: CMetab.h:178
virtual const std::string & getKey() const
QTreeWidgetItem * mpReactionsItem
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
QTreeWidgetItem * mpCompartmentsItem
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
void CQSelectionWizardPage::slotCreateCompartments ( int  state)
protectedslot

Definition at line 339 of file CQAutolayoutWizard.cpp.

References mCreateCompartmentElements, mpCompartmentsItem, mpSelectionTree, and slotItemChanged().

Referenced by CQSelectionWizardPage().

340 {
341  // set the flags on the compartment items and the All items in compartments
342  // to be checkable but leave them unchecked
343  disconnect(this->mpSelectionTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotItemChanged(QTreeWidgetItem*, int)));
344 
345  if (state == Qt::Checked)
346  {
347  this->mCreateCompartmentElements = true;
348  QTreeWidgetItem* pItem = this->mpCompartmentsItem->child(0);
349 
350  if (pItem != NULL)
351  {
352  pItem->setFlags(pItem->flags() | Qt::ItemIsUserCheckable);
353  pItem->setCheckState(0, Qt::Unchecked);
354  // now we do the same on all the children of this item
355  unsigned int i = 0, iMax = pItem->childCount();
356 
357  while (i < iMax)
358  {
359  pItem->child(i)->setFlags(pItem->child(i)->flags() | Qt::ItemIsUserCheckable);
360  pItem->child(i)->setCheckState(0, Qt::Unchecked);
361  ++i;
362  }
363  }
364  }
365  else
366  {
367  this->mCreateCompartmentElements = false;
368  this->mpCompartmentsItem->setFlags(this->mpCompartmentsItem->flags() & (~Qt::ItemIsUserCheckable));
369  this->mpCompartmentsItem->setData(0, Qt::CheckStateRole, QVariant());
370  QTreeWidgetItem* pItem = this->mpCompartmentsItem->child(0);
371 
372  if (pItem != NULL)
373  {
374  pItem->setFlags(pItem->flags() & (~Qt::ItemIsUserCheckable));
375  pItem->setData(0, Qt::CheckStateRole, QVariant());
376  // now we do the same on all the children of this item
377  unsigned int i = 0, iMax = pItem->childCount();
378 
379  while (i < iMax)
380  {
381  pItem->child(i)->setFlags(pItem->child(i)->flags() & (~Qt::ItemIsUserCheckable));
382  pItem->child(i)->setData(0, Qt::CheckStateRole, QVariant());
383  ++i;
384  }
385  }
386  }
387 
388  connect(this->mpSelectionTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotItemChanged(QTreeWidgetItem*, int)));
389 }
QTreeWidgetItem * mpCompartmentsItem
void slotItemChanged(QTreeWidgetItem *pItem, int column)
void CQSelectionWizardPage::slotItemChanged ( QTreeWidgetItem *  pItem,
int  column 
)
protectedslot

Definition at line 119 of file CQAutolayoutWizard.cpp.

References mpCompartmentsItem, mpReactionsItem, mpSelectionTree, and slotItemChanged().

Referenced by CQSelectionWizardPage(), slotCreateCompartments(), and slotItemChanged().

120 {
121  disconnect(this->mpSelectionTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotItemChanged(QTreeWidgetItem*, int)));
122  QTreeWidgetItem* pParent = pItem->parent();
123  assert(pParent != NULL);
124  bool found = false;
125 
126  if (this->mpCompartmentsItem->childCount() > 0)
127  {
128  // check if it was the "All compartments" entry
129  QTreeWidgetItem* pChild = this->mpCompartmentsItem->child(0);
130 
131  if (pItem == pChild)
132  {
133  // we have to select or deselect all immediate children
134  found = true;
135  unsigned int i = 0, iMax = pItem->childCount();
136  Qt::CheckState state = pItem->checkState(0);
137 
138  while (i < iMax)
139  {
140  pItem->child(i)->setCheckState(0, state);
141  ++i;
142  }
143  }
144  else
145  {
146  // check if it was one of the compartments entries
147  // the "All metabolite" entry, or one of the metabolites
148  int i = 0, iMax = pChild->childCount();
149  QTreeWidgetItem* pAll = NULL;
150 
151  while (i < iMax && !found)
152  {
153  if (pItem == pChild->child(i))
154  {
155  // it is a compartment node
156  // , we might have to change the state of the parent
157  found = true;
158  unsigned int j = 0, jMax = pParent->childCount();
159  bool allSelected = true;
160  bool allUnselected = true;
161 
162  while (j < jMax && (allSelected == true || allUnselected == true))
163  {
164  if (pParent->child(j)->checkState(0) == Qt::Checked)
165  {
166  allUnselected = false;
167  }
168  else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
169  {
170  allSelected = false;
171  }
172  else
173  {
174  allSelected = false;
175  allUnselected = false;
176  }
177 
178  ++j;
179  }
180 
181  if (allSelected == true)
182  {
183  pParent->setCheckState(0, Qt::Checked);
184  }
185  else if (allUnselected == true)
186  {
187  pParent->setCheckState(0, Qt::Unchecked);
188  }
189  else
190  {
191  pParent->setCheckState(0, Qt::PartiallyChecked);
192  }
193  }
194  else
195  {
196  pAll = pChild->child(i)->child(0);
197 
198  if (pAll != NULL)
199  {
200  if (pItem == pAll)
201  {
202  // we have to select or deselect all immediate children
203  found = true;
204  unsigned int j = 0, jMax = pItem->childCount();
205  Qt::CheckState state = pItem->checkState(0);
206 
207  while (j < jMax)
208  {
209  pItem->child(j)->setCheckState(0, state);
210  ++j;
211  }
212  }
213  else if (pAll == pParent)
214  {
215  found = true;
216  // a metabolites selection status has changed
217  // we have to change the state of the parent
218  unsigned int j = 0, jMax = pParent->childCount();
219  bool allSelected = true;
220  bool allUnselected = true;
221 
222  while (j < jMax && (allSelected == true || allUnselected == true))
223  {
224  if (pParent->child(j)->checkState(0) == Qt::Checked)
225  {
226  allUnselected = false;
227  }
228  else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
229  {
230  allSelected = false;
231  }
232  else
233  {
234  allSelected = false;
235  allUnselected = false;
236  }
237 
238  ++j;
239  }
240 
241  if (allSelected == true)
242  {
243  pParent->setCheckState(0, Qt::Checked);
244  }
245  else if (allUnselected == true)
246  {
247  pParent->setCheckState(0, Qt::Unchecked);
248  }
249  else
250  {
251  pParent->setCheckState(0, Qt::PartiallyChecked);
252  }
253  }
254  }
255  }
256 
257  ++i;
258  }
259  }
260  }
261 
262  if (!found && this->mpReactionsItem->childCount() > 0)
263  {
264  // check if it was the "All reactions" entry
265  QTreeWidgetItem* pChild = this->mpReactionsItem->child(0);
266 
267  if (pItem == pChild)
268  {
269  // we have to select or deselect all immediate children
270  found = true;
271  unsigned int j = 0, jMax = pItem->childCount();
272  Qt::CheckState state = pItem->checkState(0);
273 
274  while (j < jMax)
275  {
276  pItem->child(j)->setCheckState(0, state);
277  ++j;
278  }
279  }
280  else
281  {
282  // check if it was one of the reaction entries
283  int i = 0, iMax = pChild->childCount();
284 
285  while (i < iMax && !found)
286  {
287  if (pItem == pChild->child(i))
288  {
289  found = true;
290  // it is a reaction node
291  // , we might have to change the state of the parent
292  unsigned int j = 0, jMax = pParent->childCount();
293  bool allSelected = true;
294  bool allUnselected = true;
295 
296  while (j < jMax && (allSelected == true || allUnselected == true))
297  {
298  if (pParent->child(j)->checkState(0) == Qt::Checked)
299  {
300  allUnselected = false;
301  }
302  else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
303  {
304  allSelected = false;
305  }
306  else
307  {
308  allSelected = false;
309  allUnselected = false;
310  }
311 
312  ++j;
313  }
314 
315  if (allSelected == true)
316  {
317  pParent->setCheckState(0, Qt::Checked);
318  }
319  else if (allUnselected == true)
320  {
321  pParent->setCheckState(0, Qt::Unchecked);
322  }
323  else
324  {
325  pParent->setCheckState(0, Qt::PartiallyChecked);
326  }
327  }
328 
329  ++i;
330  }
331  }
332  }
333 
334  assert(found == true);
335  connect(this->mpSelectionTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotItemChanged(QTreeWidgetItem*, int)));
336 }
QTreeWidgetItem * mpReactionsItem
QTreeWidgetItem * mpCompartmentsItem
void slotItemChanged(QTreeWidgetItem *pItem, int column)

Member Data Documentation

bool CQSelectionWizardPage::mCreateCompartmentElements
protected

Definition at line 105 of file CQAutolayoutWizard.h.

Referenced by slotCreateCompartments().

QTreeWidgetItem* CQSelectionWizardPage::mpCompartmentsItem
protected
QTreeWidgetItem* CQSelectionWizardPage::mpReactionsItem
protected
QTreeWidget* CQSelectionWizardPage::mpSelectionTree
protected

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