Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_ErrorDialog.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 /*
4  * XGUI_ErrorDialog.cpp
5  *
6  *  Created on: Apr 28, 2014
7  *      Author: sbh
8  */
9 #include <XGUI_ErrorDialog.h>
10
11 #include <QDialogButtonBox>
12 #include <QHBoxLayout>
13 #include <QLabel>
14 #include <QVBoxLayout>
15 #include <QTextEdit>
16
17 XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
18     : QDialog(parent)
19 {
20   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
21   setWindowTitle(tr("Application errors"));
22   myErrorLog = new QTextEdit(this);
23   myErrorLog->setReadOnly(true);
24   aDlgLay->addWidget(myErrorLog);
25   QDialogButtonBox* aButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal,
26                                                       this);
27   aDlgLay->addWidget(aButtonBox);
28   aDlgLay->setContentsMargins(2, 2, 2, 2);
29   aDlgLay->setSpacing(2);
30   setLayout(aDlgLay);
31   resize(420, 240);
32
33   connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear()));
34   connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear()));
35 }
36
37 XGUI_ErrorDialog::~XGUI_ErrorDialog()
38 {
39 }
40
41 void XGUI_ErrorDialog::refresh()
42 {
43   myErrorLog->clear();
44   foreach(QString eachError, myErrors)
45   {
46     myErrorLog->append(eachError);
47   }
48 }
49
50 void XGUI_ErrorDialog::clear()
51 {
52   myErrorLog->clear();
53   myErrors.clear();
54   QDialog::reject();
55 }
56
57 void XGUI_ErrorDialog::addError(const QString& theError)
58 {
59   myErrors.append(theError);
60   refresh();
61   if (!isVisible()) {
62     show();
63     raise();
64     activateWindow();
65   }
66 }
67
68 void XGUI_ErrorDialog::removeError(const QString& theError)
69 {
70   myErrors.removeAll(theError);
71   refresh();
72 }