- 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 <QSettings>
#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: {
painter->fillRect(option.rect, index.data().value<QColor>());
drawFocus(painter, option, option.rect);
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
case Isovalues_list::Color: {
painter->fillRect(option.rect, index.data().value<QColor>());
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<ColorListEditor*>(editor);
if(coloreditor)
coloreditor->setColor(index.data().value<QColor>());
}
else QItemDelegate::setEditorData(editor, index);
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
if(coloreditor)
coloreditor->setColor(index.data().value<QColor>());
}
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<ColorListEditor*>(editor);
if(coloreditor)
model->setData(index, coloreditor->color());
}
else QItemDelegate::setModelData(editor, model, index);
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)
{
ColorListEditor* coloreditor = qobject_cast<ColorListEditor*>(editor);
if(coloreditor)
{
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);
}
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

View File

@ -4,10 +4,33 @@
#include <QWidget>
#include <QString>
#include <QList>
#include <QModelIndex>
#include <QItemDelegate>
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;

View File

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

View File

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

View File

@ -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 <typename PointsOutputIterator, typename TransformOperator>