#include "itemrichtextdelegate.h"

#include <QLineEdit>

ItemRichTextDelegate::ItemRichTextDelegate(QObject *parent) :
    QItemDelegate(parent)
{

}

QWidget *ItemRichTextDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QLineEdit *editor = new QLineEdit(parent);
    editor->installEventFilter(const_cast<ItemRichTextDelegate *>(this));
    return editor;
}

void ItemRichTextDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    QString value = index.model()->data(index, Qt::EditRole).toString();
    QLineEdit *dsb = static_cast<QLineEdit*>(editor);
    dsb->setText(value);
}

void ItemRichTextDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                 const QModelIndex& index) const
{
    QLineEdit *dsb = static_cast<QLineEdit*>(editor);
    //dsb->interpretText();
    //double value = dsb->value();
    model->setData(index, dsb->text());
}

void ItemRichTextDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
                                         const QModelIndex& /* index */) const
{
    editor->setGeometry(option.rect);
}
