-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
(fix) apply Library date format, fix 'dateadded' filter #16047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f7ffc42
17dab10
b97f243
d2e570e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include "library/dateformatbroadcaster.h" | ||
|
|
||
| #include "moc_dateformatbroadcaster.cpp" | ||
|
|
||
| DateFormatChangedBroadcaster::DateFormatChangedBroadcaster() { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #include <QObject> | ||
|
|
||
| #include "util/singleton.h" | ||
|
|
||
| class DateFormatChangedBroadcaster | ||
| : public QObject, | ||
| public Singleton<DateFormatChangedBroadcaster> { | ||
| Q_OBJECT | ||
| public: | ||
| signals: | ||
| void dateFormatChanged(); | ||
|
|
||
| protected: | ||
| DateFormatChangedBroadcaster(); | ||
| ~DateFormatChangedBroadcaster() override = default; | ||
| friend class Singleton<DateFormatChangedBroadcaster>; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| #include <QLocale> | ||
| #include <QRegularExpression> | ||
|
|
||
| #include "library/basetracktablemodel.h" | ||
| #include "library/dao/trackschema.h" | ||
| #include "library/queryutil.h" | ||
| #include "library/trackset/crate/crateschema.h" | ||
|
|
@@ -900,24 +901,52 @@ DateAddedFilterNode::DateAddedFilterNode(const QString& argument) | |
|
|
||
| QDateTime DateAddedFilterNode::parseDate(const QString& dateStr) const { | ||
| // Try ISO format first (YYYY-MM-DD) | ||
| // This is used by the "New" filter of the Analyze feature | ||
| qWarning() << "--> parse date" << dateStr; | ||
| QDate date = QDate::fromString(dateStr, Qt::ISODate); | ||
|
|
||
| if (!date.isValid()) { | ||
| // Try user date format set in library preferences | ||
| const QString dateFormat = BaseTrackTableModel::dateFormat(); | ||
| qWarning() << "--> invalid, try Lib format" << dateFormat; | ||
| #if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) | ||
| date = QDate::fromString(dateStr, dateFormat); | ||
|
ronso0 marked this conversation as resolved.
|
||
| // The Mixxx project was started in 2001 :) | ||
| if (date.isValid() && date.year() < 2000) { | ||
| qWarning() << "--> -> year" << date.year() << "< 2000, add 100"; | ||
| date = date.addYears(100); | ||
| qWarning() << "--> -> year < 2000, add 100" << date; | ||
| } | ||
| #else | ||
| date = QDate::fromString(dateStr, dateFormat, 2000); | ||
| #endif | ||
| } | ||
|
|
||
| if (!date.isValid()) { | ||
| qWarning() << "--> invalid, try locale format" | ||
| << QLocale().dateFormat(QLocale::ShortFormat); | ||
| // Maybe custom user format is too esoteric, or user picked | ||
| // their locale's format. | ||
| // Fall back to locale-specific short format | ||
| #if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) | ||
| // If the year component has only two digits Qt assumes the base year is 1900. | ||
| date = QLocale().toDate(dateStr, QLocale::ShortFormat); | ||
| // The Mixxx project was started in 2001 :) | ||
| if (date.isValid() && date.year() < 2000) { | ||
| qWarning() << "--> -> year" << date.year() << "< 2000, add 100"; | ||
| date = date.addYears(100); | ||
| } | ||
| #else | ||
| date = QLocale().toDate(dateStr, QLocale::ShortFormat, 20); | ||
| // With Qt 6.7+ we need to specify the base year. | ||
| date = QLocale().toDate(dateStr, QLocale::ShortFormat, 2001); | ||
|
Comment on lines
+909
to
+941
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, there is NO date filter test. And I'm not motivated to write one atm.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I have no clue how to involve BaseTrackTableModel into the test 🤷♂️ |
||
| #endif | ||
| } | ||
| if (!date.isValid()) { | ||
| qWarning() << "--> invalid, return"; | ||
| return {}; | ||
| } | ||
| qWarning() << "--> valid date:" << date; | ||
|
|
||
| if (date.year() < 2000) { | ||
| date = date.addYears(100); | ||
| } | ||
|
|
||
| // Return local date/time, don't convert to UTC, yet | ||
| return QDateTime(date, QTime(0, 0)).toUTC(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,39 +341,39 @@ void DlgPrefLibrary::slotUpdate() { | |
| checkBox_show_serato->setChecked(m_pConfig->getValue( | ||
| ConfigKey("[Library]", "ShowSeratoLibrary"), true)); | ||
|
|
||
| QString dateFormat = m_pConfig->getValue( | ||
| m_dateFormat = m_pConfig->getValue( | ||
| kDateFormatConfigKey, | ||
| BaseTrackTableModel::kDateFormatDefault); | ||
| qWarning() << "slotUpdate, dateformat:" << m_dateFormat; | ||
|
ronso0 marked this conversation as resolved.
|
||
|
|
||
| // Determine the matching preset or custom | ||
| BaseTrackTableModel::DateFormat preset = BaseTrackTableModel::DateFormat::Custom; | ||
| if (dateFormat.isEmpty()) { | ||
| if (m_dateFormat.isEmpty()) { | ||
| preset = BaseTrackTableModel::DateFormat::Native; | ||
| } else if (dateFormat == QStringLiteral("yyyy-MM-dd")) { | ||
| } else if (m_dateFormat == QStringLiteral("yyyy-MM-dd")) { | ||
| preset = BaseTrackTableModel::DateFormat::ISO8601; | ||
| } else if (dateFormat == QStringLiteral("d/M/yy")) { | ||
| } else if (m_dateFormat == QStringLiteral("d/M/yy")) { | ||
| preset = BaseTrackTableModel::DateFormat::RegionalShort; | ||
| } else if (dateFormat == QStringLiteral("dd.MM.yyyy")) { | ||
| } else if (m_dateFormat == QStringLiteral("dd.MM.yyyy")) { | ||
| preset = BaseTrackTableModel::DateFormat::RegionalLong; | ||
| } else { | ||
| m_lastCustomDateFormat = m_dateFormat; | ||
| qWarning() << "-> type: Custom"; | ||
| qWarning() << "-> store last custom format:" << m_lastCustomDateFormat; | ||
| } | ||
|
|
||
| int dateIndex = comboBox_dateFormat->findData(QVariant::fromValue(preset)); | ||
| qWarning() << "-> idx:" << dateIndex; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these warnings look more like debug comments. The mixxx warning log is already very noisy, try to be efficient and minimal in your logging output, with as few lines as possible and identifying information in the line about what's being logged. Probably these can all be totally removed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's from the TRACE commit which is of course removed before merge. The other commits look good? |
||
| if (dateIndex != -1) { | ||
| qWarning() << "-> setCurrIdx"; | ||
| const QSignalBlocker signalBlocker(comboBox_dateFormat); | ||
| comboBox_dateFormat->setCurrentIndex(dateIndex); | ||
| slotDateFormatIndexChanged(dateIndex); | ||
| } | ||
|
|
||
| if (preset == BaseTrackTableModel::DateFormat::Custom) { | ||
| comboBox_dateFormat->setEditable(true); | ||
| comboBox_dateFormat->setEditText(dateFormat); | ||
| m_lastCustomDateFormat = dateFormat; | ||
| } else { | ||
| comboBox_dateFormat->setEditable(false); | ||
| } | ||
|
|
||
| updateDateFormatPreview(dateFormat); | ||
|
|
||
| // Ensure the static member is updated on startup/load | ||
| BaseTrackTableModel::setDateFormat(dateFormat); | ||
| // Ensure the format is applied to the library view on startup/load | ||
| BaseTrackTableModel::setDateFormat(m_dateFormat); | ||
| updateDateFormatPreview(); | ||
|
|
||
| switch (m_pConfig->getValue<int>( | ||
| kTrackDoubleClickActionConfigKey, | ||
|
|
@@ -664,6 +664,9 @@ void DlgPrefLibrary::slotApply() { | |
| m_iOriginalTrackTableRowHeight = rowHeight; | ||
| } | ||
|
|
||
| m_pConfig->setValue(kDateFormatConfigKey, m_dateFormat); | ||
| BaseTrackTableModel::setDateFormat(m_dateFormat); | ||
|
|
||
| BaseTrackTableModel::setApplyPlayedTrackColor( | ||
| checkbox_played_track_color->isChecked()); | ||
| m_pConfig->set( | ||
|
|
@@ -782,20 +785,21 @@ void DlgPrefLibrary::setSeratoMetadataEnabled(bool shouldSyncTrackMetadata) { | |
| } | ||
|
|
||
| void DlgPrefLibrary::slotDateFormatIndexChanged(int index) { | ||
| qWarning() << " slotDateFormatIndexChanged" << index; | ||
| auto type = comboBox_dateFormat->itemData(index) | ||
| .value<BaseTrackTableModel::DateFormat>(); | ||
|
|
||
| QString format; | ||
| if (type == BaseTrackTableModel::DateFormat::Custom) { | ||
| // Enable editing for Custom | ||
| if (!comboBox_dateFormat->isEditable()) { | ||
| comboBox_dateFormat->setEditable(true); | ||
| comboBox_dateFormat->setEditText(m_lastCustomDateFormat); | ||
| } | ||
| qWarning() << " -> Custom, format:" << m_lastCustomDateFormat; | ||
| // Enable editing for Custom and set the custom format string | ||
| comboBox_dateFormat->setEditable(true); | ||
| comboBox_dateFormat->setEditText(m_lastCustomDateFormat); | ||
| format = m_lastCustomDateFormat; | ||
| qWarning() << " -> box text: " << comboBox_dateFormat->currentText(); | ||
| } else { | ||
| // Disable editing for Presets | ||
| comboBox_dateFormat->setEditable(false); | ||
|
|
||
| QString format; | ||
| switch (type) { | ||
| case BaseTrackTableModel::DateFormat::Native: | ||
| format = QString(); | ||
|
|
@@ -813,12 +817,13 @@ void DlgPrefLibrary::slotDateFormatIndexChanged(int index) { | |
| // Should not happen here given the if/else above | ||
| break; | ||
| } | ||
| slotDateFormatChanged(format); | ||
| } | ||
| slotDateFormatChanged(format); | ||
| } | ||
|
|
||
| void DlgPrefLibrary::slotDateFormatChanged(const QString& text) { | ||
| QString format = text; | ||
| qWarning() << " slotDateFormatChanged, text:" << text; | ||
|
ronso0 marked this conversation as resolved.
|
||
| m_dateFormat = text; | ||
| // If not editable, we are in a Preset mode, but 'text' might be the Item | ||
| // Label (e.g. "Native ...") depending on how this was called. However, our | ||
| // slotDateFormatIndexChanged calls this explicitly with the correct format | ||
|
|
@@ -831,16 +836,14 @@ void DlgPrefLibrary::slotDateFormatChanged(const QString& text) { | |
| auto type = comboBox_dateFormat->itemData(index) | ||
| .value<BaseTrackTableModel::DateFormat>(); | ||
| if (type == BaseTrackTableModel::DateFormat::Custom) { | ||
| m_lastCustomDateFormat = format; | ||
| m_lastCustomDateFormat = m_dateFormat; | ||
| } | ||
| } | ||
| } | ||
| updateDateFormatPreview(); | ||
| } | ||
|
|
||
| void DlgPrefLibrary::updateDateFormatPreview(const QString& format) { | ||
| const QString previewStr = mixxx::formatDate(QDate::currentDate(), format); | ||
| void DlgPrefLibrary::updateDateFormatPreview() { | ||
| const QString previewStr = mixxx::formatDate(QDate::currentDate(), m_dateFormat); | ||
| label_dateFormatPreview->setText(previewStr); | ||
|
|
||
| m_pConfig->setValue(kDateFormatConfigKey, format); | ||
| BaseTrackTableModel::setDateFormat(format); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, fixed