Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceSurfacicWidget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) 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.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
21 #include <qmenu.h>
22 // Added by qt3to4:
23 #include <QGridLayout>
24 #include <QLabel>
25 #include <QTreeWidget>
26 #include <QTreeWidgetItem>
27 #include <QHeaderView>
28 #include <QtWidgets>
29 
34 #include "TYSourceSurfacicWidget.h"
35 
36 #define TR(id) OLocalizator::getString("TYSourceSurfacicWidget", (id))
37 
39  : TYWidget(pElement, _pParent)
40 {
41 
42  _elmW = new TYSourceWidget(pElement, this);
43 
44  resize(300, 463);
45  setWindowTitle(TR("id_caption"));
46  _sourceSurfacicLayout = new QGridLayout();
47  setLayout(_sourceSurfacicLayout);
48 
49  _sourceSurfacicLayout->addWidget(_elmW, 0, 0);
50 
51  _groupBox = new QGroupBox(this);
52  _groupBox->setTitle(TR(""));
53  _groupBoxLayout = new QGridLayout();
54  _groupBox->setLayout(_groupBoxLayout);
55 
56  _labeSrcsCor = new QLabel(_groupBox);
57  _labeSrcsCor->setText(TR("id_srcscor_label"));
58  _groupBoxLayout->addWidget(_labeSrcsCor, 2, 0);
59 
60  _checkBoxSrcsCor = new QCheckBox(_groupBox);
61  _checkBoxSrcsCor->setText(TR(""));
62  _groupBoxLayout->addWidget(_checkBoxSrcsCor, 2, 1);
63 
64  _labelDensiteSrcsH = new QLabel(_groupBox);
65  _labelDensiteSrcsH->setText(TR("id_densitessrcsH_label"));
66  _groupBoxLayout->addWidget(_labelDensiteSrcsH, 0, 0);
67 
69  _groupBoxLayout->addWidget(_lineEditDensiteSrcsH, 0, 1);
70  QLabel* pUnitDensiteH = new QLabel(_groupBox);
71  pUnitDensiteH->setText(TR("id_unite_densite_srcs"));
72  _groupBoxLayout->addWidget(pUnitDensiteH, 0, 2);
73 
75  _groupBoxLayout->addWidget(_lineEditDensiteV, 1, 1);
76  QLabel* pUnitDensiteV = new QLabel(_groupBox);
77  pUnitDensiteV->setText(TR("id_unite_densite_srcs"));
78  _groupBoxLayout->addWidget(pUnitDensiteV, 1, 2);
79 
80  _labelDensiteSrcsV = new QLabel(_groupBox);
81  _labelDensiteSrcsV->setText(TR("id_densitessrcsV_label"));
82  _groupBoxLayout->addWidget(_labelDensiteSrcsV, 1, 0);
83 
84  _sourceSurfacicLayout->addWidget(_groupBox, 1, 0);
85 
86  _groupBoxListSrc = new QGroupBox(this);
87  _groupBoxListSrc->setTitle(TR("id_tabsrc_box"));
88  _groupBoxListSrcLayout = new QGridLayout();
90 
91  _listViewListSrc = new QTreeWidget(_groupBoxListSrc);
92  QStringList stringList;
93  stringList.append(TR(""));
94  stringList.append(TR("id_source"));
95  _listViewListSrc->setColumnCount(2);
96  _listViewListSrc->setHeaderLabels(stringList);
97  _listViewListSrc->setRootIsDecorated(true);
98 
99  _groupBoxListSrcLayout->addWidget(_listViewListSrc, 0, 0);
100 
101  _sourceSurfacicLayout->addWidget(_groupBoxListSrc, 2, 0);
102 
103  updateContent();
104 }
105 
107 
109 {
110  QString num;
111 
112  _elmW->updateContent();
113 
114  _lineEditDensiteV->setText(num.setNum(getElement()->getDensiteSrcsV(), 'f', 2));
115  _lineEditDensiteSrcsH->setText(num.setNum(getElement()->getDensiteSrcsH(), 'f', 2));
116  _checkBoxSrcsCor->setChecked(getElement()->getSrcsCorr());
117 
118  _listViewListSrc->clear();
119  for (unsigned int i = 0; i < getElement()->getNbSrcs(); i++)
120  {
121  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSrc, 0);
122  item->setText(0, QString().setNum(i));
123  item->setText(1, getElement()->getSrcs().at(i)->getName());
124  }
125 }
126 
128 {
129  _elmW->apply();
130 
131  getElement()->setSrcsCorr(_checkBoxSrcsCor->isChecked());
132  getElement()->setDensiteSrcsV(_lineEditDensiteV->text().toDouble());
133  getElement()->setDensiteSrcsH(_lineEditDensiteSrcsH->text().toDouble());
134 
135  emit modified();
136 }
137 
138 void TYSourceSurfacicWidget::editSource(QTreeWidgetItem* item)
139 {
140  int ret = getElement()->getSrc(item->text(0).toInt())->edit(this);
141 
142  if (ret == QDialog::Accepted)
143  {
144  updateContent();
145  }
146 }
147 
149 {
150  // si on trouve un item associe
151  QPoint point = _listViewListSrc->mapFrom(this, e->pos());
152  QTreeWidgetItem* item =
153  _listViewListSrc->itemAt(point.x(), point.y() - _listViewListSrc->header()->height());
154 
155  if (item != NULL)
156  {
157  QMenu* pMenu = new QMenu(this);
158 
159  QAction* prop = pMenu->addAction(TR("id_property"));
160  QAction* ret = pMenu->exec(_listViewListSrc->mapToGlobal(point));
161 
162  if (ret == prop)
163  {
164  editSource(item);
165  }
166  }
167 }
outil IHM pour une entrée utilisateur (fichier header)
#define TR(id)
outil IHM pour une source surfacique (fichier header)
outil IHM pour une source (fichier header)
TYSourceSurfacicWidget(TYSourceSurfacic *pElement, QWidget *_pParent=NULL)
virtual void contextMenuEvent(QContextMenuEvent *e)
void editSource(QTreeWidgetItem *item)
classe de l'objet IHM pour une source
virtual void updateContent()
virtual void apply()
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
void modified()