Commit c9ad2907 authored by Glen Ditchfield's avatar Glen Ditchfield 🐛
Browse files

Simplify KTimeZoneComboBox

parent 070ccf33
Pipeline #166733 passed with stage
in 1 minute and 9 seconds
......@@ -88,3 +88,22 @@ void KTimeZoneComboBoxTest::test_applyTimeZoneTo()
QCOMPARE(dt.timeSpec(), Qt::TimeZone);
QCOMPARE(dt.timeZone().id(), "Europe/Paris");
}
/**
* For the user's convenience, the first three items are the system time zone,
* "floating", and UTC.
*/
void KTimeZoneComboBoxTest::test_convenience()
{
IncidenceEditorNG::KTimeZoneComboBox combo;
combo.setCurrentIndex(0);
QVERIFY(!combo.isFloating());
QCOMPARE(combo.selectedTimeZone(), QTimeZone::systemTimeZone());
combo.setCurrentIndex(1);
QVERIFY(combo.isFloating());
combo.setCurrentIndex(2);
QVERIFY(!combo.isFloating());
QCOMPARE(combo.selectedTimeZone(), QTimeZone::utc());
}
......@@ -15,5 +15,6 @@ private Q_SLOTS:
void test_timeSpec();
void test_selectTimeZoneFor();
void test_applyTimeZoneTo();
void test_convenience();
};
......@@ -31,16 +31,18 @@ void KTimeZoneComboBoxPrivate::fillComboBox()
mParent->clear();
mZones.clear();
// Read all system time zones
// Read all known time zones.
const QList<QByteArray> lstTimeZoneIds = QTimeZone::availableTimeZoneIds();
mZones.reserve(lstTimeZoneIds.count());
std::copy(lstTimeZoneIds.begin(), lstTimeZoneIds.end(), std::back_inserter(mZones));
std::sort(mZones.begin(), mZones.end()); // clazy:exclude=detaching-member
mZones.reserve(lstTimeZoneIds.count() + 3);
// Prepend the system time zone, UTC and Floating, for convenience.
mZones.append(QTimeZone::systemTimeZoneId());
mZones.append("Floating");
mZones.append("UTC");
const auto sortStart = mZones.end();
// Prepend Local, UTC and Floating, for convenience
mZones.prepend("UTC"); // do not use i18n here index=2
mZones.prepend("Floating"); // do not use i18n here index=1
mZones.prepend(QTimeZone::systemTimeZoneId()); // index=0
std::copy(lstTimeZoneIds.begin(), lstTimeZoneIds.end(), std::back_inserter(mZones));
std::sort(sortStart, mZones.end()); // clazy:exclude=detaching-member
// Put translated zones into the combobox
for (const auto &z : std::as_const(mZones)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment