Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceSurfacicWidget.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 <qmenu.h>
22 // Added by qt3to4:
23 #include <QGridLayout>
24 #include <QLabel>
25 #include <QTreeWidget>
26 #include <QTreeWidgetItem>
27 #include <QHeaderView>
28 
33 #include "TYSourceSurfacicWidget.h"
34 
35 #define TR(id) OLocalizator::getString("TYSourceSurfacicWidget", (id))
36 
38  : TYWidget(pElement, _pParent)
39 {
40 
41  _elmW = new TYSourceWidget(pElement, this);
42 
43  resize(300, 463);
44  setWindowTitle(TR("id_caption"));
45  _sourceSurfacicLayout = new QGridLayout();
46  setLayout(_sourceSurfacicLayout);
47 
48  _sourceSurfacicLayout->addWidget(_elmW, 0, 0);
49 
50  _groupBox = new QGroupBox(this);
51  _groupBox->setTitle(TR(""));
52  _groupBoxLayout = new QGridLayout();
53  _groupBox->setLayout(_groupBoxLayout);
54 
55  _labeSrcsCor = new QLabel(_groupBox);
56  _labeSrcsCor->setText(TR("id_srcscor_label"));
57  _groupBoxLayout->addWidget(_labeSrcsCor, 2, 0);
58 
59  _checkBoxSrcsCor = new QCheckBox(_groupBox);
60  _checkBoxSrcsCor->setText(TR(""));
61  _groupBoxLayout->addWidget(_checkBoxSrcsCor, 2, 1);
62 
63  _labelDensiteSrcsH = new QLabel(_groupBox);
64  _labelDensiteSrcsH->setText(TR("id_densitessrcsH_label"));
65  _groupBoxLayout->addWidget(_labelDensiteSrcsH, 0, 0);
66 
68  _groupBoxLayout->addWidget(_lineEditDensiteSrcsH, 0, 1);
69  QLabel* pUnitDensiteH = new QLabel(_groupBox);
70  pUnitDensiteH->setText(TR("id_unite_densite_srcs"));
71  _groupBoxLayout->addWidget(pUnitDensiteH, 0, 2);
72 
74  _groupBoxLayout->addWidget(_lineEditDensiteV, 1, 1);
75  QLabel* pUnitDensiteV = new QLabel(_groupBox);
76  pUnitDensiteV->setText(TR("id_unite_densite_srcs"));
77  _groupBoxLayout->addWidget(pUnitDensiteV, 1, 2);
78 
79  _labelDensiteSrcsV = new QLabel(_groupBox);
80  _labelDensiteSrcsV->setText(TR("id_densitessrcsV_label"));
81  _groupBoxLayout->addWidget(_labelDensiteSrcsV, 1, 0);
82 
83  _sourceSurfacicLayout->addWidget(_groupBox, 1, 0);
84 
85  _groupBoxListSrc = new QGroupBox(this);
86  _groupBoxListSrc->setTitle(TR("id_tabsrc_box"));
87  _groupBoxListSrcLayout = new QGridLayout();
89 
90  _listViewListSrc = new QTreeWidget(_groupBoxListSrc);
91  QStringList stringList;
92  stringList.append(TR(""));
93  stringList.append(TR("id_source"));
94  _listViewListSrc->setColumnCount(2);
95  _listViewListSrc->setHeaderLabels(stringList);
96  _listViewListSrc->setRootIsDecorated(true);
97 
98  _groupBoxListSrcLayout->addWidget(_listViewListSrc, 0, 0);
99 
100  _sourceSurfacicLayout->addWidget(_groupBoxListSrc, 2, 0);
101 
102  updateContent();
103 }
104 
106 
108 {
109  QString num;
110 
111  _elmW->updateContent();
112 
113  _lineEditDensiteV->setText(num.setNum(getElement()->getDensiteSrcsV(), 'f', 2));
114  _lineEditDensiteSrcsH->setText(num.setNum(getElement()->getDensiteSrcsH(), 'f', 2));
115  _checkBoxSrcsCor->setChecked(getElement()->getSrcsCorr());
116 
117  _listViewListSrc->clear();
118  for (unsigned int i = 0; i < getElement()->getNbSrcs(); i++)
119  {
120  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSrc, 0);
121  item->setText(0, QString().setNum(i));
122  item->setText(1, getElement()->getSrcs().at(i)->getName());
123  }
124 }
125 
127 {
128  _elmW->apply();
129 
130  getElement()->setSrcsCorr(_checkBoxSrcsCor->isChecked());
131  getElement()->setDensiteSrcsV(_lineEditDensiteV->text().toDouble());
132  getElement()->setDensiteSrcsH(_lineEditDensiteSrcsH->text().toDouble());
133 
134  emit modified();
135 }
136 
137 void TYSourceSurfacicWidget::editSource(QTreeWidgetItem* item)
138 {
139  int ret = getElement()->getSrc(item->text(0).toInt())->edit(this);
140 
141  if (ret == QDialog::Accepted)
142  {
143  updateContent();
144  }
145 }
146 
148 {
149  // si on trouve un item associe
150  QPoint point = _listViewListSrc->mapFrom(this, e->pos());
151  QTreeWidgetItem* item =
152  _listViewListSrc->itemAt(point.x(), point.y() - _listViewListSrc->header()->height());
153 
154  if (item != NULL)
155  {
156  QMenu* pMenu = new QMenu(this);
157 
158  QAction* prop = pMenu->addAction(TR("id_property"));
159  QAction* ret = pMenu->exec(_listViewListSrc->mapToGlobal(point));
160 
161  if (ret == prop)
162  {
163  editSource(item);
164  }
165  }
166 }
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()