Skip to content

Commit 17f4dca

Browse files
committed
TEST: update track table after applying new date format in preferences
1 parent 93d6981 commit 17f4dca

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/library/basetracktablemodel.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,38 @@ void BaseTrackTableModel::setKeyColorPalette(const ColorPalette& palette) {
111111
bool BaseTrackTableModel::s_bApplyPlayedTrackColor =
112112
kApplyPlayedTrackColorDefault;
113113

114+
// static
114115
void BaseTrackTableModel::setApplyPlayedTrackColor(bool apply) {
115116
s_bApplyPlayedTrackColor = apply;
116117
}
117118

118119
const QString BaseTrackTableModel::kDateFormatDefault = QString();
119120
QString BaseTrackTableModel::s_dateFormat = BaseTrackTableModel::kDateFormatDefault;
120121

122+
// static
121123
void BaseTrackTableModel::setDateFormat(const QString& format) {
122124
s_dateFormat = format;
125+
emit broadcaster()->dateFormatChanged();
126+
}
127+
128+
void BaseTrackTableModel::slotEmitDataChangedForDateColumns() {
129+
// Notify the view to update.
130+
// These are the columns that use s_dateFormat
131+
QList<int> columns;
132+
columns.append(fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED));
133+
columns.append(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_DATETIMEADDED));
134+
columns.append(fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT));
135+
const QVector<int> roles{Qt::DisplayRole};
136+
QModelIndex topLeft;
137+
QModelIndex bottomRight;
138+
for (int i : columns) {
139+
if (i == -1) {
140+
continue;
141+
}
142+
topLeft = index(0, i);
143+
bottomRight = index(rowCount() - 1, i);
144+
emit dataChanged(topLeft, bottomRight, roles);
145+
}
123146
}
124147

125148
BaseTrackTableModel::BaseTrackTableModel(
@@ -148,6 +171,10 @@ BaseTrackTableModel::BaseTrackTableModel(
148171
this,
149172
&BaseTrackTableModel::slotCoverFound);
150173
}
174+
connect(broadcaster(),
175+
&DateFormatChangedBroadcaster::dateFormatChanged,
176+
this,
177+
&BaseTrackTableModel::slotEmitDataChangedForDateColumns);
151178
}
152179

153180
void BaseTrackTableModel::initTableColumnsAndHeaderProperties(

src/library/basetracktablemodel.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
class TrackCollectionManager;
1515

16+
/// Broadcaster (singleton) that instances connect to in order to
17+
/// refresh columns using static s_dateFormat after a new format has been set
18+
class DateFormatChangedBroadcaster : public QObject {
19+
Q_OBJECT
20+
signals:
21+
void dateFormatChanged();
22+
};
23+
1624
/// Base class for tabular track list views.
1725
///
1826
/// The abstract model behind `WTrackTableView`.
@@ -280,6 +288,8 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
280288
const CoverInfo& coverInfo,
281289
const QPixmap& pixmap);
282290

291+
void slotEmitDataChangedForDateColumns();
292+
283293
private:
284294
QVariant rawSiblingValue(
285295
const QModelIndex& index,
@@ -300,6 +310,11 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
300310
QList<QUrl> collectUrls(
301311
const QModelIndexList& indexes) const;
302312

313+
static DateFormatChangedBroadcaster* broadcaster() {
314+
static DateFormatChangedBroadcaster instance;
315+
return &instance;
316+
}
317+
303318
const QString m_previewDeckGroup;
304319

305320
double m_backgroundColorOpacity;

0 commit comments

Comments
 (0)