0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the utils of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
#include "localemodel.h"
|
|
42 |
|
|
43 |
#include <QLocale>
|
|
44 |
#include <QDate>
|
|
45 |
#include <qdebug.h>
|
|
46 |
|
|
47 |
static const int g_model_cols = 6;
|
|
48 |
|
|
49 |
struct LocaleListItem
|
|
50 |
{
|
|
51 |
int language;
|
|
52 |
int country;
|
|
53 |
};
|
|
54 |
|
|
55 |
const LocaleListItem g_locale_list[] = {
|
|
56 |
{ 1, 0 }, // C/AnyCountry
|
|
57 |
{ 3, 69 }, // Afan/Ethiopia
|
|
58 |
{ 3, 111 }, // Afan/Kenya
|
|
59 |
{ 4, 59 }, // Afar/Djibouti
|
|
60 |
{ 4, 67 }, // Afar/Eritrea
|
|
61 |
{ 4, 69 }, // Afar/Ethiopia
|
|
62 |
{ 5, 195 }, // Afrikaans/SouthAfrica
|
|
63 |
{ 5, 148 }, // Afrikaans/Namibia
|
|
64 |
{ 6, 2 }, // Albanian/Albania
|
|
65 |
{ 7, 69 }, // Amharic/Ethiopia
|
|
66 |
{ 8, 186 }, // Arabic/SaudiArabia
|
|
67 |
{ 8, 3 }, // Arabic/Algeria
|
|
68 |
{ 8, 17 }, // Arabic/Bahrain
|
|
69 |
{ 8, 64 }, // Arabic/Egypt
|
|
70 |
{ 8, 103 }, // Arabic/Iraq
|
|
71 |
{ 8, 109 }, // Arabic/Jordan
|
|
72 |
{ 8, 115 }, // Arabic/Kuwait
|
|
73 |
{ 8, 119 }, // Arabic/Lebanon
|
|
74 |
{ 8, 122 }, // Arabic/LibyanArabJamahiriya
|
|
75 |
{ 8, 145 }, // Arabic/Morocco
|
|
76 |
{ 8, 162 }, // Arabic/Oman
|
|
77 |
{ 8, 175 }, // Arabic/Qatar
|
|
78 |
{ 8, 201 }, // Arabic/Sudan
|
|
79 |
{ 8, 207 }, // Arabic/SyrianArabRepublic
|
|
80 |
{ 8, 216 }, // Arabic/Tunisia
|
|
81 |
{ 8, 223 }, // Arabic/UnitedArabEmirates
|
|
82 |
{ 8, 237 }, // Arabic/Yemen
|
|
83 |
{ 9, 11 }, // Armenian/Armenia
|
|
84 |
{ 10, 100 }, // Assamese/India
|
|
85 |
{ 12, 15 }, // Azerbaijani/Azerbaijan
|
|
86 |
{ 14, 197 }, // Basque/Spain
|
|
87 |
{ 15, 18 }, // Bengali/Bangladesh
|
|
88 |
{ 15, 100 }, // Bengali/India
|
|
89 |
{ 16, 25 }, // Bhutani/Bhutan
|
|
90 |
{ 20, 33 }, // Bulgarian/Bulgaria
|
|
91 |
{ 22, 20 }, // Byelorussian/Belarus
|
|
92 |
{ 23, 36 }, // Cambodian/Cambodia
|
|
93 |
{ 24, 197 }, // Catalan/Spain
|
|
94 |
{ 25, 44 }, // Chinese/China
|
|
95 |
{ 25, 97 }, // Chinese/HongKong
|
|
96 |
{ 25, 126 }, // Chinese/Macau
|
|
97 |
{ 25, 190 }, // Chinese/Singapore
|
|
98 |
{ 25, 208 }, // Chinese/Taiwan
|
|
99 |
{ 27, 54 }, // Croatian/Croatia
|
|
100 |
{ 28, 57 }, // Czech/CzechRepublic
|
|
101 |
{ 29, 58 }, // Danish/Denmark
|
|
102 |
{ 30, 151 }, // Dutch/Netherlands
|
|
103 |
{ 30, 21 }, // Dutch/Belgium
|
|
104 |
{ 31, 225 }, // English/UnitedStates
|
|
105 |
{ 31, 4 }, // English/AmericanSamoa
|
|
106 |
{ 31, 13 }, // English/Australia
|
|
107 |
{ 31, 21 }, // English/Belgium
|
|
108 |
{ 31, 22 }, // English/Belize
|
|
109 |
{ 31, 28 }, // English/Botswana
|
|
110 |
{ 31, 38 }, // English/Canada
|
|
111 |
{ 31, 89 }, // English/Guam
|
|
112 |
{ 31, 97 }, // English/HongKong
|
|
113 |
{ 31, 100 }, // English/India
|
|
114 |
{ 31, 104 }, // English/Ireland
|
|
115 |
{ 31, 107 }, // English/Jamaica
|
|
116 |
{ 31, 133 }, // English/Malta
|
|
117 |
{ 31, 134 }, // English/MarshallIslands
|
|
118 |
{ 31, 148 }, // English/Namibia
|
|
119 |
{ 31, 154 }, // English/NewZealand
|
|
120 |
{ 31, 160 }, // English/NorthernMarianaIslands
|
|
121 |
{ 31, 163 }, // English/Pakistan
|
|
122 |
{ 31, 170 }, // English/Philippines
|
|
123 |
{ 31, 190 }, // English/Singapore
|
|
124 |
{ 31, 195 }, // English/SouthAfrica
|
|
125 |
{ 31, 215 }, // English/TrinidadAndTobago
|
|
126 |
{ 31, 224 }, // English/UnitedKingdom
|
|
127 |
{ 31, 226 }, // English/UnitedStatesMinorOutlyingIslands
|
|
128 |
{ 31, 234 }, // English/USVirginIslands
|
|
129 |
{ 31, 240 }, // English/Zimbabwe
|
|
130 |
{ 33, 68 }, // Estonian/Estonia
|
|
131 |
{ 34, 71 }, // Faroese/FaroeIslands
|
|
132 |
{ 36, 73 }, // Finnish/Finland
|
|
133 |
{ 37, 74 }, // French/France
|
|
134 |
{ 37, 21 }, // French/Belgium
|
|
135 |
{ 37, 38 }, // French/Canada
|
|
136 |
{ 37, 125 }, // French/Luxembourg
|
|
137 |
{ 37, 142 }, // French/Monaco
|
|
138 |
{ 37, 206 }, // French/Switzerland
|
|
139 |
{ 40, 197 }, // Galician/Spain
|
|
140 |
{ 41, 81 }, // Georgian/Georgia
|
|
141 |
{ 42, 82 }, // German/Germany
|
|
142 |
{ 42, 14 }, // German/Austria
|
|
143 |
{ 42, 21 }, // German/Belgium
|
|
144 |
{ 42, 123 }, // German/Liechtenstein
|
|
145 |
{ 42, 125 }, // German/Luxembourg
|
|
146 |
{ 42, 206 }, // German/Switzerland
|
|
147 |
{ 43, 85 }, // Greek/Greece
|
|
148 |
{ 43, 56 }, // Greek/Cyprus
|
|
149 |
{ 44, 86 }, // Greenlandic/Greenland
|
|
150 |
{ 46, 100 }, // Gujarati/India
|
|
151 |
{ 47, 83 }, // Hausa/Ghana
|
|
152 |
{ 47, 156 }, // Hausa/Niger
|
|
153 |
{ 47, 157 }, // Hausa/Nigeria
|
|
154 |
{ 48, 105 }, // Hebrew/Israel
|
|
155 |
{ 49, 100 }, // Hindi/India
|
|
156 |
{ 50, 98 }, // Hungarian/Hungary
|
|
157 |
{ 51, 99 }, // Icelandic/Iceland
|
|
158 |
{ 52, 101 }, // Indonesian/Indonesia
|
|
159 |
{ 57, 104 }, // Irish/Ireland
|
|
160 |
{ 58, 106 }, // Italian/Italy
|
|
161 |
{ 58, 206 }, // Italian/Switzerland
|
|
162 |
{ 59, 108 }, // Japanese/Japan
|
|
163 |
{ 61, 100 }, // Kannada/India
|
|
164 |
{ 63, 110 }, // Kazakh/Kazakhstan
|
|
165 |
{ 64, 179 }, // Kinyarwanda/Rwanda
|
|
166 |
{ 65, 116 }, // Kirghiz/Kyrgyzstan
|
|
167 |
{ 66, 114 }, // Korean/RepublicOfKorea
|
|
168 |
{ 67, 102 }, // Kurdish/Iran
|
|
169 |
{ 67, 103 }, // Kurdish/Iraq
|
|
170 |
{ 67, 207 }, // Kurdish/SyrianArabRepublic
|
|
171 |
{ 67, 217 }, // Kurdish/Turkey
|
|
172 |
{ 69, 117 }, // Laothian/Lao
|
|
173 |
{ 71, 118 }, // Latvian/Latvia
|
|
174 |
{ 72, 49 }, // Lingala/DemocraticRepublicOfCongo
|
|
175 |
{ 72, 50 }, // Lingala/PeoplesRepublicOfCongo
|
|
176 |
{ 73, 124 }, // Lithuanian/Lithuania
|
|
177 |
{ 74, 127 }, // Macedonian/Macedonia
|
|
178 |
{ 76, 130 }, // Malay/Malaysia
|
|
179 |
{ 76, 32 }, // Malay/BruneiDarussalam
|
|
180 |
{ 77, 100 }, // Malayalam/India
|
|
181 |
{ 78, 133 }, // Maltese/Malta
|
|
182 |
{ 80, 100 }, // Marathi/India
|
|
183 |
{ 82, 143 }, // Mongolian/Mongolia
|
|
184 |
{ 84, 150 }, // Nepali/Nepal
|
|
185 |
{ 85, 161 }, // Norwegian/Norway
|
|
186 |
{ 87, 100 }, // Oriya/India
|
|
187 |
{ 88, 1 }, // Pashto/Afghanistan
|
|
188 |
{ 89, 102 }, // Persian/Iran
|
|
189 |
{ 89, 1 }, // Persian/Afghanistan
|
|
190 |
{ 90, 172 }, // Polish/Poland
|
|
191 |
{ 91, 173 }, // Portuguese/Portugal
|
|
192 |
{ 91, 30 }, // Portuguese/Brazil
|
|
193 |
{ 92, 100 }, // Punjabi/India
|
|
194 |
{ 92, 163 }, // Punjabi/Pakistan
|
|
195 |
{ 95, 177 }, // Romanian/Romania
|
|
196 |
{ 96, 178 }, // Russian/RussianFederation
|
|
197 |
{ 96, 222 }, // Russian/Ukraine
|
|
198 |
{ 99, 100 }, // Sanskrit/India
|
|
199 |
{ 100, 241 }, // Serbian/SerbiaAndMontenegro
|
|
200 |
{ 100, 27 }, // Serbian/BosniaAndHerzegowina
|
|
201 |
{ 100, 238 }, // Serbian/Yugoslavia
|
|
202 |
{ 101, 241 }, // SerboCroatian/SerbiaAndMontenegro
|
|
203 |
{ 101, 27 }, // SerboCroatian/BosniaAndHerzegowina
|
|
204 |
{ 101, 238 }, // SerboCroatian/Yugoslavia
|
|
205 |
{ 102, 195 }, // Sesotho/SouthAfrica
|
|
206 |
{ 103, 195 }, // Setswana/SouthAfrica
|
|
207 |
{ 107, 195 }, // Siswati/SouthAfrica
|
|
208 |
{ 108, 191 }, // Slovak/Slovakia
|
|
209 |
{ 109, 192 }, // Slovenian/Slovenia
|
|
210 |
{ 110, 194 }, // Somali/Somalia
|
|
211 |
{ 110, 59 }, // Somali/Djibouti
|
|
212 |
{ 110, 69 }, // Somali/Ethiopia
|
|
213 |
{ 110, 111 }, // Somali/Kenya
|
|
214 |
{ 111, 197 }, // Spanish/Spain
|
|
215 |
{ 111, 10 }, // Spanish/Argentina
|
|
216 |
{ 111, 26 }, // Spanish/Bolivia
|
|
217 |
{ 111, 43 }, // Spanish/Chile
|
|
218 |
{ 111, 47 }, // Spanish/Colombia
|
|
219 |
{ 111, 52 }, // Spanish/CostaRica
|
|
220 |
{ 111, 61 }, // Spanish/DominicanRepublic
|
|
221 |
{ 111, 63 }, // Spanish/Ecuador
|
|
222 |
{ 111, 65 }, // Spanish/ElSalvador
|
|
223 |
{ 111, 90 }, // Spanish/Guatemala
|
|
224 |
{ 111, 96 }, // Spanish/Honduras
|
|
225 |
{ 111, 139 }, // Spanish/Mexico
|
|
226 |
{ 111, 155 }, // Spanish/Nicaragua
|
|
227 |
{ 111, 166 }, // Spanish/Panama
|
|
228 |
{ 111, 168 }, // Spanish/Paraguay
|
|
229 |
{ 111, 169 }, // Spanish/Peru
|
|
230 |
{ 111, 174 }, // Spanish/PuertoRico
|
|
231 |
{ 111, 225 }, // Spanish/UnitedStates
|
|
232 |
{ 111, 227 }, // Spanish/Uruguay
|
|
233 |
{ 111, 231 }, // Spanish/Venezuela
|
|
234 |
{ 113, 111 }, // Swahili/Kenya
|
|
235 |
{ 113, 210 }, // Swahili/Tanzania
|
|
236 |
{ 114, 205 }, // Swedish/Sweden
|
|
237 |
{ 114, 73 }, // Swedish/Finland
|
|
238 |
{ 116, 209 }, // Tajik/Tajikistan
|
|
239 |
{ 117, 100 }, // Tamil/India
|
|
240 |
{ 118, 178 }, // Tatar/RussianFederation
|
|
241 |
{ 119, 100 }, // Telugu/India
|
|
242 |
{ 120, 211 }, // Thai/Thailand
|
|
243 |
{ 122, 67 }, // Tigrinya/Eritrea
|
|
244 |
{ 122, 69 }, // Tigrinya/Ethiopia
|
|
245 |
{ 124, 195 }, // Tsonga/SouthAfrica
|
|
246 |
{ 125, 217 }, // Turkish/Turkey
|
|
247 |
{ 129, 222 }, // Ukrainian/Ukraine
|
|
248 |
{ 130, 100 }, // Urdu/India
|
|
249 |
{ 130, 163 }, // Urdu/Pakistan
|
|
250 |
{ 131, 228 }, // Uzbek/Uzbekistan
|
|
251 |
{ 131, 1 }, // Uzbek/Afghanistan
|
|
252 |
{ 132, 232 }, // Vietnamese/VietNam
|
|
253 |
{ 134, 224 }, // Welsh/UnitedKingdom
|
|
254 |
{ 136, 195 }, // Xhosa/SouthAfrica
|
|
255 |
{ 138, 157 }, // Yoruba/Nigeria
|
|
256 |
{ 140, 195 }, // Zulu/SouthAfrica
|
|
257 |
{ 141, 161 }, // Nynorsk/Norway
|
|
258 |
{ 142, 27 }, // Bosnian/BosniaAndHerzegowina
|
|
259 |
{ 143, 131 }, // Divehi/Maldives
|
|
260 |
{ 144, 224 }, // Manx/UnitedKingdom
|
|
261 |
{ 145, 224 }, // Cornish/UnitedKingdom
|
|
262 |
{ 146, 83 }, // Akan/Ghana
|
|
263 |
{ 147, 100 }, // Konkani/India
|
|
264 |
{ 148, 83 }, // Ga/Ghana
|
|
265 |
{ 149, 157 }, // Igbo/Nigeria
|
|
266 |
{ 150, 111 }, // Kamba/Kenya
|
|
267 |
{ 151, 207 }, // Syriac/SyrianArabRepublic
|
|
268 |
{ 152, 67 }, // Blin/Eritrea
|
|
269 |
{ 153, 67 }, // Geez/Eritrea
|
|
270 |
{ 153, 69 }, // Geez/Ethiopia
|
|
271 |
{ 154, 157 }, // Koro/Nigeria
|
|
272 |
{ 155, 69 }, // Sidamo/Ethiopia
|
|
273 |
{ 156, 157 }, // Atsam/Nigeria
|
|
274 |
{ 157, 67 }, // Tigre/Eritrea
|
|
275 |
{ 158, 157 }, // Jju/Nigeria
|
|
276 |
{ 159, 106 }, // Friulian/Italy
|
|
277 |
{ 160, 195 }, // Venda/SouthAfrica
|
|
278 |
{ 161, 83 }, // Ewe/Ghana
|
|
279 |
{ 161, 212 }, // Ewe/Togo
|
|
280 |
{ 163, 225 }, // Hawaiian/UnitedStates
|
|
281 |
{ 164, 157 }, // Tyap/Nigeria
|
|
282 |
{ 165, 129 }, // Chewa/Malawi
|
|
283 |
};
|
|
284 |
static const int g_locale_list_count = sizeof(g_locale_list)/sizeof(g_locale_list[0]);
|
|
285 |
|
|
286 |
LocaleModel::LocaleModel(QObject *parent)
|
|
287 |
: QAbstractItemModel(parent)
|
|
288 |
{
|
|
289 |
m_data_list.append(1234.5678);
|
|
290 |
m_data_list.append(QDate::currentDate());
|
|
291 |
m_data_list.append(QDate::currentDate());
|
|
292 |
m_data_list.append(QTime::currentTime());
|
|
293 |
m_data_list.append(QTime::currentTime());
|
|
294 |
}
|
|
295 |
|
|
296 |
QVariant LocaleModel::data(const QModelIndex &index, int role) const
|
|
297 |
{
|
|
298 |
if (!index.isValid()
|
|
299 |
|| role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::ToolTipRole
|
|
300 |
|| index.column() >= g_model_cols
|
|
301 |
|| index.row() >= g_locale_list_count + 2)
|
|
302 |
return QVariant();
|
|
303 |
|
|
304 |
QVariant data;
|
|
305 |
if (index.column() < g_model_cols - 1)
|
|
306 |
data = m_data_list.at(index.column());
|
|
307 |
|
|
308 |
if (index.row() == 0) {
|
|
309 |
if (role == Qt::ToolTipRole)
|
|
310 |
return QVariant();
|
|
311 |
switch (index.column()) {
|
|
312 |
case 0:
|
|
313 |
return data.toDouble();
|
|
314 |
case 1:
|
|
315 |
return data.toDate();
|
|
316 |
case 2:
|
|
317 |
return data.toDate();
|
|
318 |
case 3:
|
|
319 |
return data.toTime();
|
|
320 |
case 4:
|
|
321 |
return data.toTime();
|
|
322 |
case 5:
|
|
323 |
return QVariant();
|
|
324 |
default:
|
|
325 |
break;
|
|
326 |
}
|
|
327 |
} else {
|
|
328 |
QLocale locale;
|
|
329 |
if (index.row() == 1) {
|
|
330 |
locale = QLocale::system();
|
|
331 |
} else {
|
|
332 |
LocaleListItem item = g_locale_list[index.row() - 2];
|
|
333 |
locale = QLocale((QLocale::Language)item.language, (QLocale::Country)item.country);
|
|
334 |
}
|
|
335 |
|
|
336 |
switch (index.column()) {
|
|
337 |
case 0:
|
|
338 |
if (role == Qt::ToolTipRole)
|
|
339 |
return QVariant();
|
|
340 |
return locale.toString(data.toDouble());
|
|
341 |
case 1:
|
|
342 |
if (role == Qt::ToolTipRole)
|
|
343 |
return locale.dateFormat(QLocale::LongFormat);
|
|
344 |
return locale.toString(data.toDate(), QLocale::LongFormat);
|
|
345 |
case 2:
|
|
346 |
if (role == Qt::ToolTipRole)
|
|
347 |
return locale.dateFormat(QLocale::ShortFormat);
|
|
348 |
return locale.toString(data.toDate(), QLocale::ShortFormat);
|
|
349 |
case 3:
|
|
350 |
if (role == Qt::ToolTipRole)
|
|
351 |
return locale.timeFormat(QLocale::LongFormat);
|
|
352 |
return locale.toString(data.toTime(), QLocale::LongFormat);
|
|
353 |
case 4:
|
|
354 |
if (role == Qt::ToolTipRole)
|
|
355 |
return locale.timeFormat(QLocale::ShortFormat);
|
|
356 |
return locale.toString(data.toTime(), QLocale::ShortFormat);
|
|
357 |
case 5:
|
|
358 |
if (role == Qt::ToolTipRole)
|
|
359 |
return QVariant();
|
|
360 |
return locale.name();
|
|
361 |
default:
|
|
362 |
break;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
|
|
366 |
return QVariant();
|
|
367 |
}
|
|
368 |
|
|
369 |
QVariant LocaleModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
370 |
{
|
|
371 |
if (role != Qt::DisplayRole)
|
|
372 |
return QVariant();
|
|
373 |
|
|
374 |
if (orientation == Qt::Horizontal) {
|
|
375 |
switch (section) {
|
|
376 |
case 0:
|
|
377 |
return QLatin1String("Double");
|
|
378 |
case 1:
|
|
379 |
return QLatin1String("Long Date");
|
|
380 |
case 2:
|
|
381 |
return QLatin1String("Short Date");
|
|
382 |
case 3:
|
|
383 |
return QLatin1String("Long Time");
|
|
384 |
case 4:
|
|
385 |
return QLatin1String("Short Time");
|
|
386 |
case 5:
|
|
387 |
return QLatin1String("Name");
|
|
388 |
default:
|
|
389 |
break;
|
|
390 |
}
|
|
391 |
} else {
|
|
392 |
if (section >= g_locale_list_count + 2)
|
|
393 |
return QVariant();
|
|
394 |
if (section == 0) {
|
|
395 |
return QLatin1String("Input");
|
|
396 |
} else if (section == 1) {
|
|
397 |
return QLatin1String("System");
|
|
398 |
} else {
|
|
399 |
LocaleListItem item = g_locale_list[section - 2];
|
|
400 |
return QLocale::languageToString((QLocale::Language)item.language)
|
|
401 |
+ QLatin1Char('/')
|
|
402 |
+ QLocale::countryToString((QLocale::Country)item.country);
|
|
403 |
}
|
|
404 |
}
|
|
405 |
|
|
406 |
return QVariant();
|
|
407 |
}
|
|
408 |
|
|
409 |
QModelIndex LocaleModel::index(int row, int column,
|
|
410 |
const QModelIndex &parent) const
|
|
411 |
{
|
|
412 |
if (parent.isValid()
|
|
413 |
|| row >= g_locale_list_count + 2
|
|
414 |
|| column >= g_model_cols)
|
|
415 |
return QModelIndex();
|
|
416 |
|
|
417 |
return createIndex(row, column);
|
|
418 |
}
|
|
419 |
|
|
420 |
QModelIndex LocaleModel::parent(const QModelIndex&) const
|
|
421 |
{
|
|
422 |
return QModelIndex();
|
|
423 |
}
|
|
424 |
|
|
425 |
int LocaleModel::columnCount(const QModelIndex&) const
|
|
426 |
{
|
|
427 |
return g_model_cols;
|
|
428 |
}
|
|
429 |
|
|
430 |
int LocaleModel::rowCount(const QModelIndex &parent) const
|
|
431 |
{
|
|
432 |
if (parent.isValid())
|
|
433 |
return 0;
|
|
434 |
return g_locale_list_count + 2;
|
|
435 |
}
|
|
436 |
|
|
437 |
Qt::ItemFlags LocaleModel::flags(const QModelIndex &index) const
|
|
438 |
{
|
|
439 |
if (!index.isValid())
|
|
440 |
return 0;
|
|
441 |
if (index.row() == 0 && index.column() == g_model_cols - 1)
|
|
442 |
return 0;
|
|
443 |
if (index.row() == 0)
|
|
444 |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
|
445 |
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
446 |
}
|
|
447 |
|
|
448 |
bool LocaleModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
449 |
{
|
|
450 |
if (!index.isValid()
|
|
451 |
|| index.row() != 0
|
|
452 |
|| index.column() >= g_model_cols - 1
|
|
453 |
|| role != Qt::EditRole
|
|
454 |
|| m_data_list.at(index.column()).type() != value.type())
|
|
455 |
return false;
|
|
456 |
|
|
457 |
m_data_list[index.column()] = value;
|
|
458 |
emit dataChanged(createIndex(1, index.column()),
|
|
459 |
createIndex(g_locale_list_count, index.column()));
|
|
460 |
|
|
461 |
return true;
|
|
462 |
}
|