Skip to content

Commit 6f83577

Browse files
committed
Implement persistent custom Date Format and fix Library layout metrics
1 parent 2140537 commit 6f83577

4 files changed

Lines changed: 149 additions & 38 deletions

File tree

src/library/basetracktablemodel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
133133
static constexpr bool kApplyPlayedTrackColorDefault = true;
134134
static void setApplyPlayedTrackColor(bool apply);
135135

136+
enum class DateFormat {
137+
Native = 0, // System Default
138+
ISO8601 = 1, // yyyy-MM-dd
139+
RegionalShort = 2, // d/M/yy
140+
RegionalLong = 3, // dd.MM.yyyy
141+
Custom = 4,
142+
};
143+
Q_ENUM(DateFormat)
144+
136145
static const QString kDateFormatDefault;
137146
static void setDateFormat(const QString& format);
138147

src/preferences/dialog/dlgpreflibrary.cpp

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DlgPrefLibrary::DlgPrefLibrary(
4242
m_pRateRangeDeck1(make_parented<ControlProxy>(
4343
QStringLiteral("[Channel1]"), QStringLiteral("rateRange"), this)) {
4444
setupUi(this);
45+
gridLayout_track_table_view->setColumnStretch(1, 1);
4546

4647
connect(pushButton_add_dir,
4748
&QPushButton::clicked,
@@ -111,19 +112,29 @@ DlgPrefLibrary::DlgPrefLibrary(
111112

112113
updateSearchLineEditHistoryOptions();
113114

114-
comboBox_dateFormat->setEditable(true);
115-
// Use empty string data for Native to invoke QLocale default
116-
comboBox_dateFormat->addItem(tr("Native (System Default)"), QString());
117-
comboBox_dateFormat->addItem(tr("ISO 8601 (yyyy-MM-dd)"), QStringLiteral("yyyy-MM-dd"));
118-
comboBox_dateFormat->addItem(tr("Regional Short (d/M/yy)"), QStringLiteral("d/M/yy"));
119-
comboBox_dateFormat->addItem(tr("Regional Long (dd.MM.yyyy)"), QStringLiteral("dd.MM.yyyy"));
120-
// Custom option is handled by the edit behavior
115+
comboBox_dateFormat->addItem(tr("Native (System Default)"),
116+
QVariant::fromValue(
117+
static_cast<int>(BaseTrackTableModel::DateFormat::Native)));
118+
comboBox_dateFormat->addItem(tr("ISO 8601 (yyyy-MM-dd)"),
119+
QVariant::fromValue(static_cast<int>(
120+
BaseTrackTableModel::DateFormat::ISO8601)));
121+
comboBox_dateFormat->addItem(tr("Regional Short (d/M/yy)"),
122+
QVariant::fromValue(static_cast<int>(
123+
BaseTrackTableModel::DateFormat::RegionalShort)));
124+
comboBox_dateFormat->addItem(tr("Regional Long (dd.MM.yyyy)"),
125+
QVariant::fromValue(static_cast<int>(
126+
BaseTrackTableModel::DateFormat::RegionalLong)));
127+
comboBox_dateFormat->addItem(tr("Custom"),
128+
QVariant::fromValue(
129+
static_cast<int>(BaseTrackTableModel::DateFormat::Custom)));
121130

122-
// Update preview initially
123-
slotDateFormatChanged(comboBox_dateFormat->currentText());
131+
connect(comboBox_dateFormat,
132+
&QComboBox::currentIndexChanged,
133+
this,
134+
&DlgPrefLibrary::slotDateFormatIndexChanged);
124135

125136
connect(comboBox_dateFormat,
126-
&QComboBox::currentTextChanged,
137+
&QComboBox::editTextChanged,
127138
this,
128139
&DlgPrefLibrary::slotDateFormatChanged);
129140

@@ -338,13 +349,32 @@ void DlgPrefLibrary::slotUpdate() {
338349
QString dateFormat = m_pConfig->getValue(
339350
kDateFormatConfigKey,
340351
BaseTrackTableModel::kDateFormatDefault);
341-
int dateIndex = comboBox_dateFormat->findData(dateFormat);
352+
353+
// Determine the matching preset or custom
354+
BaseTrackTableModel::DateFormat preset = BaseTrackTableModel::DateFormat::Custom;
355+
if (dateFormat.isEmpty()) {
356+
preset = BaseTrackTableModel::DateFormat::Native;
357+
} else if (dateFormat == QStringLiteral("yyyy-MM-dd")) {
358+
preset = BaseTrackTableModel::DateFormat::ISO8601;
359+
} else if (dateFormat == QStringLiteral("d/M/yy")) {
360+
preset = BaseTrackTableModel::DateFormat::RegionalShort;
361+
} else if (dateFormat == QStringLiteral("dd.MM.yyyy")) {
362+
preset = BaseTrackTableModel::DateFormat::RegionalLong;
363+
}
364+
365+
int dateIndex = comboBox_dateFormat->findData(QVariant::fromValue(static_cast<int>(preset)));
342366
if (dateIndex != -1) {
343367
comboBox_dateFormat->setCurrentIndex(dateIndex);
368+
}
369+
370+
if (preset == BaseTrackTableModel::DateFormat::Custom) {
371+
comboBox_dateFormat->setEditable(true);
372+
comboBox_dateFormat->setEditText(dateFormat);
373+
m_lastCustomDateFormat = dateFormat;
344374
} else {
345-
// Custom format string
346-
comboBox_dateFormat->setCurrentText(dateFormat);
375+
comboBox_dateFormat->setEditable(false);
347376
}
377+
348378
// Ensure the static member is updated on startup/load
349379
BaseTrackTableModel::setDateFormat(dateFormat);
350380

@@ -411,12 +441,12 @@ void DlgPrefLibrary::slotUpdate() {
411441
m_pConfig->getValue(
412442
kSearchBpmFuzzyRangeConfigKey,
413443
BpmFilterNode::kRelativeRangeDefault);
414-
int index = comboBox_search_bpm_fuzzy_range->findData(static_cast<int>(searchBpmFuzzyRange));
415-
if (index == -1) {
416-
index = comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent);
444+
int bpmIndex = comboBox_search_bpm_fuzzy_range->findData(static_cast<int>(searchBpmFuzzyRange));
445+
if (bpmIndex == -1) {
446+
bpmIndex = comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent);
417447
}
418-
comboBox_search_bpm_fuzzy_range->setCurrentIndex(index);
419-
slotBpmRangeSelected(index);
448+
comboBox_search_bpm_fuzzy_range->setCurrentIndex(bpmIndex);
449+
slotBpmRangeSelected(bpmIndex);
420450

421451
const auto bpmColumnPrecision =
422452
m_pConfig->getValue(
@@ -754,13 +784,59 @@ void DlgPrefLibrary::setSeratoMetadataEnabled(bool shouldSyncTrackMetadata) {
754784
}
755785
}
756786

787+
void DlgPrefLibrary::slotDateFormatIndexChanged(int index) {
788+
auto type = static_cast<BaseTrackTableModel::DateFormat>(
789+
comboBox_dateFormat->itemData(index).toInt());
790+
791+
if (type == BaseTrackTableModel::DateFormat::Custom) {
792+
// Enable editing for Custom
793+
if (!comboBox_dateFormat->isEditable()) {
794+
comboBox_dateFormat->setEditable(true);
795+
comboBox_dateFormat->setEditText(m_lastCustomDateFormat);
796+
}
797+
} else {
798+
// Disable editing for Presets
799+
comboBox_dateFormat->setEditable(false);
800+
801+
QString format;
802+
switch (type) {
803+
case BaseTrackTableModel::DateFormat::Native:
804+
format = QString();
805+
break;
806+
case BaseTrackTableModel::DateFormat::ISO8601:
807+
format = QStringLiteral("yyyy-MM-dd");
808+
break;
809+
case BaseTrackTableModel::DateFormat::RegionalShort:
810+
format = QStringLiteral("d/M/yy");
811+
break;
812+
case BaseTrackTableModel::DateFormat::RegionalLong:
813+
format = QStringLiteral("dd.MM.yyyy");
814+
break;
815+
case BaseTrackTableModel::DateFormat::Custom:
816+
// Should not happen here given the if/else above
817+
break;
818+
}
819+
slotDateFormatChanged(format);
820+
}
821+
}
822+
757823
void DlgPrefLibrary::slotDateFormatChanged(const QString& text) {
758824
QString format = text;
759-
// Check if the text matches a predefined item (like "Native (...)")
760-
int index = comboBox_dateFormat->findText(text);
761-
if (index != -1) {
762-
// Use the underlying data (e.g. empty string for Native, or "yyyy-MM-dd" for ISO)
763-
format = comboBox_dateFormat->itemData(index).toString();
825+
// If not editable, we are in a Preset mode, but 'text' might be the Item
826+
// Label (e.g. "Native ...") depending on how this was called. However, our
827+
// slotDateFormatIndexChanged calls this explicitly with the correct format
828+
// string. The editTextChanged signal only fires when editable. So 'text'
829+
// should be the correct format string in all valid cases.
830+
831+
if (comboBox_dateFormat->isEditable()) {
832+
int index = comboBox_dateFormat->currentIndex();
833+
if (index >= 0) {
834+
auto type = static_cast<BaseTrackTableModel::DateFormat>(
835+
comboBox_dateFormat->itemData(index).toInt());
836+
if (type == BaseTrackTableModel::DateFormat::Custom) {
837+
m_lastCustomDateFormat = format;
838+
}
839+
}
764840
}
765841

766842
// Update Preview

src/preferences/dialog/dlgpreflibrary.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class DlgPrefLibrary : public DlgPreferencePage, public Ui::DlgPrefLibraryDlg {
6767
void slotBpmRangeSelected(int index);
6868
void slotBpmColumnPrecisionChanged(int bpmPrecision);
6969
void slotSeratoMetadataExportClicked(bool);
70+
void slotDateFormatIndexChanged(int index);
7071
void slotDateFormatChanged(const QString& text);
7172

7273
private:
@@ -84,4 +85,6 @@ class DlgPrefLibrary : public DlgPreferencePage, public Ui::DlgPrefLibraryDlg {
8485
int m_iOriginalTrackTableRowHeight;
8586
// Listen to rate range changes in order to update the fuzzy BPM range
8687
parented_ptr<ControlProxy> m_pRateRangeDeck1;
88+
89+
QString m_lastCustomDateFormat;
8790
};

src/preferences/dialog/dlgpreflibrarydlg.ui

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@
173173
</property>
174174
<layout class="QGridLayout" name="gridLayout_track_table_view">
175175

176-
<item row="1" column="0" colspan="3">
176+
<item row="1" column="0" colspan="4">
177177
<widget class="QCheckBox" name="checkBox_edit_metadata_selected_clicked">
178178
<property name="text">
179179
<string>Edit metadata after clicking selected track</string>
180180
</property>
181181
</widget>
182182
</item>
183183

184-
<item row="2" column="0" colspan="3">
184+
<item row="2" column="0" colspan="4">
185185
<widget class="QLabel" name="label_doubeClickAction">
186186
<property name="text">
187187
<string>Track Double-Click Action:</string>
@@ -192,7 +192,7 @@
192192
</widget>
193193
</item>
194194

195-
<item row="3" column="0" colspan="3">
195+
<item row="3" column="0" colspan="4">
196196
<widget class="QRadioButton" name="radioButton_dbclick_deck">
197197
<property name="text">
198198
<string>Load track to next available deck</string>
@@ -202,21 +202,21 @@
202202
</property>
203203
</widget>
204204
</item>
205-
<item row="4" column="0" colspan="3">
205+
<item row="4" column="0" colspan="4">
206206
<widget class="QRadioButton" name="radioButton_dbclick_bottom">
207207
<property name="text">
208208
<string>Add track to Auto DJ queue (bottom)</string>
209209
</property>
210210
</widget>
211211
</item>
212-
<item row="5" column="0" colspan="3">
212+
<item row="5" column="0" colspan="4">
213213
<widget class="QRadioButton" name="radioButton_dbclick_top">
214214
<property name="text">
215215
<string>Add track to Auto DJ queue (top)</string>
216216
</property>
217217
</widget>
218218
</item>
219-
<item row="6" column="0" colspan="3">
219+
<item row="6" column="0" colspan="4">
220220
<widget class="QRadioButton" name="radioButton_dbclick_ignore">
221221
<property name="text">
222222
<string>Ignore</string>
@@ -290,7 +290,7 @@
290290
<widget class="QSpinBox" name="spinbox_bpm_precision"/>
291291
</item>
292292

293-
<item row="10" column="0" colspan="3">
293+
<item row="10" column="0" colspan="4">
294294
<widget class="QCheckBox" name="checkbox_played_track_color">
295295
<property name="text">
296296
<string>Grey out played tracks</string>
@@ -308,15 +308,38 @@
308308
</property>
309309
</widget>
310310
</item>
311-
<item row="11" column="1">
312-
<widget class="QComboBox" name="comboBox_dateFormat"/>
313-
</item>
314-
<item row="11" column="2">
315-
<widget class="QLabel" name="label_dateFormatPreview">
316-
<property name="text">
317-
<string>Preview</string>
311+
<item row="11" column="1" colspan="3">
312+
<layout class="QHBoxLayout" name="horizontalLayout_dateFormat">
313+
<property name="leftMargin">
314+
<number>0</number>
318315
</property>
319-
</widget>
316+
<property name="topMargin">
317+
<number>0</number>
318+
</property>
319+
<property name="rightMargin">
320+
<number>0</number>
321+
</property>
322+
<property name="bottomMargin">
323+
<number>0</number>
324+
</property>
325+
<item>
326+
<widget class="QComboBox" name="comboBox_dateFormat">
327+
<property name="sizePolicy">
328+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
329+
<horstretch>0</horstretch>
330+
<verstretch>0</verstretch>
331+
</sizepolicy>
332+
</property>
333+
</widget>
334+
</item>
335+
<item>
336+
<widget class="QLabel" name="label_dateFormatPreview">
337+
<property name="text">
338+
<string>Preview</string>
339+
</property>
340+
</widget>
341+
</item>
342+
</layout>
320343
</item>
321344

322345
</layout>

0 commit comments

Comments
 (0)