Salome HOME
An additional minor fix based on the issue #2917 issue script: to update some kind...
[modules/shaper.git] / src / XGUI / XGUI_ErrorDialog.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <XGUI_ErrorDialog.h>
21
22 #include <ModuleBase_Tools.h>
23 #include <Config_Translator.h>
24
25 #include <QDialogButtonBox>
26 #include <QHBoxLayout>
27 #include <QLabel>
28 #include <QVBoxLayout>
29 #include <QTextEdit>
30 #include <QTextCodec>
31
32 XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
33     : QDialog(parent)
34 {
35   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
36   setWindowTitle(tr("Application errors"));
37   myErrorLog = new QTextEdit(this);
38   myErrorLog->setReadOnly(true);
39   aDlgLay->addWidget(myErrorLog);
40   QDialogButtonBox* aButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal,
41                                                       this);
42   aDlgLay->addWidget(aButtonBox);
43   aDlgLay->setContentsMargins(2, 2, 2, 2);
44   aDlgLay->setSpacing(2);
45   setLayout(aDlgLay);
46   resize(420, 240);
47
48   connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear()));
49   connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear()));
50 }
51
52 XGUI_ErrorDialog::~XGUI_ErrorDialog()
53 {
54 }
55
56 void XGUI_ErrorDialog::refresh()
57 {
58   myErrorLog->clear();
59   foreach(QString eachError, myErrors)
60   {
61     myErrorLog->append(eachError);
62   }
63 }
64
65 void XGUI_ErrorDialog::clear()
66 {
67   myErrorLog->clear();
68   myErrors.clear();
69   QDialog::reject();
70 }
71
72 void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> theMsg)
73 {
74   std::string aError = Config_Translator::translate(*theMsg);
75   std::string aCodec = Config_Translator::codec(*theMsg);
76   QString aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aError.c_str());
77   myErrors.append(aMsg);
78   refresh();
79   if (!isVisible()) {
80     show();
81     ModuleBase_Tools::activateWindow(this, "XGUI_ErrorDialog::addError");
82   }
83 }
84
85 void XGUI_ErrorDialog::removeError(const QString& theError)
86 {
87   myErrors.removeAll(theError);
88   refresh();
89 }