Salome HOME
d389e3b3f73d6a04ae35581c56f058acd5fe8ad2
[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 <ModuleBase_Tools.h>
12
13 #include <QDialogButtonBox>
14 #include <QHBoxLayout>
15 #include <QLabel>
16 #include <QVBoxLayout>
17 #include <QTextEdit>
18
19 XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
20     : QDialog(parent)
21 {
22   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
23   setWindowTitle(tr("Application errors"));
24   myErrorLog = new QTextEdit(this);
25   myErrorLog->setReadOnly(true);
26   aDlgLay->addWidget(myErrorLog);
27   QDialogButtonBox* aButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal,
28                                                       this);
29   aDlgLay->addWidget(aButtonBox);
30   aDlgLay->setContentsMargins(2, 2, 2, 2);
31   aDlgLay->setSpacing(2);
32   setLayout(aDlgLay);
33   resize(420, 240);
34
35   connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear()));
36   connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear()));
37 }
38
39 XGUI_ErrorDialog::~XGUI_ErrorDialog()
40 {
41 }
42
43 void XGUI_ErrorDialog::refresh()
44 {
45   myErrorLog->clear();
46   foreach(QString eachError, myErrors)
47   {
48     myErrorLog->append(eachError);
49   }
50 }
51
52 void XGUI_ErrorDialog::clear()
53 {
54   myErrorLog->clear();
55   myErrors.clear();
56   QDialog::reject();
57 }
58
59 void XGUI_ErrorDialog::addError(const QString& theError)
60 {
61   myErrors.append(theError);
62   refresh();
63   if (!isVisible()) {
64     show();
65     raise();
66     ModuleBase_Tools::activateWindow(this, "XGUI_ErrorDialog::addError");
67   }
68 }
69
70 void XGUI_ErrorDialog::removeError(const QString& theError)
71 {
72   myErrors.removeAll(theError);
73   refresh();
74 }