|
9 | 9 | #include "base/Pitch.h" |
10 | 10 | #include "library/coverartcache.h" |
11 | 11 | #include "library/dao/trackschema.h" |
| 12 | +#include "library/dateformatbroadcaster.h" |
12 | 13 | #include "library/starrating.h" |
13 | 14 | #include "library/tabledelegates/bpmdelegate.h" |
14 | 15 | #include "library/tabledelegates/checkboxdelegate.h" |
@@ -111,15 +112,42 @@ void BaseTrackTableModel::setKeyColorPalette(const ColorPalette& palette) { |
111 | 112 | bool BaseTrackTableModel::s_bApplyPlayedTrackColor = |
112 | 113 | kApplyPlayedTrackColorDefault; |
113 | 114 |
|
| 115 | +// static |
114 | 116 | void BaseTrackTableModel::setApplyPlayedTrackColor(bool apply) { |
115 | 117 | s_bApplyPlayedTrackColor = apply; |
116 | 118 | } |
117 | 119 |
|
118 | 120 | const QString BaseTrackTableModel::kDateFormatDefault = QString(); |
119 | 121 | QString BaseTrackTableModel::s_dateFormat = BaseTrackTableModel::kDateFormatDefault; |
120 | 122 |
|
| 123 | +// static |
121 | 124 | void BaseTrackTableModel::setDateFormat(const QString& format) { |
122 | | - s_dateFormat = format; |
| 125 | + if (format != s_dateFormat) { |
| 126 | + s_dateFormat = format; |
| 127 | + auto* broadcaster = DateFormatChangedBroadcaster::instance(); |
| 128 | + emit broadcaster->dateFormatChanged(); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +void BaseTrackTableModel::slotEmitDataChangedForDateColumns() { |
| 133 | + // Notify the view to update. |
| 134 | + // These are the columns that use s_dateFormat |
| 135 | + QList<int> columns; |
| 136 | + columns.append(fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED)); |
| 137 | + columns.append(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_DATETIMEADDED)); |
| 138 | + columns.append(fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT)); |
| 139 | + const QVector<int> roles{Qt::DisplayRole}; |
| 140 | + QModelIndex topLeft; |
| 141 | + QModelIndex bottomRight; |
| 142 | + for (int i : columns) { |
| 143 | + if (i == -1) { |
| 144 | + // Skip if a certain model doesn't have this column |
| 145 | + continue; |
| 146 | + } |
| 147 | + topLeft = index(0, i); |
| 148 | + bottomRight = index(rowCount() - 1, i); |
| 149 | + emit dataChanged(topLeft, bottomRight, roles); |
| 150 | + } |
123 | 151 | } |
124 | 152 |
|
125 | 153 | BaseTrackTableModel::BaseTrackTableModel( |
@@ -148,6 +176,12 @@ BaseTrackTableModel::BaseTrackTableModel( |
148 | 176 | this, |
149 | 177 | &BaseTrackTableModel::slotCoverFound); |
150 | 178 | } |
| 179 | + |
| 180 | + auto* dateFormatBroadcaster = DateFormatChangedBroadcaster::instance(); |
| 181 | + connect(dateFormatBroadcaster, |
| 182 | + &DateFormatChangedBroadcaster::dateFormatChanged, |
| 183 | + this, |
| 184 | + &BaseTrackTableModel::slotEmitDataChangedForDateColumns); |
151 | 185 | } |
152 | 186 |
|
153 | 187 | void BaseTrackTableModel::initTableColumnsAndHeaderProperties( |
|
0 commit comments