Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceLineicWidget.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 <QTreeWidget>
25 #include <QLabel>
26 #include <QHeaderView>
27 #include <QtWidgets>
28 
33 #include "TYSourceLineicWidget.h"
34 
35 #define TR(id) OLocalizator::getString("TYSourceLineicWidget", (id))
36 
37 TYSourceLineicWidget::TYSourceLineicWidget(TYSourceLineic* pElement, QWidget* _pParent /*=NULL*/)
38  : TYWidget(pElement, _pParent)
39 {
40 
41  _elmW = new TYSourceWidget(pElement, this);
42 
43  resize(300, 444);
44  setWindowTitle(TR("id_caption"));
45  _sourceLineicLayout = new QGridLayout();
46 
47  _sourceLineicLayout->addWidget(_elmW, 0, 0);
48 
49  _groupBoxEdit = new QGroupBox(this);
50  _groupBoxEdit->setTitle(TR(""));
51  _groupBoxEditLayout = new QGridLayout();
53 
55  _groupBoxEditLayout->addWidget(_lineEditDensiteSrcs, 0, 1);
56  QLabel* pUnitDensite = new QLabel(_groupBoxEdit);
57  pUnitDensite->setText(TR("id_unite_densite_srcs"));
58  _groupBoxEditLayout->addWidget(pUnitDensite, 0, 2);
59 
60  _labelDensiteSrcs = new QLabel(_groupBoxEdit);
61  _labelDensiteSrcs->setText(TR("id_densitessrcs_label"));
62  _groupBoxEditLayout->addWidget(_labelDensiteSrcs, 0, 0);
63 
64  _labeSrcsCor = new QLabel(_groupBoxEdit);
65  _labeSrcsCor->setText(TR("id_srcscor_label"));
66  _groupBoxEditLayout->addWidget(_labeSrcsCor, 1, 0);
67 
68  _checkBoxSrcsCor = new QCheckBox(_groupBoxEdit);
69  _checkBoxSrcsCor->setText(TR(""));
70  _groupBoxEditLayout->addWidget(_checkBoxSrcsCor, 1, 1);
71 
72  _sourceLineicLayout->addWidget(_groupBoxEdit, 1, 0);
73 
74  _groupBoxListSrc = new QGroupBox(this);
75  _groupBoxListSrc->setTitle(TR("id_tabsrc_box"));
76  _groupBoxListSrcLayout = new QGridLayout();
78 
79  _listViewListSrc = new QTreeWidget(_groupBoxListSrc);
80  _listViewListSrc->setColumnCount(2);
81  QStringList list;
82  list.append(TR(""));
83  list.append(TR("id_source"));
84  _listViewListSrc->setHeaderLabels(list);
85  // _listViewListSrc->addColumn( TR( "" ) );
86  // _listViewListSrc->addColumn( TR( "id_source" ) );
87 
88  _listViewListSrc->setRootIsDecorated(true);
89 
90  _groupBoxListSrcLayout->addWidget(_listViewListSrc, 0, 0);
91 
92  _sourceLineicLayout->addWidget(_groupBoxListSrc, 2, 0);
93 
94  updateContent();
95 
96  setLayout(_sourceLineicLayout);
97 }
98 
100 
102 {
103  QString num;
104 
105  _elmW->updateContent();
106 
107  _lineEditDensiteSrcs->setText(num.setNum(getElement()->getDensiteSrcs(), 'f', 2));
108  _checkBoxSrcsCor->setChecked(getElement()->getSrcsCorr());
109 
110  _listViewListSrc->clear();
111  for (unsigned int i = 0; i < getElement()->getNbSrcs(); i++)
112  {
113  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSrc, 0);
114  item->setText(0, num.setNum(i));
115  item->setText(1, getElement()->getSrc(i)->getName());
116  }
117 }
118 
120 {
121  _elmW->apply();
122 
123  getElement()->setSrcsCorr(_checkBoxSrcsCor->isChecked());
124  getElement()->setDensiteSrcs(_lineEditDensiteSrcs->text().toDouble());
125 
126  emit modified();
127 }
128 
129 void TYSourceLineicWidget::editSource(QTreeWidgetItem* item)
130 {
131  int ret = getElement()->getSrc(item->text(0).toInt())->edit(this);
132 
133  if (ret == QDialog::Accepted)
134  {
135  _listViewListSrc->clear();
136  for (unsigned int i = 0; i < getElement()->getNbSrcs(); i++)
137  {
138  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSrc, 0);
139  item->setText(0, QString().setNum(i));
140  item->setText(1, getElement()->getSrc(i)->getName());
141  }
142  }
143 }
144 
145 void TYSourceLineicWidget::contextMenuEvent(QContextMenuEvent* e)
146 {
147  // si on trouve un item associe
148  QPoint point = _listViewListSrc->mapFrom(this, e->pos());
149  QTreeWidgetItem* item =
150  _listViewListSrc->itemAt(point.x(), point.y() - _listViewListSrc->header()->height());
151 
152  if (item != NULL)
153  {
154  QMenu* pMenu = new QMenu(this);
155 
156  QAction* prop = pMenu->addAction(TR("id_property"));
157  QAction* ret = pMenu->exec(_listViewListSrc->mapToGlobal(point));
158 
159  if (ret == prop)
160  {
161  editSource(item);
162  }
163  }
164 }
outil IHM pour une entrée utilisateur (fichier header)
#define TR(id)
outil IHM pour une source lineique (fichier header)
outil IHM pour une source (fichier header)
QGridLayout * _groupBoxEditLayout
virtual void contextMenuEvent(QContextMenuEvent *e)
TYLineEdit * _lineEditDensiteSrcs
TYSourceLineicWidget(TYSourceLineic *pElement, QWidget *_pParent=NULL)
QGridLayout * _groupBoxListSrcLayout
QTreeWidget * _listViewListSrc
void editSource(QTreeWidgetItem *item)
QGridLayout * _sourceLineicLayout
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()