Skip to content

Commit

Permalink
Reformat long lines & clean up tablemodels
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed May 21, 2020
1 parent 75a4012 commit 694ee97
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
10 changes: 6 additions & 4 deletions src/library/hiddentablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ HiddenTableModel::~HiddenTableModel() {
}

void HiddenTableModel::setTableModel() {
QSqlQuery query(m_database);
const QString tableName("hidden_songs");

QStringList columns;
columns << "library." + LIBRARYTABLE_ID;
// clang-format off
query.prepare("CREATE TEMPORARY VIEW IF NOT EXISTS " + tableName + " AS "
"SELECT " + columns.join(",") + " FROM library "

QSqlQuery query(m_database);
query.prepare(
"CREATE TEMPORARY VIEW IF NOT EXISTS " + tableName +
" AS SELECT " + columns.join(",") +
" FROM library "
"INNER JOIN track_locations "
"ON library.location=track_locations.id "
"WHERE mixxx_deleted=1");
Expand Down
34 changes: 13 additions & 21 deletions src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
#include "library/trackcollectionmanager.h"
#include "mixer/playermanager.h"

namespace {

const QString kDefaultLibraryFilter =
"mixxx_deleted=0 AND fs_deleted=0";

} // anonymous namespace

LibraryTableModel::LibraryTableModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace)
Expand All @@ -23,28 +16,24 @@ LibraryTableModel::LibraryTableModel(QObject* parent,
LibraryTableModel::~LibraryTableModel() {
}

void LibraryTableModel::setTableModel(int id) {
Q_UNUSED(id);
void LibraryTableModel::setTableModel() {
const QString tableName("library_view");

QStringList columns;
columns << "library." + LIBRARYTABLE_ID
<< "'' AS " + LIBRARYTABLE_PREVIEW
// For sorting the cover art column we give LIBRARYTABLE_COVERART
// the same value as the cover hash.
<< LIBRARYTABLE_COVERART_HASH + " AS " + LIBRARYTABLE_COVERART;

const QString tableName = "library_view";

QSqlQuery query(m_database);
QString queryString =
query.prepare(
"CREATE TEMPORARY VIEW IF NOT EXISTS " + tableName +
" AS "
"SELECT " +
columns.join(", ") +
" FROM library INNER JOIN track_locations "
"ON library.location = track_locations.id "
"WHERE (" +
kDefaultLibraryFilter + ")";
query.prepare(queryString);
" AS SELECT " + columns.join(",") +
" FROM library "
"INNER JOIN track_locations "
"ON library.location=track_locations.id "
"WHERE (mixxx_deleted=0 AND fs_deleted=0)");
if (!query.exec()) {
LOG_FAILED_QUERY(query);
}
Expand All @@ -53,7 +42,10 @@ void LibraryTableModel::setTableModel(int id) {
tableColumns << LIBRARYTABLE_ID;
tableColumns << LIBRARYTABLE_PREVIEW;
tableColumns << LIBRARYTABLE_COVERART;
setTable(tableName, LIBRARYTABLE_ID, tableColumns, m_pTrackCollectionManager->internalCollection()->getTrackSource());
setTable(tableName,
LIBRARYTABLE_ID,
tableColumns,
m_pTrackCollectionManager->internalCollection()->getTrackSource());
setSearch("");
setDefaultSort(fieldIndex("artist"), Qt::AscendingOrder);

Expand Down
2 changes: 1 addition & 1 deletion src/library/librarytablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LibraryTableModel : public BaseSqlTableModel {
const char* settingsNamespace);
~LibraryTableModel() override;

void setTableModel(int id =-1);
void setTableModel();

bool isColumnInternal(int column) final;
// Takes a list of locations and add the tracks to the library. Returns the
Expand Down
13 changes: 9 additions & 4 deletions src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ void PlaylistTableModel::setTableModel(int playlistId) {
// columns[2] = PLAYLISTTRACKSTABLE_DATETIMEADDED from above
columns[3] = LIBRARYTABLE_PREVIEW;
columns[4] = LIBRARYTABLE_COVERART;
setTable(playlistTableName, LIBRARYTABLE_ID, columns, m_pTrackCollectionManager->internalCollection()->getTrackSource());
setTable(playlistTableName,
LIBRARYTABLE_ID,
columns,
m_pTrackCollectionManager->internalCollection()->getTrackSource());
setSearch("");
setDefaultSort(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION), Qt::AscendingOrder);
setSort(defaultSortColumn(), defaultSortOrder());
Expand Down Expand Up @@ -281,14 +284,16 @@ TrackModel::CapabilitiesFlags PlaylistTableModel::getCapabilities() const {
TRACKMODELCAPS_LOADTOPREVIEWDECK |
TRACKMODELCAPS_RESETPLAYED;

if (m_iPlaylistId != m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().getPlaylistIdFromName(AUTODJ_TABLE)) {
if (m_iPlaylistId !=
m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().getPlaylistIdFromName(AUTODJ_TABLE)) {
// Only allow Add to AutoDJ if we aren't currently showing the AutoDJ queue.
caps |= TRACKMODELCAPS_ADDTOAUTODJ | TRACKMODELCAPS_REMOVE_PLAYLIST;
} else {
caps |= TRACKMODELCAPS_REMOVE;
}
if (m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().getHiddenType(m_iPlaylistId) == PlaylistDAO::PLHT_SET_LOG) {
// Disable reording tracks for history playlists
if (PlaylistDAO::PLHT_SET_LOG ==
m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().getHiddenType(m_iPlaylistId)) {
// Disable track reordering for history playlists
caps &= ~(TRACKMODELCAPS_REORDER | TRACKMODELCAPS_REMOVE_PLAYLIST);
}
bool locked = m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().isPlaylistLocked(m_iPlaylistId);
Expand Down
17 changes: 13 additions & 4 deletions src/library/trackset/crate/cratestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,18 @@ CrateSummarySelectResult CrateStorage::selectCratesWithTrackCount(const QList<Tr

CrateTrackSelectResult CrateStorage::selectTracksSortedByCrateNameLike(const QString& crateNameLike) const {
FwdSqlQuery query(m_database,
QString("SELECT %1,%2 FROM %3 JOIN %4 ON %5 = %6 WHERE %7 LIKE :crateNameLike ORDER BY %1")
.arg(CRATETRACKSTABLE_TRACKID, CRATETRACKSTABLE_CRATEID, CRATE_TRACKS_TABLE, CRATE_TABLE, CRATETABLE_ID, CRATETRACKSTABLE_CRATEID, CRATETABLE_NAME));
QString("SELECT %1,%2 FROM %3 "
"JOIN %4 ON %5 = %6 "
"WHERE %7 LIKE :crateNameLike "
"ORDER BY %1")
.arg(
CRATETRACKSTABLE_TRACKID,
CRATETRACKSTABLE_CRATEID,
CRATE_TRACKS_TABLE,
CRATE_TABLE,
CRATETABLE_ID,
CRATETRACKSTABLE_CRATEID,
CRATETABLE_NAME));
query.bindValue(":crateNameLike", QVariant(kSqlLikeMatchAll + crateNameLike + kSqlLikeMatchAll));

if (query.execPrepared()) {
Expand All @@ -488,8 +498,7 @@ CrateTrackSelectResult CrateStorage::selectTracksSortedByCrateNameLike(const QSt
TrackSelectResult CrateStorage::selectAllTracksSorted() const {
FwdSqlQuery query(m_database,
QString("SELECT DISTINCT %1 FROM %2 ORDER BY %1")
.arg(CRATETRACKSTABLE_TRACKID, // %1
CRATE_TRACKS_TABLE)); // %2
.arg(CRATETRACKSTABLE_TRACKID, CRATE_TRACKS_TABLE));
if (query.execPrepared()) {
return TrackSelectResult(std::move(query));
} else {
Expand Down

0 comments on commit 694ee97

Please sign in to comment.