1 /* 2 SPDX-FileCopyrightText: 2013-2015 Andreas Cord-Landwehr <cordlandwehr@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 5 */ 6 7 #ifndef PROFILEMODEL_H 8 #define PROFILEMODEL_H 9 10 #include <QAbstractListModel> 11 12 namespace LearnerProfile 13 { 14 class Learner; 15 class ProfileManager; 16 } 17 18 class QSignalMapper; 19 20 class ProfileModel : public QAbstractListModel 21 { 22 Q_OBJECT 23 Q_PROPERTY(LearnerProfile::ProfileManager *profileManager READ profileManager WRITE setProfileManager) 24 25 public: 26 enum profileRoles { NameRole = Qt::UserRole + 1, IdRole, DataRole }; 27 28 explicit ProfileModel(QObject *parent = nullptr); 29 /** 30 * Reimplemented from QAbstractListModel::roleNames() 31 */ 32 virtual QHash<int, QByteArray> roleNames() const override; 33 void setProfileManager(LearnerProfile::ProfileManager *profileManager); 34 LearnerProfile::ProfileManager *profileManager() const; 35 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 36 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; 37 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 38 39 Q_SIGNALS: 40 void profileChanged(int index); 41 42 private Q_SLOTS: 43 void onProfileAdded(LearnerProfile::Learner *learner, int index); 44 void onProfileAboutToBeRemoved(int index); 45 void emitProfileChanged(int row); 46 47 private: 48 void updateMappings(); 49 LearnerProfile::ProfileManager *m_profileManager; 50 QSignalMapper *m_signalMapper; 51 }; 52 53 #endif // PROFILEMODEL_H 54