localeselector.cpp Example File
widgets/validators/localeselector.cpp
#include "localeselector.h"
#include <QLocale>
struct SupportedLocale
{
int lang, country;
};
const SupportedLocale SUPPORTED_LOCALES[] = {
{ 1, 0 },
{ 3, 69 },
{ 3, 111 },
{ 4, 59 },
{ 4, 67 },
{ 4, 69 },
{ 5, 195 },
{ 5, 148 },
{ 6, 2 },
{ 7, 69 },
{ 8, 186 },
{ 8, 3 },
{ 8, 17 },
{ 8, 64 },
{ 8, 103 },
{ 8, 109 },
{ 8, 115 },
{ 8, 119 },
{ 8, 122 },
{ 8, 145 },
{ 8, 162 },
{ 8, 175 },
{ 8, 201 },
{ 8, 207 },
{ 8, 216 },
{ 8, 223 },
{ 8, 237 },
{ 9, 11 },
{ 10, 100 },
{ 12, 15 },
{ 14, 197 },
{ 15, 18 },
{ 15, 100 },
{ 16, 25 },
{ 20, 33 },
{ 22, 20 },
{ 23, 36 },
{ 24, 197 },
{ 25, 44 },
{ 25, 97 },
{ 25, 126 },
{ 25, 190 },
{ 25, 208 },
{ 27, 54 },
{ 28, 57 },
{ 29, 58 },
{ 30, 151 },
{ 30, 21 },
{ 31, 225 },
{ 31, 4 },
{ 31, 13 },
{ 31, 21 },
{ 31, 22 },
{ 31, 28 },
{ 31, 38 },
{ 31, 89 },
{ 31, 97 },
{ 31, 100 },
{ 31, 104 },
{ 31, 107 },
{ 31, 133 },
{ 31, 134 },
{ 31, 148 },
{ 31, 154 },
{ 31, 160 },
{ 31, 163 },
{ 31, 170 },
{ 31, 190 },
{ 31, 195 },
{ 31, 215 },
{ 31, 224 },
{ 31, 226 },
{ 31, 234 },
{ 31, 240 },
{ 33, 68 },
{ 34, 71 },
{ 36, 73 },
{ 37, 74 },
{ 37, 21 },
{ 37, 38 },
{ 37, 125 },
{ 37, 142 },
{ 37, 206 },
{ 40, 197 },
{ 41, 81 },
{ 42, 82 },
{ 42, 14 },
{ 42, 21 },
{ 42, 123 },
{ 42, 125 },
{ 42, 206 },
{ 43, 85 },
{ 43, 56 },
{ 44, 86 },
{ 46, 100 },
{ 47, 83 },
{ 47, 156 },
{ 47, 157 },
{ 48, 105 },
{ 49, 100 },
{ 50, 98 },
{ 51, 99 },
{ 52, 101 },
{ 57, 104 },
{ 58, 106 },
{ 58, 206 },
{ 59, 108 },
{ 61, 100 },
{ 63, 110 },
{ 64, 179 },
{ 65, 116 },
{ 66, 114 },
{ 67, 102 },
{ 67, 103 },
{ 67, 207 },
{ 67, 217 },
{ 69, 117 },
{ 71, 118 },
{ 72, 49 },
{ 72, 50 },
{ 73, 124 },
{ 74, 127 },
{ 76, 130 },
{ 76, 32 },
{ 77, 100 },
{ 78, 133 },
{ 80, 100 },
{ 82, 143 },
{ 84, 150 },
{ 85, 161 },
{ 87, 100 },
{ 88, 1 },
{ 89, 102 },
{ 89, 1 },
{ 90, 172 },
{ 91, 173 },
{ 91, 30 },
{ 92, 100 },
{ 92, 163 },
{ 95, 177 },
{ 96, 178 },
{ 96, 222 },
{ 99, 100 },
{ 100, 241 },
{ 100, 27 },
{ 100, 238 },
{ 101, 241 },
{ 101, 27 },
{ 101, 238 },
{ 102, 195 },
{ 103, 195 },
{ 107, 195 },
{ 108, 191 },
{ 109, 192 },
{ 110, 194 },
{ 110, 59 },
{ 110, 69 },
{ 110, 111 },
{ 111, 197 },
{ 111, 10 },
{ 111, 26 },
{ 111, 43 },
{ 111, 47 },
{ 111, 52 },
{ 111, 61 },
{ 111, 63 },
{ 111, 65 },
{ 111, 90 },
{ 111, 96 },
{ 111, 139 },
{ 111, 155 },
{ 111, 166 },
{ 111, 168 },
{ 111, 169 },
{ 111, 174 },
{ 111, 225 },
{ 111, 227 },
{ 111, 231 },
{ 113, 111 },
{ 113, 210 },
{ 114, 205 },
{ 114, 73 },
{ 116, 209 },
{ 117, 100 },
{ 118, 178 },
{ 119, 100 },
{ 120, 211 },
{ 122, 67 },
{ 122, 69 },
{ 124, 195 },
{ 125, 217 },
{ 129, 222 },
{ 130, 100 },
{ 130, 163 },
{ 131, 228 },
{ 131, 1 },
{ 132, 232 },
{ 134, 224 },
{ 136, 195 },
{ 138, 157 },
{ 140, 195 },
{ 141, 161 },
{ 142, 27 },
{ 143, 131 },
{ 144, 224 },
{ 145, 224 },
{ 146, 83 },
{ 147, 100 },
{ 148, 83 },
{ 149, 157 },
{ 150, 111 },
{ 151, 207 },
{ 152, 67 },
{ 153, 67 },
{ 153, 69 },
{ 154, 157 },
{ 155, 69 },
{ 156, 157 },
{ 157, 67 },
{ 158, 157 },
{ 159, 106 },
{ 160, 195 },
{ 161, 83 },
{ 161, 212 },
{ 163, 225 },
{ 164, 157 },
{ 165, 129 }
};
const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale);
typedef QPair<int, int> IntPair;
Q_DECLARE_METATYPE(SupportedLocale)
LocaleSelector::LocaleSelector(QWidget *parent)
: QComboBox(parent)
{
int curIndex = -1;
QLocale curLocale;
for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) {
const SupportedLocale &l = SUPPORTED_LOCALES[i];
if (l.lang == curLocale.language() && l.country == curLocale.country())
curIndex = i;
QString text = QLocale::languageToString(QLocale::Language(l.lang))
+ QLatin1Char('/')
+ QLocale::countryToString(QLocale::Country(l.country));
addItem(text, qVariantFromValue(l));
}
setCurrentIndex(curIndex);
connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int)));
}
void LocaleSelector::emitLocaleSelected(int index)
{
QVariant v = itemData(index);
if (!v.isValid())
return;
SupportedLocale l = qVariantValue<SupportedLocale>(v);
emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country)));
}