-
Notifications
You must be signed in to change notification settings - Fork 142
/
LVGLWidgetModel.cpp
56 lines (47 loc) · 1.3 KB
/
LVGLWidgetModel.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
#include "LVGLWidgetModel.h"
#include <QMimeData>
#include <QDataStream>
#include "widgets/LVGLWidget.h"
#include "LVGLCore.h"
LVGLWidgetModel::LVGLWidgetModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int LVGLWidgetModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return lvgl.widgets().size();
}
QVariant LVGLWidgetModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
return lvgl.widgets().at(index.row())->name();
return QVariant();
}
Qt::ItemFlags LVGLWidgetModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
if (index.isValid())
return Qt::ItemIsDragEnabled | defaultFlags;
else
return defaultFlags;
}
QStringList LVGLWidgetModel::mimeTypes() const
{
return QStringList() << "application/x-widget";
}
QMimeData *LVGLWidgetModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData * mimeData = new QMimeData();
QByteArray encodedData;
LVGLWidgetCast cast;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
for (const QModelIndex &index:indexes) {
if (index.isValid() && index.column() == 0) {
cast.ptr = const_cast<LVGLWidget*>(lvgl.widgets().at(index.row()));
stream << cast.i;
}
}
mimeData->setData("application/x-widget", encodedData);
return mimeData;
}