COPASI API  4.16.103
CQTabWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include <QtCore/QString>
7 
8 #include "CQTabWidget.h"
9 
10 #include "CQMessageBox.h"
11 #include "qtUtilities.h"
12 #include "CQNotes.h"
13 
15 #include "MIRIAMUI/CQRDFTreeView.h"
16 
19 #include "function/CFunction.h"
20 #include "UI/CQCompartment.h"
21 #include "UI/CQSpeciesDetail.h"
22 #include "UI/ReactionsWidget1.h"
23 
25  QWidget * parent, Qt::WindowFlags f) :
26  CopasiWidget(parent, NULL, f),
27  mPages(),
28  mObjectType(objectType),
29  mIgnoreLeave(false)
30 {
31  setupUi(this);
32 
33  mpLblName->setText("<h3>" + FROM_UTF8(ListViews::ObjectTypeName[mObjectType]) + "</h3>");
34 
35  mpTabWidget->addTab(pCopasiWidget, "Details");
36  mPages.push_back(pCopasiWidget);
37 
38  switch (mObjectType)
39  {
40  case ListViews::MODEL:
41  mpBtnNew->hide();
42  mpBtnCopy->hide();
43  mpBtnDelete->hide();
44  break;
45 
47  mpBtnNew->setText("Apply");
48  mpBtnNew->setToolTip("Apply the current parameters to the model.");
49 
50  // The break statement is intentionally missing
51 
52  default:
53  CQNotes* pNotes = new CQNotes(mpTabWidget);
54  mPages.push_back(pNotes);
55  mpTabWidget->addTab(pNotes, "Notes");
56 
57  connect(this, SIGNAL(newClicked()), pCopasiWidget, SLOT(slotBtnNew()));
58  connect(this, SIGNAL(copyClicked()), pCopasiWidget, SLOT(slotBtnCopy()));
59  connect(this, SIGNAL(deleteClicked()), pCopasiWidget, SLOT(slotBtnDelete()));
60  connect(this, SIGNAL(copyClicked()), pNotes, SLOT(slotBtnCopy()));
61  break;
62  }
63 
64  CQMiriamWidget* pMIRIAMWidget = new CQMiriamWidget(mpTabWidget);
65  mPages.push_back(pMIRIAMWidget);
66  mpTabWidget->addTab(pMIRIAMWidget, "Annotation");
67  connect(this, SIGNAL(copyClicked()), pMIRIAMWidget, SLOT(slotBtnCopy()));
68 
69  CQRDFTreeView* pRDFTreeView = new CQRDFTreeView(mpTabWidget);
70  mPages.push_back(pRDFTreeView);
71  mpTabWidget->addTab(pRDFTreeView, "RDF Browser");
72 }
73 
75 {
76  // TODO Auto-generated destructor stub
77 }
78 
80 {
81  if (mIgnoreLeave) return true;
82 
83  bool success = save();
84 
85  std::vector< CopasiWidget * >::iterator it = mPages.begin();
86  std::vector< CopasiWidget * >::iterator end = mPages.end();
87 
88  for (; it != end; ++it)
89  success &= (*it)->leave();
90 
91  return true;
92 }
93 
95 {
96  load();
97 
98  std::vector< CopasiWidget * >::iterator it = mPages.begin();
99  std::vector< CopasiWidget * >::iterator end = mPages.end();
100 
101  for (; it != end; ++it)
102  (*it)->enter(mKey);
103 
104  return true;
105 }
106 
108 {
109  if (mIgnoreUpdates) return true;
110 
111  if (objectType == mObjectType &&
112  key == mKey)
113  {
114  switch (action)
115  {
116  case ListViews::RENAME:
117  load();
118  break;
119 
120  case ListViews::DELETE:
121  mpObject = NULL;
122  break;
123 
124  default:
125  break;
126  }
127  }
128 
129  // We do not need to update the child pages as they are directly called from listviews.
130  return true;
131 }
132 
133 void CQTabWidget::selectTab(int index) const
134 {
135  mpTabWidget->setCurrentIndex(index);
136 }
137 
139 {
140  // mpObject can not be trusted
142 
143  if (mpObject != NULL)
144  {
145  mpEditName->setText(FROM_UTF8(mpObject->getObjectName()));
146 
148  {
149  const CFunction * pFunction = static_cast< const CFunction * >(mpObject);
150 
151  bool readOnly =
152  (pFunction->getType() == CFunction::PreDefined ||
153  pFunction->getType() == CFunction::MassAction);
154 
155  mpEditName->setReadOnly(readOnly);
156  mpBtnCommit->setEnabled(!readOnly);
157  mpBtnRevert->setEnabled(!readOnly);
158  mpBtnDelete->setEnabled(!readOnly);
159  }
160  }
161  else
162  {
163  mpEditName->setText("");
164  }
165 }
166 
168 {
169  // mpObject can not be trusted
171 
172  if (mpObject == NULL) return false;
173 
174  // We need to tell the sub-widgets to ignore all notifications
175  std::vector< CopasiWidget * >::iterator it = mPages.begin();
176  std::vector< CopasiWidget * >::iterator end = mPages.end();
177 
178  for (; it != end; ++it)
179  (*it)->setIgnoreUpdates(true);
180 
181  if (mpObject->getObjectName() != TO_UTF8(mpEditName->text()))
182  {
183  if (!mpObject->setObjectName(TO_UTF8(mpEditName->text())))
184  {
185  QString msg;
186  msg = "Unable to rename " + FROM_UTF8(ListViews::ObjectTypeName[mObjectType]).toLower() + " '" + FROM_UTF8(mpObject->getObjectName()) + "'\n"
187  + "to '" + mpEditName->text() + "' since a " + FROM_UTF8(ListViews::ObjectTypeName[mObjectType]).toLower() + " with that name already exists.\n";
188 
190  "Unable to rename " + FROM_UTF8(ListViews::ObjectTypeName[mObjectType]),
191  msg,
192  QMessageBox::Ok, QMessageBox::Ok);
193 
194  mpEditName->setText(FROM_UTF8(mpObject->getObjectName()));
195  }
196  else
197  {
199 
200  if (mpDataModel != NULL)
201  {
202  mpDataModel->changed();
203  }
204  }
205  }
206 
207  // We need to tell the sub-widgets to accept notifications again
208  it = mPages.begin();
209  end = mPages.end();
210 
211  for (; it != end; ++it)
212  (*it)->setIgnoreUpdates(false);
213 
214  return true;
215 }
216 
218 {
219  mpBtnCommit->setFocus();
220 
221  leave();
222  enterProtected();
223 }
224 
226 {
227  enterProtected();
228 }
229 
231 {
232  mIgnoreLeave = true;
233  emit deleteClicked();
234  mIgnoreLeave = false;
235 }
236 
238 {
239  mpBtnNew->setFocus();
240 
241  leave();
242 
243  mIgnoreLeave = true;
244  emit newClicked();
245  mIgnoreLeave = false;
246 }
247 
249 {
250  mpBtnCopy->setFocus();
251 
252  leave();
253 
254  mIgnoreLeave = true;
255 
256  // CQCompartments and CQSpecies have copy options, use CModelExpansion, and do their own switching.
257  if (QString(mPages[0]->metaObject()->className()) == "CQCompartment")
258  {
259  CQCompartment * pQCompartment = dynamic_cast< CQCompartment * >(mPages[0]);
260  pQCompartment->copy();
261  }
262  else if (QString(mPages[0]->metaObject()->className()) == "CQSpeciesDetail")
263  {
264  CQSpeciesDetail * pQSpeciesDetail = dynamic_cast< CQSpeciesDetail * >(mPages[0]);
265  pQSpeciesDetail->copy();
266  }
267  else if (QString(mPages[0]->metaObject()->className()) == "ReactionsWidget1")
268  {
269  ReactionsWidget1 * pReactionsWidget1 = dynamic_cast< ReactionsWidget1 * >(mPages[0]);
270  pReactionsWidget1->copy();
271  }
272  else
273  {
274  emit copyClicked();
275  emit newClicked();
276  }
277 
278  mIgnoreLeave = false;
279 }
virtual bool enterProtected()
Definition: CQTabWidget.cpp:94
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
void copyClicked()
const std::string & getObjectName() const
void newClicked()
CCopasiObject * get(const std::string &key)
CQTabWidget(const ListViews::ObjectType &objectType, CopasiWidget *pCopasiWidget, QWidget *parent=0, Qt::WindowFlags f=0)
Definition: CQTabWidget.cpp:24
void slotBtnDelete()
void selectTab(int index) const
CCopasiObject * mpObject
Definition: copasiWidget.h:64
const CEvaluationTree::Type & getType() const
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void changed(const bool &changed=true)
void slotBtnCopy()
bool mIgnoreUpdates
Definition: copasiWidget.h:67
std::vector< CopasiWidget * > mPages
Definition: CQTabWidget.h:56
void deleteClicked()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
void slotBtnNew()
static CKeyFactory * getKeyFactory()
virtual bool leave()
Definition: CQTabWidget.cpp:79
void slotBtnRevert()
virtual ~CQTabWidget()
Definition: CQTabWidget.cpp:74
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
void slotBtnCommit()
static const std::string ObjectTypeName[]
Definition: listviews.h:107
ListViews::ObjectType mObjectType
Definition: CQTabWidget.h:57
bool setObjectName(const std::string &name)
std::string mKey
Definition: copasiWidget.h:63
bool mIgnoreLeave
Definition: CQTabWidget.h:58