-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpostdelegate.cpp
71 lines (63 loc) · 2.44 KB
/
mpostdelegate.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*!
* \file mpostdelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of mpost delegate
*/
#include <QtGui>
#include "./mpostdelegate.h"
#include "./mpostdialog.h"
#include "./mpost.h"
MpostDelegate::MpostDelegate(MemoryModel * m, QObject *parent)
: QItemDelegate(parent) {
memory = m;
}
QWidget *MpostDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const {
QTextEdit *editor = new QTextEdit(parent);
return editor;
}
void MpostDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (qVariantCanConvert<Mpost>(index.data())) {
Mpost mpost = qVariantValue<Mpost>(index.data());
// painter->drawText(option.rect, mpre.toString());
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
/*starRating.paint(painter, option.rect, option.palette,
StarRating::ReadOnly);*/
mpost.paint(painter, option.rect, option.palette,
Mpost::ReadOnly);
} else {
QItemDelegate::paint(painter, option, index);
}
}
void MpostDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
if (qVariantCanConvert<Mpost>(index.data())) {
Mpost mpost = qVariantValue<Mpost>(index.data());
QTextEdit * textEdit = static_cast<QTextEdit*>(editor);
// lineEdit->setText(mpost.getText());
textEdit->setText(mpost.getText());
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void MpostDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
if (qVariantCanConvert<Mpost>(index.data())) {
QTextEdit *textEdit = static_cast<QTextEdit*>(editor);
Mpost mpost;
mpost.setMemory(this->memory);
mpost.setText(textEdit->toPlainText()); // lineEdit->text());
model->setData(index, qVariantFromValue(mpost));
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
void MpostDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
editor->setGeometry(option.rect);
}