#include "library/basetracktablemodel.h"
#include "library/bpmdelegate.h"
#include "library/colordelegate.h"
#include "library/coverartcache.h"
#include "library/coverartdelegate.h"
#include "library/dao/trackschema.h"
#include "library/locationdelegate.h"
#include "library/previewbuttondelegate.h"
#include "library/stardelegate.h"
#include "library/starrating.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_basetracktablemodel.cpp"
#include "track/track.h"
#include "util/assert.h"
#include "util/compatibility.h"
#include "util/datetime.h"
#include "util/logger.h"
#include "widget/wlibrary.h"
#include "widget/wtracktableview.h"
namespace {
const mixxx::Logger kLogger("BaseTrackTableModel");
constexpr double kRelativeHeightOfCoverartToolTip =
0.165; // Height of the image for the cover art tooltip (Relative to the available screen size)
const QStringList kDefaultTableColumns = {
LIBRARYTABLE_ALBUM,
LIBRARYTABLE_ALBUMARTIST,
LIBRARYTABLE_ARTIST,
LIBRARYTABLE_BPM,
LIBRARYTABLE_BPM_LOCK,
LIBRARYTABLE_BITRATE,
LIBRARYTABLE_CHANNELS,
LIBRARYTABLE_COLOR,
LIBRARYTABLE_COMMENT,
LIBRARYTABLE_COMPOSER,
LIBRARYTABLE_COVERART,
LIBRARYTABLE_DATETIMEADDED,
LIBRARYTABLE_DURATION,
LIBRARYTABLE_FILETYPE,
LIBRARYTABLE_GENRE,
LIBRARYTABLE_GROUPING,
LIBRARYTABLE_KEY,
LIBRARYTABLE_LOCATION,
LIBRARYTABLE_PLAYED,
LIBRARYTABLE_PREVIEW,
LIBRARYTABLE_RATING,
LIBRARYTABLE_REPLAYGAIN,
LIBRARYTABLE_SAMPLERATE,
LIBRARYTABLE_TIMESPLAYED,
LIBRARYTABLE_TITLE,
LIBRARYTABLE_TRACKNUMBER,
LIBRARYTABLE_YEAR,
};
inline QSqlDatabase cloneDatabase(
const QSqlDatabase& prototype) {
const auto connectionName =
uuidToStringWithoutBraces(QUuid::createUuid());
auto cloned = QSqlDatabase::cloneDatabase(
prototype,
connectionName);
DEBUG_ASSERT(cloned.isValid());
if (prototype.isOpen() && !cloned.open()) {
kLogger.warning()
<< "Failed to open cloned database connection"
<< cloned
<< cloned.lastError();
}
return cloned;
}
QSqlDatabase cloneDatabase(
TrackCollectionManager* pTrackCollectionManager) {
VERIFY_OR_DEBUG_ASSERT(pTrackCollectionManager &&
pTrackCollectionManager->internalCollection()) {
return QSqlDatabase();
}
return cloneDatabase(
pTrackCollectionManager->internalCollection()->database());
}
} // anonymous namespace
//static
QStringList BaseTrackTableModel::defaultTableColumns() {
return kDefaultTableColumns;
}
BaseTrackTableModel::BaseTrackTableModel(
const char* settingsNamespace,
TrackCollectionManager* pTrackCollectionManager,
QObject* parent)
: QAbstractTableModel(parent),
TrackModel(
cloneDatabase(pTrackCollectionManager),
settingsNamespace),
m_pTrackCollectionManager(pTrackCollectionManager),
m_previewDeckGroup(PlayerManager::groupForPreviewDeck(0)),
m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity) {
connect(&pTrackCollectionManager->internalCollection()->getTrackDAO(),
&TrackDAO::forceModelUpdate,
this,
&BaseTrackTableModel::slotRefreshAllRows);
connect(&PlayerInfo::instance(),
&PlayerInfo::trackLoaded,
this,
&BaseTrackTableModel::slotTrackLoaded);
}
void BaseTrackTableModel::initTableColumnsAndHeaderProperties(
const QStringList& tableColumns) {
m_columnCache.setColumns(tableColumns);
if (m_columnHeaders.size() < tableColumns.size()) {
m_columnHeaders.resize(tableColumns.size());
}
initHeaderProperties();
}
void BaseTrackTableModel::initHeaderProperties() {
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ALBUM,
tr("Album"),
defaultColumnWidth() * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST,
tr("Album Artist"),
defaultColumnWidth() * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_ARTIST,
tr("Artist"),
defaultColumnWidth() * 4);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_BITRATE,
tr("Bitrate"),
defaultColumnWidth());
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_BPM,
tr("BPM"),
defaultColumnWidth() * 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS,
tr("Channels"),
defaultColumnWidth() / 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COLOR,
tr("Color"),
defaultColumnWidth() / 2);
setHeaderProperties(
ColumnCache::COLUMN_LIBRARYTABLE_COMMENT,
tr("Comment"),
defaultColumnWidth() * 6);
setHeaderProperties(
ColumnCac