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

#include <CQAutolayoutWizard.h>

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

Classes

class  alphaSorter
 
class  CQListWidgetModelItem
 

Public Member Functions

 CQSideCompoundWizardPage ()
 
void getSideCompounds (std::set< const CMetab * > &sideCompounds) const
 
void setSpeciesList (const std::set< const CMetab * > &metabs)
 

Protected Slots

void slotAddButtonClicked ()
 
void slotRemoveButtonClicked ()
 
void slotSideCompoundSelectionChanged ()
 
void slotSpeciesSelectionChanged ()
 

Protected Attributes

QPushButton * mpAddButton
 
QPushButton * mpRemoveButton
 
QListWidget * mpSideCompoundList
 
QListWidget * mpSpeciesList
 
std::set< const CMetab
*, alphaSorter
mSortedSpecies
 

Detailed Description

In this page the user can select which species should be treated as side compounds by the layout algorithm.

Definition at line 128 of file CQAutolayoutWizard.h.

Constructor & Destructor Documentation

CQSideCompoundWizardPage::CQSideCompoundWizardPage ( )

Definition at line 616 of file CQAutolayoutWizard.cpp.

References mpAddButton, mpRemoveButton, mpSideCompoundList, mpSpeciesList, slotAddButtonClicked(), slotRemoveButtonClicked(), slotSideCompoundSelectionChanged(), and slotSpeciesSelectionChanged().

616  :
617  QWizardPage()
618  , mpSpeciesList(new QListWidget)
619  , mpSideCompoundList(new QListWidget)
620  , mpAddButton(new QPushButton(">>"))
621  , mpRemoveButton(new QPushButton("<<"))
622 {
623  this->setTitle("Side Compounds");
624  this->setSubTitle("Please select the species that you want to be considered as side compounds in the layout.\n\nSide compounds can be duplicated for each reaction they occur in and they might be treated differently by the layout algorithm.");
625  // the page should contain two lists
626  // and the user can push elements back and forth
627  // between the lists
628  this->mpSpeciesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
629  this->mpSideCompoundList->setSelectionMode(QAbstractItemView::ExtendedSelection);
630  QHBoxLayout* pLayout = new QHBoxLayout;
631  this->setLayout(pLayout);
632  QFrame* pFrame = new QFrame;
633  QVBoxLayout* pLayout2 = new QVBoxLayout;
634  pFrame->setLayout(pLayout2);
635  pLayout2->addWidget(new QLabel("Species"));
636  pLayout2->addWidget(this->mpSpeciesList);
637  pLayout->addWidget(pFrame);
638  pLayout2 = new QVBoxLayout;
639  pFrame = new QFrame;
640  pFrame->setLayout(pLayout2);
641  pLayout2->addStretch();
642  this->mpAddButton->setEnabled(false);
643  this->mpRemoveButton->setEnabled(false);
644  pLayout2->addWidget(this->mpAddButton);
645  pLayout2->addSpacing(20);
646  pLayout2->addWidget(this->mpRemoveButton);
647  pLayout2->addStretch();
648  pLayout->addWidget(pFrame);
649  pFrame = new QFrame;
650  pLayout2 = new QVBoxLayout;
651  pFrame->setLayout(pLayout2);
652  pLayout2->addWidget(new QLabel("Side-Species"));
653  pLayout2->addWidget(this->mpSideCompoundList);
654  pLayout->addWidget(pFrame);
655  connect(this->mpAddButton, SIGNAL(clicked()), this, SLOT(slotAddButtonClicked()));
656  connect(this->mpRemoveButton, SIGNAL(clicked()), this, SLOT(slotRemoveButtonClicked()));
657  connect(this->mpSpeciesList, SIGNAL(itemSelectionChanged()), this, SLOT(slotSpeciesSelectionChanged()));
658  connect(this->mpSideCompoundList, SIGNAL(itemSelectionChanged()), this, SLOT(slotSideCompoundSelectionChanged()));
659 }

Member Function Documentation

void CQSideCompoundWizardPage::getSideCompounds ( std::set< const CMetab * > &  sideCompounds) const

Fills the given set with the side compounds that have been selected by the user.

Definition at line 670 of file CQAutolayoutWizard.cpp.

References CQSideCompoundWizardPage::CQListWidgetModelItem::getObject(), and mpSideCompoundList.

671 {
672  sideCompounds.clear();
673  unsigned int i, iMax = this->mpSideCompoundList->count();
674  const CQListWidgetModelItem* pItem = NULL;
675  const CMetab* pMetab = NULL;
676 
677  for (i = 0; i < iMax; ++i)
678  {
679  pItem = dynamic_cast<const CQListWidgetModelItem*>(this->mpSideCompoundList->item(i));
680  assert(pItem != NULL);
681  pMetab = dynamic_cast<const CMetab*>(pItem->getObject());
682  sideCompounds.insert(pMetab);
683  }
684 }
Definition: CMetab.h:178
void CQSideCompoundWizardPage::setSpeciesList ( const std::set< const CMetab * > &  metabs)

