diff --git a/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.cpp b/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.cpp index fd4517fb8f2..1ab18f1d493 100644 --- a/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.cpp +++ b/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.cpp @@ -17,61 +17,82 @@ #include #include #include +#include +#include -class Isovalues_delegate : public QItemDelegate +Isovalues_delegate::Isovalues_delegate(QWidget* parent) : QItemDelegate(parent) {} +void Isovalues_delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { -public: - Isovalues_delegate(QWidget* parent) : QItemDelegate(parent) {} - -protected: - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const + switch(index.column()) { - switch(index.column()) - { - case Isovalues_list::Color: { - painter->fillRect(option.rect, index.data().value()); - drawFocus(painter, option, option.rect); - break; - } - default: - QItemDelegate::paint(painter, option, index); - } + case Isovalues_list::Color: { + painter->fillRect(option.rect, index.data().value()); + drawFocus(painter, option, option.rect); + break; } + default: + QItemDelegate::paint(painter, option, index); + } +} - QWidget *createEditor(QWidget *parent, - const QStyleOptionViewItem & option, - const QModelIndex & index) const +QWidget *Isovalues_delegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + if(index.column() == Isovalues_list::Color) { - if(index.column() == Isovalues_list::Color) - { - return new ColorListEditor(parent); - } - else return QItemDelegate::createEditor(parent, option, index); + return new ColorListEditor(parent); } + else if(index.column() == Isovalues_list::Isovalue) + { + QLineEdit* lineedit = new QLineEdit(parent); + lineedit->setAutoFillBackground(true); + lineedit->setValidator(new QDoubleValidator(lineedit)); + return lineedit; + } + else return QItemDelegate::createEditor(parent, option, index); +} - void setEditorData(QWidget *editor, - const QModelIndex &index) const +void Isovalues_delegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + if(index.column() == Isovalues_list::Color) { - if(index.column() == Isovalues_list::Color) - { - ColorListEditor* coloreditor = qobject_cast(editor); - if(coloreditor) - coloreditor->setColor(index.data().value()); - } - else QItemDelegate::setEditorData(editor, index); + ColorListEditor* coloreditor = qobject_cast(editor); + if(coloreditor) + coloreditor->setColor(index.data().value()); } - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const + else if(index.column() == Isovalues_list::Isovalue) { - if(index.column() == Isovalues_list::Color) - { - ColorListEditor* coloreditor = qobject_cast(editor); - if(coloreditor) - model->setData(index, coloreditor->color()); - } - else QItemDelegate::setModelData(editor, model, index); + QLineEdit* lineedit = qobject_cast(editor); + if(lineedit) + lineedit->setText(index.data().toString()); } -}; + else QItemDelegate::setEditorData(editor, index); +} +void Isovalues_delegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + if(index.column() == Isovalues_list::Color) + { + ColorListEditor* coloreditor = qobject_cast(editor); + if(coloreditor) + { + model->setData(index, coloreditor->color()); + emit new_color(index); + } + } + else if(index.column() == Isovalues_list::Isovalue) + { + QLineEdit* lineedit = qobject_cast(editor); + if(lineedit) + { + model->setData(index, lineedit->text().toDouble()); + emit new_isovalue(index); + } + } + else QItemDelegate::setModelData(editor, model, index); +} const double Isovalues_list::default_isovalue = 0.0; @@ -89,6 +110,10 @@ Isovalues_list::Isovalues_list(QWidget* parent): Isovalues_delegate* isovalues_delegate = new Isovalues_delegate(parent); treeWidget->setItemDelegate(isovalues_delegate); + connect(isovalues_delegate, SIGNAL(new_isovalue(const QModelIndex&)), + this, SIGNAL(isovalues_changed())); + connect(isovalues_delegate, SIGNAL(new_color(const QModelIndex&)), + this, SIGNAL(colors_changed())); } QColor Isovalues_list::color(const int i) const diff --git a/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.h b/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.h index 384a1a6f5d1..ac5240744df 100644 --- a/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.h +++ b/Surface_mesher/demo/Surface_mesher/qt4-demo/isovalues_list.h @@ -4,10 +4,33 @@ #include #include #include +#include +#include class QTreeWidget; class QTreeWidgetItem; +class Isovalues_delegate : public QItemDelegate +{ + Q_OBJECT +public: + Isovalues_delegate(QWidget* parent); + +signals: + void new_color(const QModelIndex&) const; + void new_isovalue(const QModelIndex&) const; + +protected: + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; + QWidget *createEditor(QWidget *parent, + const QStyleOptionViewItem & option, + const QModelIndex & index) const; + void setEditorData(QWidget *editor, + const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; +}; + class Isovalues_list : public QWidget { Q_OBJECT @@ -31,7 +54,7 @@ public slots: void on_minusButton_clicked(); signals: - void color_changed(int); + void colors_changed(); void isovalues_changed(); private: QTreeWidget* treeWidget; diff --git a/Surface_mesher/demo/Surface_mesher/qt4-demo/qt4-demo.pro b/Surface_mesher/demo/Surface_mesher/qt4-demo/qt4-demo.pro index 8cb34a71f8f..a5e72a705f2 100644 --- a/Surface_mesher/demo/Surface_mesher/qt4-demo/qt4-demo.pro +++ b/Surface_mesher/demo/Surface_mesher/qt4-demo/qt4-demo.pro @@ -25,6 +25,7 @@ HEADERS += get_polyhedral_surface.h \ viewer.h \ mainwindow.h \ isovalues_list.h \ + isovalues_list.cpp \ colorlisteditor.h \ ../../../include/CGAL/Complex_2_in_triangulation_3.h \ ../../../include/CGAL/Complex_2_in_triangulation_cell_base_3.h \ diff --git a/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.cpp b/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.cpp index 2dee49f2c45..d39f795b156 100644 --- a/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.cpp +++ b/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.cpp @@ -241,6 +241,10 @@ Volume::Volume(QObject* parent) : viewer, SLOT(interpolateToFitBoundingBox(double, double, double, double, double, double))); else CGAL_error_msg("Cannot find the viewer!"); + connect(isovalues_list, SIGNAL(colors_changed()), + viewer, SLOT(updateGL())); + connect(isovalues_list, SIGNAL(isovalues_changed()), + this, SLOT(changed_parameters())); } void Volume::set_inverse_normals(const bool b) { diff --git a/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.h b/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.h index c189f570bd0..ce850729d49 100644 --- a/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.h +++ b/Surface_mesher/demo/Surface_mesher/qt4-demo/volume.h @@ -117,11 +117,11 @@ public slots: void display_surface_mesher_result(); void set_radius_bound(double); void set_distance_bound(double); + void changed_parameters(); private: void status_message(QString); void busy() const; void not_busy() const; - void changed_parameters(); }; template