Subversion Repositories svn1-original

Rev

Rev 111 | Rev 145 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <QtGui>
#include "timedelegate.h"

/*
    timedelegate.cpp

    A delegate that allows the user to change integer values from the model
    using a date time widget.
*/

timeDelegate::timeDelegate(QObject *parent)
    : QItemDelegate(parent)
{
}

QWidget *timeDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem &/* option */,
    const QModelIndex &/* index */) const
{
    QTimeEdit *editor = new QTimeEdit(parent);
    editor->setDisplayFormat("hh:mm:ss");

    return editor;
}

void timeDelegate::setEditorData(QWidget *editor,
                                    const QModelIndex &index) const
{
    QTime value = index.model()->data(index, Qt::EditRole).toTime();

    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
    timeEdit->setTime(value);
}


void timeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex &index) const
{
    QTimeEdit *timeEdit = static_cast<QTimeEdit*>(editor);
    timeEdit->interpretText();
    QTime value = timeEdit->time();

    model->setData(index, value, Qt::EditRole);
}

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