forked from FLAME-HPC/flame_visualiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphdelegate.cpp
62 lines (53 loc) · 1.84 KB
/
graphdelegate.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
/*!
* \file graphdelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of graph delegate
*/
#include <QComboBox>
#include "./graphdelegate.h"
GraphDelegate::GraphDelegate(GraphSettingsModel *gsm, int type, QObject *parent)
: QItemDelegate(parent) {
gsmodel = gsm;
type_ = type;
}
QWidget *GraphDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const {
QComboBox *editor = new QComboBox(parent);
if (type_ == 0) {
for (int i = 0; i < gsmodel->getPlots().count(); i++) {
QString text = QString("Graph %1").arg(i+1);
editor->insertItem(i, text);
}
}
if (type_ == 1) {
editor->insertItem(0, "iteration");
editor->insertItem(1, "time scale");
}
return editor;
}
void GraphDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
QString value = index.data().toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
if (QString::compare(value, "") == 0) {
comboBox->setCurrentIndex(index.row());
} else {
for (int i = 0; i < comboBox->count(); i++) {
if (comboBox->itemText(i) == value)
comboBox->setCurrentIndex(i);
}
}
}
void GraphDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
QComboBox *comboBox = static_cast<QComboBox*>(editor);
QString value = comboBox->currentText();
model->setData(index, value, Qt::EditRole);
}
void GraphDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
editor->setGeometry(option.rect);
}