COPASI API  4.16.103
CQAutolayoutWizard.h
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #ifndef CQAutolayoutWizard_h__
7 #define CQAutolayoutWizard_h__
8 
9 // Qt includes
10 #include <QtGui/QListWidgetItem>
11 #include <QtGui/QTreeWidgetItem>
12 #include <QtGui/QWizard>
13 #include <QtGui/QWizardPage>
14 
15 #include <set>
16 #include <string>
17 #include <utility>
18 
19 // I know I am not supposed to use copasi.h in a header file,
20 // but if I don't, the cpp file created by moc will include this header
21 // without copasi.h before and compilation will fail because this header indirectly
22 // include CopasiVector which uses C_INT32
23 #include "copasi/copasi.h"
25 
26 class QPushButton;
27 class QListWidget;
28 class QTreeWidget;
29 
30 class CCompartment;
31 class CMetab;
32 class CModel;
33 class CReaction;
34 
35 class CQModelElementTreeWidgetItem : public QTreeWidgetItem
36 {
37 protected:
38  // we store the key of the object as well as the display name
39  // when we create a new object
40  std::string mKey;
41 
42 public:
43  /**
44  * Constructor which in addition to the attributes of the original class
45  * also takes a string which is the key of the object that is represented
46  * by the item.
47  */
48  CQModelElementTreeWidgetItem(const QStringList & strings, const std::string& key, int type = QTreeWidgetItem::Type);
49 
50  /**
51  * Returns a const reference to the key of the object.
52  */
53  const std::string& getKey() const;
54 
55  /**
56  * Returns a pointer to the COPASI object
57  * represented by this item.
58  */
59  CCopasiObject* getObject() const;
60 };
61 
62 /**
63  * This page is shown as the second wizard page
64  * if the user hasn't selectzed anything in the
65  * selection page.
66  */
67 class CQNoSelectionErrorWizardPage : public QWizardPage
68 {
69  Q_OBJECT
70 
71 public:
73 
74  virtual bool isComplete() const;
75 };
76 
77 /**
78  * This is the first page of the wizard.
79  * It displays a tree where the user can select the objects
80  * that should be included in the layout.
81  */
82 class CQSelectionWizardPage : public QWizardPage
83 {
84  Q_OBJECT
85 
86 public:
87  // constructor that takes a model
88  // to fill the tree
89  CQSelectionWizardPage(const CModel& model);
90 
91  /**
92  * Checks which elements have been selected in the tree
93  * and fills the containers that are passed in with those
94  * elements.
95  */
96  void fillContainers(std::set<const CCompartment*>& compartments, std::set<const CReaction*>& reactions, std::set<const CMetab*>& species) const;
97 
98 protected:
99  // fills the selection tree with elements from the model
100  void fillTree(const CModel& model);
101 
102 protected:
103  // flag that determines if compartment layout elements
104  // are created for the layout.
106 
107  // QTreeWidget for the selection of model elements
108  // for which we want to create the layout
109  QTreeWidget* mpSelectionTree;
110 
111  // Top level tree widget item that holds the compartments
112  QTreeWidgetItem* mpCompartmentsItem;
113 
114  // Top level tree widget item that holds the reactions
115  QTreeWidgetItem* mpReactionsItem;
116 
117 protected slots:
118  // is called when the state of the compartment layout creation checkbox changes
119  void slotCreateCompartments(int state);
120 
121  void slotItemChanged(QTreeWidgetItem* pItem, int column);
122 };
123 
124 /**
125  * In this page the user can select which species should be treated
126  * as side compounds by the layout algorithm.
127  */
128 class CQSideCompoundWizardPage : public QWizardPage
129 {
130  Q_OBJECT
131 
132 public:
133  // default constructor
135 
136  /**
137  * Fills the given set with the side compounds that
138  * have been selected by the user.
139  */
140  void getSideCompounds(std::set<const CMetab*>& sideCompounds) const;
141 
142  /**
143  * Passes the species that have been selected by the user
144  * for use in the layout to the page.
145  * These species are used to fill the list on the left.
146  */
147  void setSpeciesList(const std::set<const CMetab*>& metabs);
148 
149 protected:
151  {
152  public:
153  bool operator()(const CMetab* m1, const CMetab* m2) const;
154  };
155 
156  class CQListWidgetModelItem : public QListWidgetItem
157  {
158  public:
159  // constructor which takes a string that is displayed for the item
160  // and the key of a model object
161  CQListWidgetModelItem(const QString& text, const std::string& key);
162 
163  // returns the key of the associated model object
164  const std::string& getKey() const;
165 
166  CCopasiObject* getObject() const;
167 
168  protected:
169  std::string mKey;
170  };
171 
172 protected:
173  // the left list that contains the species
174  QListWidget* mpSpeciesList;
175 
176  // the right list that contains the selected side compounds
177  QListWidget* mpSideCompoundList;
178 
179  // the button that adds selected items to the
180  // side compound list
181  QPushButton* mpAddButton;
182 
183  // the button that removes items from the list of
184  // list compounds
185  QPushButton* mpRemoveButton;
186 
187  // this set sorts the metabolites alphabetically
188  std::set<const CMetab*, alphaSorter> mSortedSpecies;
189 
190 protected slots:
191  // called when the add button was clicked
192  void slotAddButtonClicked();
193 
194  // called when the remove button was clicked
196 
197  // called when the selection in the species list changes
199 
200  // called when the side compounds selection changes
202 };
203 
204 /**
205  * In this page, the user can set all parameters
206  * for the layout algorithm.
207  */
208 class CQLayoutParametersWizardPage : public QWizardPage
209 {
210  Q_OBJECT
211 };
212 
213 class CQAutolayoutWizard : public QWizard
214 {
215  Q_OBJECT
216 
217 protected:
219  {
220  NO_PAGE = -1,
225  };
226 
227  const CModel& mModel;
228 
229  // a set of species pointers for the species
230  // that shall be part of the layout
231  mutable std::set<const CMetab*> mSpecies;
232 
233  // a set of species which should be treated as side species
234  // which means that the nodes for those species are duplicated
235  // for each reaction in which they occur
236  mutable std::set<const CMetab*> mSideSpecies;
237 
238  // the a set of compartments for which we create layout elements
239  mutable std::set<const CCompartment*> mCompartments;
240 
241  // a set of reactions for which we create layout elements
242  mutable std::set<const CReaction*> mReactions;
243 
244  // remember the id of the last page we visited
246 
247 public:
248  /**
249  * Constructor needs a const reference to
250  * a COPASI model and a layout object that is filled by
251  * the wizard.
252  */
253  CQAutolayoutWizard(const CModel& model, QWidget * parent = 0, Qt::WindowFlags flags = 0);
254 
255  // Destructor
257 
258  virtual int nextId() const;
259 
260  const std::set<const CCompartment*>& getSelectedCompartments() const
261  {
262  return this->mCompartments;
263  }
264 
265  const std::set<const CReaction*>& getSelectedReactions() const
266  {
267  return this->mReactions;
268  }
269 
270  const std::set<const CMetab*>& getSelectedMetabolites() const
271  {
272  return this->mSpecies;
273  }
274 
275  const std::set<const CMetab*>& getSideMetabolites() const
276  {
277  return this->mSideSpecies;
278  }
279 
280 protected:
281  // this is called when the wizard is cloned
282  // I use this method to update the containers
283  virtual void done(int result);
284 
285  // creates the first page for the wizard
286  // This is the page where the user selects the model elements
287  QWizardPage* createSelectionPage();
288 
289  // creates the second page for the wizard
290  // here the user can decide if certain species should be
291  // treated as side components
292  QWizardPage* createSideCompoundPage();
293 
294  // creates the third page for the wizard
295  // here the user can make settings for the layout
296  // algorithm
297  QWizardPage* createLayoutParameterPage();
298 
299  // creates the error page for the wizard
300  // where the user is asked to please select element for the layout
301  QWizardPage* createErrorPage();
302 
303 protected slots:
304  // this is called whenever the page changes
305  void slotCurrentIdChanged(int id);
306 };
307 
308 #endif // CQAutolayoutWizard_h__
virtual int nextId() const
std::set< const CReaction * > mReactions
void getSideCompounds(std::set< const CMetab * > &sideCompounds) const
std::set< const CMetab * > mSideSpecies
const std::string & getKey() const
void setSpeciesList(const std::set< const CMetab * > &metabs)
void slotCreateCompartments(int state)
const std::set< const CMetab * > & getSideMetabolites() const
Definition: CMetab.h:178
void fillContainers(std::set< const CCompartment * > &compartments, std::set< const CReaction * > &reactions, std::set< const CMetab * > &species) const
virtual bool isComplete() const
std::set< const CMetab *, alphaSorter > mSortedSpecies
std::set< const CCompartment * > mCompartments
const std::set< const CReaction * > & getSelectedReactions() const
const std::set< const CMetab * > & getSelectedMetabolites() const
CQModelElementTreeWidgetItem(const QStringList &strings, const std::string &key, int type=QTreeWidgetItem::Type)
CQSelectionWizardPage(const CModel &model)
bool operator()(const CMetab *m1, const CMetab *m2) const
std::set< const CMetab * > mSpecies
QTreeWidgetItem * mpReactionsItem
QWizardPage * createErrorPage()
QWizardPage * createSelectionPage()
virtual void done(int result)
QTreeWidgetItem * mpCompartmentsItem
CCopasiObject * getObject() const
void fillTree(const CModel &model)
void slotCurrentIdChanged(int id)
Definition: CModel.h:50
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)
const std::set< const CCompartment * > & getSelectedCompartments() const
QWizardPage * createLayoutParameterPage()
QWizardPage * createSideCompoundPage()