mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
qt: add ReadableItemModel
This commit is contained in:
parent
9119d9a3f8
commit
716545f0a1
34
src/modules/interface/qt/data/ReadableItemModel.h
Normal file
34
src/modules/interface/qt/data/ReadableItemModel.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
|
#include <ReadableData.h>
|
||||||
|
|
||||||
|
class ReadableItemModel : public QStandardItemModel {
|
||||||
|
public:
|
||||||
|
ReadableItemModel() : QStandardItemModel() {}
|
||||||
|
protected:
|
||||||
|
QStringList mimeTypes() const override {return QStringList(ReadableData::mimeType());}
|
||||||
|
QMimeData *mimeData(const QModelIndexList &indices) const override {
|
||||||
|
if (indices.size() < 1) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantList itemDataList;
|
||||||
|
|
||||||
|
for (QModelIndex modelIndex : indices) {
|
||||||
|
itemDataList.append(itemFromIndex(modelIndex)->data(Qt::UserRole));
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray b_data;
|
||||||
|
QDataStream stream(&b_data, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
stream << itemDataList;
|
||||||
|
|
||||||
|
QMimeData *data = new QMimeData;
|
||||||
|
data->setData(ReadableData::mimeType(), b_data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user