Skip to content

Commit

Permalink
Merge pull request #2 from rryan/sidebar-highlight
Browse files Browse the repository at this point in the history
Some fixes.
  • Loading branch information
MK-42 committed May 31, 2015
2 parents dc1f573 + 939428f commit 4a75b85
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 133 deletions.
1 change: 0 additions & 1 deletion build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ def sources(self, build):
"library/baseplaylistfeature.cpp",
"library/playlistfeature.cpp",
"library/setlogfeature.cpp",
"library/cratehighlightdelegate.cpp",

"library/browse/browsetablemodel.cpp",
"library/browse/browsethread.cpp",
Expand Down
2 changes: 0 additions & 2 deletions src/library/analysisfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "configobject.h"
#include "treeitemmodel.h"
#include "dlganalysis.h"
#include "trackinfoobject.h"

class AnalyserQueue;
class TrackCollection;
Expand All @@ -43,7 +42,6 @@ class AnalysisFeature : public LibraryFeature {
signals:
void analysisActive(bool bActive);
void trackAnalysisStarted(int size);
void trackSelected(TrackPointer);

public slots:
void activate();
Expand Down
4 changes: 0 additions & 4 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "library/libraryfeature.h"
#include "configobject.h"
#include "library/treeitemmodel.h"
#include "trackinfoobject.h"

#ifdef __AUTODJCRATES__
#include "library/dao/autodjcratesdao.h"
Expand Down Expand Up @@ -51,9 +50,6 @@ class AutoDJFeature : public LibraryFeature {

TreeItemModel* getChildModel();

signals:
void trackSelected(TrackPointer);

public slots:
void activate();

Expand Down
30 changes: 18 additions & 12 deletions src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ BasePlaylistFeature::BasePlaylistFeature(QObject* parent,

Library* pLibrary = static_cast<Library*>(parent);
connect(pLibrary, SIGNAL(trackSelected(TrackPointer)),
this, SLOT(slotTrackSelected(TrackPointer)));
this, SLOT(slotTrackSelected(TrackPointer)));
connect(pLibrary, SIGNAL(switchToView(const QString&)),
this, SLOT(slotResetSelectedTrack()));
this, SLOT(slotResetSelectedTrack()));
}

BasePlaylistFeature::~BasePlaylistFeature() {
Expand Down Expand Up @@ -560,6 +560,9 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) {

// Create the TreeItem whose parent is the invisible root item
TreeItem* item = new TreeItem(playlist_name, QString::number(playlist_id), this, root);
item->setBold(m_pSelectedTrack && m_playlistDao.isTrackInPlaylist(
m_pSelectedTrack->getId(), playlist_id));

decorateChild(item, playlist_id);
data_list.append(item);
}
Expand Down Expand Up @@ -593,18 +596,21 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) {
return QModelIndex();
}

bool BasePlaylistFeature::isTrackInChildModel(const int trackId,
const QVariant dataPath) {
return m_playlistDao.isTrackInPlaylist(trackId, dataPath.toInt());
}

TrackPointer BasePlaylistFeature::getSelectedTrack() {
return m_pSelectedTrack;
}

void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) {
m_pSelectedTrack = pTrack;
m_childModel.triggerRepaint();
int trackId = pTrack.isNull() ? -1 : pTrack->getId();

// Set all playlists the track is in bold (or if there is no track selected,
// clear all the bolding).
int row = 0;
for (QList<QPair<int, QString> >::const_iterator it = m_playlistList.begin();
it != m_playlistList.end(); ++it, ++row) {
int playlistId = it->first;
QModelIndex index = m_childModel.index(row, 0);

bool shouldBold = m_playlistDao.isTrackInPlaylist(trackId, playlistId);
m_childModel.setData(index, shouldBold, TreeItemModel::kBoldRole);
}
}


