Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYWidget.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 
23 #include <qstring.h>
24 
29 
30 #include "TYWidget.h"
31 
32 #define TR(id) OLocalizator::getString("TYWidget", (id))
33 
34 TYWidget::TYWidget(TYElement* pElement, QWidget* parent, const char* name, Qt::WindowFlags f)
35  : QWidget(parent, f), _pElement(pElement)
36 {
37  setObjectName(QString(name));
38  _locked = false;
39 }
40 
42 
43 /*static*/ int TYWidget::edit(TYElement* pElement, QWidget* pParent /*=NULL*/)
44 {
45  TYFormDialog* pDlg = new TYFormDialog(pParent);
46  pDlg->setModal(true);
47 
48  int ret = QDialog::Rejected;
49 
50  if (pElement != nullptr)
51  {
52  pDlg->setWindowTitle(getDisplayName(pElement));
53 
54  QWidget* pMainWidget = pElement->getEditWidget();
55  pMainWidget->setParent(pDlg);
56 
57  QBoxLayout* pLayout = new QVBoxLayout();
58  pLayout->addWidget(pMainWidget);
59  pDlg->setLayout(pLayout);
60 
61  // On recupere les settings
62  TYPreferenceManager::loadGeometryFromPreferences(pMainWidget->metaObject()->className(), pDlg);
63 
64  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
65  pButtonOK->setDefault(true);
66  connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
67 
68  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
69  pButtonCancel->setShortcut(Qt::Key_Escape);
70  connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
71 
72  pLayout->addSpacing(5);
73  QBoxLayout* pBtnLayout = new QHBoxLayout();
74  pBtnLayout->setContentsMargins(10, 10, 10, 10);
75  pLayout->addLayout(pBtnLayout);
76 
77  pBtnLayout->addStretch();
78  pBtnLayout->addWidget(pButtonOK);
79  pBtnLayout->addSpacing(5);
80  pBtnLayout->addWidget(pButtonCancel);
81 
82  // Affiche la boite de dialogue
83  ret = pDlg->exec();
84 
85  // Applique les modificatins si necessaire
86  if (ret == QDialog::Accepted)
87  {
88  ((TYWidget*)pMainWidget)->apply();
89  }
90  else // Reject
91  {
92  ((TYWidget*)pMainWidget)->reject();
93  }
94 
95  // On sauve les settings
96  TYPreferenceManager::saveGeometryToPreferences(pMainWidget->metaObject()->className(), pDlg);
97 
98  // Liberation de la memoire
99  if (pParent)
100  {
101  pDlg->setParent(0);
102  }
103 
104  disconnect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
105  disconnect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
106  }
107  else
108  {
109  ret = QDialog::Rejected;
110  ;
111  }
112 
113  delete pDlg;
114 
115  return ret;
116 }
117 
118 /*static*/ QString TYWidget::getDisplayName(TYElement* pElt)
119 {
120  if (pElt == nullptr)
121  {
122  return QString();
123  }
124 
125  return OLocalizator::getString("DisplayName", pElt->getClassName());
126 }
Parent class of Tympan Qt dialogs of type form (geader file)
const char * name
#define TR(id)
Definition: TYWidget.cpp:32
outil IHM pour un objet metier de type TYElement (fichier header)
static QString getString(const QString &classname, const QString &stringId)
virtual const char * getClassName() const
Definition: TYElement.h:249
void setParent(TYElement *pParent)
Definition: TYElement.h:692
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYWidget(TYElement *pElement, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=QFlag(0))
Definition: TYWidget.cpp:34
virtual ~TYWidget()
Definition: TYWidget.cpp:41
bool _locked
Definition: TYWidget.h:117
static QString getDisplayName(TYElement *pElt)
Definition: TYWidget.cpp:118
static int edit(TYElement *pElement, QWidget *pParent=NULL)
Definition: TYWidget.cpp:43