Statistics - initial version
[scorecard] / src / cell-delegate.cpp
1 #include "cell-delegate.h"
2 #include <QtGui>
3 #include <QDebug>
4
5 CellDelegate::CellDelegate(QObject *parent) : QItemDelegate(parent) 
6 {
7   m_parent = parent;
8 }
9
10 QWidget *CellDelegate::createEditor(QWidget *parent,
11                                     const QStyleOptionViewItem &,
12                                     const QModelIndex &index) const
13 {
14   CellFilter *filter = new CellFilter(m_parent); // HACK
15
16   //CellFilter filter(parent);
17
18   QLineEdit *le = new QLineEdit(parent);
19
20   le->installEventFilter(filter);
21
22   qDebug() << "parent=" << parent << " m_parent=" << m_parent;
23   // HACK: Connect CellFilter signal to CourseDialog nextCell slot
24   connect(filter, SIGNAL(nextCell(QObject *)), m_parent, SLOT(nextCell(QObject *)));
25
26   return le;
27 }
28
29 void CellDelegate::commitAndCloseEditor()
30 {
31     QLineEdit *editor = qobject_cast<QLineEdit *>(sender());
32
33     // TODO: del editor
34     emit commitData(editor);
35     emit closeEditor(editor);
36 }
37
38 void CellDelegate::setEditorData(QWidget *editor,
39                                  const QModelIndex &index) const
40 {
41   QString value = index.model()->data(index, Qt::EditRole).toString();
42
43   QLineEdit *le = static_cast<QLineEdit *>(editor);
44
45   le->setText(value);
46 }
47
48 void CellDelegate::setModelData(QWidget *editor,
49     QAbstractItemModel *model, const QModelIndex &index) const
50 {
51     QLineEdit *le = static_cast<QLineEdit*>(editor);
52
53     QString value = le->text();
54
55     model->setData(index, value, Qt::EditRole);
56
57 }
58