-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpositiondelegate.cpp
More file actions
97 lines (81 loc) · 3.21 KB
/
positiondelegate.cpp
File metadata and controls
97 lines (81 loc) · 3.21 KB
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
89
90
91
92
93
94
95
96
97
/*!
* \file positiondelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of position delegate
*/
#include <QtGui>
#include "./positiondelegate.h"
#include "./positiondialog.h"
#include "./position.h"
PositionDelegate::PositionDelegate(QList<AgentType> *ats,
VisualSettingsModel *model, QObject *parent)
: QItemDelegate(parent) {
vsm = model;
agentTypes = ats;
}
void PositionDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
if (qVariantCanConvert<Position>(index.data())) {
Position position = qVariantValue<Position>(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);*/
position.paint(painter, option.rect, option.palette,
Position::ReadOnly);
} else {
QItemDelegate::paint(painter, option, index);
}
}
QWidget *PositionDelegate::createEditor(QWidget */*parent*/,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &index) const {
// qDebug() << "PositionDelegate parent: " << windowParent;
PositionDialog *editor =
new PositionDialog(agentTypes, vsm, index.row());
connect(editor, SIGNAL(okButton()),
this, SLOT(commitAndCloseEditor()));
connect(editor, SIGNAL(cancelButton()),
this, SLOT(rejectAndCloseEditor()));
// editor->setParent(windowParent);
editor->setModal(true);
// editor->move(100, 100);
// editor->setWindowFlags(WShowModal);
return editor;
}
void PositionDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
if (qVariantCanConvert<Position>(index.data())) {
Position position = qVariantValue<Position>(index.data());
PositionDialog *dialog = static_cast<PositionDialog*>(editor);
dialog->setPosition(position);
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void PositionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
if (qVariantCanConvert<Position>(index.data())) {
PositionDialog *dialog = static_cast<PositionDialog*>(editor);
model->setData(index, qVariantFromValue(dialog->getPosition()));
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
/*void PositionDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}*/
void PositionDelegate::commitAndCloseEditor() {
PositionDialog *editor = qobject_cast<PositionDialog *>(sender());
emit commitData(editor);
emit closeEditor(editor);
}
void PositionDelegate::rejectAndCloseEditor() {
PositionDialog *editor = qobject_cast<PositionDialog *>(sender());
emit closeEditor(editor);
}