diff --git a/src/library/features/analysis/analysisfeature.cpp b/src/library/features/analysis/analysisfeature.cpp index ec1c76133904..12ee97b37a41 100644 --- a/src/library/features/analysis/analysisfeature.cpp +++ b/src/library/features/analysis/analysisfeature.cpp @@ -61,20 +61,23 @@ QString AnalysisFeature::getSettingsName() const { return "AnalysisFeature"; } -QWidget* AnalysisFeature::createPaneWidget(KeyboardEventFilter*, int paneId) { - WTrackTableView* pTable = createTableWidget(paneId); +parented_ptr AnalysisFeature::createPaneWidget(KeyboardEventFilter*, + int paneId, QWidget* parent) { + auto pTable = createTableWidget(paneId, parent); pTable->loadTrackModel(&m_analysisLibraryTableModel); connect(pTable->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(tableSelectionChanged(const QItemSelection&, const QItemSelection&))); - return pTable; + return std::move(pTable); } -QWidget* AnalysisFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { - m_pAnalysisView = new DlgAnalysis(nullptr, this, m_pTrackCollection); +parented_ptr AnalysisFeature::createInnerSidebarWidget( + KeyboardEventFilter* pKeyboard, QWidget* parent) { + auto pAnalysisView = make_parented(parent, this, m_pTrackCollection); + m_pAnalysisView = pAnalysisView.toWeakRef(); m_pAnalysisView->setTableModel(&m_analysisLibraryTableModel); connect(this, SIGNAL(analysisActive(bool)), @@ -87,9 +90,10 @@ QWidget* AnalysisFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboar // Let the DlgAnalysis know whether or not analysis is active. bool bAnalysisActive = m_pAnalyzerQueue != nullptr; emit(analysisActive(bAnalysisActive)); + m_pAnalysisView->onShow(); - return m_pAnalysisView; + return std::move(pAnalysisView); } TreeItemModel* AnalysisFeature::getChildModel() { diff --git a/src/library/features/analysis/analysisfeature.h b/src/library/features/analysis/analysisfeature.h index 5fd5af18141e..28da30f30a59 100644 --- a/src/library/features/analysis/analysisfeature.h +++ b/src/library/features/analysis/analysisfeature.h @@ -36,8 +36,10 @@ class AnalysisFeature : public LibraryFeature { bool dropAccept(QList urls, QObject* pSource); bool dragMoveAccept(QUrl url); - QWidget* createPaneWidget(KeyboardEventFilter*, int paneId) override; - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) override; + parented_ptr createPaneWidget(KeyboardEventFilter*, int paneId, + QWidget* parent) override; + parented_ptr createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, + QWidget* parent) override; TreeItemModel* getChildModel(); void refreshLibraryModels(); diff --git a/src/library/features/autodj/autodjfeature.cpp b/src/library/features/autodj/autodjfeature.cpp index 5b96c8612a82..5fb1244fd7ce 100644 --- a/src/library/features/autodj/autodjfeature.cpp +++ b/src/library/features/autodj/autodjfeature.cpp @@ -104,8 +104,9 @@ QString AutoDJFeature::getSettingsName() const { return "AutoDJFeature"; } -QWidget* AutoDJFeature::createPaneWidget(KeyboardEventFilter*, int paneId) { - WTrackTableView* pTrackTableView = createTableWidget(paneId); +parented_ptr AutoDJFeature::createPaneWidget(KeyboardEventFilter*, + int paneId, QWidget* parent) { + auto pTrackTableView = createTableWidget(paneId, parent); pTrackTableView->loadTrackModel(m_pAutoDJProcessor->getTableModel()); connect(pTrackTableView->selectionModel(), @@ -113,29 +114,29 @@ QWidget* AutoDJFeature::createPaneWidget(KeyboardEventFilter*, int paneId) { this, SLOT(selectionChanged(const QItemSelection&, const QItemSelection&))); - return pTrackTableView; + return std::move(pTrackTableView); } -QWidget* AutoDJFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { - QTabWidget* pContainer = new QTabWidget(nullptr); +parented_ptr AutoDJFeature::createInnerSidebarWidget( + KeyboardEventFilter* pKeyboard, QWidget* parent) { + auto pContainer = make_parented(parent); // now the icon loader is set up and get an icon m_pCratesTreeItem->setIcon(WPixmapStore::getLibraryIcon( ":/images/library/ic_library_crates.png")); // Add controls - m_pAutoDJView = new DlgAutoDJ(pContainer, m_pAutoDJProcessor); + auto pAutoDJView = make_parented(pContainer.get(), m_pAutoDJProcessor); + m_pAutoDJView = pAutoDJView.toWeakRef(); m_pAutoDJView->installEventFilter(pKeyboard); - QScrollArea* pScroll = new QScrollArea(pContainer); + auto pScroll = make_parented(pContainer.get()); pScroll->setWidget(m_pAutoDJView); pScroll->setWidgetResizable(true); - pContainer->addTab(pScroll, tr("Controls")); + pContainer->addTab(pScroll.get(), tr("Controls")); // Add drop target - WLibrarySidebar* pSidebar = createLibrarySidebarWidget(pKeyboard); - pSidebar->setParent(pContainer); - - pContainer->addTab(pSidebar, tr("Track source")); + auto pSidebar = createLibrarySidebarWidget(pContainer.get()); + pContainer->addTab(pSidebar.get(), tr("Track source")); // Be informed when the user wants to add another random track. connect(m_pAutoDJProcessor,SIGNAL(randomTrackRequested(int)), @@ -143,7 +144,7 @@ QWidget* AutoDJFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) connect(m_pAutoDJView, SIGNAL(addRandomButton(bool)), this, SLOT(slotAddRandomTrack())); - return pContainer; + return std::move(pContainer); } TreeItemModel* AutoDJFeature::getChildModel() { diff --git a/src/library/features/autodj/autodjfeature.h b/src/library/features/autodj/autodjfeature.h index f3f74d21bf2a..3ff3e2dd93e5 100644 --- a/src/library/features/autodj/autodjfeature.h +++ b/src/library/features/autodj/autodjfeature.h @@ -46,8 +46,10 @@ class AutoDJFeature : public LibraryFeature { bool dropAccept(QList urls, QObject* pSource); bool dragMoveAccept(QUrl url); - QWidget* createPaneWidget(KeyboardEventFilter*, int paneId) override; - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) override; + parented_ptr createPaneWidget(KeyboardEventFilter*, int paneId, + QWidget* parent) override; + parented_ptr createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, + QWidget* parent) override; TreeItemModel* getChildModel(); diff --git a/src/library/features/baseplaylist/baseplaylistfeature.cpp b/src/library/features/baseplaylist/baseplaylistfeature.cpp index 4ea5a8dac4b4..be87473cbfb3 100644 --- a/src/library/features/baseplaylist/baseplaylistfeature.cpp +++ b/src/library/features/baseplaylist/baseplaylistfeature.cpp @@ -27,7 +27,6 @@ BasePlaylistFeature::BasePlaylistFeature(UserSettingsPointer pConfig, m_playlistDao(pTrackCollection->getPlaylistDAO()), m_trackDao(pTrackCollection->getTrackDAO()), m_pPlaylistTableModel(nullptr) { - m_childModel = new TreeItemModel; m_pCreatePlaylistAction = new QAction(tr("Create New Playlist"),this); connect(m_pCreatePlaylistAction, SIGNAL(triggered()), @@ -679,28 +678,23 @@ void BasePlaylistFeature::slotAnalyzePlaylist() { } } -TreeItemModel* BasePlaylistFeature::getChildModel() { - return m_childModel; -} - -QWidget* BasePlaylistFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, - int paneId) { - WLibraryStack* pStack = new WLibraryStack(nullptr); - m_panes[paneId] = pStack; +parented_ptr BasePlaylistFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent) { + auto pStack = make_parented(parent); + m_panes[paneId] = pStack.toWeakRef(); - WLibraryTextBrowser* edit = new WLibraryTextBrowser(pStack); + auto edit = make_parented(pStack.get()); edit->setHtml(getRootViewHtml()); edit->setOpenLinks(false); edit->installEventFilter(pKeyboard); - connect(edit, SIGNAL(anchorClicked(const QUrl)), + connect(edit.get(), SIGNAL(anchorClicked(const QUrl)), this, SLOT(htmlLinkClicked(const QUrl))); - m_browseIndexByPaneId[paneId] = pStack->addWidget(edit); + m_browseIndexByPaneId[paneId] = pStack->addWidget(edit.get()); - QWidget* pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId); - pTable->setParent(pStack); - m_tableIndexByPaneId[paneId] = pStack->addWidget(pTable); + auto pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId, pStack.get()); + m_tableIndexByPaneId[paneId] = pStack->addWidget(pTable.get()); - return pStack; + return std::move(pStack); } void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { @@ -738,8 +732,9 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selectedId) { } // Append all the newly created TreeItems in a dynamic way to the childmodel - m_childModel->insertTreeItemRows(dataList, 0); - return m_childModel->index(selectedRow, 0); + TreeItemModel *pChildModel = getChildModel(); + pChildModel->insertTreeItemRows(dataList, 0); + return pChildModel->index(selectedRow, 0); } void BasePlaylistFeature::updateChildModel(int selectedId) { @@ -750,7 +745,7 @@ void BasePlaylistFeature::updateChildModel(int selectedId) { return; } - TreeItem* item = m_childModel->getItem(index); + TreeItem* item = getChildModel()->getItem(index); VERIFY_OR_DEBUG_ASSERT(item) { return; } @@ -770,7 +765,7 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) const { return QModelIndex(); } - return m_childModel->index(row, 0); + return getConstChildModel()->index(row, 0); } void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { @@ -783,12 +778,13 @@ 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(); for (const PlaylistItem& p : m_playlistList) { QModelIndex index = indexFromPlaylistId(p.id); bool shouldBold = m_playlistsSelectedTrackIsIn.contains(p.id); - m_childModel->setData(index, shouldBold, AbstractRole::RoleBold); + pChildModel->setData(index, shouldBold, AbstractRole::RoleBold); } - m_childModel->triggerRepaint(); + pChildModel->triggerRepaint(); } diff --git a/src/library/features/baseplaylist/baseplaylistfeature.h b/src/library/features/baseplaylist/baseplaylistfeature.h index 544de2d415bd..71eb0f65ebdb 100644 --- a/src/library/features/baseplaylist/baseplaylistfeature.h +++ b/src/library/features/baseplaylist/baseplaylistfeature.h @@ -1,22 +1,15 @@ #ifndef BASEPLAYLISTFEATURE_H #define BASEPLAYLISTFEATURE_H -#include #include -#include -#include #include -#include #include #include -#include #include "library/dao/playlistdao.h" #include "library/dao/trackdao.h" #include "library/libraryfeature.h" -#include "track/track.h" -class KeyboardEventFilter; class PlaylistTableModel; class TrackCollection; class TreeItem; @@ -31,10 +24,8 @@ class BasePlaylistFeature : public LibraryFeature { QObject* parent, TrackCollection* pTrackCollection); virtual ~BasePlaylistFeature(); - - TreeItemModel* getChildModel(); - - QWidget* createPaneWidget(KeyboardEventFilter*pKeyboard, int paneId) override; + parented_ptr createPaneWidget(KeyboardEventFilter*pKeyboard, + int paneId, QWidget* parent) override; signals: void showPage(const QUrl& page); @@ -84,6 +75,8 @@ class BasePlaylistFeature : public LibraryFeature { } }; + virtual const TreeItemModel* getConstChildModel() const = 0; + virtual QModelIndex constructChildModel(int selected_id); virtual void updateChildModel(int selectedId); virtual void buildPlaylistList() = 0; @@ -121,7 +114,6 @@ class BasePlaylistFeature : public LibraryFeature { QAction *m_pAnalyzePlaylistAction; QList m_playlistList; QPersistentModelIndex m_lastRightClickedIndex; - TreeItemModel* m_childModel; TrackPointer m_pSelectedTrack; QHash m_lastChildClicked; diff --git a/src/library/features/browse/browsefeature.cpp b/src/library/features/browse/browsefeature.cpp index 8e539f124921..4b823e88a996 100644 --- a/src/library/features/browse/browsefeature.cpp +++ b/src/library/features/browse/browsefeature.cpp @@ -197,21 +197,20 @@ TreeItemModel* BrowseFeature::getChildModel() { return &m_childModel; } -QWidget* BrowseFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, - int paneId) { - WLibraryStack* pStack = new WLibraryStack(nullptr); - m_panes[paneId] = pStack; +parented_ptr BrowseFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent) { + auto pStack = make_parented(parent); + m_panes[paneId] = pStack.toWeakRef(); - WLibraryTextBrowser* pEdit = new WLibraryTextBrowser(nullptr); + auto pEdit = make_parented(pStack.get()); pEdit->setHtml(getRootViewHtml()); pEdit->installEventFilter(pKeyboard); - m_idBrowse[paneId] = pStack->addWidget(pEdit); + m_idBrowse[paneId] = pStack->addWidget(pEdit.get()); - QWidget* pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId); - pTable->setParent(pStack); - m_idTable[paneId] = pStack->addWidget(pTable); + auto pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId, pStack.get()); + m_idTable[paneId] = pStack->addWidget(pTable.get()); - return pStack; + return std::move(pStack); } void BrowseFeature::activate() { diff --git a/src/library/features/browse/browsefeature.h b/src/library/features/browse/browsefeature.h index a11874b43420..51ce6826b697 100644 --- a/src/library/features/browse/browsefeature.h +++ b/src/library/features/browse/browsefeature.h @@ -40,7 +40,8 @@ class BrowseFeature : public LibraryFeature { QString getIconPath() override; QString getSettingsName() const override; - QWidget* createPaneWidget(KeyboardEventFilter*pKeyboard, int paneId) override; + parented_ptr createPaneWidget(KeyboardEventFilter*pKeyboard, + int paneId, QWidget* parent) override; TreeItemModel* getChildModel(); diff --git a/src/library/features/crates/cratefeature.cpp b/src/library/features/crates/cratefeature.cpp index e727b63cec0f..e4134e6146f7 100644 --- a/src/library/features/crates/cratefeature.cpp +++ b/src/library/features/crates/cratefeature.cpp @@ -250,24 +250,25 @@ bool CrateFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { Parser::isPlaylistFilenameSupported(url.toLocalFile()); } -QWidget* CrateFeature::createPaneWidget(KeyboardEventFilter *pKeyboard, - int paneId) { - WLibraryStack* pContainer = new WLibraryStack(nullptr); - m_panes[paneId] = pContainer; +parented_ptr CrateFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent) { + auto pContainer = make_parented(parent); + m_panes[paneId] = pContainer.toWeakRef(); - WLibraryTextBrowser* pEdit = new WLibraryTextBrowser(pContainer); + auto pEdit = make_parented(pContainer.get()); pEdit->setHtml(formatRootViewHtml()); pEdit->setOpenLinks(false); pEdit->installEventFilter(pKeyboard); - connect(pEdit, SIGNAL(anchorClicked(const QUrl)), + connect(pEdit.get(), SIGNAL(anchorClicked(const QUrl)), this, SLOT(htmlLinkClicked(const QUrl))); - m_idBrowse[paneId] = pContainer->addWidget(pEdit); + m_idBrowse[paneId] = pContainer->addWidget(pEdit.get()); - QWidget* pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId); - m_idTable[paneId] = pContainer->addWidget(pTable); + auto pTable = LibraryFeature::createPaneWidget(pKeyboard, paneId, + pContainer.get()); + m_idTable[paneId] = pContainer->addWidget(pTable.get()); - return pContainer; + return std::move(pContainer); } TreeItemModel* CrateFeature::getChildModel() { diff --git a/src/library/features/crates/cratefeature.h b/src/library/features/crates/cratefeature.h index 9555f3e09a2c..d640740fd92b 100644 --- a/src/library/features/crates/cratefeature.h +++ b/src/library/features/crates/cratefeature.h @@ -44,7 +44,8 @@ class CrateFeature : public LibraryFeature { QObject* pSource) override; bool dragMoveAcceptChild(const QModelIndex& index, QUrl url) override; - QWidget* createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId) override; + parented_ptr createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent) override; TreeItemModel* getChildModel() override; diff --git a/src/library/features/history/historyfeature.cpp b/src/library/features/history/historyfeature.cpp index 2e3bb9176f70..fd907d34c84d 100644 --- a/src/library/features/history/historyfeature.cpp +++ b/src/library/features/history/historyfeature.cpp @@ -30,8 +30,8 @@ HistoryFeature::HistoryFeature(UserSettingsPointer pConfig, emit(slotGetNewPlaylist()); //construct child model - delete m_childModel; - m_childModel = m_pHistoryTreeModel = new HistoryTreeModel(this, m_pTrackCollection); + m_pHistoryTreeModel = std::make_unique(this, + m_pTrackCollection); constructChildModel(-1); connect(&PlayerInfo::instance(), SIGNAL(currentPlayingTrackChanged(TrackPointer)), @@ -139,6 +139,10 @@ void HistoryFeature::decorateChild(TreeItem* item, int playlist_id) { } } +TreeItemModel *HistoryFeature::getChildModel() { + return m_pHistoryTreeModel.get(); +} + QModelIndex HistoryFeature::constructChildModel(int selected_id) { buildPlaylistList(); QModelIndex index = m_pHistoryTreeModel->reloadListsTree(selected_id); @@ -199,10 +203,16 @@ void HistoryFeature::slotGetNewPlaylist() { showTrackModel(m_pPlaylistTableModel); } -QWidget* HistoryFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { - m_pSidebar = createLibrarySidebarWidget(pKeyboard); +parented_ptr HistoryFeature::createInnerSidebarWidget( + KeyboardEventFilter*, QWidget* parent) { + auto pSidebar = createLibrarySidebarWidget(parent); + m_pSidebar = pSidebar.toWeakRef(); m_pSidebar->expandAll(); - return m_pSidebar; + return std::move(pSidebar); +} + +const TreeItemModel* HistoryFeature::getConstChildModel() const { + return m_pHistoryTreeModel.get(); } void HistoryFeature::slotJoinWithNext() { diff --git a/src/library/features/history/historyfeature.h b/src/library/features/history/historyfeature.h index cc2825901ef4..8a256a762bf8 100644 --- a/src/library/features/history/historyfeature.h +++ b/src/library/features/history/historyfeature.h @@ -4,11 +4,8 @@ #define SETLOGFEATURE_H #include -#include -#include #include "library/features/baseplaylist/baseplaylistfeature.h" -#include "preferences/usersettings.h" class TrackCollection; class TreeItem; @@ -27,6 +24,7 @@ class HistoryFeature : public BasePlaylistFeature { QString getIconPath() override; QString getSettingsName() const override; void decorateChild(TreeItem *pChild, int playlist_id) override; + TreeItemModel* getChildModel() override; public slots: void onRightClick(const QPoint&) override; @@ -35,8 +33,10 @@ class HistoryFeature : public BasePlaylistFeature { void slotGetNewPlaylist(); protected: - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) override; + parented_ptr createInnerSidebarWidget(KeyboardEventFilter*, + QWidget* parent) override; + const TreeItemModel* getConstChildModel() const override; void buildPlaylistList() override; QModelIndex constructChildModel(int selected_id); PlaylistTableModel* constructTableModel() override; @@ -56,7 +56,7 @@ class HistoryFeature : public BasePlaylistFeature { QLinkedList m_recentTracks; QAction* m_pJoinWithNextAction; QAction* m_pGetNewPlaylist; - HistoryTreeModel* m_pHistoryTreeModel; + std::unique_ptr m_pHistoryTreeModel; int m_playlistId; }; diff --git a/src/library/features/maintenance/maintenancefeature.cpp b/src/library/features/maintenance/maintenancefeature.cpp index 90fd63b7eb13..a93cabb15d1c 100644 --- a/src/library/features/maintenance/maintenancefeature.cpp +++ b/src/library/features/maintenance/maintenancefeature.cpp @@ -78,21 +78,25 @@ void MaintenanceFeature::selectAll() { } } -QWidget* MaintenanceFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { +parented_ptr MaintenanceFeature::createInnerSidebarWidget( + KeyboardEventFilter* pKeyboard, QWidget* parent) { // The inner widget is a tab with the hidden and the missing controls - m_pTab = new QTabWidget(nullptr); + auto pTab = make_parented(parent); + m_pTab = pTab.toWeakRef(); m_pTab->installEventFilter(pKeyboard); connect(m_pTab, SIGNAL(currentChanged(int)), this, SLOT(slotTabIndexChanged(int))); - m_pHiddenView = new DlgHidden(m_pTab); + auto pHiddenView = make_parented(m_pTab); + m_pHiddenView = pHiddenView.toWeakRef(); m_pHiddenView->setTableModel(getHiddenTableModel()); m_pHiddenView->installEventFilter(pKeyboard); connect(m_pHiddenView, SIGNAL(unhide()), this, SLOT(slotUnhideHidden())); connect(m_pHiddenView, SIGNAL(purge()), this, SLOT(slotPurge())); connect(m_pHiddenView, SIGNAL(selectAll()), this, SLOT(selectAll())); - m_pMissingView = new DlgMissing(m_pTab); + auto pMissingView = make_parented(m_pTab); + m_pMissingView = pMissingView.toWeakRef(); m_pMissingView->setTableModel(getMissingTableModel()); m_pMissingView->installEventFilter(pKeyboard); connect(m_pMissingView, SIGNAL(purge()), this, SLOT(slotPurge())); @@ -101,15 +105,7 @@ QWidget* MaintenanceFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyb m_idExpandedHidden = m_pTab->addTab(m_pHiddenView, kHiddenTitle); m_idExpandedMissing = m_pTab->addTab(m_pMissingView, kMissingTitle); - return m_pTab; -} - -QWidget* MaintenanceFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, - int paneId) { - Q_UNUSED(pKeyboard); - WTrackTableView* pTable = LibraryFeature::createTableWidget(paneId); - - return pTable; + return std::move(pTab); } void MaintenanceFeature::slotTabIndexChanged(int index) { diff --git a/src/library/features/maintenance/maintenancefeature.h b/src/library/features/maintenance/maintenancefeature.h index c4a794235178..f91325cd6319 100644 --- a/src/library/features/maintenance/maintenancefeature.h +++ b/src/library/features/maintenance/maintenancefeature.h @@ -31,9 +31,8 @@ class MaintenanceFeature : public LibraryFeature void selectAll(); protected: - - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard); - QWidget* createPaneWidget(KeyboardEventFilter* pKeyboard, int paneId); + parented_ptr createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, + QWidget* parent); private: diff --git a/src/library/features/mixxxlibrary/mixxxlibraryfeature.cpp b/src/library/features/mixxxlibrary/mixxxlibraryfeature.cpp index 9411cf4fd828..776d44c5be15 100644 --- a/src/library/features/mixxxlibrary/mixxxlibraryfeature.cpp +++ b/src/library/features/mixxxlibrary/mixxxlibraryfeature.cpp @@ -23,24 +23,21 @@ const QString MixxxLibraryFeature::kLibraryTitle = tr("Tracks"); -const QStringList MixxxLibraryFeature::kGroupingText = - QStringList::fromStdList({ - tr("Artist > Album"), - tr("Album"), - tr("Genre > Artist > Album"), - tr("Genre > Album"), - tr("Folder") -}); +const QStringList MixxxLibraryFeature::kGroupingText { + tr("Artist > Album"), + tr("Album"), + tr("Genre > Artist > Album"), + tr("Genre > Album"), + tr("Folder") +}; -const QList MixxxLibraryFeature::kGroupingOptions = - QList::fromStdList({ - QStringList::fromStdList({ LIBRARYTABLE_ARTIST, LIBRARYTABLE_ALBUM }), - QStringList::fromStdList({ LIBRARYTABLE_ALBUM }), - QStringList::fromStdList({ LIBRARYTABLE_GENRE, LIBRARYTABLE_ARTIST, - LIBRARYTABLE_ALBUM }), - QStringList::fromStdList({ LIBRARYTABLE_GENRE, LIBRARYTABLE_ALBUM }), - QStringList::fromStdList({ LIBRARYFOLDERMODEL_FOLDER }) -}); +const QList MixxxLibraryFeature::kGroupingOptions { + { LIBRARYTABLE_ARTIST, LIBRARYTABLE_ALBUM }, + { LIBRARYTABLE_ALBUM }, + { LIBRARYTABLE_GENRE, LIBRARYTABLE_ARTIST, LIBRARYTABLE_ALBUM }, + { LIBRARYTABLE_GENRE, LIBRARYTABLE_ALBUM }, + { LIBRARYFOLDERMODEL_FOLDER } +}; MixxxLibraryFeature::MixxxLibraryFeature(UserSettingsPointer pConfig, Library* pLibrary, @@ -143,11 +140,13 @@ TreeItemModel* MixxxLibraryFeature::getChildModel() { return m_pChildModel; } -QWidget* MixxxLibraryFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) { - m_pSidebar = createLibrarySidebarWidget(pKeyboard); +parented_ptr MixxxLibraryFeature::createInnerSidebarWidget( + KeyboardEventFilter*, QWidget* parent) { + auto pSidebar = createLibrarySidebarWidget(parent); + m_pSidebar = pSidebar.toWeakRef(); m_pSidebar->setIconSize(m_pChildModel->getDefaultIconSize()); m_pChildModel->reloadTree(); - return m_pSidebar; + return std::move(pSidebaar); } void MixxxLibraryFeature::refreshLibraryModels() { diff --git a/src/library/features/mixxxlibrary/mixxxlibraryfeature.h b/src/library/features/mixxxlibrary/mixxxlibraryfeature.h index e83df973af77..3deab1972610 100644 --- a/src/library/features/mixxxlibrary/mixxxlibraryfeature.h +++ b/src/library/features/mixxxlibrary/mixxxlibraryfeature.h @@ -48,7 +48,8 @@ class MixxxLibraryFeature : public LibraryFeature { bool dropAccept(QList urls, QObject* pSource); bool dragMoveAccept(QUrl url); TreeItemModel* getChildModel(); - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) override; + parented_ptr createInnerSidebarWidget(KeyboardEventFilter*, + QWidget* parent) override; public slots: void activate() override; diff --git a/src/library/features/playlist/playlistfeature.cpp b/src/library/features/playlist/playlistfeature.cpp index 2ca429da36ef..05069ed7e03d 100644 --- a/src/library/features/playlist/playlistfeature.cpp +++ b/src/library/features/playlist/playlistfeature.cpp @@ -22,8 +22,9 @@ PlaylistFeature::PlaylistFeature(UserSettingsPointer pConfig, TrackCollection* pTrackCollection) : BasePlaylistFeature(pConfig, pLibrary, parent, pTrackCollection) { //construct child model + m_pChildModel = std::make_unique(); auto pRootItem = std::make_unique(this); - m_childModel->setRootItem(std::move(pRootItem)); + m_pChildModel->setRootItem(std::move(pRootItem)); constructChildModel(-1); } @@ -46,6 +47,10 @@ bool PlaylistFeature::isSinglePane() const { return false; } +TreeItemModel* PlaylistFeature::getChildModel() { + return m_pChildModel.get(); +} + void PlaylistFeature::onRightClick(const QPoint& globalPos) { m_lastRightClickedIndex = QModelIndex(); @@ -260,6 +265,10 @@ void PlaylistFeature::slotPlaylistTableRenamed(int playlistId, } } +const TreeItemModel* PlaylistFeature::getConstChildModel() const { + return m_pChildModel.get(); +} + QString PlaylistFeature::getRootViewHtml() const { QString playlistsTitle = tr("Playlists"); QString playlistsSummary = tr("Playlists are ordered lists of songs that allow you to plan your DJ sets."); diff --git a/src/library/features/playlist/playlistfeature.h b/src/library/features/playlist/playlistfeature.h index 7aa63d5c53e9..50f18e3efd72 100644 --- a/src/library/features/playlist/playlistfeature.h +++ b/src/library/features/playlist/playlistfeature.h @@ -4,15 +4,7 @@ #ifndef PLAYLISTFEATURE_H #define PLAYLISTFEATURE_H -#include -#include -#include -#include -#include -#include - #include "library/features/baseplaylist/baseplaylistfeature.h" -#include "preferences/usersettings.h" class TrackCollection; class TreeItem; @@ -30,6 +22,7 @@ class PlaylistFeature : public BasePlaylistFeature { QString getIconPath() override; QString getSettingsName() const override; bool isSinglePane() const override; + TreeItemModel* getChildModel() override; bool dragMoveAccept(QUrl url); bool dropAcceptChild(const QModelIndex& index, QList urls, QObject* pSource); @@ -45,12 +38,14 @@ class PlaylistFeature : public BasePlaylistFeature { void slotPlaylistTableRenamed(int playlistId, QString a_strName); protected: + const TreeItemModel* getConstChildModel() const override; void buildPlaylistList(); void decorateChild(TreeItem *pChild, int playlist_id); PlaylistTableModel* constructTableModel(); private: QString getRootViewHtml() const; + std::unique_ptr m_pChildModel; }; #endif /* PLAYLISTFEATURE_H */ diff --git a/src/library/features/recording/recordingfeature.cpp b/src/library/features/recording/recordingfeature.cpp index 2e3ff671a5a2..67a42c7c0f18 100644 --- a/src/library/features/recording/recordingfeature.cpp +++ b/src/library/features/recording/recordingfeature.cpp @@ -45,24 +45,24 @@ TreeItemModel* RecordingFeature::getChildModel() { return &m_childModel; } -QWidget* RecordingFeature::createPaneWidget( - KeyboardEventFilter* pKeyboard, int paneId) { - Q_UNUSED(pKeyboard); - WTrackTableView* pTable = LibraryFeature::createTableWidget(paneId); +parented_ptr RecordingFeature::createPaneWidget(KeyboardEventFilter*, + int paneId, QWidget* parent) { + auto pTable = LibraryFeature::createTableWidget(paneId, parent); pTable->setSorting(false); - return pTable; + return std::move(pTable); } -QWidget *RecordingFeature::createInnerSidebarWidget( - KeyboardEventFilter* pKeyboard) { - m_pRecordingView = new DlgRecording(nullptr, - m_pTrackCollection, - m_pRecordingManager); +parented_ptr RecordingFeature::createInnerSidebarWidget( + KeyboardEventFilter* pKeyboard, QWidget* parent) { + auto pRecordingView = make_parented(parent, + m_pTrackCollection, + m_pRecordingManager); + m_pRecordingView = pRecordingView.toWeakRef(); m_pRecordingView->installEventFilter(pKeyboard); m_pRecordingView->setBrowseTableModel(getBrowseTableModel()); m_pRecordingView->setProxyTrackModel(getProxyTrackModel()); - return m_pRecordingView; + return std::move(pRecordingView); } diff --git a/src/library/features/recording/recordingfeature.h b/src/library/features/recording/recordingfeature.h index d83b80cae3c5..ddcf542c59f4 100644 --- a/src/library/features/recording/recordingfeature.h +++ b/src/library/features/recording/recordingfeature.h @@ -32,8 +32,10 @@ class RecordingFeature : public LibraryFeature { QString getIconPath() override; QString getSettingsName() const override; - QWidget* createPaneWidget(KeyboardEventFilter *pKeyboard, int paneId) override; - QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard) override; + parented_ptr createPaneWidget(KeyboardEventFilter*, int paneId, + QWidget* parent) override; + parented_ptr createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, + QWidget* parent) override; TreeItemModel* getChildModel(); diff --git a/src/library/library.cpp b/src/library/library.cpp index 0709b6d80adb..41849c8dde7a 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -156,7 +156,7 @@ void Library::bindPaneWidget(WLibraryPane* pPaneWidget, void Library::bindSidebarExpanded(WBaseLibrary* expandedPane, KeyboardEventFilter* pKeyboard) { //qDebug() << "Library::bindSidebarExpanded"; - m_pSidebarExpanded = new LibrarySidebarExpandedManager(this); + m_pSidebarExpanded = std::make_unique(this); m_pSidebarExpanded->addFeatures(m_features); m_pSidebarExpanded->bindPaneWidget(expandedPane, pKeyboard); } @@ -169,7 +169,7 @@ void Library::bindBreadCrumb(WLibraryBreadCrumb* pBreadCrumb, int paneId) { void Library::destroyInterface() { m_pSidebarExpanded->deleteLater(); - m_pSidebarExpanded = nullptr; + m_pSidebarExpanded.reset(nullptr); for (LibraryPaneManager* p : m_panes) { p->deleteLater(); @@ -295,7 +295,7 @@ void Library::paneFocused(LibraryPaneManager* pPane) { return; } - if (pPane != m_pSidebarExpanded) { + if (pPane != m_pSidebarExpanded.get()) { m_focusedPaneId = pPane->getPaneId(); pPane->getCurrentFeature()->setFeaturePaneId(m_focusedPaneId); VERIFY_OR_DEBUG_ASSERT(m_focusedPaneId != -1) { diff --git a/src/library/library.h b/src/library/library.h index 40d9bcad77e4..8ec87f3e465d 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -7,16 +7,18 @@ #ifndef LIBRARY_H #define LIBRARY_H -#include -#include #include #include #include +#include +#include +#include "library/scanner/libraryscanner.h" #include "preferences/usersettings.h" -#include "track/track.h" #include "recording/recordingmanager.h" -#include "library/scanner/libraryscanner.h" +#include "track/track.h" +#include "util/parented_ptr.h" +#include "util/memory.h" class AnalysisFeature; class CrateFeature; @@ -59,9 +61,9 @@ class Library : public QObject { void bindSearchBar(WSearchLineEdit* searchLine, int id); void bindSidebarButtons(WButtonBar* sidebar); - void bindPaneWidget(WLibraryPane* libraryWidget, + void bindPaneWidget(WLibraryPane *libraryWidget, KeyboardEventFilter* pKeyboard, int paneId); - void bindSidebarExpanded(WBaseLibrary* expandedPane, + void bindSidebarExpanded(WBaseLibrary *expandedPane, KeyboardEventFilter* pKeyboard); void bindBreadCrumb(WLibraryBreadCrumb *pBreadCrumb, int paneId); @@ -173,7 +175,7 @@ class Library : public QObject { QScopedPointer m_pKeyNotation; QHash m_panes; - LibraryPaneManager* m_pSidebarExpanded; + std::unique_ptr m_pSidebarExpanded; QList m_features; QSet m_collapsedPanes; QHash m_savedFeatures; diff --git a/src/library/libraryfeature.cpp b/src/library/libraryfeature.cpp index 1bda590f623d..53b099570826 100644 --- a/src/library/libraryfeature.cpp +++ b/src/library/libraryfeature.cpp @@ -66,41 +66,40 @@ bool LibraryFeature::dragMoveAcceptChild(const QModelIndex &, QUrl) { return false; } -QWidget* LibraryFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, - int paneId) { +parented_ptr LibraryFeature::createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent) { Q_UNUSED(pKeyboard); - return createTableWidget(paneId); + return std::move(createTableWidget(paneId, parent)); } -QWidget *LibraryFeature::createSidebarWidget(KeyboardEventFilter* pKeyboard) { +parented_ptr LibraryFeature::createSidebarWidget(KeyboardEventFilter* pKeyboard, QWidget* parent) { //qDebug() << "LibraryFeature::bindSidebarWidget"; - QFrame* pContainer = new QFrame(nullptr); + auto pContainer = make_parented(parent); pContainer->setContentsMargins(0,0,0,0); - QVBoxLayout* pLayout = new QVBoxLayout(pContainer); + auto pLayout = make_parented(pContainer.get()); pLayout->setContentsMargins(0,0,0,0); pLayout->setSpacing(0); - pContainer->setLayout(pLayout); + pContainer->setLayout(pLayout.get()); - QHBoxLayout* pLayoutTitle = new QHBoxLayout(pContainer); + auto pLayoutTitle = make_parented(pContainer.get()); - QLabel* pIcon = new QLabel(pContainer); + auto pIcon = make_parented(pContainer.get()); int height = pIcon->fontMetrics().height(); pIcon->setPixmap(getIcon().pixmap(height)); - pLayoutTitle->addWidget(pIcon); + pLayoutTitle->addWidget(pIcon.get()); - QLabel* pTitle = new QLabel(title().toString(), pContainer); - pLayoutTitle->addWidget(pTitle); + auto pTitle = make_parented(title().toString(), pContainer.get()); + pLayoutTitle->addWidget(pTitle.get()); pLayoutTitle->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); - pLayout->addLayout(pLayoutTitle); + pLayout->addLayout(pLayoutTitle.get()); - QWidget* pSidebar = createInnerSidebarWidget(pKeyboard); - pSidebar->setParent(pContainer); - pLayout->addWidget(pSidebar); + auto pSidebar = createInnerSidebarWidget(pKeyboard, pContainer.get()); + pLayout->addWidget(pSidebar.get()); - return pContainer; + return std::move(pContainer); } void LibraryFeature::setFeaturePaneId(int paneId) { @@ -176,69 +175,71 @@ QList LibraryFeature::getSavedQueries() const { return m_savedDAO.getSavedQueries(this); } -WTrackTableView* LibraryFeature::createTableWidget(int paneId) { - WTrackTableView* pTrackTableView = - new WTrackTableView(nullptr, m_pConfig, m_pTrackCollection, true); - m_trackTablesByPaneId[paneId] = pTrackTableView; +parented_ptr LibraryFeature::createTableWidget(int paneId, QWidget* parent) { + auto pTrackTableView = make_parented(parent, m_pConfig, + m_pTrackCollection, true); + + m_trackTablesByPaneId[paneId] = pTrackTableView.get(); - WMiniViewScrollBar* pScrollBar = new WMiniViewScrollBar(pTrackTableView); - pTrackTableView->setScrollBar(pScrollBar); + auto pScrollBar = make_parented(pTrackTableView.get()); + pTrackTableView->setScrollBar(pScrollBar.get()); - connect(pTrackTableView, SIGNAL(loadTrack(TrackPointer)), + connect(pTrackTableView.get(), SIGNAL(loadTrack(TrackPointer)), this, SIGNAL(loadTrack(TrackPointer))); - connect(pTrackTableView, SIGNAL(loadTrackToPlayer(TrackPointer, QString, bool)), + connect(pTrackTableView.get(), SIGNAL(loadTrackToPlayer(TrackPointer, QString, bool)), this, SIGNAL(loadTrackToPlayer(TrackPointer, QString, bool))); - connect(pTrackTableView, SIGNAL(trackSelected(TrackPointer)), + connect(pTrackTableView.get(), SIGNAL(trackSelected(TrackPointer)), this, SIGNAL(trackSelected(TrackPointer))); - connect(pTrackTableView, SIGNAL(tableChanged()), + connect(pTrackTableView.get(), SIGNAL(tableChanged()), this, SLOT(restoreSaveButton())); connect(m_pLibrary, SIGNAL(setTrackTableFont(QFont)), - pTrackTableView, SLOT(setTrackTableFont(QFont))); + pTrackTableView.get(), SLOT(setTrackTableFont(QFont))); connect(m_pLibrary, SIGNAL(setTrackTableRowHeight(int)), - pTrackTableView, SLOT(setTrackTableRowHeight(int))); + pTrackTableView.get(), SLOT(setTrackTableRowHeight(int))); - return pTrackTableView; + return std::move(pTrackTableView); } -QWidget* LibraryFeature::createInnerSidebarWidget(KeyboardEventFilter *pKeyboard) { - return createLibrarySidebarWidget(pKeyboard); +parented_ptr LibraryFeature::createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, QWidget* parent) { + Q_UNUSED(pKeyboard); + return std::move(createLibrarySidebarWidget(parent)); } -WLibrarySidebar* LibraryFeature::createLibrarySidebarWidget(KeyboardEventFilter*) { - WLibrarySidebar* pSidebar = new WLibrarySidebar(nullptr); +parented_ptr LibraryFeature::createLibrarySidebarWidget(QWidget* parent) { + auto pSidebar = make_parented(parent); QAbstractItemModel* pModel = getChildModel(); pSidebar->setModel(pModel); // Set sidebar mini view - WMiniViewScrollBar* pMiniView = new WMiniViewScrollBar(pSidebar); - pMiniView->setTreeView(pSidebar); + auto pMiniView = make_parented(pSidebar.get()); + pMiniView->setTreeView(pSidebar.get()); pMiniView->setModel(pModel); - pSidebar->setVerticalScrollBar(pMiniView); + pSidebar->setVerticalScrollBar(pMiniView.get()); // invalidate probably stored QModelIndex invalidateChild(); - connect(pSidebar, SIGNAL(pressed(const QModelIndex&)), + connect(pSidebar.get(), SIGNAL(pressed(const QModelIndex&)), this, SLOT(activateChild(const QModelIndex&))); - connect(pSidebar, SIGNAL(doubleClicked(const QModelIndex&)), + connect(pSidebar.get(), SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onLazyChildExpandation(const QModelIndex&))); - connect(pSidebar, SIGNAL(rightClicked(const QPoint&, const QModelIndex&)), + connect(pSidebar.get(), SIGNAL(rightClicked(const QPoint&, const QModelIndex&)), this, SLOT(onRightClickChild(const QPoint&, const QModelIndex&))); - connect(pSidebar, SIGNAL(expanded(const QModelIndex&)), + connect(pSidebar.get(), SIGNAL(expanded(const QModelIndex&)), this, SLOT(onLazyChildExpandation(const QModelIndex&))); connect(this, SIGNAL(selectIndex(const QModelIndex&)), - pSidebar, SLOT(selectIndex(const QModelIndex&))); + pSidebar.get(), SLOT(selectIndex(const QModelIndex&))); - connect(pSidebar, SIGNAL(hovered()), + connect(pSidebar.get(), SIGNAL(hovered()), this, SLOT(slotSetHoveredSidebar())); - connect(pSidebar, SIGNAL(leaved()), + connect(pSidebar.get(), SIGNAL(leaved()), this, SLOT(slotResetHoveredSidebar())); - connect(pSidebar, SIGNAL(focusIn()), + connect(pSidebar.get(), SIGNAL(focusIn()), this, SLOT(slotSetFocusedSidebar())); - connect(pSidebar, SIGNAL(focusOut()), + connect(pSidebar.get(), SIGNAL(focusOut()), this, SLOT(slotResetFocusedSidebar())); - return pSidebar; + return std::move(pSidebar); } void LibraryFeature::showTrackModel(QAbstractItemModel *model) { diff --git a/src/library/libraryfeature.h b/src/library/libraryfeature.h index 5997f13d4977..31e0104dc27e 100644 --- a/src/library/libraryfeature.h +++ b/src/library/libraryfeature.h @@ -8,12 +8,12 @@ #include #include #include -#include #include #include "preferences/usersettings.h" #include "library/dao/savedqueriesdao.h" #include "track/track.h" +#include "util/parented_ptr.h" class Library; class KeyboardEventFilter; @@ -60,12 +60,13 @@ class LibraryFeature : public QObject { // Reimplement this to register custom views with the library widget // at the right pane. - virtual QWidget* createPaneWidget(KeyboardEventFilter* pKeyboard, - int paneId); + virtual parented_ptr createPaneWidget(KeyboardEventFilter* pKeyboard, + int paneId, QWidget* parent); // Reimplement this to register custom views with the library widget, // at the sidebar expanded pane - virtual QWidget* createSidebarWidget(KeyboardEventFilter* pKeyboard); + virtual parented_ptr createSidebarWidget(KeyboardEventFilter* pKeyboard, + QWidget* parent); virtual TreeItemModel* getChildModel() = 0; @@ -141,15 +142,15 @@ class LibraryFeature : public QObject { } // Creates a table widget with no model - WTrackTableView* createTableWidget(int paneId); + parented_ptr createTableWidget(int paneId, QWidget *parent); // Creates a WLibrarySidebar widget with the getChildModel() function as // model - WLibrarySidebar* createLibrarySidebarWidget(KeyboardEventFilter*); + parented_ptr createLibrarySidebarWidget(QWidget* parent); // Override this function to create a custom inner widget for the sidebar, // the default widget is a WLibrarySidebar widget - virtual QWidget* createInnerSidebarWidget(KeyboardEventFilter* pKeyboard); + virtual parented_ptr createInnerSidebarWidget(KeyboardEventFilter* pKeyboard, QWidget* parent); void showTrackModel(QAbstractItemModel* model); void switchToFeature(); diff --git a/src/library/librarypanemanager.cpp b/src/library/librarypanemanager.cpp index 8a3ced09e025..2bd48bf0bda3 100644 --- a/src/library/librarypanemanager.cpp +++ b/src/library/librarypanemanager.cpp @@ -24,25 +24,20 @@ void LibraryPaneManager::bindPaneWidget(WBaseLibrary* pPaneWidget, //qDebug() << "LibraryPaneManager::bindLibraryWidget" << libraryWidget; m_pPaneWidget = pPaneWidget; - connect(pPaneWidget, SIGNAL(focused()), + connect(m_pPaneWidget, SIGNAL(focused()), this, SLOT(slotPaneFocused())); - connect(pPaneWidget, SIGNAL(collapsed()), + connect(m_pPaneWidget, SIGNAL(collapsed()), this, SLOT(slotPaneCollapsed())); - connect(pPaneWidget, SIGNAL(uncollapsed()), + connect(m_pPaneWidget, SIGNAL(uncollapsed()), this, SLOT(slotPaneUncollapsed())); - if (qobject_cast(pPaneWidget) == nullptr) { + if (qobject_cast(m_pPaneWidget) == nullptr) { return; } - for (LibraryFeature* f : m_features) { - //f->bindPaneWidget(pPaneWidget, pKeyboard, m_paneId); - - QWidget* pFeaturePaneWidget = f->createPaneWidget(pKeyboard, m_paneId); - if (pFeaturePaneWidget == nullptr) { - continue; - } - pFeaturePaneWidget->setParent(pPaneWidget); - pPaneWidget->registerView(f, pFeaturePaneWidget); + for (LibraryFeature* f : m_features) { + auto pFeaturePaneWidget = f->createPaneWidget(pKeyboard, m_paneId, + m_pPaneWidget); + m_pPaneWidget->registerView(f, pFeaturePaneWidget.get()); } } diff --git a/src/library/librarypanemanager.h b/src/library/librarypanemanager.h index 52cd0f9a8f01..7a7d4e6d3e4f 100644 --- a/src/library/librarypanemanager.h +++ b/src/library/librarypanemanager.h @@ -26,7 +26,7 @@ class LibraryPaneManager : public QObject { bool initialize(); // All features must be added before adding a pane - virtual void bindPaneWidget(WBaseLibrary* pLibraryWidget, + virtual void bindPaneWidget(WBaseLibrary *pLibraryWidget, KeyboardEventFilter* pKeyboard); void bindSearchBar(WSearchLineEdit* pSearchBar); void setBreadCrumb(WLibraryBreadCrumb* pBreadCrumb); diff --git a/src/library/librarysidebarexpandedmanager.cpp b/src/library/librarysidebarexpandedmanager.cpp index 60da9906c79f..79ca8700500b 100644 --- a/src/library/librarysidebarexpandedmanager.cpp +++ b/src/library/librarysidebarexpandedmanager.cpp @@ -12,12 +12,11 @@ void LibrarySidebarExpandedManager::bindPaneWidget(WBaseLibrary* sidebarWidget, m_pPaneWidget = sidebarWidget; for (LibraryFeature* f : m_features) { - QWidget* pPane = f->createSidebarWidget(pKeyboard); - if (pPane == nullptr) { + auto pPane = f->createSidebarWidget(pKeyboard, m_pPaneWidget); + if (pPane.get() == nullptr) { continue; } - pPane->setParent(sidebarWidget); - sidebarWidget->registerView(f, pPane); + m_pPaneWidget->registerView(f, pPane.get()); } } diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 3d2b463c335b..179a71aaf087 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -1279,82 +1279,84 @@ QWidget* LegacySkinParser::parseLibraryPane(const QDomElement& node) { return nullptr; } //qDebug() << "LegacySkinParser::parseLibrary:ID" << id; - WLibraryPane* pLibraryPaneWidget = new WLibraryPane(m_pParent); + // Create the parented pointer here, actually all the parse.. functions + // should use the parented_ptr + auto pLibraryPaneWidget = make_parented(m_pParent); pLibraryPaneWidget->installEventFilter(m_pKeyboard); pLibraryPaneWidget->installEventFilter( m_pControllerManager->getControllerLearningEventFilter()); - m_pLibrary->bindPaneWidget(pLibraryPaneWidget, m_pKeyboard, id); + m_pLibrary->bindPaneWidget(pLibraryPaneWidget.get(), m_pKeyboard, id); // This must come after the bindWidget or we will not style any of the // LibraryView's because they have not been added yet. - commonWidgetSetup(node, pLibraryPaneWidget, false); - return pLibraryPaneWidget; + commonWidgetSetup(node, pLibraryPaneWidget.get(), false); + return pLibraryPaneWidget.get(); } QWidget* LegacySkinParser::parseLibrary(const QDomElement& node) { // Must add both a SearchBox and a LibraryPane - QFrame* pContainer = new QFrame(m_pParent); - QVBoxLayout* pLayout = new QVBoxLayout(pContainer); - pContainer->setLayout(pLayout); + auto pContainer = make_parented(m_pParent); + auto pLayout = make_parented(pContainer.get()); + pContainer->setLayout(pLayout.get()); - WLibraryBreadCrumb* pBreadCrumb = new WLibraryBreadCrumb(pContainer); - m_pLibrary->bindBreadCrumb(pBreadCrumb, m_paneId); - setupWidget(node, pBreadCrumb); - pLayout->addWidget(pBreadCrumb); + auto pBreadCrumb = make_parented(pContainer.get()); + m_pLibrary->bindBreadCrumb(pBreadCrumb.get(), m_paneId); + setupWidget(node, pBreadCrumb.get()); + pLayout->addWidget(pBreadCrumb.get()); - WSearchLineEdit* pSearchBox = new WSearchLineEdit(pContainer); + auto pSearchBox = make_parented(pContainer.get()); pSearchBox->setup(node, *m_pContext); - m_pLibrary->bindSearchBar(pSearchBox, m_paneId); - commonWidgetSetup(node, pSearchBox); - pLayout->addWidget(pSearchBox); + m_pLibrary->bindSearchBar(pSearchBox.get(), m_paneId); + commonWidgetSetup(node, pSearchBox.get()); + pLayout->addWidget(pSearchBox.get()); - WLibraryPane* pLibraryWidget = new WLibraryPane(pContainer); + auto pLibraryWidget = make_parented(pContainer.get()); pLibraryWidget->installEventFilter(m_pKeyboard); pLibraryWidget->installEventFilter( m_pControllerManager->getControllerLearningEventFilter()); - pLayout->addWidget(pLibraryWidget); + pLayout->addWidget(pLibraryWidget.get()); - m_pLibrary->bindPaneWidget(pLibraryWidget, m_pKeyboard, m_paneId); - commonWidgetSetup(node, pLibraryWidget, false); + m_pLibrary->bindPaneWidget(pLibraryWidget.get(), m_pKeyboard, m_paneId); + commonWidgetSetup(node, pLibraryWidget.get(), false); qDebug() << "LegacySkinParser::parseLibrary"; ++m_paneId; - return pContainer; + return pContainer.get(); } QWidget* LegacySkinParser::parseLibrarySidebar(const QDomElement& node) { // We must create both LibrarySidebarButtons and LibrarySidebarExpanded // to allow support for old skins - QFrame* pContainer = new QFrame(m_pParent); - QHBoxLayout* pLayout = new QHBoxLayout(pContainer); - pContainer->setLayout(pLayout); + auto pContainer = make_parented(m_pParent); + auto pLayout = make_parented(pContainer.get()); + pContainer->setLayout(pLayout.get()); // Create config object for WButtonBar ConfigKey confKey("[Library]", "show_icon_text"); controlFromConfigKey(confKey, true, nullptr); m_pConfig->set(confKey, QString::number(1.0)); - WVerticalScrollArea* scroll = new WVerticalScrollArea(pContainer); + auto scroll = make_parented(pContainer.get()); scroll->installEventFilter(m_pKeyboard); - pLayout->addWidget(scroll); + pLayout->addWidget(scroll.get()); - WButtonBar* pLibrarySidebar = new WButtonBar(scroll); - m_pLibrary->bindSidebarButtons(pLibrarySidebar); - scroll->setWidget(pLibrarySidebar); - connect(pLibrarySidebar, SIGNAL(ensureVisible(QWidget*)), - scroll, SLOT(slotEnsureVisible(QWidget*))); + auto pLibrarySidebar = make_parented(scroll.get()); + m_pLibrary->bindSidebarButtons(pLibrarySidebar.get()); + scroll->setWidget(pLibrarySidebar.get()); + connect(pLibrarySidebar.get(), SIGNAL(ensureVisible(QWidget*)), + scroll.get(), SLOT(slotEnsureVisible(QWidget*))); - WBaseLibrary* pLibrarySidebarExpanded = new WBaseLibrary(pContainer); + auto pLibrarySidebarExpanded = make_parented(pContainer.get()); pLibrarySidebarExpanded->installEventFilter(m_pKeyboard); pLibrarySidebarExpanded->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); - m_pLibrary->bindSidebarExpanded(pLibrarySidebarExpanded, m_pKeyboard); - pLayout->addWidget(pLibrarySidebarExpanded); + m_pLibrary->bindSidebarExpanded(pLibrarySidebarExpanded.get(), m_pKeyboard); + pLayout->addWidget(pLibrarySidebarExpanded.get()); - setupWidget(node, pLibrarySidebar); - commonWidgetSetup(node, pLibrarySidebarExpanded, false); - return pContainer; + setupWidget(node, pLibrarySidebar.get()); + commonWidgetSetup(node, pLibrarySidebarExpanded.get(), false); + return pContainer.get(); } QWidget* LegacySkinParser::parseLibrarySidebarButtons(const QDomElement& node) { @@ -1372,13 +1374,13 @@ QWidget* LegacySkinParser::parseLibrarySidebarButtons(const QDomElement& node) { return scroll; } -QWidget *LegacySkinParser::parseLibrarySidebarExpanded(const QDomElement &node) { - WBaseLibrary* pLibrarySidebarExpanded = new WBaseLibrary(m_pParent); +QWidget* LegacySkinParser::parseLibrarySidebarExpanded(const QDomElement &node) { + auto pLibrarySidebarExpanded = make_parented(m_pParent); pLibrarySidebarExpanded->installEventFilter(m_pKeyboard); pLibrarySidebarExpanded->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); - m_pLibrary->bindSidebarExpanded(pLibrarySidebarExpanded, m_pKeyboard); - commonWidgetSetup(node, pLibrarySidebarExpanded, false); - return pLibrarySidebarExpanded; + m_pLibrary->bindSidebarExpanded(pLibrarySidebarExpanded.get(), m_pKeyboard); + commonWidgetSetup(node, pLibrarySidebarExpanded.get(), false); + return pLibrarySidebarExpanded.get(); } QWidget* LegacySkinParser::parseLibraryBreadCrumb(const QDomElement& node) {