diff --git a/src/library/features/browse/foldertreemodel.cpp b/src/library/features/browse/foldertreemodel.cpp index 96993d5e85e8..86c931243d54 100644 --- a/src/library/features/browse/foldertreemodel.cpp +++ b/src/library/features/browse/foldertreemodel.cpp @@ -45,7 +45,7 @@ bool FolderTreeModel::hasChildren(const QModelIndex& parent) const { return false; } - if(item->dataPath().toString() == QUICK_LINK_NODE) + if(item->getData().toString() == QUICK_LINK_NODE) return true; //Can only happen on Windows if(item->getData().toString() == DEVICE_NODE) diff --git a/src/library/features/crates/cratefeature.cpp b/src/library/features/crates/cratefeature.cpp index 210568f7dc2f..bfd8face4e6a 100644 --- a/src/library/features/crates/cratefeature.cpp +++ b/src/library/features/crates/cratefeature.cpp @@ -96,9 +96,7 @@ CrateFeature::CrateFeature(UserSettingsPointer pConfig, this, SLOT(slotCrateTableChanged(int))); // construct child model - auto pRootItem = std::make_unique(this); - pRootItem->setLibraryFeature(this); - m_childModel.setRootItem(std::move(pRootItem)); + m_childModel.setRootItem(std::make_unique(this)); constructChildModel(-1); connect(pLibrary, SIGNAL(trackSelected(TrackPointer)), diff --git a/src/library/features/history/historytreemodel.cpp b/src/library/features/history/historytreemodel.cpp index 334ad2755634..48589b92bd3c 100644 --- a/src/library/features/history/historytreemodel.cpp +++ b/src/library/features/history/historytreemodel.cpp @@ -22,9 +22,7 @@ HistoryTreeModel::HistoryTreeModel(HistoryFeature* pFeature, } QModelIndex HistoryTreeModel::reloadListsTree(int playlistId) { - TreeItem* pRootItem = new TreeItem(); - pRootItem->setLibraryFeature(m_pFeature); - setRootItem(pRootItem); + TreeItem* pRootItem = setRootItem(std::make_unique(m_pFeature)); QString trackCountName = "TrackCount"; QString queryStr = "SELECT %1,COUNT(%2) AS %7 " @@ -72,15 +70,13 @@ QModelIndex HistoryTreeModel::reloadListsTree(int playlistId) { row = 0; change = true; QString year = QString::number(auxDate.year()); - lastYear = new TreeItem(year, -1, m_pFeature, pRootItem); - pRootItem->appendChild(lastYear); + lastYear = pRootItem->appendChild(year, -1); } if (auxDate.month() != lastDate.month() || change) { row = 0; QString month = QDate::longMonthName(auxDate.month(), QDate::StandaloneFormat); - lastMonth = new TreeItem(month, -1, m_pFeature, lastYear); - lastYear->appendChild(lastMonth); + lastMonth = lastYear->appendChild(month, -1); } QString sData = query.value(ind.iName).toString(); @@ -88,9 +84,8 @@ QModelIndex HistoryTreeModel::reloadListsTree(int playlistId) { int id = query.value(ind.iID).toInt(); - lastPlaylist = new TreeItem(sData, id, m_pFeature, lastMonth); + lastPlaylist = lastMonth->appendChild(sData, id); m_pFeature->decorateChild(lastPlaylist, id); - lastMonth->appendChild(lastPlaylist); if (id == playlistId) { selectedRow = row; selectedItem = lastPlaylist; @@ -107,7 +102,7 @@ QModelIndex HistoryTreeModel::reloadListsTree(int playlistId) { QModelIndex HistoryTreeModel::indexFromPlaylistId(int playlistId) { int row = -1; - TreeItem* pItem = findItemFromPlaylistId(m_pRootItem, playlistId, row); + TreeItem* pItem = findItemFromPlaylistId(getRootItem(), playlistId, row); return createIndex(row, 0, pItem); } @@ -125,9 +120,9 @@ QVariant HistoryTreeModel::data(const QModelIndex& index, int role) const { } QList HistoryTreeModel::idsFromItem(TreeItem* pTree) const { - if (pTree->childCount() <= 0) { + if (pTree->childRows() <= 0) { bool ok; - int value = pTree->dataPath().toInt(&ok); + int value = pTree->getData().toInt(&ok); QList ret; if (!ok) { return ret; @@ -137,7 +132,7 @@ QList HistoryTreeModel::idsFromItem(TreeItem* pTree) const { } QList res; - int size = pTree->childCount(); + int size = pTree->childRows(); for (int i = 0; i < size; ++i) { QList aux = idsFromItem(pTree->child(i)); res.append(aux); @@ -147,10 +142,10 @@ QList HistoryTreeModel::idsFromItem(TreeItem* pTree) const { TreeItem* HistoryTreeModel::findItemFromPlaylistId(TreeItem* pTree, int playlistId, int& row) const { - int size = pTree->childCount(); + int size = pTree->childRows(); if (size <= 0) { bool ok = false; - int value = pTree->dataPath().toInt(&ok); + int value = pTree->getData().toInt(&ok); if (ok && value == playlistId) { return pTree; } diff --git a/src/library/features/itunes/itunesfeature.cpp b/src/library/features/itunes/itunesfeature.cpp index ae75c5b2042b..f150020b9782 100644 --- a/src/library/features/itunes/itunesfeature.cpp +++ b/src/library/features/itunes/itunesfeature.cpp @@ -364,7 +364,7 @@ TreeItem* ITunesFeature::importLibrary() { } QXmlStreamReader xml(&itunes_file); - TreeItem* playlist_root = NULL; + TreeItem* playlist_root = nullptr; while (!xml.atEnd() && !m_cancelImport) { xml.readNext(); if (xml.isStartElement()) { @@ -376,7 +376,7 @@ TreeItem* ITunesFeature::importLibrary() { } } else if (key == "Tracks") { parseTracks(xml); - if (playlist_root != NULL) + if (playlist_root != nullptr) delete playlist_root; playlist_root = parsePlaylists(xml); } @@ -396,7 +396,7 @@ TreeItem* ITunesFeature::importLibrary() { qDebug() << "XML ERROR: " << xml.errorString(); if (playlist_root) delete playlist_root; - playlist_root = NULL; + playlist_root = nullptr; } return playlist_root; } @@ -743,7 +743,6 @@ void ITunesFeature::clearTable(QString table_name) { void ITunesFeature::onTrackCollectionLoaded() { std::unique_ptr root(m_future.result()); if (root) { - root->setLibraryFeature(this); m_childModel.setRootItem(std::move(root)); // Tell the rhythmbox track source that it should re-build its index. diff --git a/src/library/features/libraryfolder/libraryfoldermodel.cpp b/src/library/features/libraryfolder/libraryfoldermodel.cpp index 2ce0a457cd86..3131909d844c 100644 --- a/src/library/features/libraryfolder/libraryfoldermodel.cpp +++ b/src/library/features/libraryfolder/libraryfoldermodel.cpp @@ -69,7 +69,7 @@ QVariant LibraryFolderModel::data(const QModelIndex& index, int role) const { } const QString param("%1:=\"%2\""); - return param.arg("folder", pTree->dataPath().toString()); + return param.arg("folder", pTree->getData().toString()); } return TreeItemModel::data(index, role); @@ -79,11 +79,10 @@ void LibraryFolderModel::reloadTree() { //qDebug() << "LibraryFolderModel::reloadTree()"; beginResetModel(); // Remove current root - setRootItem(new TreeItem(m_pFeature)); + setRootItem(std::make_unique(m_pFeature)); // Add "show all" item - m_pShowAllItem = new TreeItem(tr("Show all"), "", m_pFeature, m_pRootItem); - m_pRootItem->appendChild(m_pShowAllItem); + m_pShowAllItem = m_pRootItem->appendChild(tr("Show all"), ""); // Get the Library directories QStringList dirs(m_pTrackCollection->getDirectoryDAO().getDirs()); @@ -118,7 +117,7 @@ void LibraryFolderModel::reloadTree() { void LibraryFolderModel::createTreeForLibraryDir(const QString& dir, QSqlQuery& query) { QStringList lastUsed; QList parent; - parent.append(m_pRootItem); + parent.append(getRootItem()); bool first = true; while (query.next()) { @@ -139,9 +138,8 @@ void LibraryFolderModel::createTreeForLibraryDir(const QString& dir, QSqlQuery& if (m_folderRecursive) { path.append("*"); } - TreeItem* pTree = new TreeItem(dir, path, m_pFeature, m_pRootItem); + TreeItem* pTree = m_pRootItem->appendChild(dir, path); pTree->setDivider(true); - m_pRootItem->appendChild(pTree); } // Do not add empty items @@ -174,9 +172,8 @@ void LibraryFolderModel::createTreeForLibraryDir(const QString& dir, QSqlQuery& fullPath.append("*"); } - TreeItem* pItem = new TreeItem(val, fullPath, m_pFeature, parent[i]); + TreeItem* pItem = parent[i]->appendChild(val, fullPath); pItem->setTrackCount(0); - parent[i]->appendChild(pItem); parent[i + 1] = pItem; lastUsed[i] = val; diff --git a/src/library/features/mixxxlibrary/mixxxlibrarytreemodel.cpp b/src/library/features/mixxxlibrary/mixxxlibrarytreemodel.cpp index 84b100b94831..29d8afabf322 100644 --- a/src/library/features/mixxxlibrary/mixxxlibrarytreemodel.cpp +++ b/src/library/features/mixxxlibrary/mixxxlibrarytreemodel.cpp @@ -135,18 +135,14 @@ void MixxxLibraryTreeModel::reloadTree() { //qDebug() << "LibraryTreeModel::reloadTracksTree"; beginResetModel(); // Create root item - TreeItem* pRootItem = new TreeItem(); - pRootItem->setLibraryFeature(m_pFeature); + TreeItem* pRootItem = setRootItem(std::make_unique(m_pFeature)); - m_pLibraryItem = new TreeItem(tr("Show all"), "", m_pFeature, pRootItem); - pRootItem->appendChild(m_pLibraryItem); + m_pLibraryItem = pRootItem->appendChild(tr("Show all"), ""); QString groupTitle = tr("Grouping Options (%1)").arg(m_sortOrder.join(" > ")); - m_pSettings = new TreeItem(groupTitle, "", m_pFeature, pRootItem); - pRootItem->appendChild(m_pSettings); + m_pSettings = pRootItem->appendChild(groupTitle, ""); // Deletes the old root item if the previous root item was not null - setRootItem(pRootItem); createTracksTree(); endResetModel(); } @@ -183,7 +179,7 @@ QVariant MixxxLibraryTreeModel::getQuery(TreeItem* pTree) const { QStringList result; // We need to know the depth before doing anything - while (pAux->parent() != m_pRootItem && pAux->parent() != nullptr) { + while (pAux->parent() != getRootItem() && pAux->parent() != nullptr) { pAux = pAux->parent(); ++depth; } @@ -191,7 +187,7 @@ QVariant MixxxLibraryTreeModel::getQuery(TreeItem* pTree) const { // Generate the query pAux = pTree; while (depth >= 0) { - QString value = pAux->dataPath().toString(); + QString value = pAux->getData().toString(); if (pAux->isDivider()) { value.append("*"); } @@ -267,7 +263,7 @@ void MixxxLibraryTreeModel::createTracksTree() { // with this we can always use parent[i] to get the parent of the element at // depth i and to set the parent we avoid checking that i + 1 < treeDepth QVector parent(treeDepth + 1, nullptr); - parent[0] = m_pRootItem; + parent[0] = getRootItem(); while (query.next()) { for (int i = 0; i < treeDepth; ++i) { @@ -292,20 +288,17 @@ void MixxxLibraryTreeModel::createTracksTree() { QChar c = StringHelper::getFirstCharForGrouping(treeItemLabel); if (lastHeader != c) { lastHeader = c; - TreeItem* pTree = new TreeItem(lastHeader, lastHeader, - m_pFeature, parent[0]); + TreeItem* pTree = + parent[0]->appendChild(lastHeader, lastHeader); pTree->setDivider(true); - parent[0]->appendChild(pTree); } } lastUsed[i] = dataPath; // We need to create a new item - TreeItem* pTree = new TreeItem(treeItemLabel, dataPath, - m_pFeature, parent[i]); + TreeItem* pTree = parent[i]->appendChild(treeItemLabel, dataPath); pTree->setTrackCount(0); - parent[i]->appendChild(pTree); parent[i + 1] = pTree; // Add coverart info diff --git a/src/library/features/playlist/playlistfeature.cpp b/src/library/features/playlist/playlistfeature.cpp index f9c92a56cdab..44b20b7389d9 100644 --- a/src/library/features/playlist/playlistfeature.cpp +++ b/src/library/features/playlist/playlistfeature.cpp @@ -22,8 +22,7 @@ PlaylistFeature::PlaylistFeature(UserSettingsPointer pConfig, TrackCollection* pTrackCollection) : BasePlaylistFeature(pConfig, pLibrary, parent, pTrackCollection) { //construct child model - TreeItem *rootItem = new TreeItem(); - m_childModel->setRootItem(rootItem); + m_childModel->setRootItem(std::make_unique(this)); constructChildModel(-1); } diff --git a/src/library/features/recording/dlgrecording.cpp b/src/library/features/recording/dlgrecording.cpp index 5132fc8f606b..3fa6ccf36c64 100644 --- a/src/library/features/recording/dlgrecording.cpp +++ b/src/library/features/recording/dlgrecording.cpp @@ -39,15 +39,11 @@ DlgRecording::~DlgRecording() { void DlgRecording::onShow() { m_recordingDir = m_pRecordingManager->getRecordingDir(); - m_browseModel.setPath(m_recordingDir); -} - -bool DlgRecording::hasFocus() const { - return QWidget::hasFocus(); + m_pBrowseModel->setPath(m_recordingDir); } void DlgRecording::refreshBrowseModel() { - m_browseModel.setPath(m_recordingDir); + m_pBrowseModel->setPath(m_recordingDir); } void DlgRecording::setBrowseTableModel(BrowseTableModel* pBrowseModel) { @@ -55,10 +51,6 @@ void DlgRecording::setBrowseTableModel(BrowseTableModel* pBrowseModel) { m_pBrowseModel->setPath(m_recordingDir); } -void DlgRecording::refreshBrowseModel() { - m_pBrowseModel->setPath(m_recordingDir); -} - void DlgRecording::toggleRecording(bool toggle) { Q_UNUSED(toggle); if (!m_pRecordingManager->isRecordingActive()) //If recording is enabled diff --git a/src/library/features/recording/recordingfeature.cpp b/src/library/features/recording/recordingfeature.cpp index 9afb871d8c6a..2665d8f7ba25 100644 --- a/src/library/features/recording/recordingfeature.cpp +++ b/src/library/features/recording/recordingfeature.cpp @@ -22,9 +22,7 @@ RecordingFeature::RecordingFeature(UserSettingsPointer pConfig, m_pBrowseModel(nullptr), m_pProxyModel(nullptr) { - TreeItem* pRoot = new TreeItem(); - pRoot->setLibraryFeature(this); - m_childModel.setRootItem(pRoot); + m_childModel.setRootItem(std::make_unique(this)); } RecordingFeature::~RecordingFeature() { diff --git a/src/library/features/rhythmbox/rhythmboxfeature.cpp b/src/library/features/rhythmbox/rhythmboxfeature.cpp index b81aae8297f2..cc95cb14912e 100644 --- a/src/library/features/rhythmbox/rhythmboxfeature.cpp +++ b/src/library/features/rhythmbox/rhythmboxfeature.cpp @@ -443,7 +443,6 @@ void RhythmboxFeature::clearTable(QString table_name) { void RhythmboxFeature::onTrackCollectionLoaded() { std::unique_ptr root(m_track_future.result()); if (root) { - root->setLibraryFeature(this); m_childModel.setRootItem(std::move(root)); // Tell the rhythmbox track source that it should re-build its index. diff --git a/src/library/features/traktor/traktorfeature.cpp b/src/library/features/traktor/traktorfeature.cpp index 5fb4caf1ea09..26febd1cf61b 100644 --- a/src/library/features/traktor/traktorfeature.cpp +++ b/src/library/features/traktor/traktorfeature.cpp @@ -173,8 +173,8 @@ void TraktorFeature::activateChild(const QModelIndex& index) { TreeItem *item = static_cast(index.internalPointer()); if (item->isPlaylist()) { - qDebug() << "Activate Traktor Playlist: " << item->dataPath().toString(); - m_pTraktorPlaylistModel->setPlaylist(item->dataPath().toString()); + qDebug() << "Activate Traktor Playlist: " << item->getData().toString(); + m_pTraktorPlaylistModel->setPlaylist(item->getData().toString()); showTrackModel(m_pTraktorPlaylistModel); showBreadCrumb(item); @@ -605,14 +605,13 @@ QString TraktorFeature::getTraktorMusicDatabase() { void TraktorFeature::onTrackCollectionLoaded() { std::unique_ptr root(m_future.result()); if (root) { - root->setLibraryFeature(this); m_childModel.setRootItem(std::move(root)); // Tell the traktor track source that it should re-build its index. m_trackSource->buildIndex(); //m_pTraktorTableModel->select(); showTrackModel(m_pTraktorTableModel); - showBreadCrumb(root); + showBreadCrumb(root.get()); qDebug() << "Traktor library loaded successfully"; } else { QMessageBox::warning( diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index 1a842897ef70..ca6e7b196656 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -221,7 +221,7 @@ void LibraryControl::sidebarWidgetDeleted() { } void LibraryControl::slotLoadSelectedTrackToGroup(QString group, bool play) { - if (!m_pLibraryWidget) { + if (!m_pLibrary) { return; } @@ -412,11 +412,11 @@ void LibraryControl::slotToggleSelectedSidebarItem(double v) { void LibraryControl::slotChooseItem(double v) { // XXX: Make this more generic? If Enter key is mapped correctly maybe we can use that - if (!m_pLibraryWidget) { + if (!m_pLibrary) { return; } // Load current track if a LibraryView object has focus - const auto activeView = m_pLibraryWidget->getActiveView(); + const auto activeView = m_pLibrary->getActiveView(); if (activeView && activeView->hasFocus()) { return slotLoadSelectedIntoFirstStopped(v); } diff --git a/src/library/librarycontrol.h b/src/library/librarycontrol.h index e531a1caa4b4..4b3427d0bb28 100644 --- a/src/library/librarycontrol.h +++ b/src/library/librarycontrol.h @@ -130,7 +130,6 @@ class LibraryControl : public QObject { std::unique_ptr m_pLoadSelectedIntoFirstStopped; // Library widgets - WLibrary* m_pLibraryWidget; WLibrarySidebar* m_pSidebarWidget; // Other variables diff --git a/src/library/treeitemmodel.cpp b/src/library/treeitemmodel.cpp index dea2c7a29e2c..31cc69b6c2d0 100644 --- a/src/library/treeitemmodel.cpp +++ b/src/library/treeitemmodel.cpp @@ -46,6 +46,7 @@ int TreeItemModel::columnCount(const QModelIndex &parent) const { QVariant TreeItemModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); + } TreeItem* item = static_cast(index.internalPointer()); if (item == nullptr) { @@ -55,7 +56,7 @@ QVariant TreeItemModel::data(const QModelIndex &index, int role) const { // We use Qt::UserRole to ask for the datapath. switch(role) { case Qt::DisplayRole: - return item->data(); + return item->getLabel(); case Qt::SizeHintRole: { QIcon icon(item->getIcon()); @@ -69,7 +70,7 @@ QVariant TreeItemModel::data(const QModelIndex &index, int role) const { case Qt::DecorationRole: return item->getIcon(); case AbstractRole::RoleDataPath: - return item->dataPath(); + return item->getData(); case AbstractRole::RoleBold: return item->isBold(); case AbstractRole::RoleDivider: @@ -77,7 +78,7 @@ QVariant TreeItemModel::data(const QModelIndex &index, int role) const { case AbstractRole::RoleBreadCrumb: return getBreadCrumbString(item); case AbstractRole::RoleGroupingLetter: - return StringHelper::getFirstCharForGrouping(item->data().toString()); + return StringHelper::getFirstCharForGrouping(item->getData().toString()); } return QVariant(); @@ -94,10 +95,10 @@ bool TreeItemModel::setData(const QModelIndex &a_rIndex, // Set the relevant data. switch (a_iRole) { case Qt::DisplayRole: - pItem->setData(a_rValue, pItem->dataPath()); + pItem->setLabel(a_rValue.toString()); break; case AbstractRole::RoleDataPath: - pItem->setData(pItem->data(), a_rValue); + pItem->setData(a_rValue); break; case AbstractRole::RoleBold: pItem->setBold(a_rValue.toBool()); @@ -241,15 +242,15 @@ void TreeItemModel::triggerRepaint() { //static QString TreeItemModel::getBreadCrumbString(TreeItem* pTree) { // Base case - if (pTree == nullptr || pTree->getFeature() == nullptr) { + if (pTree == nullptr || pTree->feature() == nullptr) { return QString(); } else if (pTree->parent() == nullptr) { - return pTree->getFeature()->title().toString(); + return pTree->feature()->title().toString(); } // Recursive case - QString text = pTree->data().toString(); + QString text = pTree->getLabel(); QString next = getBreadCrumbString(pTree->parent()); return next % QLatin1String(" > ") % text; } @@ -289,5 +290,5 @@ LibraryFeature* TreeItemModel::getFeatureFromIndex(const QModelIndex& index) con if (pTree == nullptr) { return nullptr; } - return pTree->getFeature(); + return pTree->feature(); } diff --git a/src/widget/wlibrarybreadcrumb.cpp b/src/widget/wlibrarybreadcrumb.cpp index 69b98063d147..8f2983267e4c 100644 --- a/src/widget/wlibrarybreadcrumb.cpp +++ b/src/widget/wlibrarybreadcrumb.cpp @@ -69,7 +69,7 @@ void WLibraryBreadCrumb::setPreviewed(bool value) { } void WLibraryBreadCrumb::showBreadCrumb(TreeItem* pTree) { - LibraryFeature* pFeature = pTree->getFeature(); + LibraryFeature* pFeature = pTree->feature(); DEBUG_ASSERT_AND_HANDLE(pFeature != nullptr) { return; } diff --git a/src/widget/wlibrarystack.cpp b/src/widget/wlibrarystack.cpp index 740d8cbdf6f0..2044505633ea 100644 --- a/src/widget/wlibrarystack.cpp +++ b/src/widget/wlibrarystack.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "widget/wlibrarystack.h" @@ -77,7 +78,7 @@ bool WLibraryStack::checkAndWarning(QWidget* w) { return true; } -bool hasFocus() { +bool WLibraryStack::hasFocus() const { return QStackedWidget::hasFocus(); }