forked from lemirep/Models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListItem.cpp
55 lines (45 loc) · 1.29 KB
/
ListItem.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
#include "ListModel.h"
#include <QDebug>
Models::ListItem::ListItem(QObject *parent) : QObject(parent),
parentItem(qobject_cast<ListItem *>(parent))
{
// So that when returning a ListItem from a QINVOKABLE, we have no issue
// with the QML Engine destroying our object
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
if (qobject_cast<ListItem *>(parent) != NULL)
{
qDebug() << "Parent is a list item";
}
}
bool Models::ListItem::setData(int role, const QVariant &value)
{
Q_UNUSED(role);
Q_UNUSED(value);
return false;
}
QHash<QByteArray, int> Models::ListItem::roleTypesFromName()
{
QHash<int, QByteArray> roles = this->roleNames();
QHash<QByteArray, int> typesForNameHash;
foreach (const QByteArray &val, roles.values())
typesForNameHash[val] = roles.key(val);
return typesForNameHash;
}
void Models::ListItem::triggerItemUpdate()
{
emit dataChanged();
}
bool Models::ListItem::operator<(const Models::ListItem &nextElem) const
{
Q_UNUSED(nextElem);
return false;
}
Models::ListItem &Models::ListItem::operator=(const Models::ListItem &other)
{
if (&other != this)
{
foreach (int role, this->roleNames().keys())
this->setData(role, other.data(role));
}
return *this;
}