- 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:
Laurent Rineau 2008-02-06 01:32:50 +00:00
parent 5075e30cc5
commit 3da0c8c405
5 changed files with 98 additions and 45 deletions

View File

@ -17,61 +17,82 @@
#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: switch(index.column())
Isovalues_delegate(QWidget* parent) : QItemDelegate(parent) {} {
case Isovalues_list::Color: {
painter->fillRect(option.rect, index.data().value<QColor>());
drawFocus(painter, option, option.rect);
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
}
protected: QWidget *Isovalues_delegate::createEditor(QWidget *parent,
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const const QStyleOptionViewItem & option,
const QModelIndex & index) const
{
if(index.column() == Isovalues_list::Color)
{ {
switch(index.column()) return new ColorListEditor(parent);
{
case Isovalues_list::Color: {
painter->fillRect(option.rect, index.data().value<QColor>());
drawFocus(painter, option, option.rect);
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
} }
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);
}
QWidget *createEditor(QWidget *parent, void Isovalues_delegate::setEditorData(QWidget *editor,
const QStyleOptionViewItem & option, const QModelIndex &index) const
const QModelIndex & index) const {
if(index.column() == Isovalues_list::Color)
{ {
if(index.column() == Isovalues_list::Color) ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
{ if(coloreditor)
return new ColorListEditor(parent); coloreditor->setColor(index.data().value<QColor>());
}
else return QItemDelegate::createEditor(parent, option, index);
} }
else if(index.column() == Isovalues_list::Isovalue)
void setEditorData(QWidget *editor,
const QModelIndex &index) const
{ {
if(index.column() == Isovalues_list::Color) QLineEdit* lineedit = qobject_cast<QLineEdit*>(editor);
{ if(lineedit)
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor); lineedit->setText(index.data().toString());
if(coloreditor)
coloreditor->setColor(index.data().value<QColor>());
}
else QItemDelegate::setEditorData(editor, index);
} }
void setModelData(QWidget *editor, QAbstractItemModel *model, else QItemDelegate::setEditorData(editor, index);
const QModelIndex &index) const }
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);
if(coloreditor)
{ {
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor); model->setData(index, coloreditor->color());
if(coloreditor) emit new_color(index);
model->setData(index, coloreditor->color());
} }
else QItemDelegate::setModelData(editor, model, 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);
}
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

View File

@ -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;

View File

@ -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 \

View File

@ -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) {

View File

@ -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>