the compatible code to old Qt versions did not work, therefore we now use a table which definitely works for all Qt versions

This commit is contained in:
Volker Fischer 2015-01-24 18:11:28 +00:00
parent b4f81ffaf1
commit 5a3693f6ae

View file

@ -689,33 +689,234 @@ QString CCountyFlagIcons::GetResourceReference ( const QLocale::Country eCountry
// compatibility to the very old versions of QT is not required anymore, use // compatibility to the very old versions of QT is not required anymore, use
// the new code. // the new code.
// COMPATIBLE FOR OLD QT VERSIONS: // COMPATIBLE FOR OLD QT VERSIONS -> use a table:
// There is no direct query of the country code in Qt, therefore we use a QString strISO3166 = "";
// workaround: Get the matching locales name and split the name of switch ( static_cast<int> ( eCountry ) )
// that since the second part is the country code
QLocale CurLocale ( QLocale::AnyLanguage, eCountry );
// note: in case the country was not found, the constructor of QLocale uses
// the system default, therefore we only want to use countries which are not
// the default except of the case that the country is the system default
if ( !( ( eCountry != QLocale::system().country() ) &&
( CurLocale.country() == QLocale::system().country() ) ) )
{ {
QStringList vstrLocParts = CurLocale.name().split("_"); case 1: strISO3166 = "af"; break;
case 2: strISO3166 = "al"; break;
// the second split contains the name we need case 3: strISO3166 = "dz"; break;
if ( vstrLocParts.size() > 1 ) case 4: strISO3166 = "as"; break;
{ case 5: strISO3166 = "ad"; break;
strReturn = case 6: strISO3166 = "ao"; break;
":/png/flags/res/flags/" + vstrLocParts.at ( 1 ).toLower() + ".png"; case 9: strISO3166 = "ag"; break;
case 10: strISO3166 = "ar"; break;
case 11: strISO3166 = "am"; break;
case 12: strISO3166 = "aw"; break;
case 13: strISO3166 = "au"; break;
case 14: strISO3166 = "at"; break;
case 15: strISO3166 = "az"; break;
case 16: strISO3166 = "bs"; break;
case 17: strISO3166 = "bh"; break;
case 18: strISO3166 = "bd"; break;
case 19: strISO3166 = "bb"; break;
case 20: strISO3166 = "by"; break;
case 21: strISO3166 = "be"; break;
case 22: strISO3166 = "bz"; break;
case 23: strISO3166 = "bj"; break;
case 24: strISO3166 = "bm"; break;
case 25: strISO3166 = "bt"; break;
case 26: strISO3166 = "bo"; break;
case 27: strISO3166 = "ba"; break;
case 28: strISO3166 = "bw"; break;
case 30: strISO3166 = "br"; break;
case 32: strISO3166 = "bn"; break;
case 33: strISO3166 = "bg"; break;
case 34: strISO3166 = "bf"; break;
case 35: strISO3166 = "bi"; break;
case 36: strISO3166 = "kh"; break;
case 37: strISO3166 = "cm"; break;
case 38: strISO3166 = "ca"; break;
case 39: strISO3166 = "cv"; break;
case 40: strISO3166 = "ky"; break;
case 41: strISO3166 = "cf"; break;
case 42: strISO3166 = "td"; break;
case 43: strISO3166 = "cl"; break;
case 44: strISO3166 = "cn"; break;
case 47: strISO3166 = "co"; break;
case 48: strISO3166 = "km"; break;
case 49: strISO3166 = "cd"; break;
case 50: strISO3166 = "cg"; break;
case 52: strISO3166 = "cr"; break;
case 53: strISO3166 = "ci"; break;
case 54: strISO3166 = "hr"; break;
case 55: strISO3166 = "cu"; break;
case 56: strISO3166 = "cy"; break;
case 57: strISO3166 = "cz"; break;
case 58: strISO3166 = "dk"; break;
case 59: strISO3166 = "dj"; break;
case 60: strISO3166 = "dm"; break;
case 61: strISO3166 = "do"; break;
case 62: strISO3166 = "tl"; break;
case 63: strISO3166 = "ec"; break;
case 64: strISO3166 = "eg"; break;
case 65: strISO3166 = "sv"; break;
case 66: strISO3166 = "gq"; break;
case 67: strISO3166 = "er"; break;
case 68: strISO3166 = "ee"; break;
case 69: strISO3166 = "et"; break;
case 71: strISO3166 = "fo"; break;
case 72: strISO3166 = "fj"; break;
case 73: strISO3166 = "fi"; break;
case 74: strISO3166 = "fr"; break;
case 76: strISO3166 = "gf"; break;
case 77: strISO3166 = "pf"; break;
case 79: strISO3166 = "ga"; break;
case 80: strISO3166 = "gm"; break;
case 81: strISO3166 = "ge"; break;
case 82: strISO3166 = "de"; break;
case 83: strISO3166 = "gh"; break;
case 84: strISO3166 = "gi"; break;
case 85: strISO3166 = "gr"; break;
case 86: strISO3166 = "gl"; break;
case 87: strISO3166 = "gd"; break;
case 88: strISO3166 = "gp"; break;
case 89: strISO3166 = "gu"; break;
case 90: strISO3166 = "gt"; break;
case 91: strISO3166 = "gn"; break;
case 92: strISO3166 = "gw"; break;
case 93: strISO3166 = "gy"; break;
case 94: strISO3166 = "ht"; break;
case 96: strISO3166 = "hn"; break;
case 97: strISO3166 = "hk"; break;
case 98: strISO3166 = "hu"; break;
case 99: strISO3166 = "is"; break;
case 100: strISO3166 = "in"; break;
case 101: strISO3166 = "id"; break;
case 102: strISO3166 = "ir"; break;
case 103: strISO3166 = "iq"; break;
case 104: strISO3166 = "ie"; break;
case 105: strISO3166 = "il"; break;
case 106: strISO3166 = "it"; break;
case 107: strISO3166 = "jm"; break;
case 108: strISO3166 = "jp"; break;
case 109: strISO3166 = "jo"; break;
case 110: strISO3166 = "kz"; break;
case 111: strISO3166 = "ke"; break;
case 112: strISO3166 = "ki"; break;
case 113: strISO3166 = "kp"; break;
case 114: strISO3166 = "kr"; break;
case 115: strISO3166 = "kw"; break;
case 116: strISO3166 = "kg"; break;
case 117: strISO3166 = "la"; break;
case 118: strISO3166 = "lv"; break;
case 119: strISO3166 = "lb"; break;
case 120: strISO3166 = "ls"; break;
case 121: strISO3166 = "lr"; break;
case 122: strISO3166 = "ly"; break;
case 123: strISO3166 = "li"; break;
case 124: strISO3166 = "lt"; break;
case 125: strISO3166 = "lu"; break;
case 126: strISO3166 = "mo"; break;
case 127: strISO3166 = "mk"; break;
case 128: strISO3166 = "mg"; break;
case 129: strISO3166 = "mw"; break;
case 130: strISO3166 = "my"; break;
case 132: strISO3166 = "ml"; break;
case 133: strISO3166 = "mt"; break;
case 134: strISO3166 = "mh"; break;
case 135: strISO3166 = "mq"; break;
case 136: strISO3166 = "mr"; break;
case 137: strISO3166 = "mu"; break;
case 138: strISO3166 = "yt"; break;
case 139: strISO3166 = "mx"; break;
case 140: strISO3166 = "fm"; break;
case 141: strISO3166 = "md"; break;
case 142: strISO3166 = "mc"; break;
case 143: strISO3166 = "mn"; break;
case 145: strISO3166 = "ma"; break;
case 146: strISO3166 = "mz"; break;
case 147: strISO3166 = "mm"; break;
case 148: strISO3166 = "na"; break;
case 150: strISO3166 = "np"; break;
case 151: strISO3166 = "nl"; break;
case 153: strISO3166 = "nc"; break;
case 154: strISO3166 = "nz"; break;
case 155: strISO3166 = "ni"; break;
case 156: strISO3166 = "ne"; break;
case 157: strISO3166 = "ng"; break;
case 160: strISO3166 = "mp"; break;
case 161: strISO3166 = "no"; break;
case 162: strISO3166 = "om"; break;
case 163: strISO3166 = "pk"; break;
case 164: strISO3166 = "pw"; break;
case 165: strISO3166 = "ps"; break;
case 166: strISO3166 = "pa"; break;
case 167: strISO3166 = "pg"; break;
case 168: strISO3166 = "py"; break;
case 169: strISO3166 = "pe"; break;
case 170: strISO3166 = "ph"; break;
case 172: strISO3166 = "pl"; break;
case 173: strISO3166 = "pt"; break;
case 174: strISO3166 = "pr"; break;
case 175: strISO3166 = "qa"; break;
case 176: strISO3166 = "re"; break;
case 177: strISO3166 = "ro"; break;
case 178: strISO3166 = "ru"; break;
case 179: strISO3166 = "rw"; break;
case 180: strISO3166 = "kn"; break;
case 181: strISO3166 = "lc"; break;
case 182: strISO3166 = "vc"; break;
case 183: strISO3166 = "ws"; break;
case 184: strISO3166 = "sm"; break;
case 185: strISO3166 = "st"; break;
case 186: strISO3166 = "sa"; break;
case 187: strISO3166 = "sn"; break;
case 188: strISO3166 = "sc"; break;
case 189: strISO3166 = "sl"; break;
case 190: strISO3166 = "sg"; break;
case 191: strISO3166 = "sk"; break;
case 192: strISO3166 = "si"; break;
case 193: strISO3166 = "sb"; break;
case 194: strISO3166 = "so"; break;
case 195: strISO3166 = "za"; break;
case 197: strISO3166 = "es"; break;
case 198: strISO3166 = "lk"; break;
case 201: strISO3166 = "sd"; break;
case 202: strISO3166 = "sr"; break;
case 204: strISO3166 = "sz"; break;
case 205: strISO3166 = "se"; break;
case 206: strISO3166 = "ch"; break;
case 207: strISO3166 = "sy"; break;
case 208: strISO3166 = "tw"; break;
case 209: strISO3166 = "tj"; break;
case 210: strISO3166 = "tz"; break;
case 211: strISO3166 = "th"; break;
case 212: strISO3166 = "tg"; break;
case 214: strISO3166 = "to"; break;
case 215: strISO3166 = "tt"; break;
case 216: strISO3166 = "tn"; break;
case 217: strISO3166 = "tr"; break;
case 219: strISO3166 = "tc"; break;
case 221: strISO3166 = "ug"; break;
case 222: strISO3166 = "ua"; break;
case 223: strISO3166 = "ae"; break;
case 224: strISO3166 = "gb"; break;
case 225: strISO3166 = "us"; break;
case 226: strISO3166 = "um"; break;
case 227: strISO3166 = "uy"; break;
case 228: strISO3166 = "uz"; break;
case 229: strISO3166 = "vu"; break;
case 231: strISO3166 = "ve"; break;
case 232: strISO3166 = "vn"; break;
case 233: strISO3166 = "vg"; break;
case 234: strISO3166 = "vi"; break;
case 236: strISO3166 = "eh"; break;
case 237: strISO3166 = "ye"; break;
case 239: strISO3166 = "zm"; break;
case 240: strISO3166 = "zw"; break;
case 242: strISO3166 = "me"; break;
case 243: strISO3166 = "rs"; break;
case 248: strISO3166 = "ax"; break;
}
strReturn = ":/png/flags/res/flags/" + strISO3166 + ".png";
// check if file actually exists, if not then invalidate reference // check if file actually exists, if not then invalidate reference
if ( !QFile::exists ( strReturn ) ) if ( !QFile::exists ( strReturn ) )
{ {
strReturn = ""; strReturn = "";
} }
}
}
// AT LEAST QT 4.8 IS REQUIRED: // AT LEAST QT 4.8 IS REQUIRED:
/* /*
@ -742,6 +943,14 @@ QString CCountyFlagIcons::GetResourceReference ( const QLocale::Country eCountry
{ {
strReturn = ""; strReturn = "";
} }
//else
//{
//// TEST generate table
//static FILE* pFile = fopen ( "test.dat", "w" );
//fprintf ( pFile, " case %d: strISO3166 = \"%s\"; break;\n",
// static_cast<int> ( eCountry ), vstrLocParts.at ( 1 ).toLower().toStdString().c_str() );
//fflush ( pFile );
//}
} }
} }
*/ */