]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ErrorDialog.cpp
Salome HOME
dc64a8a997a3908c25a5600b505510d52685ba34
[modules/shaper.git] / src / XGUI / XGUI_ErrorDialog.cpp
1 // Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * XGUI_ErrorDialog.cpp
22  *
23  *  Created on: Apr 28, 2014
24  *      Author: sbh
25  */
26 #include <XGUI_ErrorDialog.h>
27
28 #include <ModuleBase_Tools.h>
29 #include <Config_Translator.h>
30
31 #include <QDialogButtonBox>
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <QVBoxLayout>
35 #include <QTextEdit>
36 #include <QTextCodec>
37
38 XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
39     : QDialog(parent)
40 {
41   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
42   setWindowTitle(tr("Application errors"));
43   myErrorLog = new QTextEdit(this);
44   myErrorLog->setReadOnly(true);
45   aDlgLay->addWidget(myErrorLog);
46   QDialogButtonBox* aButtonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal,
47                                                       this);
48   aDlgLay->addWidget(aButtonBox);
49   aDlgLay->setContentsMargins(2, 2, 2, 2);
50   aDlgLay->setSpacing(2);
51   setLayout(aDlgLay);
52   resize(420, 240);
53
54   connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear()));
55   connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear()));
56 }
57
58 XGUI_ErrorDialog::~XGUI_ErrorDialog()
59 {
60 }
61
62 void XGUI_ErrorDialog::refresh()
63 {
64   myErrorLog->clear();
65   foreach(QString eachError, myErrors)
66   {
67     myErrorLog->append(eachError);
68   }
69 }
70
71 void XGUI_ErrorDialog::clear()
72 {
73   myErrorLog->clear();
74   myErrors.clear();
75   QDialog::reject();
76 }
77
78 void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> theMsg)
79 {
80   std::string aError = Config_Translator::translate(*theMsg);
81   std::string aCodec = Config_Translator::codec(*theMsg);
82   QString aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aError.c_str());
83   myErrors.append(aMsg);
84   refresh();
85   if (!isVisible()) {
86     show();
87     ModuleBase_Tools::activateWindow(this, "XGUI_ErrorDialog::addError");
88   }
89 }
90
91 void XGUI_ErrorDialog::removeError(const QString& theError)
92 {
93   myErrors.removeAll(theError);
94   refresh();
95 }