QLocale: Report textDirection() by looking to the locale script
Change-Id: Ic562b0301271ba414d5d3ff75a308d84bd288f56 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f052cefc2f
commit
bc4dcb6994
@ -2458,20 +2458,27 @@ QLocale::MeasurementSystem QLocale::measurementSystem() const
|
||||
*/
|
||||
Qt::LayoutDirection QLocale::textDirection() const
|
||||
{
|
||||
switch (language()) {
|
||||
case QLocale::Arabic:
|
||||
case QLocale::Hebrew:
|
||||
case QLocale::Persian:
|
||||
case QLocale::Pashto:
|
||||
case QLocale::Urdu:
|
||||
case QLocale::Syriac:
|
||||
case QLocale::Divehi:
|
||||
switch (script()) {
|
||||
case QLocale::ArabicScript:
|
||||
case QLocale::AvestanScript:
|
||||
case QLocale::CypriotScript:
|
||||
case QLocale::HebrewScript:
|
||||
case QLocale::ImperialAramaicScript:
|
||||
case QLocale::InscriptionalPahlaviScript:
|
||||
case QLocale::InscriptionalParthianScript:
|
||||
case QLocale::KharoshthiScript:
|
||||
case QLocale::LydianScript:
|
||||
case QLocale::MandaeanScript:
|
||||
case QLocale::MeroiticCursiveScript:
|
||||
case QLocale::MeroiticScript:
|
||||
case QLocale::SamaritanScript:
|
||||
case QLocale::SyriacScript:
|
||||
case QLocale::ThaanaScript:
|
||||
case QLocale::NkoScript:
|
||||
case QLocale::OldSouthArabianScript:
|
||||
case QLocale::OrkhonScript:
|
||||
case QLocale::PhoenicianScript:
|
||||
return Qt::RightToLeft;
|
||||
case QLocale::Punjabi:
|
||||
case QLocale::Uzbek:
|
||||
if (script() == QLocale::ArabicScript)
|
||||
return Qt::RightToLeft;
|
||||
// fall through
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -145,6 +145,9 @@ private slots:
|
||||
void measurementSystems();
|
||||
void QTBUG_26035_positivesign();
|
||||
|
||||
void textDirection_data();
|
||||
void textDirection();
|
||||
|
||||
private:
|
||||
QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
|
||||
QString m_sysapp;
|
||||
@ -1959,5 +1962,44 @@ void tst_QLocale::QTBUG_26035_positivesign()
|
||||
QVERIFY(ok);
|
||||
}
|
||||
|
||||
void tst_QLocale::textDirection_data()
|
||||
{
|
||||
QTest::addColumn<int>("language");
|
||||
QTest::addColumn<int>("script");
|
||||
QTest::addColumn<bool>("rightToLeft");
|
||||
|
||||
for (int language = QLocale::C; language <= QLocale::LastLanguage; ++language) {
|
||||
bool rightToLeft = false;
|
||||
switch (language) {
|
||||
case QLocale::Arabic:
|
||||
case QLocale::Hebrew:
|
||||
case QLocale::Kashmiri:
|
||||
case QLocale::Persian:
|
||||
case QLocale::Pashto:
|
||||
case QLocale::Urdu:
|
||||
case QLocale::Syriac:
|
||||
case QLocale::Divehi:
|
||||
rightToLeft = QLocale(QLocale::Language(language)).language() == QLocale::Language(language); // false if there is no locale data for language
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
QString testName = QLocalePrivate::languageToCode(QLocale::Language(language));
|
||||
QTest::newRow(testName.toLatin1().constData()) << language << int(QLocale::AnyScript) << rightToLeft;
|
||||
}
|
||||
QTest::newRow("pa_Arab") << int(QLocale::Punjabi) << int(QLocale::ArabicScript) << true;
|
||||
QTest::newRow("uz_Arab") << int(QLocale::Uzbek) << int(QLocale::ArabicScript) << true;
|
||||
}
|
||||
|
||||
void tst_QLocale::textDirection()
|
||||
{
|
||||
QFETCH(int, language);
|
||||
QFETCH(int, script);
|
||||
QFETCH(bool, rightToLeft);
|
||||
|
||||
QLocale locale(QLocale::Language(language), QLocale::Script(script), QLocale::AnyCountry);
|
||||
QCOMPARE(locale.textDirection() == Qt::RightToLeft, rightToLeft);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QLocale)
|
||||
#include "tst_qlocale.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user