Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/homard.git] / src / HOMARDGUI / MonEditFile.cxx
1 // Copyright (C) 2011-2012  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.
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 using namespace std;
21
22 #include "MonEditFile.h"
23
24 #include <QFile>
25 #include <QTextStream>
26 #include <QMessageBox>
27
28 #include "SalomeApp_Tools.h"
29 #include "HOMARDGUI_Utils.h"
30 #include "HomardQtCommun.h"
31 #include <utilities.h>
32
33 /* ---------------------------------------------------------
34  * MonEditFile classe derivee de EditFile
35  *               elle meme generee par uic
36  * Ouvre le fichier passe en parametre
37  * et affiche le texte correspondant dans la fenetre de log
38  * ---------------------------------------------------------
39  */
40
41 /* ---------------------------------------------------------
42  * MonEditFile Constructeur
43  * ---------------------------------------------------------
44  */
45 MonEditFile::MonEditFile( QWidget* parent,  bool modal,
46                           HOMARD::HOMARD_Gen_var myHomardGen,
47                           QString aFileName):
48 //    QWidget(0),
49     Ui_EditFile(),
50     _aFileName (aFileName)
51 {
52   MESSAGE("Debut de MonEditFile " << aFileName.toStdString().c_str());
53   setupUi(this);
54   InitConnect();
55   EditText();
56 }
57 /*
58  *  Destroys the object and frees any allocated resources
59  */
60 MonEditFile::~MonEditFile()
61 {
62    MESSAGE("Destructeur de ~MonEditFile");
63 }
64 // ------------------------------------------------------------------------
65 void MonEditFile::InitConnect()
66 // ------------------------------------------------------------------------
67 {
68     connect( buttonQuit,     SIGNAL(pressed()), this, SLOT(close()));
69     connect( buttonPrint,    SIGNAL(pressed()), this, SLOT(PushOnPrint()));
70 }
71 // ------------------------------------------------------------------------
72 void MonEditFile::EditText()
73 // ------------------------------------------------------------------------
74 {
75 // Creation de l'objet fichier QT associe
76   QFile file( _aFileName );
77 // Ouverture
78   bool bOpen = file.open( QIODevice::ReadOnly | QIODevice::Text ) ;
79 //
80   if ( bOpen )
81   {
82 // Lecture
83 //    Remarque : il serait plus clair de tout lire d'un coup mais cela ne marche pas !
84 //               alors on fait ligne par ligne et on cumule en ajoutant un saut de ligne.
85       QTextStream stream( &file );
86       QString tout;
87       while ( !stream.atEnd() )
88       {
89         tout = tout + stream.readLine() + "\n" ;
90       }
91 //       tout = stream.readAll() ;
92       QTBEditFile->setPlainText( tout );
93   }
94   else
95   {
96      // GERALD -- QMESSAGE BOX
97      MESSAGE( "EditText " << _aFileName.toStdString().c_str() << "est impossible a ouvrir ");
98   }
99 }
100 // ------------------------------------------------------------------------
101 void MonEditFile::PushOnPrint()
102 // ------------------------------------------------------------------------
103 {
104   MESSAGE("Debut de MonEditFile::PushOnPrint")
105   QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
106                             QObject::tr("HOM_INACTIVE_BUTTON") );
107   return;
108 }
109
110