File indexing completed on 2024-10-06 03:31:32

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 
0008 class LanguageListModel : public QAbstractListModel
0009 {
0010     Q_OBJECT
0011 
0012 public:
0013     enum Roles {
0014         NativeNameRole = Qt::UserRole + 1,
0015         LanguageCodeRole,
0016         FlagRole,
0017     };
0018     explicit LanguageListModel(QObject *parent = nullptr);
0019 
0020     int rowCount(const QModelIndex &parent = {}) const override;
0021     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0022     QHash<int, QByteArray> roleNames() const override;
0023 
0024     Q_INVOKABLE QString flagFromName(const QString &language) const;
0025     Q_INVOKABLE QString languageName(const QString &language) const;
0026 
0027     struct Language {
0028         QString locale;
0029         QString name;
0030     };
0031 
0032 private:
0033     QList<Language> m_availableLanguages;
0034 };