COPASI API  4.16.103
CQMessageBox.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQMessageBox.cpp,v $
3 // $Revision: 1.11 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/02 20:34:52 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include <QtGui/QTabWidget>
20 #include <QtGui/QTextEdit>
21 #include <QtGui/QVBoxLayout>
22 #include <QtGui/QGridLayout>
23 #include <QtGui/QLabel>
24 #include <QtGui/QStyle>
25 #include <QtGui/QApplication>
26 
27 #include "copasiui3window.h"
28 #include "CQMessageBox.h"
29 #include "qtUtilities.h"
30 
32 #include "model/CModel.h"
33 #include "function/CFunctionDB.h"
34 
35 CQMessageBox::CQMessageBox(Icon icon, const QString &title, const QString &text,
36  QMessageBox::StandardButtons buttons, QWidget *parent,
37  Qt::WindowFlags f):
38  QMessageBox(icon, title, QString(), buttons, parent, f),
39  mpTabWidget(NULL),
40  mpPage1(NULL),
41  mpVerticalLayoutPage1(NULL),
42  mpText1(NULL),
43  mpPage2(NULL),
44  mpVerticalLayoutPage2(NULL),
45  mpText2(NULL)
46 {
47  if (CopasiUI3Window::getMainWindow() != NULL)
48  {
50  }
51 
52  mpTabWidget = new QTabWidget(this);
53  mpTabWidget->setObjectName(QString::fromUtf8("mpTabWidget"));
54  mpTabWidget->setMinimumSize(QSize(400, 200));
55 
56  mpPage1 = new QWidget();
57  mpPage1->setObjectName(QString::fromUtf8("mpPage1"));
58 
59  mpVerticalLayoutPage1 = new QVBoxLayout(mpPage1);
60  mpVerticalLayoutPage1->setMargin(2);
61  mpVerticalLayoutPage1->setObjectName(QString::fromUtf8("mpVerticalLayoutPage1"));
62 
63  mpText1 = new QTextEdit(mpPage1);
64  mpText1->setObjectName(QString::fromUtf8("mpText1"));
65  mpText1->setReadOnly(true);
66  mpText1->setText(text);
67  mpVerticalLayoutPage1->addWidget(mpText1);
68 
69  mpTabWidget->addTab(mpPage1, QString("Messages"));
70 
71  // The code below is derived from qt-4.4.3/src/gui/dialogs/qmessagebox.cpp
72  static_cast<QGridLayout *>(layout())->addWidget(mpTabWidget, 0, 1, 1, 1);
73  QLabel * pLabel = findChild<QLabel *>("qt_msgbox_label");
74 
75  if (pLabel != NULL)
76  pLabel->hide();
77 }
78 
80 {
81  if (CopasiUI3Window::getMainWindow() != NULL)
82  {
84  }
85 }
86 
87 // static
88 QMessageBox::StandardButton CQMessageBox::information(QWidget *parent, const QString &title,
89  const QString &text, QMessageBox::StandardButtons buttons,
90  QMessageBox::StandardButton defaultButton)
91 {
93  return defaultButton;
94 
95  CQMessageBox * pMessageBox = new CQMessageBox(QMessageBox::Information, title, text, buttons, parent);
96  pMessageBox->setDefaultButton(defaultButton);
97  StandardButton choice = (StandardButton) pMessageBox->exec();
98  delete pMessageBox;
99 
100  return choice;
101 }
102 
103 QMessageBox::StandardButton CQMessageBox::question(QWidget *parent, const QString &title,
104  const QString &text, QMessageBox::StandardButtons buttons,
105  QMessageBox::StandardButton defaultButton)
106 {
108  return defaultButton;
109 
110  CQMessageBox * pMessageBox = new CQMessageBox(QMessageBox::Question, title, text, buttons, parent);
111  pMessageBox->setDefaultButton(defaultButton);
112  StandardButton choice = (StandardButton) pMessageBox->exec();
113  delete pMessageBox;
114 
115  return choice;
116 }
117 
118 // static
119 QMessageBox::StandardButton CQMessageBox::warning(QWidget *parent, const QString &title,
120  const QString &text, QMessageBox::StandardButtons buttons,
121  QMessageBox::StandardButton defaultButton)
122 {
124  return defaultButton;
125 
126  CQMessageBox * pMessageBox = new CQMessageBox(QMessageBox::Warning, title, text, buttons, parent);
127  pMessageBox->setDefaultButton(defaultButton);
128  StandardButton choice = (StandardButton) pMessageBox->exec();
129  delete pMessageBox;
130 
131  return choice;
132 }
133 
134 // static
135 QMessageBox::StandardButton CQMessageBox::critical(QWidget *parent, const QString &title,
136  const QString &text, QMessageBox::StandardButtons buttons,
137  QMessageBox::StandardButton defaultButton)
138 {
140  return defaultButton;
141 
142  CQMessageBox * pMessageBox = new CQMessageBox(QMessageBox::Critical, title, text, buttons, parent);
143  pMessageBox->setDefaultButton(defaultButton);
144  StandardButton choice = (StandardButton) pMessageBox->exec();
145  delete pMessageBox;
146 
147  return choice;
148 }
149 
150 // static
151 QMessageBox::StandardButton CQMessageBox::confirmDelete(QWidget *parent,
152  const QString &objectType, const QString &objects,
153  const std::set< const CCopasiObject * > & deletedObjects)
154 {
155  if (deletedObjects.size() == 0)
156  return QMessageBox::Ok;
157 
158  // Determine the affected data model
159  const CCopasiDataModel * pDataModel = (*deletedObjects.begin())->getObjectDataModel();
160 
161  // Determine the affected function DB
162  CFunctionDB * pFunctionDB =
163  dynamic_cast< CFunctionDB * >((*deletedObjects.begin())->getObjectAncestor("FunctionDB"));
164 
165  if (pDataModel == NULL &&
166  pFunctionDB == NULL)
167  return QMessageBox::Ok;
168 
169  if (pFunctionDB != NULL)
170  {
171  // TODO In case a function is deleted we need to loop through all data models
172  pDataModel = (*CCopasiRootContainer::getDatamodelList())[0];
173  }
174  else
175  {
177  }
178 
179  QString msg =
180  QString("Do you want to delete the listed %1?\n %2\n").arg(objectType, objects);
181 
182  std::set< const CCopasiObject * > Functions;
183  std::set< const CCopasiObject * > Reactions;
184  std::set< const CCopasiObject * > Metabolites;
185  std::set< const CCopasiObject * > Values;
186  std::set< const CCopasiObject * > Compartments;
187  std::set< const CCopasiObject * > Events;
188  std::set< const CCopasiObject * > Tasks;
189 
190  bool Used = false;
191 
192  if (pFunctionDB != NULL)
193  {
194  Used |= pFunctionDB->appendDependentFunctions(deletedObjects, Functions);
195 
196  if (Functions.size() > 0)
197  {
198  msg.append("Following functions(s) reference above and will be deleted:\n ");
199 
200  std::set< const CCopasiObject * >::const_iterator it = Functions.begin();
201  std::set< const CCopasiObject * >::const_iterator end = Functions.end();
202 
203  for (; it != end; ++it)
204  {
205  msg.append(FROM_UTF8((*it)->getObjectName()));
206  msg.append("\n ");
207  }
208 
209  msg.remove(msg.length() - 2, 2);
210  }
211  }
212 
213  const CModel * pModel = NULL;
214 
215  if (pDataModel != NULL)
216  {
217  pModel = pDataModel->getModel();
218 
219  // We need to check the tasks
220  Used |= pDataModel->appendDependentTasks(deletedObjects, Tasks);
221 
222  if (Tasks.size() > 0)
223  {
224  msg.append("Following task(s) reference above and will be modified:\n ");
225 
226  std::set< const CCopasiObject * >::const_iterator it = Tasks.begin();
227  std::set< const CCopasiObject * >::const_iterator end = Tasks.end();
228 
229  for (; it != end; ++it)
230  {
231  msg.append(FROM_UTF8((*it)->getObjectName()));
232  msg.append("\n ");
233  }
234 
235  msg.remove(msg.length() - 2, 2);
236  }
237  }
238 
239  if (pModel != NULL)
240  {
241  Used |= pModel->appendDependentModelObjects(deletedObjects, Reactions, Metabolites,
242  Compartments, Values, Events);
243 
244  if (Reactions.size() > 0)
245  {
246  msg.append("Following reactions(s) reference above and will be deleted:\n ");
247 
248  std::set< const CCopasiObject * >::const_iterator it = Reactions.begin();
249  std::set< const CCopasiObject * >::const_iterator end = Reactions.end();
250 
251  for (; it != end; ++it)
252  {
253  msg.append(FROM_UTF8((*it)->getObjectName()));
254  msg.append("\n ");
255  }
256 
257  msg.remove(msg.length() - 2, 2);
258  }
259 
260  if (Metabolites.size() > 0)
261  {
262  msg.append("Following species reference above and will be deleted:\n ");
263 
264  std::set< const CCopasiObject * >::const_iterator it = Metabolites.begin();
265  std::set< const CCopasiObject * >::const_iterator end = Metabolites.end();
266 
267  for (; it != end; ++it)
268  {
269  msg.append(FROM_UTF8((*it)->getObjectName()));
270  msg.append("\n ");
271  }
272 
273  msg.remove(msg.length() - 2, 2);
274  }
275 
276  if (Values.size() > 0)
277  {
278  msg.append("Following global quantities reference above and will be deleted:\n ");
279 
280  std::set< const CCopasiObject * >::const_iterator it = Values.begin();
281  std::set< const CCopasiObject * >::const_iterator end = Values.end();
282 
283  for (; it != end; ++it)
284  {
285  msg.append(FROM_UTF8((*it)->getObjectName()));
286  msg.append("\n ");
287  }
288 
289  msg.remove(msg.length() - 2, 2);
290  }
291 
292  if (Compartments.size() > 0)
293  {
294  msg.append("Following compartment(s) reference above and will be deleted:\n ");
295 
296  std::set< const CCopasiObject * >::const_iterator it = Compartments.begin();
297  std::set< const CCopasiObject * >::const_iterator end = Compartments.end();
298 
299  for (; it != end; ++it)
300  {
301  msg.append(FROM_UTF8((*it)->getObjectName()));
302  msg.append("\n ");
303  }
304 
305  msg.remove(msg.length() - 2, 2);
306  }
307 
308  if (Events.size() > 0)
309  {
310  msg.append("Following event(s) reference above and will be deleted:\n ");
311 
312  std::set< const CCopasiObject * >::const_iterator it = Events.begin();
313  std::set< const CCopasiObject * >::const_iterator end = Events.end();
314 
315  for (; it != end; ++it)
316  {
317  msg.append(FROM_UTF8((*it)->getObjectName()));
318  msg.append("\n ");
319  }
320 
321  msg.remove(msg.length() - 2, 2);
322  }
323  }
324 
325  StandardButton choice = QMessageBox::Ok;
326 
327  if (Used)
328  {
329  choice = CQMessageBox::question(parent, "CONFIRM DELETE", msg,
330  QMessageBox::Ok | QMessageBox::Cancel,
331  QMessageBox::Cancel);
332  }
333 
334  return choice;
335 }
336 
337 void CQMessageBox::setText(const QString & text)
338 {
339  mpText1->setText(text);
340 }
341 
342 void CQMessageBox::setFilteredText(const QString & text)
343 {
344  if (!text.isEmpty() && mpPage2 == NULL)
345  {
346  mpPage2 = new QWidget();
347  mpPage2->setObjectName(QString::fromUtf8("mpPage2"));
348 
349  mpVerticalLayoutPage2 = new QVBoxLayout(mpPage2);
350  mpVerticalLayoutPage2->setMargin(2);
351  mpVerticalLayoutPage2->setObjectName(QString::fromUtf8("mpVerticalLayoutPage2"));
352 
353  mpText2 = new QTextEdit(mpPage2);
354  mpText2->setObjectName(QString::fromUtf8("mpText2"));
355  mpText2->setReadOnly(true);
356  mpVerticalLayoutPage2->addWidget(mpText2);
357  mpTabWidget->addTab(mpPage2, QString("Minor Issues"));
358  }
359 
360  mpText2->setText(text);
361 }
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CQMessageBox(Icon icon, const QString &title, const QString &text, StandardButtons buttons=NoButton, QWidget *parent=0, Qt::WindowFlags f=Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint)
QVBoxLayout * mpVerticalLayoutPage2
Definition: CQMessageBox.h:68
void setFilteredText(const QString &text)
bool appendDependentTasks(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentTasks) const
QWidget * mpPage1
Definition: CQMessageBox.h:64
static bool isMainThread()
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static CopasiUI3Window * getMainWindow()
void setText(const QString &text)
QVBoxLayout * mpVerticalLayoutPage1
Definition: CQMessageBox.h:65
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
QTabWidget * mpTabWidget
Definition: CQMessageBox.h:63
bool appendDependentModelObjects(const std::set< const CCopasiObject * > &candidates, std::set< const CCopasiObject * > &dependentReactions, std::set< const CCopasiObject * > &dependentMetabolites, std::set< const CCopasiObject * > &dependentCompartments, std::set< const CCopasiObject * > &dependentModelValues, std::set< const CCopasiObject * > &dependentEvents) const
Definition: CModel.cpp:2364
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool appendDependentFunctions(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentFunctions) const
QTextEdit * mpText1
Definition: CQMessageBox.h:66
QTextEdit * mpText2
Definition: CQMessageBox.h:69
static CFunctionDB * getFunctionList()
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setMessageShown(const bool &shown)
Definition: CModel.h:50
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
QWidget * mpPage2
Definition: CQMessageBox.h:67