Passes the species that have been selected by the user for use in the layout to the page. These species are used to fill the list on the left.

Definition at line 691 of file CQAutolayoutWizard.cpp.

References mpSideCompoundList, mpSpeciesList, and mSortedSpecies.

692 {
693  this->mSortedSpecies.clear();
694  this->mSortedSpecies.insert(metabs.begin(), metabs.end());
695  std::set<std::string> keys;
696 
697  this->mpSpeciesList->clear();
698  std::set<const CMetab*, alphaSorter>::const_iterator it = this->mSortedSpecies.begin(), endit = this->mSortedSpecies.end();
699  QList<QListWidgetItem*> itemList;
700  int i, iMax;
701 
702  while (it != endit)
703  {
704  std::string displayName = (*it)->getObjectDisplayName();
705  keys.insert((*it)->getKey());
706  // if the item is already marked as a side compound, we don't
707  // have to add it to the species list
708  itemList = this->mpSideCompoundList->findItems(displayName.c_str(), Qt::MatchExactly);
709  i = 0;
710  iMax = itemList.size();
711  bool found = false;
712 
713  while (i < iMax)
714  {
715  if (static_cast<const CQListWidgetModelItem*>(itemList[i])->getKey() == (*it)->getKey())
716  {
717  found = true;
718  }
719 
720  ++i;
721  }
722 
723  if (found == false)
724  {
725  // the item is not a side compound, so we add it to the species list
726  this->mpSpeciesList->addItem(new CQListWidgetModelItem(displayName.c_str(), (*it)->getKey()));
727  }
728 
729  ++it;
730  }
731 
732  // now we have to go through the side compounds again and check
733  // if all the names that are in there are also in the sorted name list
734  // If not, we have to delete the item from the side compounds
735  iMax = this->mpSideCompoundList->count() - 1;
736  std::set<std::string>::const_iterator end = keys.end();
737  QListWidgetItem* pItem = NULL;
738 
739  while (iMax > 0)
740  {
741  if (keys.find(static_cast<const CQListWidgetModelItem*>(this->mpSideCompoundList->item(iMax))->getKey()) == end)
742  {
743  pItem = this->mpSideCompoundList->takeItem(iMax);
744 
745  if (pItem != NULL)
746  {
747  delete pItem;
748  }
749  }
750 
751  --iMax;
752  }
753 }
std::set< const CMetab *, alphaSorter > mSortedSpecies
void CQSideCompoundWizardPage::slotAddButtonClicked ( )
protectedslot

Definition at line 756 of file CQAutolayoutWizard.cpp.

References CQSideCompoundWizardPage::CQListWidgetModelItem::getObject(), CCopasiObject::getObjectDisplayName(), mpSideCompoundList, and mpSpeciesList.

Referenced by CQSideCompoundWizardPage().

757 {
758  // move the selected items from the species list to the side compound list
759  QList<QListWidgetItem*> selection = this->mpSpeciesList->selectedItems();
760  // insert the items into the side compound list in the correct order
761  // and remove them from the species list
762  // the items should be selected in the side compound list
763  int index = 0;
764  QList<QListWidgetItem*>::iterator it = selection.begin(), endit = selection.end();
765 
766  while (it != endit)
767  {
768  while (index < this->mpSideCompoundList->count() && static_cast<CQListWidgetModelItem*>(this->mpSideCompoundList->item(index))->getObject()->getObjectDisplayName() < static_cast<CQListWidgetModelItem*>(*it)->getObject()->getObjectDisplayName())
769  {
770  ++index;
771  }
772 
773  if (index == this->mpSideCompoundList->count())
774  {
775  // we add all items at the end
776  while (it != endit)
777  {
778  this->mpSpeciesList->takeItem(this->mpSpeciesList->row(*it));
779  this->mpSideCompoundList->addItem((*it));
780  ++it;
781  }
782  }
783 
784  // now we insert items until the item is not at the right place
785  while (it != endit && static_cast<CQListWidgetModelItem*>(this->mpSideCompoundList->item(index))->getObject()->getObjectDisplayName() > static_cast<CQListWidgetModelItem*>(*it)->getObject()->getObjectDisplayName())
786  {
787  this->mpSpeciesList->takeItem(this->mpSpeciesList->row(*it));
788  this->mpSideCompoundList->insertItem(index, *it);
789  ++it;
790  }
791  }
792 
793  // TODO set the newly added items as selected
794  // TODO disconnect and reconnect the slot that listend to the selection change
795  // TODO and emit the signal after changing the selection
796  this->mpSpeciesList->update();
797 }
void CQSideCompoundWizardPage::slotRemoveButtonClicked ( )
protectedslot

Definition at line 800 of file CQAutolayoutWizard.cpp.

References CQSideCompoundWizardPage::CQListWidgetModelItem::getObject(), CCopasiObject::getObjectDisplayName(), mpSideCompoundList, and mpSpeciesList.

Referenced by CQSideCompoundWizardPage().

801 {
802  // move the selected items from the side compound list to the species list
803  QList<QListWidgetItem*> selection = this->mpSideCompoundList->selectedItems();
804  // insert the items into the species list in the correct order
805  // and remove them from the side compound list
806  // the items should be selected in the species list
807  QList<QListWidgetItem*>::iterator it = selection.begin(), endit = selection.end();
808  int index = 0;
809 
810  while (it != endit)
811  {
812  while (index < this->mpSpeciesList->count() && static_cast<CQListWidgetModelItem*>(this->mpSpeciesList->item(index))->getObject()->getObjectDisplayName() < static_cast<CQListWidgetModelItem*>(*it)->getObject()->getObjectDisplayName())
813  {
814  ++index;
815  }
816 
817  if (index == this->mpSpeciesList->count())
818  {
819  // we add all items at the end
820  while (it != endit)
821  {
822  this->mpSideCompoundList->takeItem(this->mpSideCompoundList->row(*it));
823  this->mpSpeciesList->addItem((*it));
824  ++it;
825  }
826 
827  break;
828  }
829 
830  // now we insert items until the item is not at the right place
831  while (it != endit && static_cast<CQListWidgetModelItem*>(this->mpSpeciesList->item(index))->getObject()->getObjectDisplayName() > static_cast<CQListWidgetModelItem*>(*it)->getObject()->getObjectDisplayName())
832  {
833  this->mpSideCompoundList->takeItem(this->mpSideCompoundList->row(*it));
834  this->mpSpeciesList->insertItem(index, *it);
835  ++it;
836  }
837  }
838 
839  // TODO set the newly added items as selected
840  // TODO disconnect and reconnect the slot that listend to the selection change
841  // TODO and emit the signal after changing the selection
842  this->mpSideCompoundList->update();
843 }
void CQSideCompoundWizardPage::slotSideCompoundSelectionChanged ( )
protectedslot

Definition at line 866 of file CQAutolayoutWizard.cpp.

References mpRemoveButton, mpSideCompoundList, and mpSpeciesList.

Referenced by CQSideCompoundWizardPage().

867 {
868  // if something is selected, delete the selection in the
869  // species list and active the remove button
870  // else deactivate the remove button
871  QList<QListWidgetItem*> selection = this->mpSideCompoundList->selectedItems();
872 
873  if (selection.size() == 0)
874  {
875  this->mpRemoveButton->setEnabled(false);
876  }
877  else
878  {
879  this->mpRemoveButton->setEnabled(true);
880  this->mpSpeciesList->clearSelection();
881  }
882 }
void CQSideCompoundWizardPage::slotSpeciesSelectionChanged ( )
protectedslot

Definition at line 846 of file CQAutolayoutWizard.cpp.

References mpAddButton, mpSideCompoundList, and mpSpeciesList.

Referenced by CQSideCompoundWizardPage().

847 {
848  // if something is selected
849  // delete the selection in the side compound list
850  // if nothing is selected deactive the add button, else active the add
851  // button
852  QList<QListWidgetItem*> selection = this->mpSpeciesList->selectedItems();
853 
854  if (selection.size() == 0)
855  {
856  this->mpAddButton->setEnabled(false);
857  }
858  else
859  {
860  this->mpAddButton->setEnabled(true);
861  this->mpSideCompoundList->clearSelection();
862  }
863 }

Member Data Documentation

QPushButton* CQSideCompoundWizardPage::mpAddButton
protected

Definition at line 181 of file CQAutolayoutWizard.h.

Referenced by CQSideCompoundWizardPage(), and slotSpeciesSelectionChanged().

QPushButton* CQSideCompoundWizardPage::mpRemoveButton
protected
QListWidget* CQSideCompoundWizardPage::mpSideCompoundList
protected
QListWidget* CQSideCompoundWizardPage::mpSpeciesList
protected
std::set<const CMetab*, alphaSorter> CQSideCompoundWizardPage::mSortedSpecies
protected

Definition at line 188 of file CQAutolayoutWizard.h.

Referenced by setSpeciesList().


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