Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYDirectivityWidget.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 
25 
26 #include <qmenu.h>
27 #include <qtablewidget.h>
28 
29 // Added by qt3to4:
30 #include <QGridLayout>
31 #include <QHeaderView>
32 
33 #include "TYDirectivityWidget.h"
34 
35 #define TR(id) OLocalizator::getString("TYDirectivityWidget", (id))
36 
37 TYDirectivityWidget::TYDirectivityWidget(TYDirectivity* pElement, QWidget* _pParent /*=NULL*/)
38  : TYWidget(pElement, _pParent)
39 {
40  resize(300, 240);
41  setWindowTitle(TR("id_caption"));
42 
43  _elmW = new TYElementWidget(pElement, this);
44  _table = new QTableWidget();
45  _table->setColumnCount(3);
46  _table->setContextMenuPolicy(Qt::CustomContextMenu);
47  _table->setHorizontalHeaderItem(0, new QTableWidgetItem(TR("id_theta")));
48  _table->setHorizontalHeaderItem(1, new QTableWidgetItem(TR("id_phi")));
49  _table->setHorizontalHeaderItem(2, new QTableWidgetItem(TR("id_value")));
50 
51  QGridLayout* groupBoxLayout = new QGridLayout();
52  groupBoxLayout->addWidget(_table, 1, 0);
53 
54  QGroupBox* groupBox = new QGroupBox();
55  groupBox->setTitle(TR("id_tabangleval_box"));
56  groupBox->setLayout(groupBoxLayout);
57 
58  _directiviteLayout = new QGridLayout();
59  _directiviteLayout->addWidget(_elmW, 0, 0);
60  _directiviteLayout->addWidget(groupBox, 1, 0);
61  setLayout(_directiviteLayout);
62 
63  updateContent();
64 
65  connect(_table, &QTableWidget::customContextMenuRequested, this, &TYDirectivityWidget::showContextMenu);
66  connect(_table, &QTableWidget::itemChanged, this, &TYDirectivityWidget::apply);
67 }
68 
70 
72 {
74 
75  for (int i = 0; i < _table->rowCount(); i++)
76  {
77  _table->takeItem(i, 0);
78  _table->takeItem(i, 1);
79  }
80  _table->setRowCount(0);
81 }
82 
84 {
85  _elmW->apply();
86  emit modified();
87 }
88 
89 void TYDirectivityWidget::showContextMenu(const QPoint& pos)
90 {
91  QTableWidgetItem* item = _table->itemAt(pos);
92  if (item)
93  {
94  int row = _table->row(item);
95  QMenu* pMenu = new QMenu(this);
96  pMenu->addAction(TR("id_add"));
97 
98  if (row >= 0)
99  {
100  pMenu->addSeparator();
101  pMenu->addAction(TR("id_del"));
102  }
103 
104  pMenu->exec(pos);
105  }
106 }
#define TR(id)
outil IHM pourla directivite (fichier header)
void showContextMenu(const QPoint &pos)
TYElementWidget * _elmW
QGridLayout * _directiviteLayout
TYDirectivityWidget(TYDirectivity *pElement, QWidget *_pParent=NULL)
virtual void updateContent()
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
void modified()