Skip to content

Commit 19cabc0

Browse files
committed
TEST: add DateFormatChangedBroadcaster to force-update track table views
1 parent 93d6981 commit 19cabc0

7 files changed

Lines changed: 73 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ add_library(
13881388
src/library/coverart.cpp
13891389
src/library/coverartcache.cpp
13901390
src/library/coverartutils.cpp
1391+
src/library/dateformatbroadcaster.cpp
13911392
src/library/dao/analysisdao.cpp
13921393
src/library/dao/autodjcratesdao.cpp
13931394
src/library/dao/cuedao.cpp

src/library/basetracktablemodel.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "base/Pitch.h"
1010
#include "library/coverartcache.h"
1111
#include "library/dao/trackschema.h"
12+
#include "library/dateformatbroadcaster.h"
1213
#include "library/starrating.h"
1314
#include "library/tabledelegates/bpmdelegate.h"
1415
#include "library/tabledelegates/checkboxdelegate.h"
@@ -111,15 +112,42 @@ void BaseTrackTableModel::setKeyColorPalette(const ColorPalette& palette) {
111112
bool BaseTrackTableModel::s_bApplyPlayedTrackColor =
112113
kApplyPlayedTrackColorDefault;
113114

115+
// static
114116
void BaseTrackTableModel::setApplyPlayedTrackColor(bool apply) {
115117
s_bApplyPlayedTrackColor = apply;
116118
}
117119

118120
const QString BaseTrackTableModel::kDateFormatDefault = QString();
119121
QString BaseTrackTableModel::s_dateFormat = BaseTrackTableModel::kDateFormatDefault;
120122

123+
// static
121124
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+
}
123151
}
124152

125153
BaseTrackTableModel::BaseTrackTableModel(
@@ -148,6 +176,12 @@ BaseTrackTableModel::BaseTrackTableModel(
148176
this,
149177
&BaseTrackTableModel::slotCoverFound);
150178
}
179+
180+
auto* dateFormatBroadcaster = DateFormatChangedBroadcaster::instance();
181+
connect(dateFormatBroadcaster,
182+
&DateFormatChangedBroadcaster::dateFormatChanged,
183+
this,
184+
&BaseTrackTableModel::slotEmitDataChangedForDateColumns);
151185
}
152186

153187
void BaseTrackTableModel::initTableColumnsAndHeaderProperties(

src/library/basetracktablemodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
280280
const CoverInfo& coverInfo,
281281
const QPixmap& pixmap);
282282

283+
/// Called via signal from DateFormatChangedBroadcaster,
284+
/// will tell the view(s) to repaint date columns when visible
285+
void slotEmitDataChangedForDateColumns();
286+
283287
private:
284288
QVariant rawSiblingValue(
285289
const QModelIndex& index,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "library/dateformatbroadcaster.h"
2+
3+
#include "moc_dateformatbroadcaster.cpp"
4+
5+
DateFormatChangedBroadcaster::DateFormatChangedBroadcaster() {
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <QObject>
4+
5+
#include "util/singleton.h"
6+
7+
class DateFormatChangedBroadcaster
8+
: public QObject,
9+
public Singleton<DateFormatChangedBroadcaster> {
10+
Q_OBJECT
11+
public:
12+
signals:
13+
void dateFormatChanged();
14+
15+
protected:
16+
DateFormatChangedBroadcaster();
17+
~DateFormatChangedBroadcaster() override = default;
18+
friend class Singleton<DateFormatChangedBroadcaster>;
19+
};

src/library/library.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "library/autodj/autodjfeature.h"
1111
#include "library/banshee/bansheefeature.h"
1212
#include "library/browse/browsefeature.h"
13+
#include "library/dateformatbroadcaster.h"
1314
#ifdef __ENGINEPRIME__
1415
#include "library/export/libraryexporter.h"
1516
#endif
@@ -76,6 +77,8 @@ Library::Library(
7677
mixxx::library::prefs::kKeyNotationConfigKey)) {
7778
qRegisterMetaType<LibraryRemovalType>("LibraryRemovalType");
7879

80+
DateFormatChangedBroadcaster::createInstance();
81+
7982
connect(m_pTrackCollectionManager,
8083
&TrackCollectionManager::libraryScanFinished,
8184
this,
@@ -269,7 +272,9 @@ Library::Library(
269272
kEditMetadataSelectedClickDefault);
270273
}
271274

272-
Library::~Library() = default;
275+
Library::~Library() {
276+
DateFormatChangedBroadcaster::destroy();
277+
}
273278

274279
TrackCollectionManager* Library::trackCollectionManager() const {
275280
// Cannot be implemented inline due to forward declarations

src/test/librarytest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ LibraryTest::LibraryTest()
3535
m_pTrackCollectionManager(newTrackCollectionManager(config(), dbConnectionPooler())),
3636
m_keyNotationCO(mixxx::library::prefs::kKeyNotationConfigKey) {
3737
CoverArtCache::createInstance();
38+
DateFormatChangedBroadcaster::createInstance();
3839
}
3940

4041
LibraryTest::~LibraryTest() {
4142
CoverArtCache::destroy();
43+
DateFormatChangedBroadcaster::destroy();
4244
}
4345

4446
TrackPointer LibraryTest::getOrAddTrackByLocation(

0 commit comments

Comments
 (0)