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 PHONEMEMODEL_H
8 #define PHONEMEMODEL_H
9 
10 #include <QAbstractListModel>
11 
12 class Phoneme;
13 class Language;
14 class QSignalMapper;
15 
16 class PhonemeModel : public QAbstractListModel
17 {
18     Q_OBJECT
19     Q_PROPERTY(Language *language READ language WRITE setLanguage NOTIFY languageChanged)
20 
21 public:
22     enum courseRoles { TitleRole = Qt::UserRole + 1, IdRole, DataRole };
23 
24     explicit PhonemeModel(QObject *parent = nullptr);
25     /**
26      * Reimplemented from QAbstractListModel::roleNames()
27      */
28     virtual QHash<int, QByteArray> roleNames() const override;
29     void setLanguage(Language *language);
30     Language *language() const;
31     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
32     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
33     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
34 
35 Q_SIGNALS:
36     void phonemeChanged(int index);
37     void languageChanged();
38 
39 private Q_SLOTS:
40     void onPhonemeAboutToBeAdded(Phoneme *phoneme, int index);
41     void onPhonemeAdded();
42     void onPhonemesAboutToBeRemoved(int first, int last);
43     void onPhonemesRemoved();
44     void emitPhonemeChanged(int row);
45 
46 private:
47     void updateMappings();
48     Language *m_language;
49     QSignalMapper *m_signalMapper;
50 };
51 
52 #endif // PHONEMEMODEL_H
53