Warning, file /plasma/plasma-workspace/kcms/region_language/languagelistmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 languagelistmodel.cpp 0003 SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com> 0004 SPDX-FileCopyrightText: 2019 Kevin Ottens <kevin.ottens@enioka.com> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QAbstractListModel> 0011 0012 class SelectedLanguageModel; 0013 class RegionAndLangSettings; 0014 class KCMRegionAndLang; 0015 class LanguageListModel : public QAbstractListModel 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(SelectedLanguageModel *selectedLanguageModel READ selectedLanguageModel CONSTANT) 0019 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 0020 Q_PROPERTY(QString numberExample READ numberExample NOTIFY exampleChanged) 0021 Q_PROPERTY(QString currencyExample READ currencyExample NOTIFY exampleChanged) 0022 Q_PROPERTY(QString timeExample READ timeExample NOTIFY exampleChanged) 0023 Q_PROPERTY(QString metric READ metric NOTIFY exampleChanged) 0024 Q_PROPERTY(bool isPreviewExample READ isPreviewExample WRITE setIsPreviewExample NOTIFY isPreviewExampleChanged) 0025 public: 0026 enum Roles { NativeName = Qt::UserRole + 1, LanguageCode, Flag }; 0027 explicit LanguageListModel(QObject *parent = nullptr); 0028 0029 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0030 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0031 QHash<int, QByteArray> roleNames() const override; 0032 0033 SelectedLanguageModel *selectedLanguageModel() const; 0034 0035 int currentIndex() const; 0036 void setCurrentIndex(int index); 0037 QString numberExample() const; 0038 QString currencyExample() const; 0039 QString timeExample() const; 0040 QString paperSizeExample() const; 0041 #ifdef LC_ADDRESS 0042 QString addressExample() const; 0043 QString nameStyleExample() const; 0044 QString phoneNumbersExample() const; 0045 #endif 0046 QString metric() const; 0047 0048 // currently unused, but we need it if we want preview examples in add langauge overlay 0049 bool isPreviewExample() const; 0050 void setIsPreviewExample(bool preview); 0051 0052 Q_INVOKABLE void setRegionAndLangSettings(QObject *settings, QObject *kcm); 0053 Q_SIGNALS: 0054 void currentIndexChanged(); 0055 void exampleChanged(); 0056 void isPreviewExampleChanged(); 0057 0058 protected: 0059 friend class SelectedLanguageModel; 0060 static QString languageCodeToName(const QString &languageCode); 0061 bool isSupportedLanguage(const QString &language) const; 0062 0063 private: 0064 QString exampleHelper(const std::function<QString(const QLocale &)> &func) const; 0065 RegionAndLangSettings *m_settings{nullptr}; 0066 QList<QString> m_availableLanguages; 0067 SelectedLanguageModel *m_selectedLanguageModel; 0068 int m_index = -1; 0069 bool m_isPreviewExample = false; 0070 }; 0071 0072 class SelectedLanguageModel : public QAbstractListModel 0073 { 0074 Q_OBJECT 0075 Q_PROPERTY(bool shouldWarnMultipleLang READ shouldWarnMultipleLang NOTIFY shouldWarnMultipleLangChanged) 0076 Q_PROPERTY(bool hasImplicitLang READ hasImplicitLang NOTIFY hasImplicitLangChanged) 0077 Q_PROPERTY(QString unsupportedLanguage READ unsupportedLanguage NOTIFY unsupportedLanguageChanged) 0078 public: 0079 explicit SelectedLanguageModel(LanguageListModel *parent = nullptr); 0080 0081 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0082 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0083 void setRegionAndLangSettings(RegionAndLangSettings *settings, KCMRegionAndLang *kcm); 0084 0085 bool shouldWarnMultipleLang() const; 0086 bool hasImplicitLang() const; 0087 const QString &unsupportedLanguage() const; 0088 0089 Q_INVOKABLE void move(int from, int to); 0090 Q_INVOKABLE void remove(int index); 0091 Q_INVOKABLE void addLanguage(const QString &lang); 0092 Q_INVOKABLE void replaceLanguage(int index, const QString &lang); 0093 Q_SIGNALS: 0094 void exampleChanged(); 0095 void shouldWarnMultipleLangChanged(); 0096 void hasImplicitLangChanged(); 0097 void unsupportedLanguageChanged(); 0098 0099 private: 0100 void saveLanguages(); 0101 RegionAndLangSettings *m_settings = nullptr; 0102 QList<QString> m_selectedLanguages; 0103 bool m_hasImplicitLang = false; 0104 QString m_unsupportedLanguage; 0105 KCMRegionAndLang *m_kcm = nullptr; 0106 LanguageListModel *m_parent = nullptr; 0107 };