@@ -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+
757823void 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
0 commit comments