File indexing completed on 2024-05-12 09:05:05

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QtQml>
0007 
0008 class RawLanguageModel : public QAbstractListModel
0009 {
0010     Q_OBJECT
0011     QML_ELEMENT
0012 
0013 public:
0014     enum CustomRoles { NameRole = Qt::UserRole + 1, CodeRole, PreferredRole };
0015 
0016     explicit RawLanguageModel(QObject *parent = nullptr);
0017 
0018     QVariant data(const QModelIndex &index, int role) const override;
0019     int rowCount(const QModelIndex &parent) const override;
0020     QHash<int, QByteArray> roleNames() const override;
0021 
0022     Q_INVOKABLE QString getCode(int index) const;
0023     Q_INVOKABLE QModelIndex indexOfValue(const QString &code);
0024 
0025 private:
0026     QList<QLocale::Language> m_languages;
0027     QList<QString> m_iso639codes;
0028     QList<QString> m_preferredLanguages;
0029 };