2 * Copyright (C) 2009 Sakari Poussa
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 2.
9 #include "cell-delegate.h"
13 CellDelegate::CellDelegate(QObject *parent) : QItemDelegate(parent)
18 QWidget *CellDelegate::createEditor(QWidget *parent,
19 const QStyleOptionViewItem &,
20 const QModelIndex &index) const
22 CellFilter *filter = new CellFilter(m_parent); // HACK
24 //CellFilter filter(parent);
26 QLineEdit *le = new QLineEdit(parent);
28 le->installEventFilter(filter);
30 qDebug() << "parent=" << parent << " m_parent=" << m_parent;
31 // HACK: Connect CellFilter signal to CourseDialog nextCell slot
32 connect(filter, SIGNAL(nextCell(QObject *)), m_parent, SLOT(nextCell(QObject *)));
37 void CellDelegate::commitAndCloseEditor()
39 QLineEdit *editor = qobject_cast<QLineEdit *>(sender());
42 emit commitData(editor);
43 emit closeEditor(editor);
46 void CellDelegate::setEditorData(QWidget *editor,
47 const QModelIndex &index) const
49 QString value = index.model()->data(index, Qt::EditRole).toString();
51 QLineEdit *le = static_cast<QLineEdit *>(editor);
56 void CellDelegate::setModelData(QWidget *editor,
57 QAbstractItemModel *model, const QModelIndex &index) const
59 QLineEdit *le = static_cast<QLineEdit*>(editor);
61 QString value = le->text();
63 model->setData(index, value, Qt::EditRole);