25 #include <boost/foreach.hpp>
26 #include <boost/tuple/tuple.hpp>
27 #include <boost/math/special_functions/fpclassify.hpp>
36 #include <qcolordialog.h>
37 #include <qfiledialog.h>
39 #include <qmessagebox.h>
40 #include <qtablewidget.h>
42 #include <QGridLayout>
44 #include <QTextStream>
49 #define TR(id) OLocalizator::getString("TYPaletteWidget", (id))
52 :
TYWidget(pElement, _pParent, NULL, Qt::Dialog)
58 setWindowTitle(
TR(
"id_caption"));
67 QGroupBox* pGroupBoxColorMap =
new QGroupBox(
this);
68 pGroupBoxColorMap->setTitle(
TR(
"id_editarray"));
69 QVBoxLayout* internalLayout =
new QVBoxLayout();
70 pGroupBoxColorMap->setLayout(internalLayout);
72 internalLayout->addWidget(
_editor);
76 QGroupBox* pGroupBoxPreview =
new QGroupBox(
this);
77 pGroupBoxPreview->setTitle(
TR(
"id_lookuptableview"));
89 QGroupBox* pGroupBoxSaveLoad =
new QGroupBox(
this);
90 pGroupBoxSaveLoad->setTitle(
TR(
"id_saveload"));
91 QGridLayout* pGroupBoxSaveLoadLayout =
new QGridLayout();
92 pGroupBoxSaveLoad->setLayout(pGroupBoxSaveLoadLayout);
137 if (!getElement()->resetFromPreferences())
139 getElement()->resetToDefault();
140 getElement()->saveToPreferences();
148 bool ret = limits->exec();
149 if (ret == QDialog::Accepted)
157 QString qFileName = QFileDialog::getOpenFileName(
this,
"Choose a file", QString(),
"XML (*.xml)");
159 if (!qFileName.isEmpty())
161 if (!qFileName.endsWith(
".xml"))
170 (*getElement()) = *pPalette;
177 qFileName.toUtf8().data());
182 QMessageBox::information(
this,
"Tympan",
TR(
"id_import_ok").arg(qFileName));
186 QMessageBox::warning(
this,
"Tympan",
TR(
"id_import_failed").arg(qFileName));
193 QString qFileName = QFileDialog::getSaveFileName(
this,
"Choose a file", QString(),
"XML (*.xml)");
195 if (qFileName.isEmpty())
200 if (!qFileName.endsWith(
".xml"))
208 QFileInfo fi(qFileName);
214 QFile* file =
new QFile(qFileName);
216 QMessageBox::warning(
this,
"Attention",
TR(
"id_file_exist"), QMessageBox::Yes, QMessageBox::No))
218 case QMessageBox::Yes:
221 QMessageBox::warning(
this,
"Attention",
TR(
"id_file_cannot_be_clear"));
225 case QMessageBox::No:
240 QMessageBox::information(
this,
"Tympan",
TR(
"id_export_ok").arg(qFileName));
244 QMessageBox::warning(
this,
"Tympan",
TR(
"id_export_failed").arg(qFileName));
252 : QAbstractTableModel(parent), p_palette(p_palette_)
271 inf = -std::numeric_limits<float>::infinity();
272 sup = +std::numeric_limits<float>::infinity();
278 if (row <
rowCount(QModelIndex()) - 1)
286 if (!index.isValid())
290 switch (index.column())
295 if (role == Qt::DisplayRole)
297 return TR(
"id_editarrayInfinity");
302 case Qt::DisplayRole:
308 case Qt::CheckStateRole:
309 return checked_rows.count(index.row()) ? Qt::Checked : Qt::Unchecked;
311 case Qt::TextAlignmentRole:
312 return Qt::AlignRight;
319 case Qt::BackgroundRole:
336 return TR(
"id_editarraycol0");
339 return TR(
"id_editarraycol1");
349 if (!index.isValid())
351 return Qt::ItemIsEnabled;
353 Qt::ItemFlags
flags = QAbstractTableModel::flags(index);
354 flags |= Qt::ItemIsEditable;
355 flags &= ~Qt::ItemIsSelectable;
356 switch (index.column())
362 flags &= ~Qt::ItemIsEditable;
363 flags &= ~Qt::ItemIsUserCheckable;
367 flags |= Qt::ItemIsUserCheckable;
374 assert(
false &&
"Should never be reachable");
382 if (!index.isValid())
391 switch (index.column())
401 real_value = value.toFloat(&ok);
407 emit dataChanged(index, index);
412 case Qt::CheckStateRole:
413 if (value == Qt::Checked)
428 case Qt::BackgroundRole:
430 qcolor = value.value<QColor>();
432 emit dataChanged(index, index);
436 assert(
false &&
"This should be an unreachable case");
441 assert(
false &&
"This should be an unreachable case");
451 beginRemoveRows(QModelIndex(), r, r);
455 assert(ok &&
"This value must be valid");
462 emit dataChanged(index(0, 0), index(
rowCount() - 1, 1));
473 if (value == noiseLevel)
477 if (value > noiseLevel)
484 beginInsertRows(QModelIndex(), r, r);
487 emit dataChanged(index(r, 0), index(r, 1));
494 const QModelIndex& index)
const
496 return new QWidget(parent);
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);
515 assert(ok &&
"Connection failed for validateColor()");
521 QColorDialog* dialog = qobject_cast<QColorDialog*>(this->sender());
522 QWidget* editor = dialog->parentWidget();
523 if (dialog->result() == QDialog::Accepted)
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);
532 emit closeEditor(editor, QAbstractItemDelegate::NoHint);
536 const QModelIndex& index)
const
538 QColor color = editor->palette().color(QPalette::Base);
539 model->setData(index, color);
545 const QModelIndex& index)
const
547 QDoubleSpinBox* editor =
new QDoubleSpinBox(parent);
548 editor->setDecimals(1);
550 const PaletteModel* model = qobject_cast<const PaletteModel*>(index.model());
551 assert(model &&
"This cast shoul always succeed.");
553 editor->setMinimum(inf);
554 editor->setMaximum(sup);
562 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
563 assert(spinbox &&
"THis cast is expecto to always work.");
566 spinbox->setValue(value);
571 QString(
"Invalid value for noise level : %1").arg(index.model()->data(index).toString()));
576 const QModelIndex& index)
const
578 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
579 spinbox->interpretText();
581 model->setData(index, value, Qt::EditRole);
587 : QFrame(parent), newNoiseLevelSpin(NULL), newNoiseLevelButton(NULL), deleteNoiseLevelButton(NULL),
588 p_palette(palette_), p_table(NULL), color_delegate(this), value_delegate(this),
595 QVBoxLayout* main_layout =
new QVBoxLayout(
this);
596 QFrame* hframe =
new QFrame();
597 main_layout->addWidget(hframe);
599 QHBoxLayout* addEntryLayout =
new QHBoxLayout(hframe);
600 addEntryLayout->addWidget(
new QLabel(
TR(
"id_noise_level"), hframe), 1);
614 assert(ok &&
"Connection failed for addNoiseLevel");
624 assert(ok &&
"Connection failed for addNoiseLevel");
627 p_table =
new QTableView(
this);
629 main_layout->addWidget(
p_table, 1);
637 assert(ok &&
"Connection failed for slot propagateModelChanges");
659 qobject_cast<PaletteModel*>(
p_table->model())->deleteSelectedRows();
665 : QDialog(_pParent), _pElement(pElement)
668 setWindowTitle(
TR(
"id_caption_limits"));
671 QGroupBox*
_groupBox =
new QGroupBox(
this);
672 QGridLayout* internalLayout =
new QGridLayout();
690 QBoxLayout* pBtnLayout =
new QHBoxLayout();
692 pBtnLayout->addStretch(1);
694 QPushButton* pButtonOK =
new QPushButton(
TR(
"id_ok_btn"),
this);
695 pButtonOK->setDefault(
true);
697 pBtnLayout->addWidget(pButtonOK);
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);
704 internalLayout->addLayout(pBtnLayout, 3, 1);
outil IHM pour une entrée utilisateur (fichier header)
static const OColor WHITE
virtual void debug(const char *message,...)
virtual void error(const char *message,...)
static OMessageManager * get()
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)
PaletteValueDelegate value_delegate
QDoubleSpinBox * newNoiseLevelSpin
void notifyTYPaletteExternalyChanged()
PaletteColorDelegate color_delegate
QPushButton * newNoiseLevelButton
void paletteChanged(const TYPalette *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()
QVariant data(const QModelIndex &index, int role) const
PaletteModel(TYPalette *p_palette, QObject *parent=NULL)
int rowCount(const QModelIndex &parent=QModelIndex()) const
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 definition d'une palette.
bool removeValue(values_type value)
Removes an existing bound.
void makeLinearPalette(unsigned int nb_colors, float value_min, float value_max)
Make a linear palette from a min/max couple.
const color_map_type & getColorMap() const
Get de la lookup table.
size_t getNbColors() const
Getter for the number of colors.
const OColor & getColorFromIndex(unsigned i) const
Get de la couleur par index.
static LPTYPalette loadPaletteFromFile(const QString &qFileName)
Create a new TYPalette from an XML file Holding only one Palette.
bool savePaletteToFile(const QString &qFileName)
Save the Palette into a file with the name given.
values_type getValueMax() const
Get de la valeur max.
TYPalette::values_type getValueFromIndex(unsigned i) const
Get de la valeur par index.
bool moveValue(values_type old_value, values_type new_value)
Moves an existing bound,.
float values_type
The real number type used to store values (typically double or float)
values_type getValueMin() const
Get de la valeur min.
bool insertColor(values_type value, const OColor &color)
Insert a new color or update an existing one.