From 86b16df3f11a9ec96210ee175745580882d9b15e Mon Sep 17 00:00:00 2001 From: jmigual Date: Sat, 21 Jan 2017 09:39:46 +0100 Subject: [PATCH 1/3] Fix style issues and remove unnecessary code --- .../savedqueries/dlgsavedquerieseditor.cpp | 4 ++-- src/library/abstractmodelroles.h | 2 +- src/library/coverartdelegate.cpp | 2 +- src/library/dao/savedqueriesdao.h | 2 +- .../baseplaylist/baseplaylistfeature.cpp | 18 ++---------------- 5 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/dialog/savedqueries/dlgsavedquerieseditor.cpp b/src/dialog/savedqueries/dlgsavedquerieseditor.cpp index a71bc4adf10..4a79a726225 100644 --- a/src/dialog/savedqueries/dlgsavedquerieseditor.cpp +++ b/src/dialog/savedqueries/dlgsavedquerieseditor.cpp @@ -34,13 +34,13 @@ void DlgSavedQueriesEditor::accept() { } void DlgSavedQueriesEditor::removeQuery() { - QItemSelectionModel* model = tableView->selectionModel(); + auto model = tableView->selectionModel(); if (model == nullptr) return; QModelIndexList selected = model->selectedRows(); QSet removedRows; - for (const QModelIndex& index : selected) { + for (const auto& index : selected) { removedRows << index.row(); } diff --git a/src/library/abstractmodelroles.h b/src/library/abstractmodelroles.h index f9e4a4d1397..2b17336b285 100644 --- a/src/library/abstractmodelroles.h +++ b/src/library/abstractmodelroles.h @@ -3,7 +3,7 @@ #include -enum AbstractRole { +enum class AbstractRole { RoleData = Qt::UserRole, RoleBold, RoleDivider, diff --git a/src/library/coverartdelegate.cpp b/src/library/coverartdelegate.cpp index 7669a561335..843d656a1f3 100644 --- a/src/library/coverartdelegate.cpp +++ b/src/library/coverartdelegate.cpp @@ -91,7 +91,7 @@ void CoverArtDelegate::paint(QPainter* painter, // Draw original item without text as background opt.text = QString(); - const QWidget *widget = opt.widget; + const auto widget = opt.widget; QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); diff --git a/src/library/dao/savedqueriesdao.h b/src/library/dao/savedqueriesdao.h index a172977c061..7b3618b5bf3 100644 --- a/src/library/dao/savedqueriesdao.h +++ b/src/library/dao/savedqueriesdao.h @@ -10,7 +10,7 @@ #define SAVEDQUERYTABLE "savedQueries" -enum SavedQueryColumns { +enum class SavedQueryColumns { ID, LIBRARYFEATURE, QUERY, diff --git a/src/library/features/baseplaylist/baseplaylistfeature.cpp b/src/library/features/baseplaylist/baseplaylistfeature.cpp index 365a363b5eb..ec92e3c5d72 100644 --- a/src/library/features/baseplaylist/baseplaylistfeature.cpp +++ b/src/library/features/baseplaylist/baseplaylistfeature.cpp @@ -128,7 +128,7 @@ void BasePlaylistFeature::activate() { adoptPreselectedPane(); auto modelIt = m_lastChildClicked.constFind(m_featurePane); - if (modelIt != m_lastChildClicked.constEnd() && (*modelIt).isValid()) { + if (modelIt != m_lastChildClicked.constEnd() && modelIt->isValid()) { qDebug() << "BasePlaylistFeature::activate" << "m_lastChildClicked found"; // Open last clicked Playlist in the preselectded pane activateChild(*modelIt); @@ -341,21 +341,7 @@ void BasePlaylistFeature::slotDeletePlaylist() { return; } - m_playlistDao.deletePlaylist(playlistId); - - // This avoids a bug where the m_lastChildClicked index is still a valid - // index but it's not true since we just deleted it - for (auto it = m_playlistTableModel.begin(); - it != m_playlistTableModel.end(); ++it) { - - if ((*it)->getPlaylist() == playlistId) { - // Show the browse widget, this avoids a problem when the same - // playlist is shown twice and gets deleted. One of the panes - // gets still showing the unexisting playlist. - m_lastChildClicked[it.key()] = QModelIndex(); - showBrowse(it.key()); - } - } + m_playlistDao.deletePlaylist(playlistId); activate(); } } From 7bcb5005f85012b3d34a2567146960a8d3dac0d3 Mon Sep 17 00:00:00 2001 From: jmigual Date: Sat, 21 Jan 2017 10:37:46 +0100 Subject: [PATCH 2/3] Fix more style issues and bugfix some compilation issues --- .../savedqueries/dlgsavedquerieseditor.cpp | 3 ++- src/library/abstractmodelroles.h | 2 +- src/library/dao/savedqueriesdao.h | 2 +- .../features/analysis/analysisfeature.cpp | 22 +++++-------------- .../features/analysis/analysisfeature.h | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/dialog/savedqueries/dlgsavedquerieseditor.cpp b/src/dialog/savedqueries/dlgsavedquerieseditor.cpp index 4a79a726225..df5f288f5c3 100644 --- a/src/dialog/savedqueries/dlgsavedquerieseditor.cpp +++ b/src/dialog/savedqueries/dlgsavedquerieseditor.cpp @@ -17,7 +17,8 @@ DlgSavedQueriesEditor::DlgSavedQueriesEditor(LibraryFeature* pFeature, m_pTrackCollection->getSavedQueriesDAO(), parent); tableView->setModel(pSaveModel); - for (int i = 0; i < SavedQueryColumns::NUM_COLUMNS; ++i) { + int numColumns = static_cast(SavedQueryColumns::NUM_COLUMNS); + for (int i = 0; i < numColumns; ++i) { tableView->setColumnHidden(i, pSaveModel->isColumnInternal(i)); } diff --git a/src/library/abstractmodelroles.h b/src/library/abstractmodelroles.h index 2b17336b285..f9e4a4d1397 100644 --- a/src/library/abstractmodelroles.h +++ b/src/library/abstractmodelroles.h @@ -3,7 +3,7 @@ #include -enum class AbstractRole { +enum AbstractRole { RoleData = Qt::UserRole, RoleBold, RoleDivider, diff --git a/src/library/dao/savedqueriesdao.h b/src/library/dao/savedqueriesdao.h index 7b3618b5bf3..a172977c061 100644 --- a/src/library/dao/savedqueriesdao.h +++ b/src/library/dao/savedqueriesdao.h @@ -10,7 +10,7 @@ #define SAVEDQUERYTABLE "savedQueries" -enum class SavedQueryColumns { +enum SavedQueryColumns { ID, LIBRARYFEATURE, QUERY, diff --git a/src/library/features/analysis/analysisfeature.cpp b/src/library/features/analysis/analysisfeature.cpp index 786a5d77f3f..ec1c7613390 100644 --- a/src/library/features/analysis/analysisfeature.cpp +++ b/src/library/features/analysis/analysisfeature.cpp @@ -24,7 +24,8 @@ AnalysisFeature::AnalysisFeature(UserSettingsPointer pConfig, m_pAnalyzerQueue(nullptr), m_iOldBpmEnabled(0), m_analysisTitleName(tr("Analyze")), - m_pAnalysisView(nullptr){ + m_pAnalysisView(nullptr), + m_analysisLibraryTableModel(this, m_pTrackCollection) { m_childModel.setRootItem(std::make_unique(this)); setTitleDefault(); @@ -62,7 +63,7 @@ QString AnalysisFeature::getSettingsName() const { QWidget* AnalysisFeature::createPaneWidget(KeyboardEventFilter*, int paneId) { WTrackTableView* pTable = createTableWidget(paneId); - pTable->loadTrackModel(getAnalysisTableModel()); + pTable->loadTrackModel(&m_analysisLibraryTableModel); connect(pTable->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, @@ -74,7 +75,7 @@ QWidget* AnalysisFeature::createPaneWidget(KeyboardEventFilter*, int paneId) { QWidget* AnalysisFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { m_pAnalysisView = new DlgAnalysis(nullptr, this, m_pTrackCollection); - m_pAnalysisView->setTableModel(getAnalysisTableModel()); + m_pAnalysisView->setTableModel(&m_analysisLibraryTableModel); connect(this, SIGNAL(analysisActive(bool)), m_pAnalysisView, SLOT(analysisActive(bool))); @@ -194,11 +195,9 @@ void AnalysisFeature::tableSelectionChanged(const QItemSelection&, bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { Q_UNUSED(pSource); - QList files = - DragAndDropHelper::supportedTracksFromUrls(urls, false, true); + auto files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = - m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + auto trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); analyzeTracks(trackIds); return trackIds.size() > 0; } @@ -206,12 +205,3 @@ bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { bool AnalysisFeature::dragMoveAccept(QUrl url) { return SoundSourceProxy::isUrlSupported(url); } - -AnalysisLibraryTableModel* AnalysisFeature::getAnalysisTableModel() { - if (m_pAnalysisLibraryTableModel.isNull()) { - m_pAnalysisLibraryTableModel = - new AnalysisLibraryTableModel(this, m_pTrackCollection); - } - - return m_pAnalysisLibraryTableModel; -} diff --git a/src/library/features/analysis/analysisfeature.h b/src/library/features/analysis/analysisfeature.h index 8e9e5e15dbf..5fd5af18141 100644 --- a/src/library/features/analysis/analysisfeature.h +++ b/src/library/features/analysis/analysisfeature.h @@ -78,7 +78,7 @@ class AnalysisFeature : public LibraryFeature { TreeItemModel m_childModel; QString m_analysisTitleName; QPointer m_pAnalysisView; - QPointer m_pAnalysisLibraryTableModel; + AnalysisLibraryTableModel m_analysisLibraryTableModel; }; From dafb168d1582f25acdd52f3852ac828e3d7360e8 Mon Sep 17 00:00:00 2001 From: jmigual Date: Sat, 21 Jan 2017 10:42:03 +0100 Subject: [PATCH 3/3] Fix bug when getting query from folders and then from another group --- src/library/features/libraryfolder/libraryfoldermodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/features/libraryfolder/libraryfoldermodel.cpp b/src/library/features/libraryfolder/libraryfoldermodel.cpp index 16311c14ddf..d63c0e3f51d 100644 --- a/src/library/features/libraryfolder/libraryfoldermodel.cpp +++ b/src/library/features/libraryfolder/libraryfoldermodel.cpp @@ -71,7 +71,7 @@ QVariant LibraryFolderModel::data(const QModelIndex& index, int role) const { if (role == AbstractRole::RoleQuery) { // User has clicked the show all item or we are showing the library // instead of the folders - if (!m_folderRecursive || pTree == m_pShowAll || pTree == m_pGrouping) { + if (!m_showFolders || pTree == m_pShowAll || pTree == m_pGrouping) { return MixxxLibraryTreeModel::data(index, role); }