Skip to content

Commit

Permalink
Move the m_pKeyNotation Control Object to the library class. This ens…
Browse files Browse the repository at this point in the history
…ures it will be initalize only once.

Use ControlProxy in the ColoumnCache instead.
  • Loading branch information
daschuer committed Sep 14, 2016
1 parent 0f7a17e commit dcff13a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/library/columncache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
#include "library/dao/cratedao.h"
#include "track/keyutils.h"
#include "track/key_preferences.h"
#include "control/controlproxy.h"

ColumnCache::ColumnCache(const QStringList& columns) {
m_pKeyNotationCP = new ControlProxy("[Library]", "key_notation", this);
m_pKeyNotationCP->connectValueChanged(SLOT(slotSetKeySortOrder(double)));

// ColumnCache is initialized before the preferences, so slotSetKeySortOrder is called
// for again if DlgPrefKey sets the [Library]. key_notation CO to a value other than
// KeyUtils::CUSTOM as Mixxx is starting.

setColumns(columns);
}

void ColumnCache::setColumns(const QStringList& columns) {
m_columnsByIndex.clear();
Expand Down Expand Up @@ -92,9 +104,13 @@ void ColumnCache::setColumns(const QStringList& columns) {
m_columnSortByIndex.insert(m_columnIndexByEnum[COLUMN_PLAYLISTTRACKSTABLE_LOCATION], sortNoCase);
m_columnSortByIndex.insert(m_columnIndexByEnum[COLUMN_PLAYLISTTRACKSTABLE_ARTIST], sortNoCase);
m_columnSortByIndex.insert(m_columnIndexByEnum[COLUMN_PLAYLISTTRACKSTABLE_TITLE], sortNoCase);

slotSetKeySortOrder(m_pKeyNotationCP->get());
}

void ColumnCache::slotSetKeySortOrder(double notation) {
if (m_columnIndexByEnum[COLUMN_LIBRARYTABLE_KEY] < 0) return;

std::vector<mixxx::track::io::key::ChromaticKey> sortOrder;
if (notation != static_cast<double>(KeyUtils::LANCELOT)) {
sortOrder = {
Expand Down
17 changes: 4 additions & 13 deletions src/library/columncache.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include <QMap>
#include <QStringList>

#include "control/controlobject.h"
#include "track/keyutils.h"
#include "preferences/usersettings.h"

class ControlProxy;

// Caches the index of frequently used columns and provides a lookup-table of
// column name to index.
class ColumnCache : public QObject {
Expand Down Expand Up @@ -72,17 +73,7 @@ class ColumnCache : public QObject {
NUM_COLUMNS
};

ColumnCache() { }
ColumnCache(const QStringList& columns) {
setColumns(columns);
m_pKeyNotation = new ControlObject(ConfigKey("[Library]", "key_notation"));
connect(m_pKeyNotation, SIGNAL(valueChanged(double)),
this, SLOT(slotSetKeySortOrder(double)));
slotSetKeySortOrder(static_cast<double>((KeyUtils::CUSTOM)));
// ColumnCache is initialized before the preferences, so slotSetKeySortOrder is called
// for again if DlgPrefKey sets the [Library]. key_notation CO to a value other than
// KeyUtils::CUSTOM as Mixxx is starting.
}
explicit ColumnCache(const QStringList& columns = QStringList());

void setColumns(const QStringList& columns);

Expand Down Expand Up @@ -121,7 +112,7 @@ class ColumnCache : public QObject {
int m_columnIndexByEnum[NUM_COLUMNS];

private:
ControlObject* m_pKeyNotation;
ControlProxy* m_pKeyNotationCP;

private slots:
void slotSetKeySortOrder(double);
Expand Down
2 changes: 2 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Library::Library(QObject* parent, UserSettingsPointer pConfig,
m_scanner(m_pTrackCollection, pConfig) {
qRegisterMetaType<Library::RemovalType>("Library::RemovalType");

m_pKeyNotation.reset(new ControlObject(ConfigKey("[Library]", "key_notation")));

connect(&m_scanner, SIGNAL(scanStarted()),
this, SIGNAL(scanStarted()));
connect(&m_scanner, SIGNAL(scanFinished()),
Expand Down
1 change: 1 addition & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Library : public QObject {
LibraryScanner m_scanner;
QFont m_trackTableFont;
int m_iTrackTableRowHeight;
QScopedPointer<ControlObject> m_pKeyNotation;
};

#endif /* LIBRARY_H */

0 comments on commit dcff13a

Please sign in to comment.