-
Notifications
You must be signed in to change notification settings - Fork 1
/
sortdelegate.cpp
88 lines (74 loc) · 2.95 KB
/
sortdelegate.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*!
* \file sortdelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of message sort delegate
*/
#include <QtGui>
#include "./sortdelegate.h"
#include "./sortdialog.h"
#include "./messagesort.h"
SortDelegate::SortDelegate(Machine * m, Communication * comm , QObject *parent)
: QItemDelegate(parent) {
machine = m;
communication = comm;
}
void SortDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (qVariantCanConvert<MessageSort>(index.data())) {
MessageSort sort = qVariantValue<MessageSort>(index.data());
// painter->drawText(option.rect, Comm.toString());
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
/*starRating.paint(painter, option.rect, option.palette,
StarRating::ReadOnly);*/
sort.paint(painter, option.rect, option.palette,
MessageSort::ReadOnly);
} else {
QItemDelegate::paint(painter, option, index);
}
}
QWidget *SortDelegate::createEditor(QWidget */*parent*/,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &index) const {
SortDialog *editor = new SortDialog(machine,
&communication->messageModel->
getMessages()[index.row()].messageType);
connect(editor, SIGNAL(accepted()), this, SLOT(commitAndCloseEditor()));
connect(editor, SIGNAL(rejected()), this, SLOT(commitAndCloseEditor()));
// editor->setParent(windowParent);
editor->setModal(true);
// editor->move(100, 100);
// editor->setWindowFlags(WShowModal);
return editor;
}
void SortDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
if (qVariantCanConvert<MessageSort>(index.data())) {
MessageSort sort = qVariantValue<MessageSort>(index.data());
SortDialog *dialog = static_cast<SortDialog*>(editor);
dialog->setSort(sort);
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void SortDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
if (qVariantCanConvert<MessageSort>(index.data())) {
SortDialog *dialog = static_cast<SortDialog*>(editor);
model->setData(index, qVariantFromValue(dialog->getSort()));
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
/*void CommDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}*/
void SortDelegate::commitAndCloseEditor() {
SortDialog *editor = qobject_cast<SortDialog *>(sender());
emit commitData(editor);
emit closeEditor(editor);
}