25 #include <boost/foreach.hpp>
26 #include <boost/tuple/tuple.hpp>
27 #include <boost/math/special_functions/fpclassify.hpp>
38 #include <qcolordialog.h>
39 #include <qfiledialog.h>
41 #include <qmessagebox.h>
42 #include <qtablewidget.h>
44 #include <QGridLayout>
46 #include <QTextStream>
50 #define TR(id) OLocalizator::getString("TYPaletteWidget", (id))
53 :
TYWidget(pElement, _pParent, NULL, Qt::Dialog)
59 setWindowTitle(
TR(
"id_caption"));
68 QGroupBox* pGroupBoxColorMap =
new QGroupBox(
this);
69 pGroupBoxColorMap->setTitle(
TR(
"id_editarray"));
70 QVBoxLayout* internalLayout =
new QVBoxLayout();
71 pGroupBoxColorMap->setLayout(internalLayout);
73 internalLayout->addWidget(
_editor);
77 QGroupBox* pGroupBoxPreview =
new QGroupBox(
this);
78 pGroupBoxPreview->setTitle(
TR(
"id_lookuptableview"));
90 QGroupBox* pGroupBoxSaveLoad =
new QGroupBox(
this);
91 pGroupBoxSaveLoad->setTitle(
TR(
"id_saveload"));
92 QGridLayout* pGroupBoxSaveLoadLayout =
new QGridLayout();
93 pGroupBoxSaveLoad->setLayout(pGroupBoxSaveLoadLayout);
138 if (!getElement()->resetFromPreferences())
140 getElement()->resetToDefault();
141 getElement()->saveToPreferences();
149 bool ret = limits->exec();
150 if (ret == QDialog::Accepted)
158 QString qFileName = QFileDialog::getOpenFileName(
this,
"Choose a file", QString(),
"XML (*.xml)");
160 if (!qFileName.isEmpty())
162 if (!qFileName.endsWith(
".xml"))
171 (*getElement()) = *pPalette;
178 qFileName.toUtf8().data());
183 QMessageBox::information(
this,
"Tympan",
TR(
"id_import_ok").arg(qFileName));
187 QMessageBox::warning(
this,
"Tympan",
TR(
"id_import_failed").arg(qFileName));
194 QString qFileName = QFileDialog::getSaveFileName(
this,
"Choose a file", QString(),
"XML (*.xml)");
196 if (qFileName.isEmpty())
201 if (!qFileName.endsWith(
".xml"))
209 QFileInfo fi(qFileName);
215 QFile* file =
new QFile(qFileName);
217 QMessageBox::warning(
this,
"Attention",
TR(
"id_file_exist"), QMessageBox::Yes, QMessageBox::No))
219 case QMessageBox::Yes:
222 QMessageBox::warning(
this,
"Attention",
TR(
"id_file_cannot_be_clear"));
226 case QMessageBox::No:
241 QMessageBox::information(
this,
"Tympan",
TR(
"id_export_ok").arg(qFileName));
245 QMessageBox::warning(
this,
"Tympan",
TR(
"id_export_failed").arg(qFileName));
253 : QAbstractTableModel(parent), p_palette(p_palette_)
272 inf = -std::numeric_limits<float>::infinity();
273 sup = +std::numeric_limits<float>::infinity();
279 if (row <
rowCount(QModelIndex()) - 1)
287 if (!index.isValid())
291 switch (index.column())
296 if (role == Qt::DisplayRole)
298 return TR(
"id_editarrayInfinity");
303 case Qt::DisplayRole:
309 case Qt::CheckStateRole:
310 return checked_rows.count(index.row()) ? Qt::Checked : Qt::Unchecked;
312 case Qt::TextAlignmentRole:
313 return Qt::AlignRight;
320 case Qt::BackgroundRole:
337 return TR(
"id_editarraycol0");
340 return TR(
"id_editarraycol1");
350 if (!index.isValid())
352 return Qt::ItemIsEnabled;
354 Qt::ItemFlags
flags = QAbstractTableModel::flags(index);
355 flags |= Qt::ItemIsEditable;
356 flags &= ~Qt::ItemIsSelectable;
357 switch (index.column())
363 flags &= ~Qt::ItemIsEditable;
364 flags &= ~Qt::ItemIsUserCheckable;
368 flags |= Qt::ItemIsUserCheckable;
375 assert(
false &&
"Should never be reachable");
383 if (!index.isValid())
392 switch (index.column())
402 real_value = value.toFloat(&ok);
408 emit dataChanged(index, index);
413 case Qt::CheckStateRole:
414 if (value == Qt::Checked)
429 case Qt::BackgroundRole:
431 qcolor = value.value<QColor>();
433 emit dataChanged(index, index);
437 assert(
false &&
"This should be an unreachable case");
442 assert(
false &&
"This should be an unreachable case");
452 beginRemoveRows(QModelIndex(), r, r);
456 assert(ok &&
"This value must be valid");
463 emit dataChanged(index(0, 0), index(
rowCount() - 1, 1));
474 if (value == noiseLevel)
478 if (value > noiseLevel)
485 beginInsertRows(QModelIndex(), r, r);
488 emit dataChanged(index(r, 0), index(r, 1));
495 const QModelIndex& index)
const
497 return new QWidget(parent);
506 QColor qcolor = index.model()->data(index, Qt::BackgroundRole).value<QColor>();
507 QPalette p = editor->palette();
508 p.setColor(QPalette::Window, qcolor);
509 p.setColor(QPalette::Base, qcolor);
510 QColorDialog* dialog =
new QColorDialog(editor);
511 dialog->setCurrentColor(qcolor);
516 assert(ok &&
"Connection failed for validateColor()");
522 QColorDialog* dialog = qobject_cast<QColorDialog*>(this->sender());
523 QWidget* editor = dialog->parentWidget();
524 if (dialog->result() == QDialog::Accepted)
526 QColor qcolor = dialog->currentColor();
527 QPalette p = editor->palette();
528 p.setColor(QPalette::Window, qcolor);
529 p.setColor(QPalette::Base, qcolor);
530 editor->setPalette(p);
531 emit commitData(editor);
533 emit closeEditor(editor, QAbstractItemDelegate::NoHint);
537 const QModelIndex& index)
const
539 QColor color = editor->palette().color(QPalette::Base);
540 model->setData(index, color);
546 const QModelIndex& index)
const
548 QDoubleSpinBox* editor =
new QDoubleSpinBox(parent);
549 editor->setDecimals(1);
551 const PaletteModel* model = qobject_cast<const PaletteModel*>(index.model());
552 assert(model &&
"This cast shoul always succeed.");
554 editor->setMinimum(inf);
555 editor->setMaximum(sup);
563 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
564 assert(spinbox &&
"THis cast is expecto to always work.");
567 spinbox->setValue(value);
572 QString(
"Invalid value for noise level : %1").arg(index.model()->data(index).toString()));
577 const QModelIndex& index)
const
579 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(editor);
580 spinbox->interpretText();
582 model->setData(index, value, Qt::EditRole);
588 : QFrame(parent), newNoiseLevelSpin(NULL), newNoiseLevelButton(NULL), deleteNoiseLevelButton(NULL),
589 p_palette(palette_), p_table(NULL), color_delegate(this), value_delegate(this),
596 QVBoxLayout* main_layout =
new QVBoxLayout(
this);
597 QFrame* hframe =
new QFrame();
598 main_layout->addWidget(hframe);
600 QHBoxLayout* addEntryLayout =
new QHBoxLayout(hframe);
601 addEntryLayout->addWidget(
new QLabel(
TR(
"id_noise_level"), hframe), 1);
615 assert(ok &&
"Connection failed for addNoiseLevel");
625 assert(ok &&
"Connection failed for addNoiseLevel");
628 p_table =
new QTableView(
this);
630 main_layout->addWidget(
p_table, 1);
638 assert(ok &&
"Connection failed for slot propagateModelChanges");
660 qobject_cast<PaletteModel*>(
p_table->model())->deleteSelectedRows();
666 : QDialog(_pParent), _pElement(pElement)
669 setWindowTitle(
TR(
"id_caption_limits"));
672 QGroupBox*
_groupBox =
new QGroupBox(
this);
673 QGridLayout* internalLayout =
new QGridLayout();
691 QBoxLayout* pBtnLayout =
new QHBoxLayout();
693 pBtnLayout->addStretch(1);
695 QPushButton* pButtonOK =
new QPushButton(
TR(
"id_ok_btn"),
this);
696 pButtonOK->setDefault(
true);
698 pBtnLayout->addWidget(pButtonOK);
700 QPushButton* pButtonCancel =
new QPushButton(
TR(
"id_cancel_btn"),
this);
701 pButtonCancel->setShortcut(Qt::Key_Escape);
702 QObject::connect(pButtonCancel, &QPushButton::clicked,
this, &TYPaletteLimitsWidget::reject);
703 pBtnLayout->addWidget(pButtonCancel);
705 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.