File indexing completed on 2024-09-01 05:09:46
0001 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0002 // SPDX-FileCopyrightText: 2020-2022 Harald Sitter <sitter@kde.org> 0003 0004 #pragma once 0005 0006 #include <memory> 0007 0008 #include <QAbstractListModel> 0009 0010 class PatientModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 public: 0014 enum ItemRole { 0015 IndexRole = Qt::UserRole + 1, 0016 ObjectRole, 0017 }; 0018 0019 explicit PatientModel(const QMetaObject &mo, QObject *parent = nullptr); 0020 0021 [[nodiscard]] QHash<int, QByteArray> roleNames() const final; 0022 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const final; 0023 [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0024 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0025 [[nodiscard]] int role(const QByteArray &roleName) const; 0026 0027 // Takes ownership. 0028 void addObject(std::unique_ptr<QObject> patient); 0029 0030 Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged) 0031 bool ready() const; 0032 void setReady(bool ready); 0033 Q_SIGNAL void readyChanged(); 0034 0035 private Q_SLOTS: 0036 void propertyChanged(); 0037 0038 private: 0039 int initRoleNames(const QMetaObject &mo); 0040 void addDynamicRoleNames(int maxEnumValue, QObject *object); 0041 [[nodiscard]] QMetaMethod propertyChangedMetaMethod() const; 0042 0043 QList<QObject *> m_objects; 0044 QHash<int, QByteArray> m_roles; 0045 QHash<int, QByteArray> m_objectProperties; 0046 QHash<int, int> m_signalIndexToProperties; 0047 bool m_ready = false; 0048 };