-
Notifications
You must be signed in to change notification settings - Fork 1
/
texteditdelegate.cpp
41 lines (34 loc) · 1.25 KB
/
texteditdelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*!
* \file texteditdelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of text box edit delegate
*/
#include <QTextEdit>
#include "./texteditdelegate.h"
TextEditDelegate::TextEditDelegate(QObject * parent)
: QItemDelegate(parent) {
}
QWidget *TextEditDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const {
QTextEdit * editor = new QTextEdit(parent);
return editor;
}
void TextEditDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
QString value = index.data().toString();
QTextEdit *textEdit = static_cast<QTextEdit*>(editor);
textEdit->setText(value);
}
void TextEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
QTextEdit *textEdit = static_cast<QTextEdit*>(editor);
QString value = textEdit->toPlainText();
model->setData(index, value, Qt::EditRole);
}
void TextEditDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
editor->setGeometry(option.rect);
}