QDateTimeParser: always use locale for AM/PM texts
The default implementation used the locale, the reimplementation supported translating the texts. This mixing of l10n and i18n concepts resulted in bugs and inconsistencies. Using the texts for AM/PM from the locale that is set on the date/time control is sufficient. [ChangeLog][QtWidgets][QDateTimeParser] AM/PM strings in QDateTimeEdit and other classes using QDateTimeParser are provided by the locale, and are no longer translatable. Change-Id: I83a5dab470ae5ba35b3ce4040ad1877908f462c7 Fixes: QTBUG-75866 Task-number: QTBUG-72833 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
399f815143
commit
6e3b5801d2
@ -77,7 +77,6 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
class Q_CORE_EXPORT QDateTimeParser
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QDateTimeParser)
|
||||
public:
|
||||
enum Context {
|
||||
FromString,
|
||||
@ -267,10 +266,11 @@ protected: // for the benefit of QDateTimeEditPrivate
|
||||
return skipToNextSection(section, current, QStringRef(§ionText));
|
||||
}
|
||||
QString stateName(State s) const;
|
||||
QString getAmPmText(AmPm ap, Case cs) const;
|
||||
|
||||
virtual QDateTime getMinimum() const;
|
||||
virtual QDateTime getMaximum() const;
|
||||
virtual int cursorPosition() const { return -1; }
|
||||
virtual QString getAmPmText(AmPm ap, Case cs) const;
|
||||
virtual QLocale locale() const { return defaultLocale; }
|
||||
|
||||
mutable int currentSectionIndex;
|
||||
|
@ -2308,33 +2308,6 @@ void QDateTimeEdit::paintEvent(QPaintEvent *event)
|
||||
style()->drawComplexControl(QStyle::CC_ComboBox, &optCombo, &p, this);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the string for AM and PM markers.
|
||||
|
||||
If a translation for "AM" and "PM" is installed, then use that.
|
||||
Otherwise, use the default implementation, which uses the locale.
|
||||
*/
|
||||
QString QDateTimeEditPrivate::getAmPmText(AmPm ap, Case cs) const
|
||||
{
|
||||
QString original;
|
||||
QString translated;
|
||||
if (ap == AmText) {
|
||||
original = QLatin1String(cs == UpperCase ? "AM" : "am");
|
||||
translated = (cs == UpperCase ? QDateTimeParser::tr("AM") : QDateTimeParser::tr("am"));
|
||||
} else {
|
||||
original = QLatin1String(cs == UpperCase ? "PM" : "pm");
|
||||
translated = (cs == UpperCase ? QDateTimeParser::tr("PM") : QDateTimeParser::tr("pm"));
|
||||
}
|
||||
|
||||
// This logic fails if a translation exists but doesn't change the string,
|
||||
// which we can accept as a corner-case for which a locale-derived answer
|
||||
// will be acceptable.
|
||||
if (original != translated)
|
||||
return translated;
|
||||
|
||||
return QDateTimeParser::getAmPmText(ap, cs);
|
||||
}
|
||||
|
||||
int QDateTimeEditPrivate::absoluteIndex(QDateTimeEdit::Section s, int index) const
|
||||
{
|
||||
for (int i=0; i<sectionNodes.size(); ++i) {
|
||||
|
@ -97,7 +97,6 @@ public:
|
||||
QDateTime getMinimum() const override { return minimum.toDateTime(); }
|
||||
QDateTime getMaximum() const override { return maximum.toDateTime(); }
|
||||
QLocale locale() const override { return q_func()->locale(); }
|
||||
QString getAmPmText(AmPm ap, Case cs) const override;
|
||||
int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; }
|
||||
|
||||
int absoluteIndex(QDateTimeEdit::Section s, int index) const;
|
||||
|
Loading…
Reference in New Issue
Block a user