=== modified file 'mixxx/src/dlgautodj.cpp' --- mixxx/src/dlgautodj.cpp 2011-04-24 06:00:11 +0000 +++ mixxx/src/dlgautodj.cpp 2011-08-27 18:18:45 +0000 @@ -37,8 +37,7 @@ m_pAutoDJTableModel = new PlaylistTableModel(this, pTrackCollection); int playlistId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE); if (playlistId < 0) { - m_playlistDao.createPlaylist(AUTODJ_TABLE, true); - playlistId = m_playlistDao.getPlaylistIdFromName(AUTODJ_TABLE); + playlistId = m_playlistDao.createPlaylist(AUTODJ_TABLE, true); } m_pAutoDJTableModel->setPlaylist(playlistId); m_pTrackTableView->loadTrackModel(m_pAutoDJTableModel); === modified file 'mixxx/src/library/cratefeature.cpp' --- mixxx/src/library/cratefeature.cpp 2011-07-19 18:12:33 +0000 +++ mixxx/src/library/cratefeature.cpp 2011-08-27 21:06:14 +0000 @@ -22,10 +22,13 @@ CrateFeature::CrateFeature(QObject* parent, TrackCollection* pTrackCollection, ConfigObject* pConfig) : m_pTrackCollection(pTrackCollection), + m_crateDao(pTrackCollection->getCrateDAO()), m_crateListTableModel(this, pTrackCollection->getDatabase()), - m_pConfig(pConfig), - m_crateTableModel(this, pTrackCollection) { - m_pCreateCrateAction = new QAction(tr("New Crate"),this); + m_crateTableModel(this, pTrackCollection), + m_pConfig(pConfig) +{ + Q_UNUSED(parent); + m_pCreateCrateAction = new QAction(tr("New Crate"),this); connect(m_pCreateCrateAction, SIGNAL(triggered()), this, SLOT(slotCreateCrate())); @@ -48,6 +51,19 @@ connect(m_pExportPlaylistAction, SIGNAL(triggered()), this, SLOT(slotExportPlaylist())); + connect(&m_crateDao, SIGNAL(added(int)), + this, SLOT(slotCrateTableChanged(int))); + + connect(&m_crateDao, SIGNAL(deleted(int)), + this, SLOT(slotCrateTableChanged(int))); + + connect(&m_crateDao, SIGNAL(renamed(int)), + this, SLOT(slotCrateTableChanged(int))); + + connect(&m_crateDao, SIGNAL(lockChanged(int)), + this, SLOT(slotCrateTableChanged(int))); + + m_crateListTableModel.setTable("crates"); m_crateListTableModel.setSort(m_crateListTableModel.fieldIndex("name"), Qt::AscendingOrder); @@ -57,7 +73,7 @@ // construct child model TreeItem *rootItem = new TreeItem(); m_childModel.setRootItem(rootItem); - constructChildModel(); + constructChildModel(-1); } CrateFeature::~CrateFeature() { @@ -78,12 +94,13 @@ } bool CrateFeature::dropAccept(QUrl url) { + Q_UNUSED(url) return false; } bool CrateFeature::dropAcceptChild(const QModelIndex& index, QUrl url) { QString crateName = index.data().toString(); - int crateId = m_pTrackCollection->getCrateDAO().getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByName(crateName); //XXX: See the comment in PlaylistFeature::dropAcceptChild() about // QUrl::toLocalFile() vs. QUrl::toString() usage. @@ -99,23 +116,21 @@ qDebug() << "CrateFeature::dropAcceptChild adding track" << trackId << "to crate" << crateId; - CrateDAO& crateDao = m_pTrackCollection->getCrateDAO(); - if (trackId >= 0) - return crateDao.addTrackToCrate(trackId, crateId); + return m_crateDao.addTrackToCrate(trackId, crateId); return false; } bool CrateFeature::dragMoveAccept(QUrl url) { - return false; + Q_UNUSED(url) + return false; } bool CrateFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { //TODO: Filter by supported formats regex and reject anything that doesn't match. QString crateName = index.data().toString(); - CrateDAO& crateDao = m_pTrackCollection->getCrateDAO(); - int crateId = crateDao.getCrateIdByName(crateName); - bool locked = crateDao.isCrateLocked(crateId); + int crateId = m_crateDao.getCrateIdByName(crateName); + bool locked = m_crateDao.isCrateLocked(crateId); QFileInfo file(url.toLocalFile()); bool formatSupported = SoundSourceProxy::isFilenameSupported(file.fileName()); @@ -124,8 +139,11 @@ void CrateFeature::bindWidget(WLibrarySidebar* sidebarWidget, WLibrary* libraryWidget, - MixxxKeyboard* keyboard) { - WLibraryTextBrowser* edit = new WLibraryTextBrowser(libraryWidget); + MixxxKeyboard* keyboard) +{ + Q_UNUSED(sidebarWidget); + Q_UNUSED(keyboard); + WLibraryTextBrowser* edit = new WLibraryTextBrowser(libraryWidget); connect(this, SIGNAL(showPage(const QUrl&)), edit, SLOT(setSource(const QUrl&))); libraryWidget->registerView("CRATEHOME", edit); @@ -144,7 +162,7 @@ if (!index.isValid()) return; QString crateName = index.data().toString(); - int crateId = m_pTrackCollection->getCrateDAO().getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByName(crateName); m_crateTableModel.setCrate(crateId); emit(showTrackModel(&m_crateTableModel)); } @@ -161,10 +179,9 @@ m_lastRightClickedIndex = index; QString crateName = index.data().toString(); - CrateDAO& crateDAO = m_pTrackCollection->getCrateDAO(); - int crateId = crateDAO.getCrateIdByName(crateName); + int crateId = m_crateDao.getCrateIdByName(crateName); - bool locked = crateDAO.isCrateLocked(crateId); + bool locked = m_crateDao.isCrateLocked(crateId); m_pDeleteCrateAction->setEnabled(!locked); m_pRenameCrateAction->setEnabled(!locked); @@ -187,7 +204,6 @@ QString name; bool validNameGiven = false; - CrateDAO& crateDao = m_pTrackCollection->getCrateDAO(); do { bool ok = false; @@ -200,7 +216,7 @@ if (!ok) return; - int existingId = crateDao.getCrateIdByName(name); + int existingId = m_crateDao.getCrateIdByName(name); if (existingId != -1) { QMessageBox::warning(NULL, @@ -218,17 +234,10 @@ } while (!validNameGiven); - bool crateCreated = crateDao.createCrate(name); + int crate_id = m_crateDao.createCrate(name); - if (crateCreated) { - clearChildModel(); - m_crateListTableModel.select(); - constructChildModel(); - // Switch to the new crate. - int crate_id = crateDao.getCrateIdByName(name); - m_crateTableModel.setCrate(crate_id); + if (crate_id != -1) { emit(showTrackModel(&m_crateTableModel)); - // TODO(XXX) set sidebar selection emit(featureUpdated()); } else { qDebug() << "Error creating crate with name " << name; @@ -242,22 +251,19 @@ void CrateFeature::slotDeleteCrate() { QString crateName = m_lastRightClickedIndex.data().toString(); - CrateDAO &crateDao = m_pTrackCollection->getCrateDAO(); - int crateId = crateDao.getCrateIdByName(crateName); - bool locked = crateDao.isCrateLocked(crateId); + int crateId = m_crateDao.getCrateIdByName(crateName); + bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { qDebug() << "Skipping crate deletion because crate" << crateId << "is locked."; return; } - bool deleted = crateDao.deleteCrate(crateId); + bool deleted = m_crateDao.deleteCrate(crateId); if (deleted) { - clearChildModel(); - m_crateListTableModel.select(); - constructChildModel(); emit(featureUpdated()); + activate(); } else { qDebug() << "Failed to delete crateId" << crateId; } @@ -265,9 +271,8 @@ void CrateFeature::slotRenameCrate() { QString oldName = m_lastRightClickedIndex.data().toString(); - CrateDAO &crateDao = m_pTrackCollection->getCrateDAO(); - int crateId = crateDao.getCrateIdByName(oldName); - bool locked = crateDao.isCrateLocked(crateId); + int crateId = m_crateDao.getCrateIdByName(oldName); + bool locked = m_crateDao.isCrateLocked(crateId); if (locked) { qDebug() << "Skipping crate rename because crate" << crateId << "is locked."; @@ -290,7 +295,7 @@ return; } - int existingId = m_pTrackCollection->getCrateDAO().getCrateIdByName(newName); + int existingId = m_crateDao.getCrateIdByName(newName); if (existingId != -1) { QMessageBox::warning(NULL, @@ -308,12 +313,8 @@ } while (!validNameGiven); - if (m_pTrackCollection->getCrateDAO().renameCrate(crateId, newName)) { - clearChildModel(); - m_crateListTableModel.select(); - constructChildModel(); + if (m_crateDao.renameCrate(crateId, newName)) { emit(featureUpdated()); - m_crateTableModel.setCrate(crateId); } else { qDebug() << "Failed to rename crateId" << crateId; } @@ -322,17 +323,12 @@ void CrateFeature::slotToggleCrateLock() { QString crateName = m_lastRightClickedIndex.data().toString(); - CrateDAO& crateDAO = m_pTrackCollection->getCrateDAO(); - int crateId = crateDAO.getCrateIdByName(crateName); - bool locked = !crateDAO.isCrateLocked(crateId); + int crateId = m_crateDao.getCrateIdByName(crateName); + bool locked = !m_crateDao.isCrateLocked(crateId); - if (!crateDAO.setCrateLocked(crateId, locked)) { + if (!m_crateDao.setCrateLocked(crateId, locked)) { qDebug() << "Failed to toggle lock of crateId " << crateId; } - - TreeItem* crateItem = m_childModel.getItem(m_lastRightClickedIndex); - crateItem->setIcon( - locked ? QIcon(":/images/library/ic_library_locked.png") : QIcon()); } @@ -341,14 +337,14 @@ * we require the sidebar model not to reset. * This method queries the database and does dynamic insertion */ -void CrateFeature::constructChildModel() +QModelIndex CrateFeature::constructChildModel(int selected_id) { - QList data_list; + QList data_list; int nameColumn = m_crateListTableModel.record().indexOf("name"); int idColumn = m_crateListTableModel.record().indexOf("id"); - //Access the invisible root item + int selected_row = -1; + // Access the invisible root item TreeItem* root = m_childModel.getItem(QModelIndex()); - CrateDAO &crateDao = m_pTrackCollection->getCrateDAO(); for (int row = 0; row < m_crateListTableModel.rowCount(); ++row) { QModelIndex ind = m_crateListTableModel.index(row, nameColumn); @@ -356,14 +352,23 @@ ind = m_crateListTableModel.index(row, idColumn); int crate_id = m_crateListTableModel.data(ind).toInt(); - //Create the TreeItem whose parent is the invisible root item + if ( selected_id == crate_id) { + // save index for selection + selected_row = row; m_childModel.index(selected_row, 0); + } + + // Create the TreeItem whose parent is the invisible root item TreeItem* item = new TreeItem(crate_name, crate_name, this, root); - bool locked = crateDao.isCrateLocked(crate_id); + bool locked = m_crateDao.isCrateLocked(crate_id); item->setIcon(locked ? QIcon(":/images/library/ic_library_locked.png") : QIcon()); data_list.append(item); } - //Append all the newly created TreeItems in a dynamic way to the childmodel + // Append all the newly created TreeItems in a dynamic way to the childmodel m_childModel.insertRows(data_list, 0, m_crateListTableModel.rowCount()); + if (selected_row == -1) { + return QModelIndex(); + } + return m_childModel.index(selected_row, 0); } /** @@ -416,9 +421,12 @@ if(playlist_parser) delete playlist_parser; } + void CrateFeature::onLazyChildExpandation(const QModelIndex &index){ + Q_UNUSED(index); //Nothing to do because the childmodel is not of lazy nature. } + void CrateFeature::slotExportPlaylist(){ qDebug() << "Export playlist" << m_lastRightClickedIndex.data(); QString file_location = QFileDialog::getSaveFileName(NULL, @@ -455,3 +463,14 @@ ParserM3u::writeM3UFile(file_location, playlist_items, useRelativePath); } } + +void CrateFeature::slotCrateTableChanged(int crateId) { + //qDebug() << "slotPlaylistTableChanged() playlistId:" << playlistId; + clearChildModel(); + m_crateListTableModel.select(); + m_lastRightClickedIndex = constructChildModel(crateId); + // Switch the view to the crate. + m_crateTableModel.setCrate(crateId); + // Update selection + emit(featureSelect(this, m_lastRightClickedIndex)); +} === modified file 'mixxx/src/library/cratefeature.h' --- mixxx/src/library/cratefeature.h 2011-03-12 13:10:25 +0000 +++ mixxx/src/library/cratefeature.h 2011-08-25 19:51:12 +0000 @@ -49,11 +49,14 @@ void slotImportPlaylist(); void slotExportPlaylist(); + void slotCrateTableChanged(int playlistId); + private: - void constructChildModel(); + QModelIndex constructChildModel(int selected_id); void clearChildModel(); TrackCollection* m_pTrackCollection; + CrateDAO& m_crateDao; QAction *m_pCreateCrateAction; QAction *m_pDeleteCrateAction; QAction *m_pRenameCrateAction; === modified file 'mixxx/src/library/dao/cratedao.cpp' --- mixxx/src/library/dao/cratedao.cpp 2011-07-19 18:12:33 +0000 +++ mixxx/src/library/dao/cratedao.cpp 2011-08-25 20:55:41 +0000 @@ -32,7 +32,7 @@ return query.value(0).toInt(); } -bool CrateDAO::createCrate(const QString& name) { +int CrateDAO::createCrate(const QString& name) { QSqlQuery query(m_database); qDebug() << "createCrate()" << name; @@ -41,12 +41,12 @@ if (!query.exec()) { qDebug() << query.lastError(); - return false; + return -1; } int crateId = query.lastInsertId().toInt(); emit(added(crateId)); - return true; + return crateId; } bool CrateDAO::renameCrate(int crateId, const QString& newName) { @@ -65,6 +65,7 @@ } Q_ASSERT(m_database.commit()); + emit(renamed(crateId)); return true; } @@ -85,6 +86,7 @@ } Q_ASSERT(m_database.commit()); + emit(lockChanged(crateId)); return true; } === modified file 'mixxx/src/library/dao/cratedao.h' --- mixxx/src/library/dao/cratedao.h 2011-07-19 18:12:33 +0000 +++ mixxx/src/library/dao/cratedao.h 2011-08-25 20:56:30 +0000 @@ -24,7 +24,7 @@ void initialize(); unsigned int crateCount(); - bool createCrate(const QString& name); + int createCrate(const QString& name); bool deleteCrate(int crateId); bool renameCrate(int crateId, const QString& newName); bool setCrateLocked(int crateId, bool locked); @@ -42,6 +42,8 @@ void changed(int crateId); void trackAdded(int crateId, int trackId); void trackRemoved(int crateId, int trackId); + void renamed(int crateId); + void lockChanged(int crateId); private: QSqlDatabase& m_database; === modified file 'mixxx/src/library/dao/playlistdao.cpp' --- mixxx/src/library/dao/playlistdao.cpp 2011-07-19 18:12:33 +0000 +++ mixxx/src/library/dao/playlistdao.cpp 2011-08-27 18:23:22 +0000 @@ -38,7 +38,7 @@ if (!query.exec()) { qDebug() << query.lastError(); m_database.rollback(); - return false; + return -1; } //query.finish(); @@ -61,7 +61,7 @@ if (!query.exec()) { qDebug() << query.lastError(); m_database.rollback(); - return false; + return -1; } //query.finish(); @@ -69,18 +69,18 @@ //Commit the transaction m_database.commit(); emit(added(playlistId)); - return true; + return playlistId; } -/** Find out the name of the playlist at the given position */ -QString PlaylistDAO::getPlaylistName(unsigned int position) +/** Find out the name of the playlist at the given Id */ +QString PlaylistDAO::getPlaylistName(int playlistId) { // qDebug() << "PlaylistDAO::getPlaylistName" << QThread::currentThread() << m_database.connectionName(); QSqlQuery query(m_database); query.prepare("SELECT name FROM Playlists " - "WHERE position = :position"); - query.bindValue(":position", position); + "WHERE id= :id"); + query.bindValue(":id", playlistId); if (!query.exec()) { qDebug() << "getPlaylistName" << query.lastError(); @@ -164,6 +164,7 @@ } else { m_database.commit(); + emit(renamed(playlistId)); } } @@ -185,6 +186,7 @@ } Q_ASSERT(m_database.commit()); + emit(lockChanged(playlistId)); return true; } @@ -270,7 +272,7 @@ return numRecords; } -int PlaylistDAO::getPlaylistId(int position) +int PlaylistDAO::getPlaylistId(int index) { // qDebug() << "PlaylistDAO::getPlaylistId" // << QThread::currentThread() << m_database.connectionName(); @@ -281,7 +283,7 @@ if (query.exec()) { int currentRow = 0; while(query.next()) { - if (currentRow++ == position) { + if (currentRow++ == index) { int id = query.value(0).toInt(); return id; } @@ -293,6 +295,7 @@ return -1; } + bool PlaylistDAO::isHidden(int playlistId) { // qDebug() << "PlaylistDAO::isHidden" // << QThread::currentThread() << m_database.connectionName(); === modified file 'mixxx/src/library/dao/playlistdao.h' --- mixxx/src/library/dao/playlistdao.h 2011-07-19 18:12:33 +0000 +++ mixxx/src/library/dao/playlistdao.h 2011-08-27 18:24:23 +0000 @@ -31,13 +31,13 @@ /** Find out how many playlists exist. */ unsigned int playlistCount(); /** Get the name of the playlist at the given position */ - QString getPlaylistName(unsigned int position); + QString getPlaylistName(int playlistId); // Get the playlist id by its name int getPlaylistIdFromName(QString name); - /** Get the id of the playlist at position. Note that the position is the + /** Get the id of the playlist at index. Note that the index is the * natural position in the database table, not the display order position * column stored in the database. */ - int getPlaylistId(int position); + int getPlaylistId(int index); // Returns true if the playlist with playlistId is hidden bool isHidden(int playlistId); /** Remove a track from a playlist */ @@ -52,6 +52,8 @@ void changed(int playlistId); void trackAdded(int playlistId, int trackId, int position); void trackRemoved(int playlistId, int trackId, int position); + void renamed(int playlistId); + void lockChanged(int playlistId); private: QSqlDatabase& m_database; }; === modified file 'mixxx/src/library/legacylibraryimporter.cpp' --- mixxx/src/library/legacylibraryimporter.cpp 2010-11-19 01:54:28 +0000 +++ mixxx/src/library/legacylibraryimporter.cpp 2011-08-27 17:50:24 +0000 @@ -148,8 +148,7 @@ //Create the playlist with the imported name. //qDebug() << "Importing playlist:" << current.name; - m_playlistDao.createPlaylist(current.name, false); - int playlistId = m_playlistDao.getPlaylistIdFromName(current.name); + int playlistId = m_playlistDao.createPlaylist(current.name); //For each track ID in the XML... QList trackIDs = current.indexes; === modified file 'mixxx/src/library/libraryfeature.h' --- mixxx/src/library/libraryfeature.h 2011-03-10 14:06:26 +0000 +++ mixxx/src/library/libraryfeature.h 2011-08-27 17:47:42 +0000 @@ -66,7 +66,8 @@ void featureIsLoading(LibraryFeature*); /** emit this signal if the foreign music collection has been imported/parsed. **/ void featureLoadingFinished(LibraryFeature*s); - + /** emit this signal to move the selection **/ + void featureSelect(LibraryFeature* pFeature, const QModelIndex& index); }; === modified file 'mixxx/src/library/playlistfeature.cpp' --- mixxx/src/library/playlistfeature.cpp 2011-03-28 22:19:06 +0000 +++ mixxx/src/library/playlistfeature.cpp 2011-08-27 21:06:26 +0000 @@ -21,11 +21,11 @@ PlaylistFeature::PlaylistFeature(QObject* parent, TrackCollection* pTrackCollection, ConfigObject* pConfig) : LibraryFeature(parent), - // m_pTrackCollection(pTrackCollection), m_playlistDao(pTrackCollection->getPlaylistDAO()), m_trackDao(pTrackCollection->getTrackDAO()), - m_pConfig(pConfig), - m_playlistTableModel(this, pTrackCollection->getDatabase()) { + m_playlistTableModel(this, pTrackCollection->getDatabase()), + m_pConfig(pConfig) +{ m_pPlaylistTableModel = new PlaylistTableModel(this, pTrackCollection); m_pCreatePlaylistAction = new QAction(tr("New Playlist"),this); @@ -55,6 +55,18 @@ connect(m_pExportPlaylistAction, SIGNAL(triggered()), this, SLOT(slotExportPlaylist())); + connect(&m_playlistDao, SIGNAL(added(int)), + this, SLOT(slotPlaylistTableChanged(int))); + + connect(&m_playlistDao, SIGNAL(deleted(int)), + this, SLOT(slotPlaylistTableChanged(int))); + + connect(&m_playlistDao, SIGNAL(renamed(int)), + this, SLOT(slotPlaylistTableChanged(int))); + + connect(&m_playlistDao, SIGNAL(lockChanged(int)), + this, SLOT(slotPlaylistTableChanged(int))); + // Setup the sidebar playlist model m_playlistTableModel.setTable("Playlists"); m_playlistTableModel.setFilter("hidden=0"); @@ -65,7 +77,7 @@ //construct child model TreeItem *rootItem = new TreeItem(); m_childModel.setRootItem(rootItem); - constructChildModel(); + constructChildModel(-1); } PlaylistFeature::~PlaylistFeature() { @@ -89,8 +101,11 @@ void PlaylistFeature::bindWidget(WLibrarySidebar* sidebarWidget, WLibrary* libraryWidget, - MixxxKeyboard* keyboard) { - WLibraryTextBrowser* edit = new WLibraryTextBrowser(libraryWidget); + MixxxKeyboard* keyboard) +{ + Q_UNUSED(sidebarWidget); + Q_UNUSED(keyboard); + WLibraryTextBrowser* edit = new WLibraryTextBrowser(libraryWidget); connect(this, SIGNAL(showPage(const QUrl&)), edit, SLOT(setSource(const QUrl&))); libraryWidget->registerView("PLAYLISTHOME", edit); @@ -182,17 +197,10 @@ } while (!validNameGiven); - bool playlistCreated = m_playlistDao.createPlaylist(name); + int playlistId = m_playlistDao.createPlaylist(name); - if (playlistCreated) { - clearChildModel(); - m_playlistTableModel.select(); - constructChildModel(); + if (playlistId != -1) { emit(featureUpdated()); - //Switch the view to the new playlist. - int playlistId = m_playlistDao.getPlaylistIdFromName(name); - m_pPlaylistTableModel->setPlaylist(playlistId); - // TODO(XXX) set sidebar selection emit(showTrackModel(m_pPlaylistTableModel)); } else { @@ -250,11 +258,7 @@ } while (!validNameGiven); m_playlistDao.renamePlaylist(playlistId, newName); - clearChildModel(); - m_playlistTableModel.select(); - constructChildModel(); - emit(featureUpdated()); - m_pPlaylistTableModel->setPlaylist(playlistId); + emit(featureUpdated()); } @@ -267,9 +271,6 @@ if (!m_playlistDao.setPlaylistLocked(playlistId, locked)) { qDebug() << "Failed to toggle lock of playlistId " << playlistId; } - - TreeItem* playlistItem = m_childModel.getItem(m_lastRightClickedIndex); - playlistItem->setIcon(locked ? QIcon(":/images/library/ic_library_locked.png") : QIcon()); } void PlaylistFeature::slotDeletePlaylist() @@ -283,20 +284,18 @@ return; } - if (m_lastRightClickedIndex.isValid() && - !m_playlistDao.isPlaylistLocked(playlistId)) { + if (m_lastRightClickedIndex.isValid()) { Q_ASSERT(playlistId >= 0); - clearChildModel(); m_playlistDao.deletePlaylist(playlistId); - m_playlistTableModel.select(); - constructChildModel(); emit(featureUpdated()); + activate(); } } bool PlaylistFeature::dropAccept(QUrl url) { + Q_UNUSED(url); return false; } @@ -336,7 +335,8 @@ } bool PlaylistFeature::dragMoveAccept(QUrl url) { - return false; + Q_UNUSED(url); + return false; } bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { @@ -354,20 +354,22 @@ TreeItemModel* PlaylistFeature::getChildModel() { return &m_childModel; } + /** * Purpose: When inserting or removing playlists, * we require the sidebar model not to reset. * This method queries the database and does dynamic insertion */ -void PlaylistFeature::constructChildModel() +QModelIndex PlaylistFeature::constructChildModel(int selected_id) { QList data_list; int nameColumn = m_playlistTableModel.record().indexOf("name"); int idColumn = m_playlistTableModel.record().indexOf("id"); - - //Access the invisible root item + int selected_row = -1; + // Access the invisible root item TreeItem* root = m_childModel.getItem(QModelIndex()); - //Create new TreeItems for the playlists in the database + + // Create new TreeItems for the playlists in the database for (int row = 0; row < m_playlistTableModel.rowCount(); ++row) { QModelIndex ind = m_playlistTableModel.index(row, nameColumn); QString playlist_name = m_playlistTableModel.data(ind).toString(); @@ -375,14 +377,23 @@ int playlist_id = m_playlistTableModel.data(ind).toInt(); bool locked = m_playlistDao.isPlaylistLocked(playlist_id); - //Create the TreeItem whose parent is the invisible root item + if ( selected_id == playlist_id) { + // save index for selection + selected_row = row; + } + + // Create the TreeItem whose parent is the invisible root item TreeItem* item = new TreeItem(playlist_name, playlist_name, this, root); item->setIcon(locked ? QIcon(":/images/library/ic_library_locked.png") : QIcon()); data_list.append(item); } - //Append all the newly created TreeItems in a dynamic way to the childmodel + // Append all the newly created TreeItems in a dynamic way to the childmodel m_childModel.insertRows(data_list, 0, m_playlistTableModel.rowCount()); + if (selected_row == -1) { + return QModelIndex(); + } + return m_childModel.index(selected_row, 0); } /** @@ -431,9 +442,12 @@ //delete the parser object if(playlist_parser) delete playlist_parser; } + void PlaylistFeature::onLazyChildExpandation(const QModelIndex &index){ - //Nothing to do because the childmodel is not of lazy nature. + Q_UNUSED(index); + //Nothing to do because the childmodel is not of lazy nature. } + void PlaylistFeature::slotExportPlaylist(){ qDebug() << "Export playlist" << m_lastRightClickedIndex.data(); QString file_location = QFileDialog::getSaveFileName(NULL, @@ -471,6 +485,7 @@ } } + void PlaylistFeature::slotAddToAutoDJ() { //qDebug() << "slotAddToAutoDJ() row:" << m_lastRightClickedIndex.data(); @@ -483,3 +498,16 @@ } emit(featureUpdated()); } + +void PlaylistFeature::slotPlaylistTableChanged(int playlistId) { + //qDebug() << "PlaylistFeature::slotPlaylistTableChanged() playlistId:" << playlistId; + + clearChildModel(); + m_playlistTableModel.select(); + m_lastRightClickedIndex = constructChildModel(playlistId); + + // Switch the view to the playlist. + m_pPlaylistTableModel->setPlaylist(playlistId); + // Update selection + emit(featureSelect(this, m_lastRightClickedIndex)); +} === modified file 'mixxx/src/library/playlistfeature.h' --- mixxx/src/library/playlistfeature.h 2011-03-26 12:29:21 +0000 +++ mixxx/src/library/playlistfeature.h 2011-08-27 17:38:28 +0000 @@ -55,9 +55,10 @@ void slotImportPlaylist(); void slotExportPlaylist(); + void slotPlaylistTableChanged(int playlistId); private: - void constructChildModel(); + QModelIndex constructChildModel(int selected_id); void clearChildModel(); PlaylistTableModel* m_pPlaylistTableModel; === modified file 'mixxx/src/library/sidebarmodel.cpp' --- mixxx/src/library/sidebarmodel.cpp 2011-03-27 20:12:33 +0000 +++ mixxx/src/library/sidebarmodel.cpp 2011-08-27 21:12:03 +0000 @@ -17,11 +17,14 @@ void SidebarModel::addLibraryFeature(LibraryFeature* feature) { m_sFeatures.push_back(feature); - connect(feature, SIGNAL(featureUpdated()), this, SLOT(refreshData())); + connect(feature, SIGNAL(featureUpdated()), + this, SLOT(refreshData())); connect(feature, SIGNAL(featureIsLoading(LibraryFeature*)), this, SLOT(slotFeatureIsLoading(LibraryFeature*))); connect(feature, SIGNAL(featureLoadingFinished(LibraryFeature*)), - this,SLOT(slotFeatureLoadingFinished(LibraryFeature*))); + this, SLOT(slotFeatureLoadingFinished(LibraryFeature*))); + connect(feature, SIGNAL(featureSelect(LibraryFeature*, const QModelIndex&)), + this, SLOT(slotFeatureSelect(LibraryFeature*, const QModelIndex&))); QAbstractItemModel* model = feature->getChildModel(); @@ -108,19 +111,23 @@ return QModelIndex(); } else { TreeItem* tree_item = (TreeItem*)index.internalPointer(); + TreeItem* tree_item_parent = tree_item->parent(); // if we have selected an item at the first level of a childnode - if (tree_item->parent()->data() == "$root"){ - LibraryFeature* feature = tree_item->getFeature(); - for (int i = 0; i < m_sFeatures.size(); ++i) { - if (feature == m_sFeatures[i]) { - // create a ModelIndex for parent 'this' having a - // library feature at position 'i' - return createIndex(i, 0, (void*)this); - } - } + + if (tree_item_parent) { + if (tree_item_parent->data() == "$root"){ + LibraryFeature* feature = tree_item->getFeature(); + for (int i = 0; i < m_sFeatures.size(); ++i) { + if (feature == m_sFeatures[i]) { + // create a ModelIndex for parent 'this' having a + // library feature at position 'i' + return createIndex(i, 0, (void*)this); + } + } + } + // if we have selected an item at some deeper level of a childnode + return createIndex(tree_item_parent->row(), 0 , tree_item_parent); } - // if we have selected an item at some deeper level of a childnode - return createIndex(tree_item->parent()->row(), 0 , tree_item->parent()); } } return QModelIndex(); @@ -144,7 +151,8 @@ } int SidebarModel::columnCount(const QModelIndex& parent) const { - //qDebug() << "SidebarModel::columnCount parent=" << parent; + Q_UNUSED(parent); + //qDebug() << "SidebarModel::columnCount parent=" << parent; // TODO(rryan) will we ever have columns? I don't think so. return 1; } @@ -314,6 +322,8 @@ } void SidebarModel::slotDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { + Q_UNUSED(topLeft); + Q_UNUSED(bottomRight); //qDebug() << "slotDataChanged topLeft:" << topLeft << "bottomRight:" << bottomRight; } @@ -332,13 +342,19 @@ } void SidebarModel::slotRowsInserted(const QModelIndex& parent, int start, int end) { - // qDebug() << "slotRowsInserted" << parent << start << end; + Q_UNUSED(parent); + Q_UNUSED(start); + Q_UNUSED(end); + // qDebug() << "slotRowsInserted" << parent << start << end; //QModelIndex newParent = translateSourceIndex(parent); endInsertRows(); } void SidebarModel::slotRowsRemoved(const QModelIndex& parent, int start, int end) { - //qDebug() << "slotRowsRemoved" << parent << start << end; + Q_UNUSED(parent); + Q_UNUSED(start); + Q_UNUSED(end); + //qDebug() << "slotRowsRemoved" << parent << start << end; //QModelIndex newParent = translateSourceIndex(parent); endRemoveRows(); } @@ -357,16 +373,16 @@ */ void SidebarModel::slotFeatureIsLoading(LibraryFeature * feature) { - featureRenamed(feature); - selectFeature(feature); + featureRenamed(feature); + slotFeatureSelect(feature); } /* Tobias: This slot is somewhat redundant but I decided * to leave it for code readability reasons */ void SidebarModel::slotFeatureLoadingFinished(LibraryFeature * feature){ - featureRenamed(feature); - selectFeature(feature); + featureRenamed(feature); + slotFeatureSelect(feature); } void SidebarModel::featureRenamed(LibraryFeature* pFeature){ @@ -378,11 +394,19 @@ } } -void SidebarModel::selectFeature(LibraryFeature* pFeature) { - for (int i=0; i < m_sFeatures.size(); ++i) { - if (m_sFeatures[i] == pFeature) { - QModelIndex ind = index(i, 0); - emit(selectIndex(ind)); - } +void SidebarModel::slotFeatureSelect(LibraryFeature* pFeature, const QModelIndex& featureIndex) +{ + QModelIndex ind; + if (featureIndex.isValid()) { + TreeItem* item = (TreeItem*)featureIndex.internalPointer(); + ind = createIndex(featureIndex.row(), featureIndex.column(), item); + } else { + for (int i=0; i < m_sFeatures.size(); ++i) { + if (m_sFeatures[i] == pFeature) { + ind = index(i, 0); + break; + } + } } + emit(selectIndex(ind)); } === modified file 'mixxx/src/library/sidebarmodel.h' --- mixxx/src/library/sidebarmodel.h 2011-03-27 20:12:33 +0000 +++ mixxx/src/library/sidebarmodel.h 2011-08-27 17:45:52 +0000 @@ -39,7 +39,7 @@ void doubleClicked(const QModelIndex& index); void rightClicked(const QPoint& globalPos, const QModelIndex& index); void refreshData(); - void selectFeature(LibraryFeature* pFeature); + void slotFeatureSelect(LibraryFeature* pFeature, const QModelIndex& index = QModelIndex()); // Slots for every single QAbstractItemModel signal // void slotColumnsAboutToBeInserted(const QModelIndex& parent, int start, int end);