Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYGetLibraryDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
21 #include <qcursor.h>
22 #include <qmessagebox.h>
23 #include <qpushbutton.h>
24 // Added by qt3to4:
25 #include <QGridLayout>
26 #include <QBoxLayout>
27 #include <QHBoxLayout>
28 
29 #include "Tympan/core/logging.h"
35 #include "TYGetLibraryDialog.h"
36 
37 #define TR(id) OLocalizator::getString("TYGetLibraryDialog", (id))
38 
39 TYGetLibraryDialog::TYGetLibraryDialog(int filter, QWidget* parent, const char* name, Qt::WindowFlags f)
40  : QDialog(parent, f)
41 {
42  setObjectName(name);
43  setWindowTitle(TR("id_caption"));
44 
45  // Layout
46  QGridLayout* pLayout = new QGridLayout();
47  setLayout(pLayout);
48 
49  // On affiche la bibliotheque
50  _pLibrary = new TYLibraryWidget(filter, this);
51  pLayout->addWidget(_pLibrary, 0, 0);
52 
53  // Push buttons
54  QBoxLayout* pBtnLayout = new QHBoxLayout();
55  pLayout->addLayout(pBtnLayout, 1, 0);
56  pBtnLayout->addStretch(1);
57 
58  _pOpenBtn = new QPushButton(TR("id_ok_btn"), this);
59  _pOpenBtn->setEnabled(false);
60  QObject::connect(_pOpenBtn, &QPushButton::clicked, this, &TYGetLibraryDialog::openSelected);
61  pBtnLayout->addWidget(_pOpenBtn);
62 
63  QPushButton* pCloseBtn = new QPushButton(TR("id_cancel_btn"), this);
64  pCloseBtn->setShortcut(Qt::Key_Escape);
65  QObject::connect(pCloseBtn, &QPushButton::clicked, this, &TYGetLibraryDialog::reject);
66  pBtnLayout->addWidget(pCloseBtn);
67 
69 }
70 
72 {
73  QObject::disconnect(_pOpenBtn, &QPushButton::clicked, this, &TYGetLibraryDialog::openSelected);
75 }
76 
78 {
79  return _elements;
80 }
81 
83 {
84  QList<QString> selectedElts = _pLibrary->getSelectedEltsList();
85 
86  if (selectedElts.size() == 0)
87  {
88  return;
89  }
90 
91  if (QMessageBox::question(this, TR("id_box_caption"), TR("id_box_text"), TR("id_box_yes"),
92  TR("id_box_no"), QString(), 0, 1))
93  {
94  return;
95  }
96 
97  accept();
98 
99  _elements.clear();
100 
101  TYApplication::setOverrideCursor(Qt::WaitCursor);
102 
103  TYElement::setRegenerateID(true); // Force le renouvellement de l'Id des fichiers importes
104 
105  for (unsigned int i = 0; i < selectedElts.size(); ++i)
106  {
107  // QString filename = QDir::convertSeparators(getTYApp()->tympanUserDir() + "/library/" +
108  // selectedElts[i] + ".xml");
109  QString filename =
110  QDir::toNativeSeparators(_pLibrary->getCurrentDir() + "/" + selectedElts[i] + ".xml");
111 
112  // Chargement effectif du fichier
113  TYXMLManager xmlManager;
114  int res = xmlManager.load(filename.toLatin1(), _elements);
115 
116  // Backup du fichier (si le fichier est valide)
117  if (res == 1)
118  {
119  bool bBackupOk = getTYMainWnd()->backupFile(filename);
120 
121  if (!bBackupOk)
122  {
123  OMessageManager::get()->info("***********************************************");
124  OMessageManager::get()->info("* *");
125  OMessageManager::get()->info("* La copie de sauvegarde n'a pas fonctionne ! *");
126  OMessageManager::get()->info("* *");
127  OMessageManager::get()->info("***********************************************");
128  }
129  }
130  else
131  {
132  OMessageManager::get()->info("************************************************");
133  OMessageManager::get()->info("* *");
134  OMessageManager::get()->info("* Le document n est pas valide. *");
135  OMessageManager::get()->info("* La copie de sauvegarde du dernier document *");
136  OMessageManager::get()->info("* valide a ete preservee avec la terminaison *");
137  OMessageManager::get()->info("* .bak *");
138  OMessageManager::get()->info("* *");
139  OMessageManager::get()->info("************************************************");
140  }
141  }
142 
143  TYElement::setRegenerateID(false); // Revient a l'etat initial
144 
145  TYApplication::restoreOverrideCursor();
146 }
147 
148 void TYGetLibraryDialog::setEnableButton(const QString& str)
149 {
150  if (str.isNull())
151  {
152  _pOpenBtn->setEnabled(false);
153  }
154  else
155  {
156  _pOpenBtn->setEnabled(true);
157  }
158 }
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:345
#define TR(id)
Boite de dialogue pour la lecture d'un element dans la bibliotheque (fichier header)
Widget pour lister les elements de la bibilotheque (fichier header)
Fenetre principale de l'application Tympan (fichier header)
const char * name
static OMessageManager * get()
Definition: logging.cpp:108
virtual void info(const char *message,...)
Definition: logging.cpp:143
static void setRegenerateID(const bool &bRegenerate)
Definition: TYElement.h:923
LPTYElementArray getElements()
LPTYElementArray _elements
La collection d'element.
void setEnableButton(const QString &)
Active ou non le bouton _pOpenBtn.
QPushButton * _pOpenBtn
Le bouton open.
TYGetLibraryDialog(int filter, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=QFlag(0))
void openSelected()
Lit la selection.
TYLibraryWidget * _pLibrary
La librarie.
Widget pour lister les elements de la bibilotheque.
const QList< QString > & getSelectedEltsList() const
const QString getCurrentDir() const
void highlighted(const QString &)
bool backupFile(const QString &fileName)
int load(const QString &fileName, LPTYElementArray &eltCollection)