Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPaletteWidget.h
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 
27 #ifndef __TY_PALETTE_WIDGET__
28 #define __TY_PALETTE_WIDGET__
29 
30 #include <vector>
31 #include <memory>
32 #include <set>
33 
34 #include "Tympan/core/color.h"
36 
37 class TYLineEdit;
38 class TYElementWidget;
40 class PaletteEditor;
41 
42 #include "TYWidget.h"
43 
44 #include <QtWidgets>
45 #include <QFrame>
46 #include <qdialog.h>
47 #include <qwidget.h>
48 #include <QVBoxLayout>
49 #include <QGroupBox>
50 #include <QLabel>
51 #include <QLineEdit>
52 #include <QItemDelegate>
53 #include <QDoubleSpinBox>
54 #include <QTableView>
55 #include <QTextStream>
56 
57 class TYPalette;
58 
59 class TYPaletteLimitsWidget : public QDialog
60 {
61  Q_OBJECT
62 
63 public:
64  TYPaletteLimitsWidget(TYPalette* pElement, QWidget* _pParent = nullptr);
65 
66 public slots:
67  virtual void updateContent(); // Override
68  virtual void apply(); // Override
69 protected:
71  QVBoxLayout* _layout;
72  QGroupBox* _groupBox;
78  QLineEdit* _lineEdit_nb_colors;
79 };
80 
85 class TYPaletteWidget : public TYWidget
86 {
87  Q_OBJECT
88 
90 
91  // Methodes
92 public:
96  TYPaletteWidget(TYPalette* pElement, QWidget* _pParent = NULL);
97 
101  virtual ~TYPaletteWidget();
102 
103 public slots:
104  virtual void updateContent(); // Override
105  virtual void apply(); // Override
106 
110  void resetPalette();
111 
115  void loadPalette();
116 
120  void savePalette();
121 
125  void makeLinearPalette();
126 
127 protected:
128  QVBoxLayout* _paletteLayout;
129 
130  // Element
134 
135  // Boutons Save/Load
140 
141 private:
143 };
144 
145 // Auxilliary classes used to build the widget using Qt Model/View architecture
146 
150 class PaletteModel : public QAbstractTableModel
151 {
152  Q_OBJECT
153 
154 public:
155  PaletteModel(TYPalette* p_palette, QObject* parent = NULL);
156  virtual ~PaletteModel();
157 
158  void getBoundsForValue(unsigned i, float& inf, float& sup) const;
159 
160 public slots:
161  int rowCount(const QModelIndex& parent = QModelIndex()) const;
162  int columnCount(const QModelIndex& parent = QModelIndex()) const;
163 
164  QVariant data(const QModelIndex& index, int role) const;
165  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
166 
167  Qt::ItemFlags flags(const QModelIndex& index) const;
168  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
169 
170  void deleteSelectedRows();
171  void addRow(float noiseLevel);
172 
173 protected:
174  bool isSpecialInfiniteCell(const QModelIndex& index) const
175  {
176  return index.row() == rowCount(QModelIndex()) - 1;
177  }
178 
179 protected:
181  std::set<unsigned> checked_rows;
182 };
183 // class PaletteModel
184 
188 class PaletteColorDelegate : public QItemDelegate
189 {
190  Q_OBJECT
191 
192 public:
193  PaletteColorDelegate(QObject* parent = NULL) : QItemDelegate(parent){};
194 
195  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
196  const QModelIndex& index) const;
197 
198  void setEditorData(QWidget* editor, const QModelIndex& index) const;
199  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
200 protected slots:
201  void validateColor();
202 };
203 // class PaletteColorDelegate
204 
208 class PaletteValueDelegate : public QItemDelegate
209 {
210  Q_OBJECT
211 
212 public:
213  PaletteValueDelegate(QObject* parent = NULL) : QItemDelegate(parent){};
214 
215  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
216  const QModelIndex& index) const;
217 
218  void setEditorData(QWidget* editor, const QModelIndex& index) const;
219  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
220 };
221 // class PaletteColorDelegate
222 
223 class PaletteEditor : public QFrame
224 {
225  Q_OBJECT
226 
227 public:
228  PaletteEditor(TYPalette* palette, QWidget* parent = NULL);
229  virtual ~PaletteEditor();
231 
232 signals:
233  void paletteChanged(const TYPalette* palette);
234 
235 protected slots:
236  void addNoiseLevel();
237  void deleteNoiseLevels();
238  void propagateModelChanges(const QModelIndex& topLeft, const QModelIndex& bottomRight);
239 
240 protected:
241  QDoubleSpinBox* newNoiseLevelSpin;
242  QPushButton* newNoiseLevelButton;
245  QTableView* p_table;
249 };
250 // class PaletteEditor
251 
252 #endif // __TY_PALETTE_WIDGET__
outil IHM pour un objet metier de type TYElement (fichier header)
#define TY_DECL_METIER_WIDGET(classname)
Definition: TYWidget.h:31
(Qt) Delegate for displaying and editing colors
void setEditorData(QWidget *editor, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
PaletteColorDelegate(QObject *parent=NULL)
PaletteEditor(TYPalette *palette, QWidget *parent=NULL)
QPushButton * deleteNoiseLevelButton
void propagateModelChanges(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QTableView * p_table
PaletteValueDelegate value_delegate
virtual ~PaletteEditor()
QDoubleSpinBox * newNoiseLevelSpin
void notifyTYPaletteExternalyChanged()
PaletteColorDelegate color_delegate
PaletteModel * p_model
QPushButton * newNoiseLevelButton
void paletteChanged(const TYPalette *palette)
TYPalette * p_palette
(Qt) Data model for a TYPalette
void addRow(float noiseLevel)
bool isSpecialInfiniteCell(const QModelIndex &index) const
void getBoundsForValue(unsigned i, float &inf, float &sup) const
std::set< unsigned > checked_rows
void deleteSelectedRows()
virtual ~PaletteModel()
QVariant data(const QModelIndex &index, int role) const
PaletteModel(TYPalette *p_palette, QObject *parent=NULL)
int rowCount(const QModelIndex &parent=QModelIndex()) const
TYPalette * p_palette
Qt::ItemFlags flags(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
(Qt) Delegate for displaying and editing colors
PaletteValueDelegate(QObject *parent=NULL)
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
classe de l'objet IHM pour un element
TYPaletteLimitsWidget(TYPalette *pElement, QWidget *_pParent=nullptr)
TYLineEdit * _lineEdit_upper_bound
virtual void updateContent()
TYLineEdit * _lineEdit_lower_bound
QLineEdit * _lineEdit_nb_colors
classe de l'objet IHM pour une palette
QPushButton * _pushButtonLinearPalette
void updateLegacyFromPalette()
virtual ~TYPaletteWidget()
TYElementWidget * _elmW
QPushButton * _pushButtonSavePalette
QPushButton * _pushButtonLoadPalette
QPushButton * _pushButtonResetPalette
virtual void updateContent()
PaletteEditor * _editor
virtual void apply()
TYPaletteWidget(TYPalette *pElement, QWidget *_pParent=NULL)
TYLabeledLookupTableWidget * p_previewWidget
QVBoxLayout * _paletteLayout
Classe de definition d'une palette.
Definition: TYPalette.h:41
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43