Skip to content

Commit

Permalink
Merge pull request #2502 from uklotzde/treeitemfeature
Browse files Browse the repository at this point in the history
TreeItem: Initialize LibraryFeature consistently
  • Loading branch information
Holzhaus authored Feb 15, 2020
2 parents 4ef6ab9 + e611cbb commit 26fc46f
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 100 deletions.
4 changes: 2 additions & 2 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
m_playlistDao.setAutoDJProcessor(m_pAutoDJProcessor);

// Create the "Crates" tree-item under the root item.
auto pRootItem = std::make_unique<TreeItem>(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
m_pCratesTreeItem = pRootItem->appendChild(tr("Crates"));
m_pCratesTreeItem->setIcon(QIcon(":/images/library/ic_library_crates.svg"));

Expand Down Expand Up @@ -215,7 +215,7 @@ void AutoDJFeature::slotCrateChanged(CrateId crateId) {
// No child item for crate found
// -> Create and append a new child item for this crate
QList<TreeItem*> rows;
rows.append(new TreeItem(this, crate.getName(), crate.getId().toVariant()));
rows.append(new TreeItem(crate.getName(), crate.getId().toVariant()));
QModelIndex parentIndex = m_childModel.index(0, 0);
m_childModel.insertTreeItemRows(rows, m_crateList.length(), parentIndex);
DEBUG_ASSERT(rows.isEmpty()); // ownership passed to m_childModel
Expand Down
2 changes: 1 addition & 1 deletion src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void BansheeFeature::activate() {

m_isActivated = true;

auto pRootItem = std::make_unique<TreeItem>(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
QList<BansheeDbConnection::Playlist> playlists = m_connection.getPlaylists();
for (const BansheeDbConnection::Playlist& playlist: playlists) {
qDebug() << playlist.name;
Expand Down
2 changes: 1 addition & 1 deletion src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) {
}

// Create the TreeItem whose parent is the invisible root item
TreeItem* item = new TreeItem(this, playlistLabel, playlistId);
TreeItem* item = new TreeItem(playlistLabel, playlistId);
item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId));

decorateChild(item, playlistId);
Expand Down
13 changes: 4 additions & 9 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BrowseFeature::BrowseFeature(
m_proxyModel.setDynamicSortFilter(true);

// The invisible root item of the child model
auto pRootItem = std::make_unique<TreeItem>(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);

m_pQuickLinkItem = pRootItem->appendChild(tr("Quick Links"), QUICK_LINK_NODE);

Expand Down Expand Up @@ -153,7 +153,7 @@ void BrowseFeature::slotAddQuickLink() {
QString name = extractNameFromPath(spath);

QModelIndex parent = m_childModel.index(m_pQuickLinkItem->parentRow(), 0);
auto pNewChild = std::make_unique<TreeItem>(this, name, vpath);
auto pNewChild = std::make_unique<TreeItem>(name, vpath);
QList<TreeItem*> rows;
rows.append(pNewChild.get());
pNewChild.release();
Expand Down Expand Up @@ -312,7 +312,7 @@ void BrowseFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index

namespace {
// Get the list of devices (under "Removable Devices" section).
QList<TreeItem*> getRemovableDevices(LibraryFeature* pFeature) {
QList<TreeItem*> getRemovableDevices() {
QList<TreeItem*> ret;
#if defined(__WINDOWS__)
// Repopulate drive list
Expand All @@ -332,7 +332,6 @@ QList<TreeItem*> getRemovableDevices(LibraryFeature* pFeature) {
display_path.chop(1);
}
TreeItem* driveLetter = new TreeItem(
pFeature,
display_path, // Displays C:
drive.filePath()); // Displays C:/
ret << driveLetter;
Expand All @@ -354,13 +353,10 @@ QList<TreeItem*> getRemovableDevices(LibraryFeature* pFeature) {
// Convert devices into a QList<TreeItem*> for display.
foreach(QFileInfo device, devices) {
TreeItem* folder = new TreeItem(
pFeature,
device.fileName(),
QVariant(device.filePath() + QStringLiteral("/")));
ret << folder;
}
#else
Q_UNUSED(pFeature);
#endif
return ret;
}
Expand Down Expand Up @@ -404,7 +400,7 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) {

// If we are on the special device node
if (path == DEVICE_NODE) {
folders += getRemovableDevices(this);
folders += getRemovableDevices();
} else {
// we assume that the path refers to a folder in the file system
// populate childs
Expand All @@ -424,7 +420,6 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) {
// Once the items are added to the TreeItemModel,
// the models takes ownership of them and ensures their deletion
TreeItem* folder = new TreeItem(
this,
one.fileName(),
QVariant(one.absoluteFilePath() + QStringLiteral("/")));
folders << folder;
Expand Down
4 changes: 2 additions & 2 deletions src/library/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CrateFeature::CrateFeature(Library* pLibrary,
initActions();

// construct child model
m_childModel.setRootItem(std::make_unique<TreeItem>(this));
m_childModel.setRootItem(TreeItem::newRoot(this));
rebuildChildModel();

connectLibrary(pLibrary);
Expand Down Expand Up @@ -192,7 +192,7 @@ QString CrateFeature::formatRootViewHtml() const {

std::unique_ptr<TreeItem> CrateFeature::newTreeItemForCrateSummary(
const CrateSummary& crateSummary) {
auto pTreeItem = std::make_unique<TreeItem>(this);
auto pTreeItem = TreeItem::newRoot(this);
updateTreeItemForCrateSummary(pTreeItem.get(), crateSummary);
return pTreeItem;
}
Expand Down
6 changes: 3 additions & 3 deletions src/library/itunes/itunesfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void ITunesFeature::parseTrack(QXmlStreamReader& xml, QSqlQuery& query) {

TreeItem* ITunesFeature::parsePlaylists(QXmlStreamReader& xml) {
qDebug() << "Parse iTunes playlists";
TreeItem* rootItem = new TreeItem(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
QSqlQuery query_insert_to_playlists(m_database);
query_insert_to_playlists.prepare("INSERT INTO itunes_playlists (id, name) "
"VALUES (:id, :name)");
Expand All @@ -660,15 +660,15 @@ TreeItem* ITunesFeature::parsePlaylists(QXmlStreamReader& xml) {
parsePlaylist(xml,
query_insert_to_playlists,
query_insert_to_playlist_tracks,
rootItem);
pRootItem.get());
continue;
}
if (xml.isEndElement()) {
if (xml.name() == "array")
break;
}
}
return rootItem;
return pRootItem.release();
}

bool ITunesFeature::readNextStartElement(QXmlStreamReader& xml) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/mixxxlibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary,
// These rely on the 'default' track source being present.
m_pLibraryTableModel = new LibraryTableModel(this, pLibrary->trackCollections(), "mixxx.db.model.library");

auto pRootItem = std::make_unique<TreeItem>(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
pRootItem->appendChild(kMissingTitle);
pRootItem->appendChild(kHiddenTitle);

Expand Down
2 changes: 1 addition & 1 deletion src/library/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PlaylistFeature::PlaylistFeature(
"mixxx.db.model.playlist"));

//construct child model
auto pRootItem = std::make_unique<TreeItem>(this);
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
m_childModel.setRootItem(std::move(pRootItem));
constructChildModel(-1);
}
Expand Down
36 changes: 13 additions & 23 deletions src/library/rekordbox/rekordboxfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void clearTable(QSqlDatabase& database, QString tableName) {
}

// This function is executed in a separate thread other than the main thread
QList<TreeItem*> findRekordboxDevices(RekordboxFeature* rekordboxFeature) {
QList<TreeItem*> findRekordboxDevices() {
QThread* thisThread = QThread::currentThread();
thisThread->setPriority(QThread::LowPriority);

Expand All @@ -86,20 +86,16 @@ QList<TreeItem*> findRekordboxDevices(RekordboxFeature* rekordboxFeature) {
QFileInfo rbDBFileInfo(drive.filePath() + kPdbPath);

if (rbDBFileInfo.exists() && rbDBFileInfo.isFile()) {
TreeItem* foundDevice = new TreeItem(rekordboxFeature);
QList<QString> data;

QString displayPath = drive.filePath();
if (displayPath.endsWith("/")) {
displayPath.chop(1);
}

QList<QString> data;
data << drive.filePath();
data << IS_RECORDBOX_DEVICE;

foundDevice->setLabel(displayPath);
foundDevice->setData(QVariant(data));

TreeItem* foundDevice = new TreeItem(
std::move(displayPath),
QVariant(data));
foundDevices << foundDevice;
}
}
Expand All @@ -126,15 +122,12 @@ QList<TreeItem*> findRekordboxDevices(RekordboxFeature* rekordboxFeature) {
QFileInfo rbDBFileInfo(device.filePath() + QStringLiteral("/") + kPdbPath);

if (rbDBFileInfo.exists() && rbDBFileInfo.isFile()) {
TreeItem* foundDevice = new TreeItem(rekordboxFeature);
QList<QString> data;

data << device.filePath();
data << IS_RECORDBOX_DEVICE;

foundDevice->setLabel(device.fileName());
foundDevice->setData(QVariant(data));

TreeItem* foundDevice = new TreeItem(
device.fileName(),
QVariant(data));
foundDevices << foundDevice;
}
}
Expand All @@ -145,15 +138,12 @@ QList<TreeItem*> findRekordboxDevices(RekordboxFeature* rekordboxFeature) {
QFileInfo rbDBFileInfo(device.filePath() + QStringLiteral("/") + kPdbPath);

if (rbDBFileInfo.exists() && rbDBFileInfo.isFile()) {
TreeItem* foundDevice = new TreeItem(rekordboxFeature);
QList<QString> data;

data << device.filePath();
data << IS_RECORDBOX_DEVICE;

foundDevice->setLabel(device.fileName());
foundDevice->setData(QVariant(data));

auto* foundDevice = new TreeItem(
device.fileName(),
QVariant(data));
foundDevices << foundDevice;
}
}
Expand Down Expand Up @@ -1063,7 +1053,7 @@ RekordboxFeature::RekordboxFeature(
connect(&m_devicesFutureWatcher, SIGNAL(finished()), this, SLOT(onRekordboxDevicesFound()));
connect(&m_tracksFutureWatcher, SIGNAL(finished()), this, SLOT(onTracksFound()));
// initialize the model
m_childModel.setRootItem(std::make_unique<TreeItem>(this));
m_childModel.setRootItem(TreeItem::newRoot(this));
}

RekordboxFeature::~RekordboxFeature() {
Expand Down Expand Up @@ -1150,7 +1140,7 @@ void RekordboxFeature::activate() {
qDebug() << "RekordboxFeature::activate()";

// Let a worker thread do the XML parsing
m_devicesFuture = QtConcurrent::run(findRekordboxDevices, this);
m_devicesFuture = QtConcurrent::run(findRekordboxDevices);
m_devicesFutureWatcher.setFuture(m_devicesFuture);
m_title = tr("(loading) Rekordbox");
//calls a slot in the sidebar model such that 'Rekordbox (isLoading)' is displayed.
Expand Down
8 changes: 3 additions & 5 deletions src/library/rhythmbox/rhythmboxfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ TreeItem* RhythmboxFeature::importPlaylists() {
"INSERT INTO rhythmbox_playlist_tracks (playlist_id, track_id, position) "
"VALUES (:playlist_id, :track_id, :position)");
//The tree structure holding the playlists
TreeItem* rootItem = new TreeItem(this);
std::unique_ptr<TreeItem> rootItem = TreeItem::newRoot(this);

QXmlStreamReader xml(&db);
while (!xml.atEnd() && !m_cancelImport) {
Expand Down Expand Up @@ -253,13 +253,11 @@ TreeItem* RhythmboxFeature::importPlaylists() {
// do error handling
qDebug() << "Cannot process Rhythmbox music collection";
qDebug() << "XML ERROR: " << xml.errorString();
delete rootItem;
return NULL;
return nullptr;
}
db.close();

return rootItem;

return rootItem.release();
}

void RhythmboxFeature::importTrack(QXmlStreamReader &xml, QSqlQuery &query) {
Expand Down
3 changes: 1 addition & 2 deletions src/library/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ SetlogFeature::SetlogFeature(
/*show-all-tracks*/ true));

//construct child model
auto pRootItem = std::make_unique<TreeItem>(this);
m_childModel.setRootItem(std::move(pRootItem));
m_childModel.setRootItem(TreeItem::newRoot(this));
constructChildModel(-1);

m_pJoinWithPreviousAction = new QAction(tr("Join with previous"), this);
Expand Down
6 changes: 3 additions & 3 deletions src/library/traktor/traktorfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ TreeItem* TraktorFeature::parsePlaylists(QXmlStreamReader &xml) {

QString delimiter = "-->";

TreeItem *rootItem = new TreeItem(this);
TreeItem * parent = rootItem;
std::unique_ptr<TreeItem> rootItem = TreeItem::newRoot(this);
TreeItem* parent = rootItem.get();

QSqlQuery query_insert_to_playlists(m_database);
query_insert_to_playlists.prepare("INSERT INTO traktor_playlists (name) "
Expand Down Expand Up @@ -452,7 +452,7 @@ TreeItem* TraktorFeature::parsePlaylists(QXmlStreamReader &xml) {
}
}
}
return rootItem;
return rootItem.release();
}

void TraktorFeature::parsePlaylistEntries(
Expand Down
Loading

0 comments on commit 26fc46f

Please sign in to comment.