Expand Down
11 changes: 4 additions & 7 deletions src/library/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class BasePlaylistFeature : public LibraryFeature {
void bindWidget(WLibrary* libraryWidget,
MixxxKeyboard* keyboard);

TrackPointer getSelectedTrack();
virtual bool isTrackInChildModel(const int trackId, const QVariant dataPath);

signals:
void showPage(const QUrl& page);
void analyzeTracks(QList<int>);
Expand Down Expand Up @@ -95,14 +92,14 @@ class BasePlaylistFeature : public LibraryFeature {
TreeItemModel m_childModel;
TrackPointer m_pSelectedTrack;

private slots:
void slotTrackSelected(TrackPointer pTrack);
void slotResetSelectedTrack();

private:
virtual QString getRootViewHtml() const = 0;

QString m_rootViewName;

private slots:
void slotTrackSelected(TrackPointer pTrack);
void slotResetSelectedTrack();
};

#endif /* BASEPLAYLISTFEATURE_H */
2 changes: 0 additions & 2 deletions src/library/browse/browsefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <QString>

#include "configobject.h"
#include "trackinfoobject.h"
#include "library/browse/browsetablemodel.h"
#include "library/browse/foldertreemodel.h"
#include "library/libraryfeature.h"
Expand Down Expand Up @@ -57,7 +56,6 @@ class BrowseFeature : public LibraryFeature {
void setRootIndex(const QModelIndex&);
void requestAddDir(QString);
void scanLibrary();
void trackSelected(TrackPointer);

private:
QString getRootViewHtml() const;
Expand Down
30 changes: 17 additions & 13 deletions src/library/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ CrateFeature::CrateFeature(Library* pLibrary,
constructChildModel(-1);

connect(pLibrary, SIGNAL(trackSelected(TrackPointer)),
this, SLOT(slotTrackSelected(TrackPointer)));
this, SLOT(slotTrackSelected(TrackPointer)));
connect(pLibrary, SIGNAL(switchToView(const QString&)),
this, SLOT(slotResetSelectedTrack()));
this, SLOT(slotResetSelectedTrack()));
}

