COPASI API  4.16.103
wizard.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 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 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2004 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <QtCore/QDir>
16 
17 #include "wizard.h"
18 #include "UI/CQMessageBox.h"
19 #include "UI/listviews.h"
20 #include "UI/copasiui3window.h"
21 
22 #include "copasi.h"
23 
24 #include "commandline/COptions.h"
25 
26 #include <iostream>
27 
28 /*
29  * Constructs a WizardDialog as a child of 'parent', with the
30  * name 'name' and widget flags set to 'f'.
31  *
32  * The dialog will by default be modeless, unless you set 'modal' to
33  * true to construct a modal dialog.
34  */
35 WizardDialog::WizardDialog(QWidget* parent, const char* /* name */, bool /* modal */, Qt::WindowFlags fl):
36  QDialog(parent, fl),
37  copasiMainWindow(NULL),
38  buttonGroup(NULL)
39 {
40  setupUi(this);
41 
42  std::string WizardDir;
43  COptions::getValue("WizardDir", WizardDir);
44 
45  if (!WizardDir.empty())
46  {
47  // the next line will hopefully ensure that this works under windows as well.
48  WizardDialog::helpPath = "file:///" + QDir(WizardDir.c_str()).absolutePath();
49  QString source = WizardDialog::helpPath + "/" + WizardDialog::texts[0];
50  this->textBrowser->setSource(source);
51  }
52  else
53  {
54  this->textBrowser->setText(WizardDialog::Error);;
55  }
56 
57  buttonGroup = new QButtonGroup(this);
58 
59  buttonGroup->addButton(button1, 0);
60  buttonGroup->addButton(button2, 1);
61  buttonGroup->addButton(button3, 2);
62  buttonGroup->addButton(button4, 3);
63  buttonGroup->addButton(button5, 4);
64  buttonGroup->addButton(button6, 5);
65 
66  buttonGroup->button(0)->setChecked(true);
67 
68  connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(buttonGroup2_clicked(int)));
69  connect(textBrowser, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(textBrowser_anchorClicked(const QUrl &)));
70 }
71 
72 /*
73  * Destroys the object and frees any allocated resources
74  */
76 {
77  // no need to delete child widgets, Qt does it all for us
78 }
79 
80 const char* WizardDialog::texts[6] = {"TutWiz-Step1.html", "TutWiz-Step2.html", "TutWiz-Step3.html", "TutWiz-Step4.html", "TutWiz-Step5.html", "TutWiz-Step6.html"};
81 
82 const char* WizardDialog::Error = "<html><head><title>Error</title></head><body><h1>Could not find help files.<br><br>Please set the COPASI_HELP_PATH environment variable to the absolute path that contains the html help files!</h1></body></html>";
83 
84 QString WizardDialog::helpPath = "";
85 
87 {
88  int checkedId = this->buttonGroup->checkedId();
89 
90  if (checkedId == 0)
91  {
92  this->backButton->setEnabled(false);
93  this->forwardButton->setEnabled(true);
94  }
95  else if (checkedId == 5)
96  {
97  this->forwardButton->setEnabled(false);
98  this->backButton->setEnabled(true);
99  }
100  else
101  {
102  this->forwardButton->setEnabled(true);
103  this->backButton->setEnabled(true);
104  }
105 
106  if (WizardDialog::helpPath != "")
107  {
108  QString source = WizardDialog::helpPath + "/" + WizardDialog::texts[checkedId];
109  this->textBrowser->setSource(source);
110  }
111 }
112 
114 {
115  buttonGroup->button(buttonGroup->checkedId() + 1)->setChecked(true);
116  buttonGroup2_clicked(this->buttonGroup->checkedId());
117 }
118 
120 {
121  buttonGroup->button(buttonGroup->checkedId() - 1)->setChecked(true);
122  buttonGroup2_clicked(this->buttonGroup->checkedId());
123 }
124 
126 {
127  QString name = url.fragment();
128 
129  std::cout << name.toUtf8().data() << std::endl;
130 
131  CopasiUI3Window * pMainWindow = dynamic_cast<CopasiUI3Window *>(copasiMainWindow);
132 
133  if (name == "Model Settings")
134  {
135  if (pMainWindow)
136  pMainWindow->getMainWidget()->switchToOtherWidget(1, "");
137  }
138  else if (name == "Reaction Overview")
139  {
140  if (pMainWindow)
141  pMainWindow->getMainWidget()->switchToOtherWidget(114, "");
142  }
143  else if (name == "Report Definition")
144  {
145  if (pMainWindow)
146  pMainWindow->getMainWidget()->switchToOtherWidget(43, "");
147  }
148  else if (name == "Step 1")
149  {
150  buttonGroup->button(0)->setChecked(true);
151  buttonGroup2_clicked(this->buttonGroup->checkedId());
152  }
153  else if (name == "Time Course")
154  {
155  if (pMainWindow)
156  pMainWindow->getMainWidget()->switchToOtherWidget(23, "");
157  }
158  else if (name == "Plot Definition Overview")
159  {
160  if (pMainWindow)
161  pMainWindow->getMainWidget()->switchToOtherWidget(42, "");
162  }
163  else
164  {
165  CQMessageBox::information(this, "Error", "Link not found",
166  QMessageBox::Ok, QMessageBox::Ok);
167  }
168 }
169 
170 void WizardDialog::setCopasiMainWindow(QWidget * copasiMainWindow)
171 {
172  this->copasiMainWindow = copasiMainWindow;
173 }
virtual void textBrowser_anchorClicked(const QUrl &url)
Definition: wizard.cpp:125
static const char * Error
Definition: wizard.h:42
~WizardDialog()
Definition: wizard.cpp:75
QWidget * copasiMainWindow
Definition: wizard.h:44
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual void setCopasiMainWindow(QWidget *copasiMainWindow)
Definition: wizard.cpp:170
virtual void backButton_clicked()
Definition: wizard.cpp:119
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static const char * texts[6]
Definition: wizard.h:31
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
WizardDialog(QWidget *parent=0, const char *name=0, bool modal=false, Qt::WindowFlags fl=0)
Definition: wizard.cpp:35
static QString helpPath
Definition: wizard.h:43
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
ListViews * getMainWidget()
virtual void forwardButton_clicked()
Definition: wizard.cpp:113
virtual void buttonGroup2_clicked(int)
Definition: wizard.cpp:86
QButtonGroup * buttonGroup
Definition: wizard.h:45