-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqlrelationaldelegate.cpp
82 lines (67 loc) · 3.24 KB
/
mysqlrelationaldelegate.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
//#include "mysqlrelationaldelegate.h"
//#include <QSqlRelationalTableModel>
//#include <QSortFilterProxyModel>
//#include <QDebug>
//#include <QSqlRecord>
//mySqlRelationalDelegate::mySqlRelationalDelegate(QObject *parent) :
// QSqlRelationalDelegate (parent)
//{
//}
//QWidget *mySqlRelationalDelegate::createEditor(QWidget *aParent, const QStyleOptionViewItem &option, const QModelIndex &index) const
//{
// const QSqlRelationalTableModel sqlModel;
// QComboBox *combo = new QComboBox(aParent);
// combo->setModel(sqlModel.relationModel(index.column()));
// combo->setModelColumn(sqlModel.fieldIndex(sqlModel.relation(index.column()).displayColumn()));
// combo->installEventFilter(const_cast<mySqlRelationalDelegate>(*this));
// return combo;
//}
//void mySqlRelationalDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
//{
// QString strVal = "";
// const QSqlRelationalTableModel sqlModel = qobject_cast<const QSqlRelationalTableModel>(index.model());
// if (!sqlModel )
// {
// const QSortFilterProxyModel* proxyModel = qobject_cast<const QSortFilterProxyModel *>(index.model());
// if (proxyModel) {
// strVal = proxyModel->data(index).toString();
// }
// } else {
// strVal = sqlModel->data(index).toString();
// }
// QComboBox combo = qobject_cast<QComboBox>(editor);
// if (strVal.isEmpty() || !combo) {
// QItemDelegate::setEditorData(editor, index);
// return;
// }
// combo->setCurrentIndex(combo->findText(strVal));
//}
//void mySqlRelationalDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
//{
// if (!index.isValid())
// return;
// QSqlRelationalTableModel sqlModel = qobject_cast<QSqlRelationalTableModel>(model);
// QSortFilterProxyModel* proxyModel = NULL;
// if (!sqlModel )
// {
// proxyModel = qobject_cast<QSortFilterProxyModel >(model);
// if (proxyModel)
// sqlModel = qobject_cast<QSqlRelationalTableModel>(proxyModel->sourceModel());
// }
// QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
// QComboBox combo = qobject_cast<QComboBox>(editor);
// if ([[Image:sqlModel || |]]childModel || !combo) {
// QItemDelegate::setModelData(editor, model, index);
// return;
// }
// int currentItem = combo->currentIndex();
// int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
// int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
// if (proxyModel) {
// proxyModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
// proxyModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
// } else {
// sqlModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
// sqlModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
// }
//}