mirror of https://github.com/CGAL/cgal
- More complete delegate, to trigger signals when isovalues or colors are
changed. - The new delegate also uses as editor for isovalues a QLineEdit with a QDoubleValidator, instead of a QDoubleSpinBox.
This commit is contained in:
parent
5075e30cc5
commit
3da0c8c405
|
|
@ -17,15 +17,12 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QDoubleValidator>
|
||||||
|
|
||||||
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: {
|
case Isovalues_list::Color: {
|
||||||
|
|
@ -36,42 +33,66 @@ protected:
|
||||||
default:
|
default:
|
||||||
QItemDelegate::paint(painter, option, index);
|
QItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent,
|
QWidget *Isovalues_delegate::createEditor(QWidget *parent,
|
||||||
const QStyleOptionViewItem & option,
|
const QStyleOptionViewItem & option,
|
||||||
const QModelIndex & index) const
|
const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
if(index.column() == Isovalues_list::Color)
|
if(index.column() == Isovalues_list::Color)
|
||||||
{
|
{
|
||||||
return new ColorListEditor(parent);
|
return new ColorListEditor(parent);
|
||||||
}
|
}
|
||||||
else return QItemDelegate::createEditor(parent, option, index);
|
else if(index.column() == Isovalues_list::Isovalue)
|
||||||
}
|
|
||||||
|
|
||||||
void setEditorData(QWidget *editor,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
|
QLineEdit* lineedit = new QLineEdit(parent);
|
||||||
|
lineedit->setAutoFillBackground(true);
|
||||||
|
lineedit->setValidator(new QDoubleValidator(lineedit));
|
||||||
|
return lineedit;
|
||||||
|
}
|
||||||
|
else return QItemDelegate::createEditor(parent, option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<ColorListEditor*>(editor);
|
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
|
||||||
if(coloreditor)
|
if(coloreditor)
|
||||||
coloreditor->setColor(index.data().value<QColor>());
|
coloreditor->setColor(index.data().value<QColor>());
|
||||||
}
|
}
|
||||||
else QItemDelegate::setEditorData(editor, index);
|
else if(index.column() == Isovalues_list::Isovalue)
|
||||||
}
|
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
|
QLineEdit* lineedit = qobject_cast<QLineEdit*>(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)
|
if(index.column() == Isovalues_list::Color)
|
||||||
{
|
{
|
||||||
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
|
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
|
||||||
if(coloreditor)
|
if(coloreditor)
|
||||||
|
{
|
||||||
model->setData(index, coloreditor->color());
|
model->setData(index, coloreditor->color());
|
||||||
|
emit new_color(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(index.column() == Isovalues_list::Isovalue)
|
||||||
|
{
|
||||||
|
QLineEdit* lineedit = qobject_cast<QLineEdit*>(editor);
|
||||||
|
if(lineedit)
|
||||||
|
{
|
||||||
|
model->setData(index, lineedit->text().toDouble());
|
||||||
|
emit new_isovalue(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else QItemDelegate::setModelData(editor, model, index);
|
else QItemDelegate::setModelData(editor, model, index);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const double Isovalues_list::default_isovalue = 0.0;
|
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);
|
Isovalues_delegate* isovalues_delegate = new Isovalues_delegate(parent);
|
||||||
|
|
||||||
treeWidget->setItemDelegate(isovalues_delegate);
|
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
|
QColor Isovalues_list::color(const int i) const
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,33 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QItemDelegate>
|
||||||
|
|
||||||
class QTreeWidget;
|
class QTreeWidget;
|
||||||
class QTreeWidgetItem;
|
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
|
class Isovalues_list : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -31,7 +54,7 @@ public slots:
|
||||||
void on_minusButton_clicked();
|
void on_minusButton_clicked();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void color_changed(int);
|
void colors_changed();
|
||||||
void isovalues_changed();
|
void isovalues_changed();
|
||||||
private:
|
private:
|
||||||
QTreeWidget* treeWidget;
|
QTreeWidget* treeWidget;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ HEADERS += get_polyhedral_surface.h \
|
||||||
viewer.h \
|
viewer.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
isovalues_list.h \
|
isovalues_list.h \
|
||||||
|
isovalues_list.cpp \
|
||||||
colorlisteditor.h \
|
colorlisteditor.h \
|
||||||
../../../include/CGAL/Complex_2_in_triangulation_3.h \
|
../../../include/CGAL/Complex_2_in_triangulation_3.h \
|
||||||
../../../include/CGAL/Complex_2_in_triangulation_cell_base_3.h \
|
../../../include/CGAL/Complex_2_in_triangulation_cell_base_3.h \
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,10 @@ Volume::Volume(QObject* parent) :
|
||||||
viewer, SLOT(interpolateToFitBoundingBox(double, double, double, double, double, double)));
|
viewer, SLOT(interpolateToFitBoundingBox(double, double, double, double, double, double)));
|
||||||
else
|
else
|
||||||
CGAL_error_msg("Cannot find the viewer!");
|
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) {
|
void Volume::set_inverse_normals(const bool b) {
|
||||||
|
|
|
||||||
|
|
@ -117,11 +117,11 @@ public slots:
|
||||||
void display_surface_mesher_result();
|
void display_surface_mesher_result();
|
||||||
void set_radius_bound(double);
|
void set_radius_bound(double);
|
||||||
void set_distance_bound(double);
|
void set_distance_bound(double);
|
||||||
|
void changed_parameters();
|
||||||
private:
|
private:
|
||||||
void status_message(QString);
|
void status_message(QString);
|
||||||
void busy() const;
|
void busy() const;
|
||||||
void not_busy() const;
|
void not_busy() const;
|
||||||
void changed_parameters();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename PointsOutputIterator, typename TransformOperator>
|
template <typename PointsOutputIterator, typename TransformOperator>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue