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