-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconditiondelegate.cpp
116 lines (96 loc) · 3.64 KB
/
conditiondelegate.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*!
* \file conditiondelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of condition delegate
*/
#include <QtGui>
#include "./conditiondelegate.h"
#include "./condition.h"
#include "./conditiondialog.h"
ConditionDelegate::ConditionDelegate(QList<AgentType> *ats,
VisualSettingsModel *model, QObject *parent)
: QItemDelegate(parent) {
vsm = model;
agentTypes = ats;
isVisual = true;
}
ConditionDelegate::ConditionDelegate(QList<AgentType> *ats,
GraphSettingsModel *model, QObject *parent)
: QItemDelegate(parent) {
gsm = model;
agentTypes = ats;
isVisual = false;
}
void ConditionDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
if (qVariantCanConvert<Condition>(index.data())) {
Condition condition = qVariantValue<Condition>(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);*/
condition.paint(painter, option.rect, option.palette,
Condition::ReadOnly);
} else {
QItemDelegate::paint(painter, option, index);
}
}
QWidget *ConditionDelegate::createEditor(QWidget */*parent*/,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &index) const {
QString agentType;
// Todo Use flag instead of relying on pointers being set
// (check pointers too!)
/* If visualsettingmodel */
if (isVisual) {
agentType = vsm->getRule(index.row())->agentType();
} else {
/* If graphsettingmodel */
agentType = gsm->getPlot(index.row())->getYaxis();
}
ConditionDialog *editor = new ConditionDialog(agentTypes, agentType,
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 ConditionDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
if (qVariantCanConvert<Condition>(index.data())) {
Condition condition = qVariantValue<Condition>(index.data());
ConditionDialog *dialog = static_cast<ConditionDialog*>(editor);
dialog->setCondition(condition);
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void ConditionDelegate::setModelData(QWidget *editor,
QAbstractItemModel *model, const QModelIndex &index) const {
if (qVariantCanConvert<Condition>(index.data())) {
ConditionDialog *dialog = static_cast<ConditionDialog*>(editor);
model->setData(index, qVariantFromValue(dialog->getCondition()));
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
/*void conditionDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}*/
void ConditionDelegate::commitAndCloseEditor() {
ConditionDialog *editor = qobject_cast<ConditionDialog *>(sender());
emit commitData(editor);
emit closeEditor(editor);
}
void ConditionDelegate::rejectAndCloseEditor() {
ConditionDialog *editor = qobject_cast<ConditionDialog *>(sender());
emit closeEditor(editor);
}