(Hopefully) fix selection order of items - and order added to playqueue.

This commit is contained in:
craig.p.drummond
2013-09-03 18:40:50 +00:00
committed by craig.p.drummond
parent aaaf3ee6c4
commit 13c4d2bfc6
21 changed files with 175 additions and 132 deletions

View File

@@ -26,6 +26,10 @@
12. If playqueue is cleared when dynamizer is running, then also stop
dynamizer.
1.1.3
-----
1. (Hopefully) fix selection order of items - and order added to playqueue.
1.1.2
-----
1. Fix build due to broken translation files.

View File

@@ -149,9 +149,9 @@ QString DevicesPage::activeFsDeviceUdi() const
Device * DevicesPage::activeFsDevice() const
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (0==selected.size()) {
if (selected.isEmpty()) {
return 0;
}
@@ -185,11 +185,9 @@ Device * DevicesPage::activeFsDevice() const
QStringList DevicesPage::playableUrls() const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QStringList();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -202,11 +200,9 @@ QStringList DevicesPage::playableUrls() const
QList<Song> DevicesPage::selectedSongs() const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QList<Song>();
}
qSort(selected);
// Ensure all songs are from UMS/Remote devices...
QString udi;
@@ -281,7 +277,7 @@ void DevicesPage::searchItems()
void DevicesPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool haveTracks=false;
bool onlyFs=true;
bool singleUdi=true;
@@ -364,7 +360,7 @@ void DevicesPage::copyToLibrary()
{
const QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return;
}
@@ -396,7 +392,7 @@ void DevicesPage::copyToLibrary()
void DevicesPage::configureDevice()
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
@@ -411,7 +407,7 @@ void DevicesPage::configureDevice()
void DevicesPage::refreshDevice()
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
@@ -472,7 +468,7 @@ void DevicesPage::deleteSongs()
{
const QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return;
}
@@ -532,7 +528,7 @@ void DevicesPage::forgetRemoteDevice()
void DevicesPage::toggleDevice()
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
}
@@ -644,7 +640,7 @@ void DevicesPage::editDetails()
if (AlbumDetailsDialog::instanceCount()) {
return;
}
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
}

View File

