Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPaletteWidget.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 
23 #include <limits>
24 
25 #include <boost/foreach.hpp>
26 #include <boost/tuple/tuple.hpp>
27 #include <boost/math/special_functions/fpclassify.hpp>
28 
30 #include "Tympan/core/logging.h"
31 #include "TYLookupTableWidget.h"
34 
35 #include <math.h>
36 #include <qcolordialog.h>
37 #include <qfiledialog.h>
38 #include <qpainter.h>
39 #include <qmessagebox.h>
40 #include <qtablewidget.h>
41 // Added by qt3to4:
42 #include <QGridLayout>
43 #include <QLabel>
44 #include <QTextStream>
45 
46 #include "TYPaletteWidget.h"
47 #include "TYElementWidget.h"
48 
49 #define TR(id) OLocalizator::getString("TYPaletteWidget", (id))
50 
51 TYPaletteWidget::TYPaletteWidget(TYPalette* pElement, QWidget* _pParent /*=NULL*/)
52  : TYWidget(pElement, _pParent, NULL, Qt::Dialog)
53 {
54 #ifndef NDEBUG
55  bool ok = false;
56 #endif
57  resize(500, 800);
58  setWindowTitle(TR("id_caption"));
59  _paletteLayout = new QVBoxLayout();
60  setLayout(_paletteLayout);
61 
62  // ELEMENT
63  _elmW = new TYElementWidget(pElement, this);
64  _paletteLayout->addWidget(_elmW);
65 
66  // ColorMap table
67  QGroupBox* pGroupBoxColorMap = new QGroupBox(this);
68  pGroupBoxColorMap->setTitle(TR("id_editarray"));
69  QVBoxLayout* internalLayout = new QVBoxLayout();
70  pGroupBoxColorMap->setLayout(internalLayout);
71  _editor = new PaletteEditor(getElement());
72  internalLayout->addWidget(_editor);
73  _paletteLayout->addWidget(pGroupBoxColorMap, 1);
74 
75  // ColorMap preview
76  QGroupBox* pGroupBoxPreview = new QGroupBox(this);
77  pGroupBoxPreview->setTitle(TR("id_lookuptableview"));
78  // NB The internal layout of the pGroupBoxPreview is set by TYLabeledLookupTableWidget()
79  p_previewWidget = new TYLabeledLookupTableWidget(getElement(), pGroupBoxPreview);
80  _paletteLayout->addWidget(pGroupBoxPreview);
81 #ifndef NDEBUG
82  ok =
83 #endif
86  assert(ok);
87 
88  // SAVE/LOAD/RESET
89  QGroupBox* pGroupBoxSaveLoad = new QGroupBox(this);
90  pGroupBoxSaveLoad->setTitle(TR("id_saveload"));
91  QGridLayout* pGroupBoxSaveLoadLayout = new QGridLayout();
92  pGroupBoxSaveLoad->setLayout(pGroupBoxSaveLoadLayout);
93  // Load button
94  _pushButtonLoadPalette = new QPushButton(pGroupBoxSaveLoad);
95  _pushButtonLoadPalette->setText(TR("id_load"));
96  pGroupBoxSaveLoadLayout->addWidget(_pushButtonLoadPalette, 0, 0);
97  QObject::connect(_pushButtonLoadPalette, &QPushButton::clicked, this, &TYPaletteWidget::loadPalette);
98  // Save button
99  _pushButtonSavePalette = new QPushButton(pGroupBoxSaveLoad);
100  _pushButtonSavePalette->setText(TR("id_save"));
101  pGroupBoxSaveLoadLayout->addWidget(_pushButtonSavePalette, 0, 1);
102  QObject::connect(_pushButtonSavePalette, &QPushButton::clicked, this, &TYPaletteWidget::savePalette);
103  // Reset button
104  _pushButtonResetPalette = new QPushButton(pGroupBoxSaveLoad);
105  _pushButtonResetPalette->setText(TR("id_reset"));
106  pGroupBoxSaveLoadLayout->addWidget(_pushButtonResetPalette, 0, 2);
107  QObject::connect(_pushButtonResetPalette, &QPushButton::clicked, this, &TYPaletteWidget::resetPalette);
108  // Linear button
109  _pushButtonLinearPalette = new QPushButton(pGroupBoxSaveLoad);
110  _pushButtonLinearPalette->setText(TR("id_linear"));
111  pGroupBoxSaveLoadLayout->addWidget(_pushButtonLinearPalette, 0, 3);
112  QObject::connect(_pushButtonLinearPalette, &QPushButton::clicked, this,
114 
115  _paletteLayout->addWidget(pGroupBoxSaveLoad);
116 
117  updateContent();
118 }
119 
121 
123 {
124  // Mise a jour de l'element
125  _elmW->updateContent();
127 }
128 
129 void TYPaletteWidget::apply() // Override
130 {
131  // Element
132  _elmW->apply();
133 }
134 
136 {
137  if (!getElement()->resetFromPreferences())
138  {
139  getElement()->resetToDefault();
140  getElement()->saveToPreferences();
141  }
142  updateContent();
143 }
144 
146 {
147  TYPaletteLimitsWidget* limits = new TYPaletteLimitsWidget(getElement(), this);
148  bool ret = limits->exec();
149  if (ret == QDialog::Accepted)
150  {
151  updateContent();
152  }
153 }
154 
156 {
157  QString qFileName = QFileDialog::getOpenFileName(this, "Choose a file", QString(), "XML (*.xml)");
158 
159  if (!qFileName.isEmpty())
160  {
161  if (!qFileName.endsWith(".xml"))
162  {
163  qFileName += ".xml";
164  }
165 
166  bool loaded = false;
167  LPTYPalette pPalette = TYPalette::loadPaletteFromFile(qFileName);
168  if (pPalette)
169  {
170  (*getElement()) = *pPalette;
171  updateContent();
172  loaded = true;
173  }
174  else
175  {
176  OMessageManager::get()->error("Invalid Palette file %s : the one element is not a Palette.",
177  qFileName.toUtf8().data());
178  }
179 
180  if (loaded)
181  {
182  QMessageBox::information(this, "Tympan", TR("id_import_ok").arg(qFileName));
183  }
184  else
185  {
186  QMessageBox::warning(this, "Tympan", TR("id_import_failed").arg(qFileName));
187  }
188  }
189 }
190 
192 {
193  QString qFileName = QFileDialog::getSaveFileName(this, "Choose a file", QString(), "XML (*.xml)");
194 
195  if (qFileName.isEmpty())
196  {
197  return;
198  }
199 
200  if (!qFileName.endsWith(".xml"))
201  {
202  qFileName += ".xml";
203  }
204 
205  bool save = true;
206 
207  // Verification de l'etat du fichier
208  QFileInfo fi(qFileName);
209 
210  // Si le fichier existe , on demande confirmation a l'utilisateur
211  if (fi.exists())
212  {
213  // On ecrase le fichier, puis on sauve
214  QFile* file = new QFile(qFileName);
215  switch (
216  QMessageBox::warning(this, "Attention", TR("id_file_exist"), QMessageBox::Yes, QMessageBox::No))
217  {
218  case QMessageBox::Yes:
219  if (!file->remove())
220  {
221  QMessageBox::warning(this, "Attention", TR("id_file_cannot_be_clear"));
222  save = false;
223  }
224  break;
225  case QMessageBox::No:
226  save = false;
227  break;
228  }
229 
230  delete file;
231  }
232 
233  if (save)
234  {
235  LPTYPalette pPalette = new TYPalette(*getElement());
236 
237  bool status = pPalette->savePaletteToFile(qFileName);
238  if (status)
239  {
240  QMessageBox::information(this, "Tympan", TR("id_export_ok").arg(qFileName));
241  }
242  else
243  {
244  QMessageBox::warning(this, "Tympan", TR("id_export_failed").arg(qFileName));
245  }
246  }
247 }
248 
249 /* --------------- class PaletteModel --------------- */
250 
251 PaletteModel::PaletteModel(TYPalette* p_palette_, QObject* parent)
252  : QAbstractTableModel(parent), p_palette(p_palette_)
253 {
254 }
255 
257 
258 int PaletteModel::rowCount(const QModelIndex& parent) const
259 {
260  return static_cast<int>(p_palette->getNbColors());
261 }
262 
263 int PaletteModel::columnCount(const QModelIndex& parent) const
264 {
265  return 2;
266 }
267 
268 void PaletteModel::getBoundsForValue(unsigned row, float& inf, float& sup) const
269 
270 {
271  inf = -std::numeric_limits<float>::infinity();
272  sup = +std::numeric_limits<float>::infinity();
273 
274  if (row > 0)
275  {
276  inf = p_palette->getValueFromIndex(row - 1);
277  }
278  if (row < rowCount(QModelIndex()) - 1)
279  {
280  sup = p_palette->getValueFromIndex(row + 1);
281  }
282 }
283 
284 QVariant PaletteModel::data(const QModelIndex& index, int role) const
285 {
286  if (!index.isValid())
287  {
288  return QVariant();
289  }
290  switch (index.column())
291  {
292  case 0: // Request noise level (1st column)
293  if (isSpecialInfiniteCell(index)) // Last cell can not be edited
294  {
295  if (role == Qt::DisplayRole)
296  {
297  return TR("id_editarrayInfinity");
298  }
299  }
300  switch (role)
301  {
302  case Qt::DisplayRole:
303  return QString("%1").arg(p_palette->getValueFromIndex(index.row()), 0, 'f', 1);
304  break;
305  case Qt::EditRole:
306  return p_palette->getValueFromIndex(index.row());
307  break;
308  case Qt::CheckStateRole:
309  return checked_rows.count(index.row()) ? Qt::Checked : Qt::Unchecked;
310  break;
311  case Qt::TextAlignmentRole:
312  return Qt::AlignRight;
313  break;
314  }
315  break;
316  case 1: // Request color (2nd column)
317  switch (role)
318  {
319  case Qt::BackgroundRole:
320  OColor ocolor(p_palette->getColorFromIndex(index.row()));
321  return toQColor(ocolor);
322  break;
323  }
324  break;
325  default:
326  break;
327  }
328  return QVariant();
329 }
330 
331 QVariant PaletteModel::headerData(int section, Qt::Orientation orientation, int role) const
332 {
333  switch (section)
334  {
335  case 0:
336  return TR("id_editarraycol0");
337  break;
338  case 1:
339  return TR("id_editarraycol1");
340  break;
341  default:
342  return QVariant();
343  break;
344  }
345 }
346 
347 Qt::ItemFlags PaletteModel::flags(const QModelIndex& index) const
348 {
349  if (!index.isValid())
350  {
351  return Qt::ItemIsEnabled;
352  }
353  Qt::ItemFlags flags = QAbstractTableModel::flags(index);
354  flags |= Qt::ItemIsEditable;
355  flags &= ~Qt::ItemIsSelectable;
356  switch (index.column())
357  {
358  case 0:
359  if (isSpecialInfiniteCell(index))
360  {
361  // No edition possible for the last row value
362  flags &= ~Qt::ItemIsEditable;
363  flags &= ~Qt::ItemIsUserCheckable;
364  }
365  else
366  {
367  flags |= Qt::ItemIsUserCheckable;
368  }
369  break;
370  case 1:
371  // Nothing specific yet
372  break;
373  default:
374  assert(false && "Should never be reachable");
375  break;
376  }
377  return flags;
378 }
379 
380 bool PaletteModel::setData(const QModelIndex& index, const QVariant& value, int role)
381 {
382  if (!index.isValid())
383  {
384  return false;
385  }
386  TYPalette::values_type real_value = NAN;
387  QColor qcolor;
388  bool ok = false;
389  TYPalette::values_type old_value = p_palette->getValueFromIndex(index.row());
390 
391  switch (index.column())
392  {
393  case 0: // Request noise level (1st column)
394  if (isSpecialInfiniteCell(index)) // Last cell can not be edited
395  {
396  return false;
397  }
398  switch (role)
399  {
400  case Qt::EditRole:
401  real_value = value.toFloat(&ok);
402  if (ok)
403  {
404  ok = p_palette->moveValue(old_value, real_value);
405  if (ok)
406  {
407  emit dataChanged(index, index);
408  }
409  return ok;
410  }
411  break;
412  case Qt::CheckStateRole:
413  if (value == Qt::Checked)
414  {
415  ok = checked_rows.insert(index.row()).second;
416  }
417  else
418  {
419  ok = checked_rows.erase(index.row()) == 1;
420  }
421  break;
422  }
423  return ok;
424  break;
425  case 1: // Request color (2nd column)
426  switch (role)
427  {
428  case Qt::BackgroundRole:
429  case Qt::EditRole:
430  qcolor = value.value<QColor>();
431  p_palette->insertColor(old_value, toOColor(qcolor));
432  emit dataChanged(index, index);
433  return true;
434  break;
435  default:
436  assert(false && "This should be an unreachable case");
437  break;
438  }
439  break;
440  default:
441  assert(false && "This should be an unreachable case");
442  break;
443  }
444  return false; // to make the compiler happy with all exec path having a return.
445 }
446 
448 {
449  BOOST_REVERSE_FOREACH(unsigned r, checked_rows)
450  {
451  beginRemoveRows(QModelIndex(), r, r);
453 #ifndef NDEBUG
454  bool ok = p_palette->removeValue(value);
455  assert(ok && "This value must be valid");
456 #else
457  p_palette->removeValue(value);
458 #endif
459  endRemoveRows();
460  }
461  checked_rows.clear();
462  emit dataChanged(index(0, 0), index(rowCount() - 1, 1));
463 }
464 
465 void PaletteModel::addRow(float noiseLevel)
466 {
467  TYPalette::values_type value = NAN;
468  OColor color;
469  unsigned r = 0;
470  // We look for the index r of the row to be created
471  BOOST_FOREACH (boost::tie(value, color), p_palette->getColorMap())
472  {
473  if (value == noiseLevel)
474  {
475  return; // We don't try to inser duplicates
476  }
477  if (value > noiseLevel)
478  {
479  break;
480  }
481  ++r;
482  }
483  // Now r is the index of the new row
484  beginInsertRows(QModelIndex(), r, r);
485  p_palette->insertColor(noiseLevel, OColor::WHITE);
486  endInsertRows();
487  emit dataChanged(index(r, 0), index(r, 1));
488  checked_rows.clear();
489 }
490 
491 /* --------------- class PaletteColorDelegate --------------- */
492 
493 QWidget* PaletteColorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
494  const QModelIndex& index) const
495 {
496  return new QWidget(parent);
497 }
498 
499 void PaletteColorDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
500 {
501 #ifndef NDEBUG
502  bool ok = false;
503 #endif
504 
505  QColor qcolor = index.model()->data(index, Qt::BackgroundRole).value<QColor>();
506  QPalette p = editor->palette();
507  p.setColor(QPalette::Window, qcolor);
508  p.setColor(QPalette::Base, qcolor);
509  QColorDialog* dialog = new QColorDialog(editor);
510  dialog->setCurrentColor(qcolor);
511 #ifndef NDEBUG
512  ok =
513 #endif
514  QObject::connect(dialog, &QColorDialog::finished, this, &PaletteColorDelegate::validateColor);
515  assert(ok && "Connection failed for validateColor()");
516  dialog->show();
517 }
518 
520 {
521  QColorDialog* dialog = qobject_cast<QColorDialog*>(this->sender());
522  QWidget* editor = dialog->parentWidget();
523  if (dialog->result() == QDialog::Accepted)
524  {
525  QColor qcolor = dialog->currentColor();
526  QPalette p = editor->palette();
527  p.setColor(QPalette::Window, qcolor);
528  p.setColor(QPalette::Base, qcolor);
529  editor->setPalette(p);
530  emit commitData(editor);
531  }
532  emit closeEditor(editor, QAbstractItemDelegate::NoHint);
533 }
534 
535 void PaletteColorDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
536  const QModelIndex& index) const
537 {
538  QColor color = editor->palette().color(QPalette::Base);
539  model->setData(index, color);
540 }
541 
542 /* --------------- class PaletteValueDelegate --------------- */
543 
544 QWidget* PaletteValueDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
545  const QModelIndex& index) const
546 {
547  QDoubleSpinBox* editor = new QDoubleSpinBox(parent);
548  editor->setDecimals(1);
549  TYPalette::values_type inf = NAN, sup = NAN;
550  const PaletteModel* model = qobject_cast<const PaletteModel*>(index.model());
551  assert(model && "This cast shoul always succeed.");
552  model->getBoundsForValue(index.row(), inf, sup);
553  editor->setMinimum(inf);
554  editor->setMaximum(sup);
555  return editor;
556 }
557 
558 void PaletteValueDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
559 {
560  bool ok = false;
561  TYPalette::values_type value = index.model()->data(index).toFloat(&ok);
562  QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
563  assert(spinbox && "THis cast is expecto to always work.");
564  if (ok)
565  {
566  spinbox->setValue(value);
567  }
568  else
569  {
571  QString("Invalid value for noise level : %1").arg(index.model()->data(index).toString()));
572  }
573 }
574 
575 void PaletteValueDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
576  const QModelIndex& index) const
577 {
578  QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
579  spinbox->interpretText();
580  TYPalette::values_type value = spinbox->value();
581  model->setData(index, value, Qt::EditRole);
582 }
583 
584 /* --------------- class PaletteColorDelegate --------------- */
585 
586 PaletteEditor::PaletteEditor(TYPalette* palette_, QWidget* parent)
587  : QFrame(parent), newNoiseLevelSpin(NULL), newNoiseLevelButton(NULL), deleteNoiseLevelButton(NULL),
588  p_palette(palette_), p_table(NULL), color_delegate(this), value_delegate(this),
589  p_model(new PaletteModel(p_palette, this))
590 {
591 #ifndef NDEBUG
592  bool ok = false;
593 #endif
594 
595  QVBoxLayout* main_layout = new QVBoxLayout(this);
596  QFrame* hframe = new QFrame();
597  main_layout->addWidget(hframe);
598 
599  QHBoxLayout* addEntryLayout = new QHBoxLayout(hframe);
600  addEntryLayout->addWidget(new QLabel(TR("id_noise_level"), hframe), 1);
601 
602  newNoiseLevelSpin = new QDoubleSpinBox();
603  newNoiseLevelSpin->setSuffix(" dBA");
604  newNoiseLevelSpin->setMaximum(1000);
605  newNoiseLevelSpin->setDecimals(1);
606  addEntryLayout->addWidget(newNoiseLevelSpin, 1);
607 
608  newNoiseLevelButton = new QPushButton();
609  newNoiseLevelButton->setText(TR("id_newentry"));
610 #ifndef NDEBUG
611  ok =
612 #endif
613  QObject::connect(newNoiseLevelButton, &QPushButton::pressed, this, &PaletteEditor::addNoiseLevel);
614  assert(ok && "Connection failed for addNoiseLevel");
615  addEntryLayout->addWidget(newNoiseLevelButton, 1);
616 
617  deleteNoiseLevelButton = new QPushButton();
618  deleteNoiseLevelButton->setText(TR("id_delete_sel"));
619 #ifndef NDEBUG
620  ok =
621 #endif
622  QObject::connect(deleteNoiseLevelButton, &QPushButton::pressed, this,
624  assert(ok && "Connection failed for addNoiseLevel");
625  addEntryLayout->addWidget(deleteNoiseLevelButton, 1);
626 
627  p_table = new QTableView(this);
628  p_table->setModel(p_model);
629  main_layout->addWidget(p_table, 1);
630  p_table->setItemDelegateForColumn(0, &value_delegate);
631  p_table->setItemDelegateForColumn(1, &color_delegate);
632 
633 #ifndef NDEBUG
634  ok =
635 #endif
636  connect(p_model, &PaletteModel::dataChanged, this, &PaletteEditor::propagateModelChanges);
637  assert(ok && "Connection failed for slot propagateModelChanges");
638 }
639 
641 
643 {
645 };
646 
647 void PaletteEditor::propagateModelChanges(const QModelIndex& topLeft, const QModelIndex& bottomRight)
648 {
650 }
651 
653 {
654  qobject_cast<PaletteModel*>(p_table->model())->addRow(newNoiseLevelSpin->value());
655 }
656 
658 {
659  qobject_cast<PaletteModel*>(p_table->model())->deleteSelectedRows();
660 }
661 
662 // ================================================================================
663 
665  : QDialog(_pParent), _pElement(pElement)
666 {
667  Q_ASSERT(pElement);
668  setWindowTitle(TR("id_caption_limits"));
669  resize(300, 174);
670 
671  QGroupBox* _groupBox = new QGroupBox(this);
672  QGridLayout* internalLayout = new QGridLayout();
673  _groupBox->setLayout(internalLayout);
674  _label_lower_bound = new QLabel(_groupBox);
675  _label_lower_bound->setText(TR("id_lb_label"));
676  _label_upper_bound = new QLabel(_groupBox);
677  _label_upper_bound->setText(TR("id_ub_label"));
678  _label_nb_colors = new QLabel(_groupBox);
679  _label_nb_colors->setText(TR("id_nb_label"));
682  _lineEdit_nb_colors = new QLineEdit(_groupBox);
683  internalLayout->addWidget(_label_lower_bound, 0, 0);
684  internalLayout->addWidget(_lineEdit_lower_bound, 0, 1);
685  internalLayout->addWidget(_label_upper_bound, 1, 0);
686  internalLayout->addWidget(_lineEdit_upper_bound, 1, 1);
687  internalLayout->addWidget(_label_nb_colors, 2, 0);
688  internalLayout->addWidget(_lineEdit_nb_colors, 2, 1);
689 
690  QBoxLayout* pBtnLayout = new QHBoxLayout();
691 
692  pBtnLayout->addStretch(1);
693 
694  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), this);
695  pButtonOK->setDefault(true);
696  QObject::connect(pButtonOK, &QPushButton::clicked, this, &TYPaletteLimitsWidget::apply);
697  pBtnLayout->addWidget(pButtonOK);
698 
699  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), this);
700  pButtonCancel->setShortcut(Qt::Key_Escape);
701  QObject::connect(pButtonCancel, &QPushButton::clicked, this, &TYPaletteLimitsWidget::reject);
702  pBtnLayout->addWidget(pButtonCancel);
703 
704  internalLayout->addLayout(pBtnLayout, 3, 1);
705  updateContent();
706 }
707 
709 {
710  _lineEdit_lower_bound->setText(QString().setNum(_pElement->getValueMin(), 'f', 2));
711  _lineEdit_upper_bound->setText(QString().setNum(_pElement->getValueMax(), 'f', 2));
712  _lineEdit_nb_colors->setText(QString().setNum(_pElement->getNbColors()));
713 }
714 
716 {
717  double lower_bound = _lineEdit_lower_bound->text().toDouble();
718  double upper_bound = _lineEdit_upper_bound->text().toDouble();
719  unsigned int nb_colors = _lineEdit_nb_colors->text().toUInt();
720 
721  _pElement->makeLinearPalette(nb_colors, lower_bound, upper_bound);
722  accept();
723 }
outil IHM pour un element (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
Outil IHM utile a l'affichage de la palette de couleur (fichier header)
OColor toOColor(const QColor &color)
QColor toQColor(const OColor &color)
#define TR(id)
Outil IHM pour une palette (fichier header)
Definition: color.h:31
static const OColor WHITE
Definition: color.h:93
virtual void debug(const char *message,...)
Definition: logging.cpp:151
virtual void error(const char *message,...)
Definition: logging.cpp:127
static OMessageManager * get()
Definition: logging.cpp:108
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
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)
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
virtual void apply()
virtual void updateContent()
void update(const TYPalette *palette)
TYPaletteLimitsWidget(TYPalette *pElement, QWidget *_pParent=nullptr)
TYLineEdit * _lineEdit_upper_bound
virtual void updateContent()
TYLineEdit * _lineEdit_lower_bound
QLineEdit * _lineEdit_nb_colors
QPushButton * _pushButtonLinearPalette
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
bool removeValue(values_type value)
Removes an existing bound.
Definition: TYPalette.cpp:253
void makeLinearPalette(unsigned int nb_colors, float value_min, float value_max)
Make a linear palette from a min/max couple.
Definition: TYPalette.cpp:551
const color_map_type & getColorMap() const
Get de la lookup table.
Definition: TYPalette.h:226
size_t getNbColors() const
Getter for the number of colors.
Definition: TYPalette.h:122
const OColor & getColorFromIndex(unsigned i) const
Get de la couleur par index.
Definition: TYPalette.cpp:499
static LPTYPalette loadPaletteFromFile(const QString &qFileName)
Create a new TYPalette from an XML file Holding only one Palette.
Definition: TYPalette.cpp:524
bool savePaletteToFile(const QString &qFileName)
Save the Palette into a file with the name given.
Definition: TYPalette.cpp:541
values_type getValueMax() const
Get de la valeur max.
Definition: TYPalette.h:112
TYPalette::values_type getValueFromIndex(unsigned i) const
Get de la valeur par index.
Definition: TYPalette.cpp:511
bool moveValue(values_type old_value, values_type new_value)
Moves an existing bound,.
Definition: TYPalette.cpp:216
float values_type
The real number type used to store values (typically double or float)
Definition: TYPalette.h:49
values_type getValueMin() const
Get de la valeur min.
Definition: TYPalette.h:102
bool insertColor(values_type value, const OColor &color)
Insert a new color or update an existing one.
Definition: TYPalette.cpp:205
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43