-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmlstandarditemmodel.cpp
45 lines (38 loc) · 1.1 KB
/
qmlstandarditemmodel.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
#include "qmlstandarditemmodel.h"
#include <QDebug>
QmlStandardItemModel::QmlStandardItemModel(QObject *parent) :
QStandardItemModel(parent)
{
}
void QmlStandardItemModel::applyRoles()
{
m_roles.clear();
for (int i = 0; i < this->columnCount(); i++)
{
QString role=this->headerData(i, Qt::Horizontal).toString();
m_roles[Qt::UserRole + i + 1] = QVariant(role).toByteArray();
// qDebug()<< Q_FUNC_INFO << this->headerData(i, Qt::Horizontal);
}
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
setRoleNames(m_roles);
#endif
}
QHash<int, QByteArray> QmlStandardItemModel::roleNames() const
{
// qDebug() << Q_FUNC_INFO << m_roles;
return m_roles;
}
QVariant QmlStandardItemModel::data(const QModelIndex &index, int role) const
{
QVariant value;
if(role < Qt::UserRole)
{
value = QStandardItemModel::data(index, role);
}
else {
int columnIdx = role - Qt::UserRole - 1;
QModelIndex modelIndex = this->index(index.row(), columnIdx);
value = QStandardItemModel::data(modelIndex, Qt::DisplayRole);
}
return value;
}