@@ -103,7 +103,7 @@ void DynamicPage::searchItems()
void DynamicPage::controlActions()
{
QModelIndexList selected=qobject_cast<Dynamic *>(sender()) ? QModelIndexList() : view->selectedIndexes();
QModelIndexList selected=qobject_cast<Dynamic *>(sender()) ? QModelIndexList() : view->selectedIndexes(false); // Dont need sorted selection here...
editAction->setEnabled(1==selected.count());
Dynamic::self()->startAct()->setEnabled(1==selected.count());
@@ -132,7 +132,7 @@ void DynamicPage::add()
void DynamicPage::edit()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;
@@ -164,7 +164,7 @@ void DynamicPage::remove()
void DynamicPage::start()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;
@@ -179,7 +179,7 @@ void DynamicPage::stop()
void DynamicPage::toggle()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;

View File

@@ -110,11 +110,9 @@ void AlbumsPage::setItemSize(int v)
QStringList AlbumsPage::selectedFiles(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QStringList();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -127,11 +125,9 @@ QStringList AlbumsPage::selectedFiles(bool allowPlaylists) const
QList<Song> AlbumsPage::selectedSongs(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QList<Song>();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -143,7 +139,7 @@ QList<Song> AlbumsPage::selectedSongs(bool allowPlaylists) const
Song AlbumsPage::coverRequest() const
{
QModelIndexList selected = view->selectedIndexes();
QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1==selected.count()) {
QList<Song> songs=AlbumsModel::self()->songs(QModelIndexList() << proxy.mapToSource(selected.at(0)), false);
@@ -195,7 +191,7 @@ void AlbumsPage::deleteSongs()
void AlbumsPage::itemActivated(const QModelIndex &)
{
if (1==view->selectedIndexes().size()) {//doubleclick should only have one selected item
if (1==view->selectedIndexes(false).size()) {//doubleclick should only have one selected item
addSelectionToPlaylist();
}
}
@@ -223,7 +219,7 @@ void AlbumsPage::updateGenres(const QModelIndex &idx)
void AlbumsPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool enable=selected.count()>0;
StdActions::self()->addToPlayQueueAction->setEnabled(enable);

View File

@@ -128,7 +128,7 @@ void FolderPage::searchItems()
void FolderPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool enable=selected.count()>0;
StdActions::self()->addToPlayQueueAction->setEnabled(enable);
@@ -158,7 +158,7 @@ void FolderPage::controlActions()
void FolderPage::itemDoubleClicked(const QModelIndex &)
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return; //doubleclick should only have one selected item
}
@@ -172,7 +172,7 @@ void FolderPage::itemDoubleClicked(const QModelIndex &)
void FolderPage::openFileManager()
{
#ifndef Q_OS_WIN
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
}
@@ -208,11 +208,9 @@ QList<Song> FolderPage::selectedSongs(EmptySongMod esMod, bool allowPlaylists) c
QStringList FolderPage::selectedFiles(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QStringList();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {

View File

@@ -128,11 +128,9 @@ void LibraryPage::clear()
QStringList LibraryPage::selectedFiles(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QStringList();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -145,11 +143,9 @@ QStringList LibraryPage::selectedFiles(bool allowPlaylists) const
QList<Song> LibraryPage::selectedSongs(bool allowPlaylists) const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QList<Song>();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -161,7 +157,7 @@ QList<Song> LibraryPage::selectedSongs(bool allowPlaylists) const
Song LibraryPage::coverRequest() const
{
QModelIndexList selected = view->selectedIndexes();
QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1==selected.count()) {
QModelIndex idx=proxy.mapToSource(selected.at(0));
@@ -286,7 +282,7 @@ void LibraryPage::showAlbum(const QString &artist, const QString &album)
void LibraryPage::itemDoubleClicked(const QModelIndex &)
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return; //doubleclick should only have one selected item
}
@@ -325,7 +321,7 @@ void LibraryPage::updateGenres(const QModelIndex &idx)
void LibraryPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool enable=selected.count()>0;
StdActions::self()->addToPlayQueueAction->setEnabled(enable);

View File

@@ -1050,12 +1050,12 @@ void MainWindow::mpdConnectionStateChanged(bool connected)
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if ((Qt::Key_Enter==event->key() || Qt::Key_Return==event->key()) &&
playQueue->hasFocus() && !playQueue->selectionModel()->selectedRows().isEmpty()) {
//play the first selected song
QModelIndexList selection=playQueue->selectionModel()->selectedRows();
qSort(selection);
playQueueItemActivated(selection.first());
if ((Qt::Key_Enter==event->key() || Qt::Key_Return==event->key()) && playQueue->hasFocus()) {
QModelIndexList selection=playQueue->selectedIndexes();
if (!selection.isEmpty()) {
//play the first selected song
playQueueItemActivated(selection.first());
}
}
}
@@ -1080,7 +1080,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::playQueueItemsSelected(bool s)
{
bool haveItems=playQueue->model()->rowCount()>0;
bool singleSelection=1==playQueue->selectedIndexes().count();
bool singleSelection=1==playQueue->selectedIndexes(false).count(); // Dont need sorted selection here...
removeFromPlayQueueAction->setEnabled(s && haveItems);
locateTrackAction->setEnabled(singleSelection);
copyTrackInfoAction->setEnabled(s && haveItems);
@@ -1589,7 +1589,7 @@ void MainWindow::stopAfterCurrentTrack()
void MainWindow::stopAfterTrack()
{
QModelIndexList selected=playQueue->selectedIndexes();
QModelIndexList selected=playQueue->selectedIndexes(false); // Dont need sorted selection here...
if (1==selected.count()) {
QModelIndex idx=playQueueProxyModel.mapToSource(selected.first());
@@ -1712,7 +1712,7 @@ void MainWindow::realSearchPlayQueue()
if (filter!=playQueueProxyModel.filterText()) {
playQueue->setFilterActive(!filter.isEmpty());
playQueue->selectionModel()->clear();
playQueue->clearSelection();
playQueueProxyModel.update(filter);
QModelIndex idx=playQueueProxyModel.mapFromSource(playQueueModel.index(playQueueModel.currentSongRow(), 0));
playQueue->updateRows(idx.row(), current.key, autoScrollPlayQueue && playQueueProxyModel.isEmpty() && MPDState_Playing==MPDStatus::self()->state());
@@ -2204,7 +2204,6 @@ void MainWindow::addToExistingStoredPlaylist(const QString &name, bool pq)
if (items.isEmpty()) {
files = playQueueModel.filenames();
} else {
qSort(items);
foreach (const QModelIndex &idx, items) {
Song s = playQueueModel.getSongByRow(playQueueProxyModel.mapToSource(idx).row());
if (!s.file.isEmpty()) {

View File

@@ -120,11 +120,9 @@ void PlaylistsPage::clear()
//QStringList PlaylistsPage::selectedFiles() const
//{
// QModelIndexList indexes=view->selectedIndexes();
//
// if (0==indexes.size()) {
// if (indexes.isEmpty()) {
// return QStringList();
// }
// qSort(indexes);
//
// QModelIndexList mapped;
// foreach (const QModelIndex &idx, indexes) {
@@ -218,9 +216,9 @@ void PlaylistsPage::savePlaylist()
void PlaylistsPage::renamePlaylist()
{
const QModelIndexList items = view->selectedIndexes();
const QModelIndexList items = view->selectedIndexes(false); // Dont need sorted selection here...
if (items.size() == 1) {
if (1==items.size()) {
QModelIndex sourceIndex = proxy.mapToSource(items.first());
QString name = PlaylistsModel::self()->data(sourceIndex, Qt::DisplayRole).toString();
QString newName = InputDialog::getText(i18n("Rename Playlist"), i18n("Enter new name for playlist:"), name, 0, this);
@@ -257,7 +255,7 @@ void PlaylistsPage::itemDoubleClicked(const QModelIndex &index)
void PlaylistsPage::addItemsToPlayQueue(const QModelIndexList &indexes, bool replace, quint8 priorty)
{
if (0==indexes.size()) {
if (indexes.isEmpty()) {
return;
}
@@ -272,16 +270,13 @@ void PlaylistsPage::addItemsToPlayQueue(const QModelIndexList &indexes, bool rep
return;
}
}
QModelIndexList sorted=indexes;
qSort(sorted);
QModelIndexList mapped;
foreach (const QModelIndex &idx, sorted) {
mapped.prepend(proxy.mapToSource(idx));
foreach (const QModelIndex &idx, indexes) {
mapped.append(proxy.mapToSource(idx));
}
QStringList files=PlaylistsModel::self()->filenames(mapped);
if (!files.isEmpty()) {
emit add(files, replace, priorty);
view->clearSelection();
@@ -293,7 +288,7 @@ QList<Song> PlaylistsPage::selectedSongs() const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QList<Song>();
}
@@ -317,7 +312,7 @@ void PlaylistsPage::addSelectionToDevice(const QString &udi)
void PlaylistsPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool canRename=false;
bool enableActions=selected.count()>0;

View File

@@ -374,7 +374,6 @@ QList<Song> PlaylistsModel::songs(const QModelIndexList &indexes) const
}
}
}
qSort(songs);
return songs;
}

View File

@@ -108,13 +108,12 @@ QString OnlineServicesPage::activeService() const
OnlineService * OnlineServicesPage::activeSrv() const
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (0==selected.size()) {
if (selected.isEmpty()) {
return 0;
}
QString udi;
OnlineService *activeSrv=0;
foreach (const QModelIndex &idx, selected) {
QModelIndex index = proxy.mapToSource(idx);
@@ -141,11 +140,9 @@ OnlineService * OnlineServicesPage::activeSrv() const
QStringList OnlineServicesPage::selectedFiles() const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QStringList();
}
qSort(selected);
QModelIndexList mapped;
foreach (const QModelIndex &idx, selected) {
@@ -158,11 +155,9 @@ QStringList OnlineServicesPage::selectedFiles() const
QList<Song> OnlineServicesPage::selectedSongs() const
{
QModelIndexList selected = view->selectedIndexes();
if (0==selected.size()) {
if (selected.isEmpty()) {
return QList<Song>();
}
qSort(selected);
QString name;
QModelIndexList mapped;
@@ -203,7 +198,7 @@ void OnlineServicesPage::refresh()
void OnlineServicesPage::itemDoubleClicked(const QModelIndex &)
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return; //doubleclick should only have one selected item
}
@@ -224,7 +219,7 @@ void OnlineServicesPage::controlSearch(bool on)
QString prevSearchService=searchService;
searchService=QString();
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1==selected.count()) {
MusicLibraryItem *item = static_cast<MusicLibraryItem *>(proxy.mapToSource(selected.at(0)).internalPointer());
if (MusicLibraryItem::Type_Root==item->itemType()) {
@@ -325,7 +320,7 @@ void OnlineServicesPage::searchItems()
void OnlineServicesPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();
QModelIndexList selected=view->selectedIndexes(false); // Dont need sorted selection here...
bool srvSelected=false;
bool canDownload=false;
bool canConfigure=false;
@@ -371,7 +366,7 @@ void OnlineServicesPage::controlActions()
void OnlineServicesPage::configureService()
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
@@ -386,7 +381,7 @@ void OnlineServicesPage::configureService()
void OnlineServicesPage::refreshService()
{
const QModelIndexList selected = view->selectedIndexes();
const QModelIndexList selected = view->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;

View File

@@ -173,15 +173,11 @@ void StreamsPage::addSelectionToPlaylist(bool replace, quint8 priorty)
void StreamsPage::addItemsToPlayQueue(const QModelIndexList &indexes, bool replace, quint8 priorty)
{
if (0==indexes.size()) {
if (indexes.isEmpty()) {
return;
}
QModelIndexList sorted=indexes;
qSort(sorted);
QModelIndexList mapped;
foreach (const QModelIndex &idx, sorted) {
foreach (const QModelIndex &idx, indexes) {
mapped.append(proxy->mapToSource(idx));
}
@@ -208,8 +204,7 @@ void StreamsPage::configureStreams()
return;
}
QModelIndexList selected = itemView()->selectedIndexes();
QModelIndexList selected = itemView()->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;
}
@@ -299,7 +294,7 @@ void StreamsPage::add()
void StreamsPage::addBookmark()
{
QModelIndexList selected = itemView()->selectedIndexes();
QModelIndexList selected = itemView()->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;
@@ -369,7 +364,7 @@ void StreamsPage::reload()
return;
}
QModelIndexList selected = itemView()->selectedIndexes();
QModelIndexList selected = itemView()->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.count()) {
return;
}
@@ -459,7 +454,7 @@ void StreamsPage::edit()
return;
}
QModelIndexList selected = itemView()->selectedIndexes();
QModelIndexList selected = itemView()->selectedIndexes(false); // Dont need sorted selection here...
if (1!=selected.size()) {
return;
@@ -506,7 +501,7 @@ StreamsModel::CategoryItem * StreamsPage::getSearchCategory()
{
bool srch=searching;
searching=false;
QModelIndexList selected = itemView()->selectedIndexes();
QModelIndexList selected = itemView()->selectedIndexes(false); // Dont need sorted selection here...
searching=srch;
if (1!=selected.size()) {
@@ -554,7 +549,7 @@ void StreamsPage::controlSearch(bool on)
void StreamsPage::controlActions()
{
QModelIndexList selected=itemView()->selectedIndexes();
QModelIndexList selected=itemView()->selectedIndexes(false); // Dont need sorted selection here...
bool haveSelection=!selected.isEmpty();
bool enableAddToFav=true;
bool onlyStreamsSelected=true;

View File

@@ -623,13 +623,17 @@ void GroupedView::toggle(const QModelIndex &idx)
// Calculate list of selected indexes. If a collapsed album is selected, we also pretend all of its tracks
// are selected.
QModelIndexList GroupedView::selectedIndexes() const
QModelIndexList GroupedView::selectedIndexes(bool sorted) const
{
QModelIndexList indexes = selectionModel()->selectedRows();
QSet<QModelIndex> allIndexes;
QModelIndexList indexes = TreeView::selectedIndexes(sorted);
QSet<QModelIndex> indexSet;
QModelIndexList sel;
foreach (const QModelIndex &idx, indexes) {
allIndexes.insert(idx);
if (!indexSet.contains(idx)) {
indexSet.insert(idx);
sel.append(idx);
}
if (!idx.data(GroupedView::Role_IsCollection).toBool()) {
quint16 key=idx.data(GroupedView::Role_Key).toUInt();
quint32 collection=idx.data(GroupedView::Role_CollectionId).toUInt();
@@ -642,7 +646,10 @@ QModelIndexList GroupedView::selectedIndexes() const
quint32 nextCollection=idx.data(GroupedView::Role_CollectionId).toUInt();
if (nextCollection==collection && nextKey==key) {
allIndexes.insert(next);
if (!indexSet.contains(next)) {
indexSet.insert(next);
sel.append(next);
}
} else {
break;
}
@@ -653,7 +660,7 @@ QModelIndexList GroupedView::selectedIndexes() const
}
}
}
return allIndexes.toList();
return sel;
}
// If we are dropping onto a collapsed album, and we are in the bottom 1/2 of the row - then

View File

@@ -78,7 +78,8 @@ public:
(startClosed && controlledAlbums[collection].contains(key)) ||
(!startClosed && !controlledAlbums[collection].contains(key)); }
void toggle(const QModelIndex &idx);
QModelIndexList selectedIndexes() const;
QModelIndexList selectedIndexes() const { return selectedIndexes(false); }
QModelIndexList selectedIndexes(bool sorted) const;
void dropEvent(QDropEvent *event);
void collectionRemoved(quint32 key);
void expand(const QModelIndex &idx);

View File

@@ -619,14 +619,14 @@ void ItemView::setMode(Mode m)
}
}
QModelIndexList ItemView::selectedIndexes() const
QModelIndexList ItemView::selectedIndexes(bool sorted) const
{
if (Mode_SimpleTree==mode || Mode_DetailedTree==mode) {
return treeView->selectedIndexes();
} else if(Mode_GroupedTree==mode) {
return groupedView->selectedIndexes();
return treeView->selectedIndexes(sorted);
} else if (Mode_GroupedTree==mode) {
return groupedView->selectedIndexes(sorted);
}
return listView->selectedIndexes();
return listView->selectedIndexes(sorted);
}
void ItemView::setLevel(int l, bool haveChildren)

View File

@@ -103,11 +103,10 @@ public:
void setLevel(int level, bool haveChildren=true);
QAbstractItemView * view() const;
void setModel(ProxyModel *m);
void clearSelection() { selectionModel()->clearSelection(); }
QItemSelectionModel * selectionModel() const { return view()->selectionModel(); }
void clearSelection() { view()->selectionModel()->clearSelection(); }
void setCurrentIndex(const QModelIndex &idx) { view()->setCurrentIndex(idx); }
void select(const QModelIndex &idx);
QModelIndexList selectedIndexes() const;
QModelIndexList selectedIndexes(bool sorted=true) const;
QString searchText() const;
void clearSearchText();
void setUniformRowHeights(bool v);

View File

@@ -54,7 +54,7 @@ ListView::~ListView()
void ListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
QListView::selectionChanged(selected, deselected);
bool haveSelection=selectedIndexes().count();
bool haveSelection=haveSelectedItems();
setContextMenuPolicy(haveSelection ? Qt::ActionsContextMenu : (menu ? Qt::CustomContextMenu : Qt::NoContextMenu));
emit itemsSelected(haveSelection);
@@ -62,19 +62,20 @@ void ListView::selectionChanged(const QItemSelection &selected, const QItemSelec
bool ListView::haveSelectedItems() const
{
return selectedIndexes().count()>0;
// Dont need the sorted type of 'selectedIndexes' here...
return selectionModel()->selectedIndexes().count()>0;
}
bool ListView::haveUnSelectedItems() const
{
return selectedIndexes().count()!=model()->rowCount();
// Dont need the sorted type of 'selectedIndexes' here...
return selectionModel()->selectedIndexes().count()!=model()->rowCount();
}
void ListView::startDrag(Qt::DropActions supportedActions)
{
QModelIndexList indexes = selectedIndexes();
if (indexes.count() > 0) {
qSort(indexes);
QMimeData *data = model()->mimeData(indexes);
if (!data) {
return;
@@ -108,10 +109,12 @@ void ListView::mouseReleaseEvent(QMouseEvent *event)
}
}
QModelIndexList ListView::selectedIndexes() const
QModelIndexList ListView::selectedIndexes(bool sorted) const
{
QModelIndexList indexes=selectionModel()->selectedIndexes();
qSort(indexes);
if (sorted) {
qSort(indexes);
}
return indexes;
}

View File

@@ -43,7 +43,8 @@ public:
bool haveUnSelectedItems() const;
void startDrag(Qt::DropActions supportedActions);
void mouseReleaseEvent(QMouseEvent *event);
QModelIndexList selectedIndexes() const;
QModelIndexList selectedIndexes() const { return selectedIndexes(false); }
QModelIndexList selectedIndexes(bool sorted) const;
virtual void setModel(QAbstractItemModel *m);
void addDefaultAction(QAction *act);
void setBackgroundImage(const QIcon &icon);

View File

@@ -347,6 +347,12 @@ bool PlayQueueView::haveUnSelectedItems()
return isGrouped() ? groupedView->haveUnSelectedItems() : treeView->haveUnSelectedItems();
}
void PlayQueueView::clearSelection()
{
groupedView->selectionModel()->clear();
treeView->selectionModel()->clear();
}
QHeaderView * PlayQueueView::header()
{
return treeView->header();
@@ -372,9 +378,9 @@ bool PlayQueueView::hasFocus() const
return isGrouped() ? groupedView->hasFocus() : treeView->hasFocus();
}
QModelIndexList PlayQueueView::selectedIndexes() const
QModelIndexList PlayQueueView::selectedIndexes(bool sorted) const
{
return groupedView==currentWidget() ? groupedView->selectedIndexes() : selectionModel()->selectedRows();
return isGrouped() ? groupedView->selectedIndexes(sorted) : treeView->selectedIndexes(sorted);
}
QList<Song> PlayQueueView::selectedSongs() const

View File

@@ -103,14 +103,14 @@ public:
void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
bool haveSelectedItems();
bool haveUnSelectedItems();
QItemSelectionModel * selectionModel() const { return view()->selectionModel(); }
void setCurrentIndex(const QModelIndex &idx) { view()->setCurrentIndex(idx); }
void clearSelection();
QHeaderView * header();
QAbstractItemView * tree() const;
QAbstractItemView * list() const;
QAbstractItemView * view() const;
bool hasFocus() const;
QModelIndexList selectedIndexes() const;
QModelIndexList selectedIndexes(bool sorted=true) const;
QList<Song> selectedSongs() const;
float fade() { return fadeValue; }
void setFade(float value);

View File

@@ -33,6 +33,7 @@
#include <QMimeData>
#include <QMap>
#include <QStyle>
#include <QList>
#ifdef ENABLE_KDE_SUPPORT
#include <KDE/KGlobalSettings>
@@ -129,7 +130,7 @@ void TreeView::setExpandOnClick()
void TreeView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
QTreeView::selectionChanged(selected, deselected);
bool haveSelection=selectedIndexes().count();
bool haveSelection=haveSelectedItems();
if (!alwaysAllowMenu) {
setContextMenuPolicy(haveSelection ? Qt::ActionsContextMenu : Qt::NoContextMenu);
@@ -139,20 +140,20 @@ void TreeView::selectionChanged(const QItemSelection &selected, const QItemSelec
bool TreeView::haveSelectedItems() const
{
return selectedIndexes().count()>0;
// Dont need the sorted type of 'selectedIndexes' here...
return selectionModel()->selectedIndexes().count()>0;
}
bool TreeView::haveUnSelectedItems() const
{
return selectedIndexes().count()!=model()->rowCount();
// Dont need the sorted type of 'selectedIndexes' here...
return selectionModel()->selectedIndexes().count()!=model()->rowCount();
}
void TreeView::startDrag(Qt::DropActions supportedActions)
{
QModelIndexList indexes = selectedIndexes();
if (indexes.count() > 0) {
qSort(indexes);
QMimeData *data = model()->mimeData(indexes);
if (!data) {
return;
@@ -186,15 +187,65 @@ void TreeView::mouseReleaseEvent(QMouseEvent *event)
}
}
QModelIndexList TreeView::selectedIndexes() const
QModelIndexList TreeView::selectedIndexes(bool sorted) const
{
QModelIndexList indexes=selectionModel()->selectedIndexes();
QMap<int, QModelIndex> sort;
return sorted ? sortIndexes(selectionModel()->selectedIndexes()) : selectionModel()->selectedIndexes();
}
foreach (const QModelIndex &idx, indexes) {
sort.insertMulti(visualRect(idx).y(), idx);
struct Index : public QModelIndex
{
Index(const QModelIndex &i)
: QModelIndex(i)
{
QModelIndex idx=i;
while (idx.isValid()) {
rows.prepend(idx.row());
idx=idx.parent();
}
count=rows.count();
}
return sort.values();
bool operator<(const Index &rhs) const
{
int toCompare=qMax(count, rhs.count);
for (int i=0; i<toCompare; ++i) {
qint32 left=i<count ? rows.at(i) : -1;
qint32 right=i<rhs.count ? rhs.rows.at(i) : -1;
if (left<right) {
return true;
} else if (left>right) {
return false;
}
}
return false;
}
QList<qint32> rows;
int count;
};
QModelIndexList TreeView::sortIndexes(const QModelIndexList &list)
{
if (list.isEmpty()) {
return list;
}
// QModelIndex::operator< sorts on row first - but this messes things up if rows
// have different parents. Therefore, we use the sort above - so that the hierarchy is preserved.
// First, create the list of 'Index' items to be sorted...
QList<Index> toSort;
foreach (const QModelIndex &i, list) {
toSort.append(Index(i));
}
// Call qSort on these - this will use operator<
qSort(toSort);
// Now convert the QList<Index> into a QModelIndexList
QModelIndexList sorted;
foreach (const Index &i, toSort) {
sorted.append(i);
}
return sorted;
}
void TreeView::expandAll(const QModelIndex &idx)

View File

@@ -39,6 +39,7 @@ public:
static QPixmap createBgndPixmap(const QIcon &icon);
static void setForceSingleClick(bool v);
static bool getForceSingleClick();
static QModelIndexList sortIndexes(const QModelIndexList &list);
TreeView(QWidget *parent=0, bool menuAlwaysAllowed=false);
virtual ~TreeView();
@@ -50,7 +51,8 @@ public:
bool haveUnSelectedItems() const;
void startDrag(Qt::DropActions supportedActions);
void mouseReleaseEvent(QMouseEvent *event);
QModelIndexList selectedIndexes() const;
QModelIndexList selectedIndexes() const { return selectedIndexes(true); }
QModelIndexList selectedIndexes(bool sorted) const;
void expandAll(const QModelIndex &idx=QModelIndex());
virtual void expand(const QModelIndex &idx);
virtual void setModel(QAbstractItemModel *m);