Skip to content
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

Create TrackSetTableModel as base for Crate- & PlaylistTableModel #2717

Merged
merged 7 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/trackcollection.cpp
src/library/trackcollectionmanager.cpp
src/library/trackloader.cpp
src/library/tracksettablemodel.cpp
src/library/traktor/traktorfeature.cpp
src/library/treeitem.cpp
src/library/treeitemmodel.cpp
Expand Down
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ def sources(self, build):
"src/library/crate/cratetablemodel.cpp",

"src/library/playlisttablemodel.cpp",
"src/library/tracksettablemodel.cpp",
"src/library/libraryfeature.cpp",
"src/library/analysisfeature.cpp",
"src/library/autodj/autodjfeature.cpp",
Expand Down
7 changes: 2 additions & 5 deletions src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ TrackId BaseExternalPlaylistModel::getTrackId(const QModelIndex& index) const {
}

bool BaseExternalPlaylistModel::isColumnInternal(int column) {
if (column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
return column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
(PlayerManager::numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW))) {
return true;
}
return false;
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW));
}

Qt::ItemFlags BaseExternalPlaylistModel::flags(const QModelIndex &index) const {
Expand Down
8 changes: 2 additions & 6 deletions src/library/baseexternaltrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,9 @@ TrackId BaseExternalTrackModel::doGetTrackId(const TrackPointer& pTrack) const {
}

bool BaseExternalTrackModel::isColumnInternal(int column) {
// Used for preview deck widgets.
if (column == fieldIndex(LIBRARYTABLE_ID) ||
return column == fieldIndex(LIBRARYTABLE_ID) ||
(PlayerManager::numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW))) {
return true;
}
return false;
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW));
}

Qt::ItemFlags BaseExternalTrackModel::flags(const QModelIndex &index) const {
Expand Down
5 changes: 1 addition & 4 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ BaseSqlTableModel::BaseSqlTableModel(
QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace)
: BaseTrackTableModel(
settingsNamespace,
pTrackCollectionManager,
parent),
: BaseTrackTableModel(parent, pTrackCollectionManager, settingsNamespace),
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
m_pTrackCollectionManager(pTrackCollectionManager),
m_database(pTrackCollectionManager->internalCollection()->database()),
m_bInitialized(false),
Expand Down
8 changes: 3 additions & 5 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ QStringList BaseTrackTableModel::defaultTableColumns() {
}

BaseTrackTableModel::BaseTrackTableModel(
const char* settingsNamespace,
QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
QObject* parent)
const char* settingsNamespace)
: QAbstractTableModel(parent),
TrackModel(
cloneDatabase(pTrackCollectionManager),
settingsNamespace),
TrackModel(cloneDatabase(pTrackCollectionManager), settingsNamespace),
m_pTrackCollectionManager(pTrackCollectionManager),
m_previewDeckGroup(PlayerManager::groupForPreviewDeck(0)),
m_backgroundColorOpacity(WLibrary::kDefaultTrackTableBackgroundColorOpacity) {
Expand Down
4 changes: 2 additions & 2 deletions src/library/basetracktablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {

public:
explicit BaseTrackTableModel(
const char* settingsNamespace,
QObject* parent,
TrackCollectionManager* const pTrackCollectionManager,
QObject* parent);
const char* settingsNamespace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like this can be a QString initialized by a QStringLiteral()
Since we store the value finally, you may use a value parameter + std::move() when passing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have to be changed in quite a few places, so I'd like to refrain from that for now

~BaseTrackTableModel() override = default;

///////////////////////////////////////////////////////
Expand Down
8 changes: 1 addition & 7 deletions src/library/crate/crateid.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef MIXXX_CRATEID_H
#define MIXXX_CRATEID_H

#pragma once

#include "util/db/dbid.h"


class CrateId: public DbId {
public:
// Inherit constructors from base class
Expand All @@ -13,6 +10,3 @@ class CrateId: public DbId {

Q_DECLARE_TYPEINFO(CrateId, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(CrateId)


#endif // MIXXX_CRATEID_H
29 changes: 4 additions & 25 deletions src/library/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "library/crate/cratetablemodel.h"

#include "library/dao/trackschema.h"
Expand All @@ -7,15 +6,10 @@
#include "mixer/playermanager.h"
#include "util/db/fwdsqlquery.h"

#include <QtDebug>

CrateTableModel::CrateTableModel(QObject* pParent,
TrackCollectionManager* pTrackCollectionManager)
: BaseSqlTableModel(pParent, pTrackCollectionManager,
"mixxx.db.model.crate") {
}

CrateTableModel::~CrateTableModel() {
CrateTableModel::CrateTableModel(
QObject* pParent,
TrackCollectionManager* pTrackCollectionManager)
: TrackSetTableModel(pParent, pTrackCollectionManager, "mixxx.db.model.crate") {
}

void CrateTableModel::selectCrate(CrateId crateId) {
Expand Down Expand Up @@ -127,21 +121,6 @@ TrackModel::CapabilitiesFlags CrateTableModel::getCapabilities() const {
return caps;
}

bool CrateTableModel::isColumnInternal(int column) {
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID)||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH);;
}

int CrateTableModel::addTracks(const QModelIndex& index,
const QList<QString>& locations) {
Q_UNUSED(index);
Expand Down
24 changes: 8 additions & 16 deletions src/library/crate/cratetablemodel.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
#ifndef MIXXX_CRATETABLEMODEL_H
#define MIXXX_CRATETABLEMODEL_H

#pragma once

#include "library/basesqltablemodel.h"

#include "library/crate/crateid.h"
#include "library/tracksettablemodel.h"


class CrateTableModel : public BaseSqlTableModel {
class CrateTableModel : public TrackSetTableModel {
Q_OBJECT

public:
CrateTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager);
~CrateTableModel() final;
~CrateTableModel() final = default;

void selectCrate(
CrateId crateId = CrateId());
void selectCrate(CrateId crateId = CrateId());
CrateId selectedCrate() const {
return m_selectedCrate;
}

bool addTrack(const QModelIndex &index, QString location);
bool addTrack(const QModelIndex& index, QString location);

// From TrackModel
bool isColumnInternal(int column) final;
void removeTracks(const QModelIndexList& indices) final;
// Returns the number of unsuccessful track additions
/// Returns the number of unsuccessful additions.
int addTracks(const QModelIndex& index, const QList<QString>& locations) final;

CapabilitiesFlags getCapabilities() const final;

private:
CrateId m_selectedCrate;
};


#endif // MIXXX_CRATETABLEMODEL_H
9 changes: 3 additions & 6 deletions src/library/hiddentablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,16 @@ void HiddenTableModel::unhideTracks(const QModelIndexList& indices) {
}

bool HiddenTableModel::isColumnInternal(int column) {
if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID)||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH)) {
return true;
}
return false;
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH);
}

// Override flags from BaseSqlModel since we don't want edit this model
Expand Down
38 changes: 17 additions & 21 deletions src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,24 @@ int LibraryTableModel::addTracks(const QModelIndex& index,
}

bool LibraryTableModel::isColumnInternal(int column) {
if ((column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_URL)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CUEPOINT)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_WAVESUMMARYHEX)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_SAMPLERATE)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_HEADERPARSED)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID))||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS)) ||
(column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED)) ||
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_URL) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CUEPOINT) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_WAVESUMMARYHEX) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_SAMPLERATE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_HEADERPARSED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION)) ||
(column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH))) {
return true;
}

return false;
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH);
}

TrackModel::CapabilitiesFlags LibraryTableModel::getCapabilities() const {
Expand Down
9 changes: 3 additions & 6 deletions src/library/missingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ void MissingTableModel::purgeTracks(const QModelIndexList& indices) {


bool MissingTableModel::isColumnInternal(int column) {
if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID)||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH)) {
return true;
}
return false;
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH);
}

// Override flags from BaseSqlModel since we don't want edit this model
Expand Down
37 changes: 11 additions & 26 deletions src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"

#include "mixer/playermanager.h"

PlaylistTableModel::PlaylistTableModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
bool showAll)
: BaseSqlTableModel(parent, pTrackCollectionManager, settingsNamespace),
PlaylistTableModel::PlaylistTableModel(
QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
bool keepDeletedTracks)
: TrackSetTableModel(parent, pTrackCollectionManager, settingsNamespace),
m_iPlaylistId(-1),
m_showAll(showAll) {
m_keepDeletedTracks(keepDeletedTracks) {
}

void PlaylistTableModel::initSortColumnMapping() {
Expand Down Expand Up @@ -62,10 +61,10 @@ void PlaylistTableModel::setTableModel(int playlistId) {

m_iPlaylistId = playlistId;

if (!m_showAll) {
if (!m_keepDeletedTracks) {
// From Mixxx 2.1 we drop tracks that have been explicitly deleted
// in the library (mixxx_deleted = 0) from playlists.
// These invisible tracks, consuming a playlist position number where
// These invisible tracks, consuming a playlist position number were
// a source user of confusion in the past.
m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().removeHiddenTracks(m_iPlaylistId);
}
Expand Down Expand Up @@ -244,22 +243,8 @@ void PlaylistTableModel::shuffleTracks(const QModelIndexList& shuffle, const QMo
}

bool PlaylistTableModel::isColumnInternal(int column) {
if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID)||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH)) {
return true;
}
return false;
return column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
TrackSetTableModel::isColumnInternal(column);
}

bool PlaylistTableModel::isColumnHiddenByDefault(int column) {
Expand Down
Loading