CrateFeature::~CrateFeature() {
Expand All @@ -120,11 +120,6 @@ QIcon CrateFeature::getIcon() {
return QIcon(":/images/library/ic_library_crates.png");
}

bool CrateFeature::isTrackInChildModel(const int trackId,
const QVariant dataPath) {
return m_crateDao.isTrackInCrate(trackId, dataPath.toInt());
}

int CrateFeature::crateIdFromIndex(QModelIndex index) {
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
if (item == NULL) {
Expand Down Expand Up @@ -520,6 +515,8 @@ QModelIndex CrateFeature::constructChildModel(int selected_id) {
TreeItem* item = new TreeItem(crate_name, QString::number(crate_id), this, root);
bool locked = m_crateDao.isCrateLocked(crate_id);
item->setIcon(locked ? QIcon(":/images/library/ic_library_locked.png") : QIcon());
item->setBold(m_pSelectedTrack && m_crateDao.isTrackInCrate(
m_pSelectedTrack->getId(), crate_id));
data_list.append(item);
}

Expand Down Expand Up @@ -715,16 +712,23 @@ QString CrateFeature::getRootViewHtml() const {
return html;
}

TrackPointer CrateFeature::getSelectedTrack() {
return m_pSelectedTrack;
}

void CrateFeature::slotTrackSelected(TrackPointer pTrack) {
m_pSelectedTrack = pTrack;
m_childModel.triggerRepaint();
int trackId = pTrack.isNull() ? -1 : pTrack->getId();

// Set all crates the track is in bold (or if there is no track selected,
// clear all the bolding).
int row = 0;
for (QList<QPair<int, QString> >::const_iterator it = m_crateList.begin();
it != m_crateList.end(); ++it, ++row) {
int crateId = it->first;
QModelIndex index = m_childModel.index(row, 0);

bool shouldBold = m_crateDao.isTrackInCrate(trackId, crateId);
m_childModel.setData(index, shouldBold, TreeItemModel::kBoldRole);
}
}

void CrateFeature::slotResetSelectedTrack() {
slotTrackSelected(TrackPointer());
}

11 changes: 4 additions & 7 deletions src/library/cratefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class CrateFeature : public LibraryFeature {

TreeItemModel* getChildModel();

TrackPointer getSelectedTrack();
virtual bool isTrackInChildModel(const int trackId, const QVariant dataPath);

signals:
void analyzeTracks(QList<int>);

Expand All @@ -65,6 +62,10 @@ class CrateFeature : public LibraryFeature {
void slotCrateTableRenamed(int playlistId, QString a_strName);
void htmlLinkClicked(const QUrl& link);

private slots:
void slotTrackSelected(TrackPointer pTrack);
void slotResetSelectedTrack();

private:
QString getRootViewHtml() const;
QModelIndex constructChildModel(int selected_id);
Expand All @@ -91,10 +92,6 @@ class CrateFeature : public LibraryFeature {
TreeItemModel m_childModel;
ConfigObject<ConfigValue>* m_pConfig;
TrackPointer m_pSelectedTrack;

private slots:
void slotTrackSelected(TrackPointer pTrack);
void slotResetSelectedTrack();
};

#endif /* CRATEFEATURE_H */
45 changes: 0 additions & 45 deletions src/library/cratehighlightdelegate.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions src/library/cratehighlightdelegate.h

This file was deleted.

9 changes: 1 addition & 8 deletions src/library/libraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ class LibraryFeature : public QObject {
virtual void bindWidget(WLibrary* /* libraryWidget */,
MixxxKeyboard* /* keyboard */) {}
virtual TreeItemModel* getChildModel() = 0;
virtual TrackPointer getSelectedTrack() {
return TrackPointer();
}
virtual bool isTrackInChildModel(const int trackId, const QVariant dataPath) {
Q_UNUSED(trackId);
Q_UNUSED(dataPath);
return false;
}

public slots:
// called when you single click on the root item
Expand Down Expand Up @@ -103,6 +95,7 @@ class LibraryFeature : public QObject {
void featureSelect(LibraryFeature* pFeature, const QModelIndex& index);
// emit this signal to enable/disable the cover art widget
void enableCoverArtDisplay(bool);
void trackSelected(TrackPointer pTrack);
};

#endif /* LIBRARYFEATURE_H */
3 changes: 0 additions & 3 deletions src/library/mixxxlibraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "library/dao/trackdao.h"
#include "treeitemmodel.h"
#include "configobject.h"
#include "trackinfoobject.h"

class DlgHidden;
class DlgMissing;
Expand All @@ -42,8 +41,6 @@ class MixxxLibraryFeature : public LibraryFeature {
TreeItemModel* getChildModel();
void bindWidget(WLibrary* pLibrary,
MixxxKeyboard* pKeyboard);
signals:
void trackSelected(TrackPointer);

public slots:
void activate();
Expand Down
6 changes: 5 additions & 1 deletion src/library/sidebarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ QVariant SidebarModel::data(const QModelIndex& index, int role) const {
} else {
return tree_item->dataPath();
}
} else if (role == Qt::UserRole) {
} else if (role == TreeItemModel::kDataPathRole) {
// We use Qt::UserRole to ask for the datapath.
return tree_item->dataPath();
} else if (role == Qt::FontRole) {
QFont font;
font.setBold(tree_item->isBold());
return font;
} else if (role == Qt::DecorationRole) {
return tree_item->getIcon();
}
Expand Down
2 changes: 2 additions & 0 deletions src/library/treeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ TreeItem::TreeItem(const QString &data, const QString &data_path,
m_dataPath = data_path;
m_parentItem = parent;
m_feature = feature;
m_bold = false;
}

TreeItem::TreeItem() {
m_data = "$root";
m_dataPath = "$root";
m_parentItem = NULL;
m_feature = NULL;
m_bold = false;
}

TreeItem::~TreeItem() {
Expand Down
9 changes: 9 additions & 0 deletions src/library/treeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class TreeItem {
/* Returns the Library feature object to which an item belongs to */
LibraryFeature* getFeature();

void setBold(bool bold) {
m_bold = bold;
}
bool isBold() const {
return m_bold;
}


void setIcon(const QIcon& icon);
QIcon getIcon();

Expand All @@ -57,6 +65,7 @@ class TreeItem {
QString m_dataPath;
QString m_data;
LibraryFeature* m_feature;
bool m_bold;

TreeItem *m_parentItem;
QIcon m_icon;
Expand Down
Loading

0 comments on commit 4a75b85

Please sign in to comment.