Alex Jbanca 4e81f8f220
feat(StatusQ.Models): Adding SingleModelItemData helper component (#14891)
SingleModelItemData is a generic component that can provide a live object extract from an arbitrary QAbstractItemModel*
2024-06-04 13:08:52 +03:00

28 lines
737 B
C++

#pragma once
#include <QAbstractListModel>
class SnapshotModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit SnapshotModel(QObject* parent = nullptr);
explicit SnapshotModel(const QAbstractItemModel& model, bool recursive = true, QObject* parent = nullptr);
~SnapshotModel();
int rowCount(const QModelIndex& parent = {}) const override;
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex& index, int role) const override;
void grabSnapshot(const QAbstractItemModel& model, bool recursive = true);
void clearSnapshot();
QVariant data(int row, int role) const;
private:
QHash<int, QList<QVariant>> m_data;
QHash<int, QByteArray> m_roles;
};