Skip to content

Commit 23a54d8

Browse files
committed
Use QVariant::fromValue(Q_ENUM) for DateFormat preference
1 parent c848eb6 commit 23a54d8

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

src/preferences/dialog/dlgpreflibrary.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,15 @@ DlgPrefLibrary::DlgPrefLibrary(
113113
updateSearchLineEditHistoryOptions();
114114

115115
comboBox_dateFormat->addItem(tr("Native (System Default)"),
116-
QVariant::fromValue(
117-
static_cast<int>(BaseTrackTableModel::DateFormat::Native)));
116+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Native));
118117
comboBox_dateFormat->addItem(tr("ISO 8601 (yyyy-MM-dd)"),
119-
QVariant::fromValue(static_cast<int>(
120-
BaseTrackTableModel::DateFormat::ISO8601)));
118+
QVariant::fromValue(BaseTrackTableModel::DateFormat::ISO8601));
121119
comboBox_dateFormat->addItem(tr("Regional Short (d/M/yy)"),
122-
QVariant::fromValue(static_cast<int>(
123-
BaseTrackTableModel::DateFormat::RegionalShort)));
120+
QVariant::fromValue(BaseTrackTableModel::DateFormat::RegionalShort));
124121
comboBox_dateFormat->addItem(tr("Regional Long (dd.MM.yyyy)"),
125-
QVariant::fromValue(static_cast<int>(
126-
BaseTrackTableModel::DateFormat::RegionalLong)));
122+
QVariant::fromValue(BaseTrackTableModel::DateFormat::RegionalLong));
127123
comboBox_dateFormat->addItem(tr("Custom"),
128-
QVariant::fromValue(
129-
static_cast<int>(BaseTrackTableModel::DateFormat::Custom)));
124+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Custom));
130125

131126
connect(comboBox_dateFormat,
132127
&QComboBox::currentIndexChanged,
@@ -295,7 +290,8 @@ void DlgPrefLibrary::slotResetToDefaults() {
295290
comboBox_search_bpm_fuzzy_range->setCurrentIndex(
296291
comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent));
297292

298-
int dateIndex = comboBox_dateFormat->findData(BaseTrackTableModel::kDateFormatDefault);
293+
int dateIndex = comboBox_dateFormat->findData(
294+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Native));
299295
if (dateIndex != -1) {
300296
comboBox_dateFormat->setCurrentIndex(dateIndex);
301297
} else {
@@ -362,7 +358,7 @@ void DlgPrefLibrary::slotUpdate() {
362358
preset = BaseTrackTableModel::DateFormat::RegionalLong;
363359
}
364360

365-
int dateIndex = comboBox_dateFormat->findData(QVariant::fromValue(static_cast<int>(preset)));
361+
int dateIndex = comboBox_dateFormat->findData(QVariant::fromValue(preset));
366362
if (dateIndex != -1) {
367363
comboBox_dateFormat->setCurrentIndex(dateIndex);
368364
}
@@ -785,8 +781,8 @@ void DlgPrefLibrary::setSeratoMetadataEnabled(bool shouldSyncTrackMetadata) {
785781
}
786782

787783
void DlgPrefLibrary::slotDateFormatIndexChanged(int index) {
788-
auto type = static_cast<BaseTrackTableModel::DateFormat>(
789-
comboBox_dateFormat->itemData(index).toInt());
784+
auto type = comboBox_dateFormat->itemData(index)
785+
.value<BaseTrackTableModel::DateFormat>();
790786

791787
if (type == BaseTrackTableModel::DateFormat::Custom) {
792788
// Enable editing for Custom
@@ -831,8 +827,8 @@ void DlgPrefLibrary::slotDateFormatChanged(const QString& text) {
831827
if (comboBox_dateFormat->isEditable()) {
832828
int index = comboBox_dateFormat->currentIndex();
833829
if (index >= 0) {
834-
auto type = static_cast<BaseTrackTableModel::DateFormat>(
835-
comboBox_dateFormat->itemData(index).toInt());
830+
auto type = comboBox_dateFormat->itemData(index)
831+
.value<BaseTrackTableModel::DateFormat>();
836832
if (type == BaseTrackTableModel::DateFormat::Custom) {
837833
m_lastCustomDateFormat = format;
838834
}

0 commit comments

Comments
 (0)