8 #include <QtGui/QCheckBox>
9 #include <QtGui/QFrame>
10 #include <QtGui/QLabel>
11 #include <QtCore/QList>
12 #include <QtGui/QListWidget>
13 #include <QtGui/QMessageBox>
14 #include <QtGui/QPushButton>
15 #include <QtCore/QString>
16 #include <QtCore/QStringList>
17 #include <QtGui/QTreeWidget>
18 #include <QtGui/QVBoxLayout>
38 QTreeWidgetItem(strings, type)
59 if (!this->
mKey.empty())
72 this->setTitle(tr(
"No selection Error"));
73 QVBoxLayout* pLayout =
new QVBoxLayout;
74 this->setLayout(pLayout);
75 QLabel* pLabel =
new QLabel(
"<font color='red'>Please go back to the selection page and select some model elements for which to create a layout.</font>");
76 QFont font = pLabel->font();
78 font.setPointSize(font.pointSize() * 2);
79 pLabel->setFont(font);
80 pLabel->setWordWrap(
true);
81 pLayout->addWidget(pLabel);
93 , mCreateCompartmentElements(false)
94 , mpSelectionTree(new QTreeWidget)
95 , mpCompartmentsItem(new QTreeWidgetItem((QTreeWidget*)NULL, QStringList(QString(tr(
"Compartments")))))
96 , mpReactionsItem(new QTreeWidgetItem((QTreeWidget*)NULL, QStringList(QString(tr(
"Reactions")))))
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);
104 QCheckBox* pCheckBox =
new QCheckBox(
"create compartment elements");
105 pCheckBox->setChecked(
false);
107 pLayout->addWidget(pCheckBox);
112 QList<QTreeWidgetItem*> items;
122 QTreeWidgetItem* pParent = pItem->parent();
123 assert(pParent != NULL);
135 unsigned int i = 0, iMax = pItem->childCount();
136 Qt::CheckState state = pItem->checkState(0);
140 pItem->child(i)->setCheckState(0, state);
148 int i = 0, iMax = pChild->childCount();
149 QTreeWidgetItem* pAll = NULL;
151 while (i < iMax && !found)
153 if (pItem == pChild->child(i))
158 unsigned int j = 0, jMax = pParent->childCount();
159 bool allSelected =
true;
160 bool allUnselected =
true;
162 while (j < jMax && (allSelected ==
true || allUnselected ==
true))
164 if (pParent->child(j)->checkState(0) == Qt::Checked)
166 allUnselected =
false;
168 else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
175 allUnselected =
false;
181 if (allSelected ==
true)
183 pParent->setCheckState(0, Qt::Checked);
185 else if (allUnselected ==
true)
187 pParent->setCheckState(0, Qt::Unchecked);
191 pParent->setCheckState(0, Qt::PartiallyChecked);
196 pAll = pChild->child(i)->child(0);
204 unsigned int j = 0, jMax = pItem->childCount();
205 Qt::CheckState state = pItem->checkState(0);
209 pItem->child(j)->setCheckState(0, state);
213 else if (pAll == pParent)
218 unsigned int j = 0, jMax = pParent->childCount();
219 bool allSelected =
true;
220 bool allUnselected =
true;
222 while (j < jMax && (allSelected ==
true || allUnselected ==
true))
224 if (pParent->child(j)->checkState(0) == Qt::Checked)
226 allUnselected =
false;
228 else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
235 allUnselected =
false;
241 if (allSelected ==
true)
243 pParent->setCheckState(0, Qt::Checked);
245 else if (allUnselected ==
true)
247 pParent->setCheckState(0, Qt::Unchecked);
251 pParent->setCheckState(0, Qt::PartiallyChecked);
271 unsigned int j = 0, jMax = pItem->childCount();
272 Qt::CheckState state = pItem->checkState(0);
276 pItem->child(j)->setCheckState(0, state);
283 int i = 0, iMax = pChild->childCount();
285 while (i < iMax && !found)
287 if (pItem == pChild->child(i))
292 unsigned int j = 0, jMax = pParent->childCount();
293 bool allSelected =
true;
294 bool allUnselected =
true;
296 while (j < jMax && (allSelected ==
true || allUnselected ==
true))
298 if (pParent->child(j)->checkState(0) == Qt::Checked)
300 allUnselected =
false;
302 else if (pParent->child(j)->checkState(0) == Qt::Unchecked)
309 allUnselected =
false;
315 if (allSelected ==
true)
317 pParent->setCheckState(0, Qt::Checked);
319 else if (allUnselected ==
true)
321 pParent->setCheckState(0, Qt::Unchecked);
325 pParent->setCheckState(0, Qt::PartiallyChecked);
334 assert(found ==
true);
345 if (state == Qt::Checked)
352 pItem->setFlags(pItem->flags() | Qt::ItemIsUserCheckable);
353 pItem->setCheckState(0, Qt::Unchecked);
355 unsigned int i = 0, iMax = pItem->childCount();
359 pItem->child(i)->setFlags(pItem->child(i)->flags() | Qt::ItemIsUserCheckable);
360 pItem->child(i)->setCheckState(0, Qt::Unchecked);
374 pItem->setFlags(pItem->flags() & (~Qt::ItemIsUserCheckable));
375 pItem->setData(0, Qt::CheckStateRole, QVariant());
377 unsigned int i = 0, iMax = pItem->childCount();
381 pItem->child(i)->setFlags(pItem->child(i)->flags() & (~Qt::ItemIsUserCheckable));
382 pItem->child(i)->setData(0, Qt::CheckStateRole, QVariant());
398 if (compartments.
size() > 0 && metabs.
size() > 0)
407 QTreeWidgetItem* pItem =
new QTreeWidgetItem(QStringList(QString(tr(
"All Compartments"))));
408 pItem->setFlags(pItem->flags() & (!Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
411 QList<QTreeWidgetItem*> children, children2;
412 unsigned int i = 0, iMax = compartments.
size();
413 QTreeWidgetItem *pChild1;
415 QTreeWidgetItem *pItem2 = NULL, *pItem3 = NULL;
417 unsigned int j, jMax;
418 const CMetab* pMetab = NULL;
422 pCompartment = compartments[i];
423 assert(pCompartment != NULL);
425 pChild1->setFlags(pChild1->flags() & (!Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
428 assert(pMetabs != NULL);
430 if (pMetabs->
size() > 0)
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);
438 jMax = pMetabs->
size();
442 pMetab = (*pMetabs)[j];
443 assert(pMetab != NULL);
445 pItem3->setFlags(pItem3->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
446 pItem3->setCheckState(0, Qt::Checked);
447 children2.append(pItem3);
451 pItem2->addChildren(children2);
455 children.append(pChild1);
459 pItem->addChildren(children);
461 if (reactions.
size() > 0)
464 pItem =
new QTreeWidgetItem(QStringList(QString(tr(
"All Reactions"))));
465 pItem->setFlags(pItem->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
466 pItem->setCheckState(0, Qt::Checked);
470 iMax = reactions.
size();
475 pReaction = reactions[i];
476 assert(pReaction != NULL);
478 pChild1->setFlags(pChild1->flags() | (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled));
479 pChild1->setCheckState(0, Qt::Checked);
481 children2.append(pChild1);
485 pItem->addChildren(children2);
498 compartments.clear();
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;
514 pChild = pItem->child(i);
515 assert(pChild != NULL);
517 if ((pChild->flags() & Qt::ItemIsUserCheckable) && pChild->checkState(0) == Qt::Checked)
520 assert(pModelItem != NULL);
522 assert(pCompartment != NULL);
523 compartments.insert(pCompartment);
526 pItem2 = pChild->child(0);
536 jMax = pItem2->childCount();
540 pChild2 = pItem2->child(j);
542 if ((pChild2->flags() & Qt::ItemIsUserCheckable) && pChild2->checkState(0) == Qt::Checked)
545 assert(pModelItem != NULL);
547 assert(pMetab != NULL);
548 species.insert(pMetab);
564 QTreeWidgetItem* pItem = this->
mpReactionsItem->child(0), *pChild = NULL;
566 unsigned int i = 0, iMax;
567 iMax = pItem->childCount();
572 pChild = pItem->child(i);
574 if ((pChild->flags() & Qt::ItemIsUserCheckable) && pChild->checkState(0) == Qt::Checked)
577 assert(pModelItem != NULL);
579 assert(pReaction != NULL);
580 reactions.insert(pReaction);
592 QListWidgetItem(text)
607 if (!this->mKey.empty())
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.");
628 this->
mpSpeciesList->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"));
637 pLayout->addWidget(pFrame);
638 pLayout2 =
new QVBoxLayout;
640 pFrame->setLayout(pLayout2);
641 pLayout2->addStretch();
645 pLayout2->addSpacing(20);
647 pLayout2->addStretch();
648 pLayout->addWidget(pFrame);
650 pLayout2 =
new QVBoxLayout;
651 pFrame->setLayout(pLayout2);
652 pLayout2->addWidget(
new QLabel(
"Side-Species"));
654 pLayout->addWidget(pFrame);
672 sideCompounds.clear();
675 const CMetab* pMetab = NULL;
677 for (i = 0; i < iMax; ++i)
680 assert(pItem != NULL);
682 sideCompounds.insert(pMetab);
695 std::set<std::string> keys;
699 QList<QListWidgetItem*> itemList;
704 std::string displayName = (*it)->getObjectDisplayName();
705 keys.insert((*it)->getKey());
708 itemList = this->
mpSideCompoundList->findItems(displayName.c_str(), Qt::MatchExactly);
710 iMax = itemList.size();
715 if (static_cast<const CQListWidgetModelItem*>(itemList[i])->getKey() == (*it)->getKey())
736 std::set<std::string>::const_iterator end = keys.end();
737 QListWidgetItem* pItem = NULL;
741 if (keys.find(static_cast<const CQListWidgetModelItem*>(this->mpSideCompoundList->item(iMax))->getKey()) == end)
759 QList<QListWidgetItem*> selection = this->
mpSpeciesList->selectedItems();
764 QList<QListWidgetItem*>::iterator it = selection.begin(), endit = selection.end();
807 QList<QListWidgetItem*>::iterator it = selection.begin(), endit = selection.end();
852 QList<QListWidgetItem*> selection = this->
mpSpeciesList->selectedItems();
854 if (selection.size() == 0)
873 if (selection.size() == 0)
891 QWizard(parent, flags)
895 this->setOptions(this->options() | QWizard::HaveFinishButtonOnEarlyPages);
896 this->setOptions(this->options() & ~QWizard::NoCancelButton);
897 this->setWindowTitle(tr(
"Autolayout Wizard"));
945 if (result == QDialog::Accepted)
971 if (this->
mSpecies.find(*it) == speciesEnd)
994 this->QWizard::done(result);
1027 switch (this->currentId())
virtual int nextId() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
std::set< const CReaction * > mReactions
CCopasiVectorNS< CMetab > & getMetabolites()
const CCopasiVector< CMetab > & getMetabolites() const
void getSideCompounds(std::set< const CMetab * > &sideCompounds) const
std::set< const CMetab * > mSideSpecies
virtual size_t size() const
void setSpeciesList(const std::set< const CMetab * > &metabs)
void slotCreateCompartments(int state)
CCopasiObject * get(const std::string &key)
virtual const std::string & getKey() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const std::string & getKey() const
QPushButton * mpAddButton
void fillContainers(std::set< const CCompartment * > &compartments, std::set< const CReaction * > &reactions, std::set< const CMetab * > &species) const
bool mCreateCompartmentElements
virtual bool isComplete() const
std::set< const CMetab *, alphaSorter > mSortedSpecies
QListWidget * mpSpeciesList
std::set< const CCompartment * > mCompartments
CQSelectionWizardPage(const CModel &model)
bool operator()(const CMetab *m1, const CMetab *m2) const
void slotSideCompoundSelectionChanged()
virtual const std::string & getKey() const
void slotAddButtonClicked()
std::set< const CMetab * > mSpecies
CQNoSelectionErrorWizardPage()
QTreeWidgetItem * mpReactionsItem
QWizardPage * createErrorPage()
void slotSpeciesSelectionChanged()
CQSideCompoundWizardPage()
QWizardPage * createSelectionPage()
virtual void done(int result)
CCopasiObject * getObject() const
CCopasiVectorNS< CCompartment > & getCompartments()
QPushButton * mpRemoveButton
static CKeyFactory * getKeyFactory()
QTreeWidgetItem * mpCompartmentsItem
CCopasiVectorNS< CReaction > & getReactions()
QTreeWidget * mpSelectionTree
void fillTree(const CModel &model)
void slotCurrentIdChanged(int id)
void slotItemChanged(QTreeWidgetItem *pItem, int column)
CQAutolayoutWizard(const CModel &model, QWidget *parent=0, Qt::WindowFlags flags=0)
CQListWidgetModelItem(const QString &text, const std::string &key)
QWizardPage * createLayoutParameterPage()
QWizardPage * createSideCompoundPage()
void slotRemoveButtonClicked()
QListWidget * mpSideCompoundList