Skip to content

Commit

Permalink
Merge pull request mixxxdj#18 from jmigual/jmigual-library-redesign
Browse files Browse the repository at this point in the history
Fix some coding issues
  • Loading branch information
daschuer authored Mar 1, 2017
2 parents a9716b9 + 0504ffa commit b7b3344
Show file tree
Hide file tree
Showing 46 changed files with 222 additions and 218 deletions.
8 changes: 3 additions & 5 deletions src/dialog/savedqueries/dlgsavedquerieseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ DlgSavedQueriesEditor::DlgSavedQueriesEditor(LibraryFeature* pFeature,
m_pTrackCollection(pTrackCollection),
m_pFeature(pFeature) {
setupUi(this);
SavedQueriesTableModel *pSaveModel =
new SavedQueriesTableModel(m_pFeature,
m_pTrackCollection->getSavedQueriesDAO(),
parent);
tableView->setModel(pSaveModel);
auto pSaveModel = make_parented<SavedQueriesTableModel>(m_pFeature,
m_pTrackCollection->getSavedQueriesDAO(), parent);
tableView->setModel(pSaveModel.get());
int numColumns = static_cast<int>(SavedQueryColumns::NUM_COLUMNS);
for (int i = 0; i < numColumns; ++i) {
tableView->setColumnHidden(i, pSaveModel->isColumnInternal(i));
Expand Down
5 changes: 5 additions & 0 deletions src/dialog/savedqueries/savedqueriestablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class SavedQueriesTableModel : public QAbstractTableModel
int columnCount(const QModelIndex& parent = QModelIndex()) const;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());

#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
// Added to avoid compilation error when using Qt4
using QObject::parent;
#endif

public slots:

bool submit() override;
Expand Down
6 changes: 2 additions & 4 deletions src/library/features/analysis/analysisfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/features/analysis/analysisfeature.h"
#include "library/features/analysis/dlganalysis.h"
#include "library/librarytablemodel.h"
#include "library/trackcollection.h"
#include "sources/soundsourceproxy.h"
#include "util/debug.h"
#include "util/dnd.h"
#include "widget/wanalysislibrarytableview.h"
#include "widget/wtracktableview.h"
Expand Down Expand Up @@ -75,7 +73,7 @@ parented_ptr<QWidget> AnalysisFeature::createPaneWidget(KeyboardEventFilter*,

parented_ptr<QWidget> AnalysisFeature::createInnerSidebarWidget(
KeyboardEventFilter* pKeyboard, QWidget* parent) {
auto pAnalysisView = make_parented<DlgAnalysis>(parent, this, m_pTrackCollection);
auto pAnalysisView = make_parented<DlgAnalysis>(parent, this);

m_pAnalysisView = pAnalysisView.toWeakRef();
m_pAnalysisView->setTableModel(&m_analysisLibraryTableModel);
Expand All @@ -96,7 +94,7 @@ parented_ptr<QWidget> AnalysisFeature::createInnerSidebarWidget(
return pAnalysisView;
}

TreeItemModel* AnalysisFeature::getChildModel() {
QPointer<TreeItemModel> AnalysisFeature::getChildModel() {
return &m_childModel;
}

Expand Down
8 changes: 2 additions & 6 deletions src/library/features/analysis/analysisfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
#ifndef ANALYSISFEATURE_H
#define ANALYSISFEATURE_H

#include <QStringListModel>
#include <QUrl>
#include <QObject>
#include <QVariant>
#include <QIcon>
#include <QList>

#include "library/libraryfeature.h"
#include "library/features/analysis/dlganalysis.h"
#include "library/treeitemmodel.h"
#include "preferences/usersettings.h"

class AnalyzerQueue;
class DlgAnalysis;
class TrackCollection;

class AnalysisFeature : public LibraryFeature {
Expand All @@ -41,7 +37,7 @@ class AnalysisFeature : public LibraryFeature {
parented_ptr<QWidget> createInnerSidebarWidget(KeyboardEventFilter* pKeyboard,
QWidget* parent) override;

TreeItemModel* getChildModel();
QPointer<TreeItemModel> getChildModel();
void refreshLibraryModels();
void stopAnalysis();

Expand Down
17 changes: 6 additions & 11 deletions src/library/features/analysis/dlganalysis.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#include <QSqlTableModel>

#include "library/features/analysis/analysisfeature.h"
#include "library/features/analysis/dlganalysis.h"
#include "library/trackcollection.h"
#include "library/dao/trackschema.h"
#include "util/assert.h"
#include "widget/wanalysislibrarytableview.h"
#include "widget/wskincolor.h"
#include "widget/wwidget.h"

DlgAnalysis::DlgAnalysis(QWidget* parent, AnalysisFeature *pAnalysis,
TrackCollection* pTrackCollection)
DlgAnalysis::DlgAnalysis(QWidget* parent, AnalysisFeature* pAnalysis)
: QFrame(parent),
m_pTrackCollection(pTrackCollection),
m_bAnalysisActive(false),
m_pAnalysis(pAnalysis),
m_tracksInQueue(0),
Expand All @@ -27,7 +19,7 @@ DlgAnalysis::DlgAnalysis(QWidget* parent, AnalysisFeature *pAnalysis,
this, SLOT(analyze()));

connect(pushButtonSelectAll, SIGNAL(clicked()),
m_pAnalysis, SLOT(selectAll()));
m_pAnalysis.data(), SLOT(selectAll()));
}

DlgAnalysis::~DlgAnalysis() {
Expand All @@ -36,7 +28,8 @@ DlgAnalysis::~DlgAnalysis() {
void DlgAnalysis::onShow() {
// Refresh table
// There might be new tracks dropped to other views
m_pAnalysisLibraryTableModel->select();
if (!m_pAnalysisLibraryTableModel.isNull())
m_pAnalysisLibraryTableModel->select();

// TODO(rryan): This triggers a library search before the UI has even
// started up. Accounts for 0.2% of skin creation time. Get rid of this!
Expand All @@ -48,6 +41,8 @@ void DlgAnalysis::analyze() {
if (m_bAnalysisActive) {
m_pAnalysis->stopAnalysis();
} else {
if (m_pAnalysisLibraryTableModel.isNull())
return;
QList<TrackId> trackIds;
for (QModelIndex selectedIndex : m_selectedIndexes) {
TrackId trackId(selectedIndex.sibling(
Expand Down
17 changes: 5 additions & 12 deletions src/library/features/analysis/dlganalysis.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#ifndef DLGANALYSIS_H
#define DLGANALYSIS_H

#include <QItemSelection>
#include <QButtonGroup>
#include <QPointer>

#include "library/features/analysis/analysislibrarytablemodel.h"
#include "library/features/analysis/analysisfeature.h"
#include "library/features/analysis/ui_dlganalysis.h"
#include "library/libraryview.h"
#include "library/trackcollection.h"
#include "preferences/usersettings.h"

class AnalysisLibraryTableModel;
class WAnalysisLibraryTableView;
class AnalysisFeature;

class DlgAnalysis : public QFrame, public Ui::DlgAnalysis {
Expand All @@ -20,9 +16,7 @@ class DlgAnalysis : public QFrame, public Ui::DlgAnalysis {

public:

DlgAnalysis(QWidget *parent,
AnalysisFeature* pAnalysis,
TrackCollection* pTrackCollection);
DlgAnalysis(QWidget* parent, AnalysisFeature* pAnalysis);
~DlgAnalysis() override;

void onShow();
Expand All @@ -45,11 +39,10 @@ class DlgAnalysis : public QFrame, public Ui::DlgAnalysis {

private:
//Note m_pTrackTablePlaceholder is defined in the .ui file
TrackCollection* m_pTrackCollection;
bool m_bAnalysisActive;
QButtonGroup m_songsButtonGroup;
AnalysisLibraryTableModel* m_pAnalysisLibraryTableModel;
AnalysisFeature* m_pAnalysis;
QPointer<AnalysisLibraryTableModel> m_pAnalysisLibraryTableModel;
QPointer<AnalysisFeature> m_pAnalysis;
int m_tracksInQueue;
int m_currentTrack;

Expand Down
2 changes: 1 addition & 1 deletion src/library/features/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ parented_ptr<QWidget> AutoDJFeature::createInnerSidebarWidget(
return pContainer;
}

TreeItemModel* AutoDJFeature::getChildModel() {
QPointer<TreeItemModel> AutoDJFeature::getChildModel() {
return &m_childModel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/features/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AutoDJFeature : public LibraryFeature {
parented_ptr<QWidget> createInnerSidebarWidget(KeyboardEventFilter* pKeyboard,
QWidget* parent) override;

TreeItemModel* getChildModel();
QPointer<TreeItemModel> getChildModel();

public slots:
void activate();
Expand Down
2 changes: 1 addition & 1 deletion src/library/features/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void BansheeFeature::activateChild(const QModelIndex& index) {
}
}

TreeItemModel* BansheeFeature::getChildModel() {
QPointer<TreeItemModel> BansheeFeature::getChildModel() {
return &m_childModel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/features/banshee/bansheefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BansheeFeature : public BaseExternalLibraryFeature {
QString getIconPath() override;
QString getSettingsName() const override;

virtual TreeItemModel* getChildModel();
virtual QPointer<TreeItemModel> getChildModel();

public slots:
virtual void activate();
Expand Down
28 changes: 18 additions & 10 deletions src/library/features/baseplaylist/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ QPointer<PlaylistTableModel> BasePlaylistFeature::getPlaylistTableModel(int pane
}
auto it = m_playlistTableModel.find(paneId);
if (it == m_playlistTableModel.end() || it->isNull()) {
it = m_playlistTableModel.insert(paneId, constructTableModel());
auto pTableModel = constructTableModel();
it = m_playlistTableModel.insert(paneId, pTableModel.toWeakRef());
}
return *it;
}
Expand Down Expand Up @@ -627,7 +628,7 @@ QString BasePlaylistFeature::getValidPlaylistName() const {
return name;
}

QSet<int> BasePlaylistFeature::playlistIdsFromIndex(const QModelIndex &index) const {
QSet<int> BasePlaylistFeature::playlistIdsFromIndex(const QModelIndex& index) const {
bool ok = false;
int playlistId = index.data(AbstractRole::RoleData).toInt(&ok);
QSet<int> set;
Expand Down Expand Up @@ -712,9 +713,13 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) {
*/
QModelIndex BasePlaylistFeature::constructChildModel(int selectedId) {
buildPlaylistList();
QList<TreeItem*> dataList;
int selectedRow = -1;

QPointer<TreeItemModel> pChildModel = getChildModel();
if (pChildModel.isNull())
return QModelIndex();

TreeItem* pRoot = pChildModel->setRootItem(std::make_unique<TreeItem>(this));

int row = 0;
for (const PlaylistItem& p : m_playlistList) {
if (selectedId == p.id) {
Expand All @@ -723,17 +728,14 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selectedId) {
}

// Create the TreeItem whose parent is the invisible root item
TreeItem* item = new TreeItem(this, p.name, p.id);
TreeItem* item = pRoot->appendChild(p.name, p.id);
item->setBold(m_playlistsSelectedTrackIsIn.contains(p.id));

decorateChild(item, p.id);
dataList.append(item);
++row;
}

// Append all the newly created TreeItems in a dynamic way to the childmodel
TreeItemModel *pChildModel = getChildModel();
pChildModel->insertTreeItemRows(dataList, 0);
return pChildModel->index(selectedRow, 0);
}

Expand All @@ -744,8 +746,11 @@ void BasePlaylistFeature::updateChildModel(int selectedId) {
if (!index.isValid()) {
return;
}
QPointer<TreeItemModel> pChildModel = getChildModel();
VERIFY_OR_DEBUG_ASSERT (pChildModel.isNull())
return;

TreeItem* item = getChildModel()->getItem(index);
TreeItem* item = pChildModel->getItem(index);
VERIFY_OR_DEBUG_ASSERT(item) {
return;
}
Expand Down Expand Up @@ -778,7 +783,10 @@ void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) {

// Set all playlists the track is in bold (or if there is no track selected,
// clear all the bolding).
TreeItemModel* pChildModel = getChildModel();
QPointer<TreeItemModel> pChildModel = getChildModel();
VERIFY_OR_DEBUG_ASSERT(!pChildModel.isNull())
return;

for (const PlaylistItem& p : m_playlistList) {
QModelIndex index = indexFromPlaylistId(p.id);

Expand Down
8 changes: 4 additions & 4 deletions src/library/features/baseplaylist/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BasePlaylistFeature : public LibraryFeature {
void slotRenamePlaylist();
void slotTogglePlaylistLock();
void slotImportPlaylist();
void slotImportPlaylistFile(const QString &playlist_file);
void slotImportPlaylistFile(const QString& playlist_file);
void slotCreateImportPlaylist();
void slotExportPlaylist();
// Copy all of the tracks in a playlist to a new directory.
Expand Down Expand Up @@ -85,7 +85,7 @@ class BasePlaylistFeature : public LibraryFeature {
QString getValidPlaylistName() const;

QPointer<PlaylistTableModel> getPlaylistTableModel(int paneId = -1);
virtual PlaylistTableModel* constructTableModel() = 0;
virtual parented_ptr<PlaylistTableModel> constructTableModel() = 0;

virtual QSet<int> playlistIdsFromIndex(const QModelIndex& index) const;
int playlistIdFromIndex(const QModelIndex& index) const;
Expand All @@ -96,8 +96,8 @@ class BasePlaylistFeature : public LibraryFeature {
// on failure.
virtual QModelIndex indexFromPlaylistId(int playlistId) const;

PlaylistDAO &m_playlistDao;
TrackDAO &m_trackDao;
PlaylistDAO& m_playlistDao;
TrackDAO& m_trackDao;
QPointer<PlaylistTableModel> m_pPlaylistTableModel;
QHash<int, QPointer<PlaylistTableModel> > m_playlistTableModel;
QAction *m_pCreatePlaylistAction;
Expand Down
Loading

0 comments on commit b7b3344

Please sign in to comment.