Fix selection of items in sync dialog

This commit is contained in:
craig.p.drummond
2013-06-17 18:36:19 +00:00
committed by craig.p.drummond
parent de0e979266
commit a8d753d4f6
2 changed files with 54 additions and 12 deletions

View File

@@ -24,13 +24,14 @@
#include "synccollectionwidget.h"
#include "treeview.h"
#include "musiclibraryproxymodel.h"
#include "musiclibraryitemartist.h"
#include "musiclibraryitemalbum.h"
#include "musiclibraryitemsong.h"
#include "icon.h"
#include "localize.h"
#include "actioncollection.h"
#include <QTimer>
#include <QAction>
#include <QDebug>
SyncCollectionWidget::SyncCollectionWidget(QWidget *parent, const QString &title, const QString &action, bool showCovers)
: QWidget(parent)
@@ -191,21 +192,59 @@ void SyncCollectionWidget::songsChecked(const QSet<Song> &songs)
updateStats();
}
void SyncCollectionWidget::dataChanged(const QModelIndex &tl, const QModelIndex &br)
{
Q_UNUSED(br)
QModelIndex index = proxy->mapToSource(tl);
MusicLibraryItem *item=static_cast<MusicLibraryItem *>(index.internalPointer());
if (MusicLibraryItem::Type_Song==item->itemType()) {
Song s=static_cast<MusicLibraryItemSong *>(item)->song();
if (Qt::Checked==item->checkState()) {
checkedSongs.insert(s);
} else {
checkedSongs.remove(s);
QModelIndex firstIndex = proxy->mapToSource(tl);
QModelIndex lastIndex = proxy->mapToSource(br);
const MusicLibraryItem *item=static_cast<const MusicLibraryItem *>(firstIndex.internalPointer());
switch (item->itemType()) {
case MusicLibraryItem::Type_Artist:
for (int i=firstIndex.row(); i<=lastIndex.row(); ++i) {
QModelIndex index=model->index(i, 0, firstIndex.parent());
const MusicLibraryItemArtist *artist=static_cast<const MusicLibraryItemArtist *>(index.internalPointer());
foreach (const MusicLibraryItem *alItem, artist->childItems()) {
foreach (const MusicLibraryItem *sItem, static_cast<const MusicLibraryItemContainer *>(alItem)->childItems()) {
Song s=static_cast<const MusicLibraryItemSong *>(sItem)->song();
if (Qt::Checked==item->checkState()) {
checkedSongs.insert(s);
} else {
checkedSongs.remove(s);
}
}
}
}
button->setEnabled(!checkedSongs.isEmpty());
updateStats();
break;
case MusicLibraryItem::Type_Album:
for (int i=firstIndex.row(); i<=lastIndex.row(); ++i) {
QModelIndex index=model->index(i, 0, firstIndex.parent());
const MusicLibraryItemAlbum *album=static_cast<const MusicLibraryItemAlbum *>(index.internalPointer());
foreach (const MusicLibraryItem *sItem, album->childItems()) {
Song s=static_cast<const MusicLibraryItemSong *>(sItem)->song();
if (Qt::Checked==item->checkState()) {
checkedSongs.insert(s);
} else {
checkedSongs.remove(s);
}
}
}
break;
case MusicLibraryItem::Type_Song:
for (int i=firstIndex.row(); i<=lastIndex.row(); ++i) {
QModelIndex index=model->index(i, 0, firstIndex.parent());
Song s=static_cast<MusicLibraryItemSong *>(index.internalPointer())->song();
if (Qt::Checked==item->checkState()) {
checkedSongs.insert(s);
} else {
checkedSongs.remove(s);
}
}
default:
break;
}
button->setEnabled(!checkedSongs.isEmpty());
updateStats();
}
void SyncCollectionWidget::updateStats()

View File

@@ -385,6 +385,7 @@ bool MusicLibraryModel::setData(const QModelIndex &idx, const QVariant &value, i
}
emit dataChanged(index(0, 0, artistIndex), index(0, artistItem->childCount(), artistIndex));
}
emit dataChanged(idx, idx);
break;
}
case MusicLibraryItem::Type_Album: {
@@ -399,6 +400,7 @@ bool MusicLibraryModel::setData(const QModelIndex &idx, const QVariant &value, i
}
emit dataChanged(index(0, 0, albumIndex), index(0, albumItem->childCount(), albumIndex));
setParentState(artistIndex, value.toBool(), artistItem, item);
emit dataChanged(idx, idx);
break;
}
case MusicLibraryItem::Type_Song: {
@@ -409,6 +411,7 @@ bool MusicLibraryModel::setData(const QModelIndex &idx, const QVariant &value, i
QModelIndex albumIndex=index(artistItem->childItems().indexOf(albumItem), 0, artistIndex);
setParentState(albumIndex, value.toBool(), albumItem, item);
setParentState(artistIndex, Qt::Unchecked!=albumItem->checkState(), artistItem, albumItem);
emit dataChanged(idx, idx);
break;
}
case MusicLibraryItem::Type_Root: