Skip to content

Commit

Permalink
Some more code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Apr 12, 2021
1 parent 4f7f9f7 commit 1f70f71
Show file tree
Hide file tree
Showing 48 changed files with 873 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/engine/sync/enginesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EngineSync : public BaseSyncableListener {
void requestBpmUpdate(Syncable* pSyncable, double bpm) override;
void notifyInstantaneousBpmChanged(Syncable* pSyncable, double bpm) override;
void notifyBeatDistanceChanged(Syncable* pSyncable, double beatDistance) override;
void notifyPlayingAudible(Syncable* pSyncable, bool playing) override;
void notifyPlayingAudible(Syncable* pSyncable, bool playingAudible) override;
void notifyScratching(Syncable* pSyncable, bool scratching) override;

// Used to pick a sync target for cases where master sync mode is not sufficient.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sync/syncable.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SyncableListener {
virtual void notifyBeatDistanceChanged(
Syncable* pSyncable, double beatDistance) = 0;

virtual void notifyPlayingAudible(Syncable* pSyncable, bool playing) = 0;
virtual void notifyPlayingAudible(Syncable* pSyncable, bool playingAudible) = 0;

virtual Syncable* getMasterSyncable() = 0;
};
2 changes: 1 addition & 1 deletion src/engine/sync/synccontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void SyncControl::updateAudible() {
int channelIndex = m_pChannel->getChannelIndex();
if (channelIndex >= 0) {
CSAMPLE_GAIN gain = getEngineMaster()->getMasterGain(channelIndex);
bool newAudible = gain > CSAMPLE_GAIN_ZERO ? true : false;
bool newAudible = gain > CSAMPLE_GAIN_ZERO;
if (m_audible != newAudible) {
m_audible = newAudible;
m_pEngineSync->notifyPlayingAudible(this, m_pPlayButton->toBool() && m_audible);
Expand Down
8 changes: 7 additions & 1 deletion src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "library/trackcollection.h"
#include "preferences/usersettings.h"
#include "track/track_decl.h"
#include "widget/wtracktableview.h"

class PlaylistTableModel;
class WLibrary;
class WTrackTableView;

class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
Q_OBJECT
Expand All @@ -33,6 +33,12 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void loadSelectedTrack() override;
void loadSelectedTrackToGroup(const QString& group, bool play) override;
void moveSelection(int delta) override;
void saveCurrentViewState() override {
m_pTrackTableView->saveCurrentViewState();
};
bool restoreCurrentViewState(bool fromSearch = false) override {
return m_pTrackTableView->restoreCurrentViewState(fromSearch);
};

public slots:
void shufflePlaylistButton(bool buttonChecked);
Expand Down
17 changes: 9 additions & 8 deletions src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#include "track/track.h"

BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
const QString& playlistsTable,
const QString& playlistTracksTable,
QSharedPointer<BaseTrackCache> trackSource)
: BaseSqlTableModel(parent, pTrackCollectionManager,
settingsNamespace),
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
const QString& playlistsTable,
const QString& playlistTracksTable,
QSharedPointer<BaseTrackCache> trackSource)
: BaseSqlTableModel(parent, pTrackCollectionManager, settingsNamespace),
m_playlistsTable(playlistsTable),
m_playlistTracksTable(playlistTracksTable),
m_trackSource(trackSource) {
m_trackSource(trackSource),
m_currentPlaylistId(-1) {
}

BaseExternalPlaylistModel::~BaseExternalPlaylistModel() {
Expand Down Expand Up @@ -140,6 +140,7 @@ void BaseExternalPlaylistModel::setPlaylist(const QString& playlist_path) {
return;
}

m_currentPlaylistId = playlistId;
columns[2] = LIBRARYTABLE_PREVIEW;
setTable(playlistViewTable, columns[0], columns, m_trackSource);
setDefaultSort(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down
23 changes: 18 additions & 5 deletions src/library/baseexternalplaylistmodel.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#pragma once

#include <QtSql>
#include <QItemDelegate>
#include <QString>
#include <QObject>
#include <QModelIndex>
#include <QObject>
#include <QString>
#include <QStringBuilder>
#include <QtSql>

#include "library/trackmodel.h"
#include "library/basesqltablemodel.h"
#include "library/librarytablemodel.h"
#include "library/dao/playlistdao.h"
#include "library/dao/trackdao.h"
#include "library/librarytablemodel.h"
#include "library/trackmodel.h"
#include "util/string.h"

class BaseExternalPlaylistModel : public BaseSqlTableModel {
Q_OBJECT
Expand All @@ -28,11 +30,22 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel {
bool isColumnInternal(int column) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
CapabilitiesFlags getCapabilities() const override;
QString modelKey(bool noSearch = false) const override {
if (noSearch) {
return QStringLiteral("external/") +
QString::number(m_currentPlaylistId);
}
return QStringLiteral("external/") +
QString::number(m_currentPlaylistId) +
QStringLiteral("#") +
currentSearch();
}

private:
TrackId doGetTrackId(const TrackPointer& pTrack) const override;

QString m_playlistsTable;
QString m_playlistTracksTable;
QSharedPointer<BaseTrackCache> m_trackSource;
int m_currentPlaylistId;
};
6 changes: 5 additions & 1 deletion src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) {
//qDebug() << "BasePlaylistFeature::activateChild()" << index;
int playlistId = playlistIdFromIndex(index);
if (playlistId != -1) {
emit saveModelState();
m_pPlaylistTableModel->setTableModel(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
Expand All @@ -166,6 +167,7 @@ void BasePlaylistFeature::activatePlaylist(int playlistId) {
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId;
QModelIndex index = indexFromPlaylistId(playlistId);
if (playlistId != -1 && index.isValid()) {
emit saveModelState();
m_pPlaylistTableModel->setTableModel(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
Expand Down Expand Up @@ -433,6 +435,7 @@ void BasePlaylistFeature::slotCreateImportPlaylist() {

lastPlaylistId = m_playlistDao.createPlaylist(name);
if (lastPlaylistId != -1) {
emit saveModelState();
m_pPlaylistTableModel->setTableModel(lastPlaylistId);
} else {
QMessageBox::warning(nullptr,
Expand Down Expand Up @@ -487,7 +490,7 @@ void BasePlaylistFeature::slotExportPlaylist() {
// This will only export songs that we think exist on default
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this, m_pLibrary->trackCollections(), "mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist());
pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down Expand Up @@ -525,6 +528,7 @@ void BasePlaylistFeature::slotExportTrackFiles() {
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this, m_pLibrary->trackCollections(), "mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist());
pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down
3 changes: 2 additions & 1 deletion src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void BaseSqlTableModel::select() {
if (!m_bInitialized) {
return;
}
beginResetModel();
// We should be able to detect when a select() would be a no-op. The DAO's
// do not currently broadcast signals for when common things happen. In the
// future, we can turn this check on and avoid a lot of needless
Expand Down Expand Up @@ -329,7 +330,7 @@ void BaseSqlTableModel::select() {
std::move(trackIdToRows));
// Both rowInfo and trackIdToRows (might) have been moved and
// must not be used afterwards!

endResetModel();
qDebug() << this << "select() took" << time.elapsed().debugMillisWithUnit()
<< m_rowInfo.size();
}
Expand Down
11 changes: 10 additions & 1 deletion src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ class BaseSqlTableModel : public BaseTrackTableModel {
int fieldIndex(
ColumnCache::Column column) const final;

virtual QString modelKey(bool noSearch = false) const override {
if (noSearch) {
return QStringLiteral("table:") + m_tableName;
}
return QStringLiteral("table:") + m_tableName +
QStringLiteral("#") +
currentSearch();
}

protected:
///////////////////////////////////////////////////////////////////////////
// Inherited from BaseTrackTableModel
Expand All @@ -96,6 +105,7 @@ class BaseSqlTableModel : public BaseTrackTableModel {
QList<TrackRef> getTrackRefs(const QModelIndexList& indices) const;

QSqlDatabase m_database;
QString m_tableName;

QString m_tableOrderBy;
int m_columnIndexBySortColumnId[static_cast<int>(TrackModel::SortColumnId::IdMax)];
Expand Down Expand Up @@ -138,7 +148,6 @@ class BaseSqlTableModel : public BaseTrackTableModel {

QVector<RowInfo> m_rowInfo;

QString m_tableName;
QString m_idColumn;
QSharedPointer<BaseTrackCache> m_trackSource;
QStringList m_tableColumns;
Expand Down
6 changes: 6 additions & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ BrowseFeature::BrowseFeature(
&BrowseFeature::requestAddDir,
pLibrary,
&Library::slotRequestAddDir);
connect(&m_browseModel,
&BrowseTableModel::restoreModelState,
this,
&LibraryFeature::restoreModelState);

m_pAddQuickLinkAction = new QAction(tr("Add to Quick Links"),this);
connect(m_pAddQuickLinkAction,
Expand Down Expand Up @@ -249,6 +253,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) {

QString path = item->getData().toString();
if (path == QUICK_LINK_NODE || path == DEVICE_NODE) {
emit saveModelState();
m_browseModel.setPath(MDir());
} else {
// Open a security token for this path and if we do not have access, ask
Expand All @@ -263,6 +268,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) {
return;
}
}
emit saveModelState();
m_browseModel.setPath(dir);
}
emit showTrackModel(&m_proxyModel);
Expand Down
1 change: 1 addition & 0 deletions src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void BrowseTableModel::slotInsert(const QList< QList<QStandardItem*> >& rows,
appendRow(rows.at(i));
}
}
emit restoreModelState();
}

TrackModel::CapabilitiesFlags BrowseTableModel::getCapabilities() const {
Expand Down
13 changes: 13 additions & 0 deletions src/library/browse/browsetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
bool isColumnSortable(int column) const override;
TrackModel::SortColumnId sortColumnIdFromColumnIndex(int index) const override;
int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) const override;
QString modelKey(bool noSearch = false) const override {
if (noSearch) {
return QStringLiteral("browse/") +
m_current_directory.dir().path();
} else {
return QStringLiteral("browse/") +
m_current_directory.dir().path() +
QStringLiteral("#") +
currentSearch();
}
}
signals:
void restoreModelState();

public slots:
void slotClear(BrowseTableModel*);
Expand Down
2 changes: 2 additions & 0 deletions src/library/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ void CrateFeature::activateChild(const QModelIndex& index) {
VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) {
return;
}
emit saveModelState();
m_crateTableModel.selectCrate(crateId);
emit showTrackModel(&m_crateTableModel);
emit enableCoverArtDisplay(true);
Expand All @@ -297,6 +298,7 @@ bool CrateFeature::activateCrate(CrateId crateId) {
VERIFY_OR_DEBUG_ASSERT(index.isValid()) {
return false;
}
emit saveModelState();
m_lastRightClickedIndex = index;
m_crateTableModel.selectCrate(crateId);
emit showTrackModel(&m_crateTableModel);
Expand Down
21 changes: 21 additions & 0 deletions src/library/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "library/crate/cratetablemodel.h"

#include <QStringBuilder>
#include <QtDebug>

#include "library/dao/trackschema.h"
Expand All @@ -9,6 +10,7 @@
#include "moc_cratetablemodel.cpp"
#include "track/track.h"
#include "util/db/fwdsqlquery.h"
#include "util/string.h"

CrateTableModel::CrateTableModel(QObject* pParent,
TrackCollectionManager* pTrackCollectionManager)
Expand Down Expand Up @@ -191,3 +193,22 @@ void CrateTableModel::removeTracks(const QModelIndexList& indices) {

select();
}

QString CrateTableModel::modelKey(bool noSearch) const {
if (this->m_selectedCrate.isValid()) {
if (noSearch) {
return QStringLiteral("crate/") +
QString::number(m_selectedCrate.value());
}
return QStringLiteral("crate/") +
QString::number(m_selectedCrate.value()) +
QStringLiteral("#") +
currentSearch();
} else {
if (noSearch) {
return QStringLiteral("crate");
}
return QStringLiteral("crate#") +
currentSearch();
}
}
1 change: 1 addition & 0 deletions src/library/crate/cratetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CrateTableModel final : public BaseSqlTableModel {
// Returns the number of unsuccessful track additions
int addTracks(const QModelIndex& index, const QList<QString>& locations) final;
CapabilitiesFlags getCapabilities() const final;
QString modelKey(bool noSearch = false) const override;

private:
CrateId m_selectedCrate;
Expand Down
19 changes: 19 additions & 0 deletions src/library/dao/settingsdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,22 @@ bool SettingsDAO::setValue(const QString& name, const QVariant& value) const {
}
return true;
}

bool SettingsDAO::deleteValue(const QString& name) const {
const QString statement =
QStringLiteral("DELETE FROM ") +
kTable +
QStringLiteral(" WHERE name = :name");
QSqlQuery query(m_database);
VERIFY_OR_DEBUG_ASSERT(query.prepare(statement)) {
return false;
}
query.bindValue(QStringLiteral(":name"), name);
VERIFY_OR_DEBUG_ASSERT(query.exec()) {
kLogger.warning()
<< "Failed to delete" << name
<< query.lastError();
return false;
}
return true;
}
2 changes: 2 additions & 0 deletions src/library/dao/settingsdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SettingsDAO final {
bool setValue(
const QString& name,
const QVariant& value) const;
bool deleteValue(
const QString& name) const;

const QSqlDatabase& database() const {
return m_database;
Expand Down
Loading

0 comments on commit 1f70f71

Please sign in to comment.