-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartDelegate.cpp
More file actions
29 lines (25 loc) · 1.08 KB
/
Copy pathChartDelegate.cpp
File metadata and controls
29 lines (25 loc) · 1.08 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
#include "ChartDelegate.h"
#include <QTableView>
#include <QLineEdit>
#include "ChartModel.h"
chartDelegate::chartDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
QWidget * chartDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const {
QLineEdit *valueEditor = new QLineEdit(parent);
return valueEditor;
}
void chartDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{
if(index.isValid()){
const chartModel * chartMod = dynamic_cast<const chartModel*>(index.model());
QVariant value = chartMod->data(index);
QLineEdit * valueEditor = dynamic_cast<QLineEdit*>(editor);
valueEditor->insert(value.toString());
}
}
void chartDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
if(index.isValid()){
QLineEdit* valueEditor = dynamic_cast<QLineEdit*>(editor);
QVariant value = valueEditor->text();
chartModel * chartMod = dynamic_cast<chartModel*>(model);
chartMod->setData(index,value);
}
}