-
Notifications
You must be signed in to change notification settings - Fork 1
/
soundlistview.cpp
75 lines (55 loc) · 2.77 KB
/
soundlistview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# include "soundlistview.h"
# include "soundlistdelegate.h"
SoundListView::SoundListView(QWidget *parent) : QListView(parent) {
setItemDelegate(new SoundListDelegate(this));
setupModels();
switchToActivityDisplay();
}
// --- public slots -----------------------------
void SoundListView::switchToPlaylistListingDisplay() {
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(soundSelected(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPlaylist(QModelIndex)));
this->setModel(playlistModel);
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPlaylist(QModelIndex)));
}
void SoundListView::switchToLikeDisplay() {
disconnect(this, SIGNAL(doubleClicked(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPlaylist(QModelIndex)));
this->setModel(likeModel);
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(soundSelected(QModelIndex)));
}
void SoundListView::switchToActivityDisplay() {
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(soundSelected(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPlaylist(QModelIndex)));
this->setModel(activityModel);
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectActivity(QModelIndex)));
}
void SoundListView::refresh() {
soundStorage->fill();
}
// --- private methods --------------------------
void SoundListView::setupModels() {
soundStorage = new SoundStorage(this);
likeModel = new LikeModel(soundStorage, this);
playlistModel = new PlaylistModel(soundStorage, this);
activityModel = new ActivityListModel(soundStorage, this);
}
// --- private slots ----------------------------
void SoundListView::selectPlaylist(QModelIndex index) {
// introducing a possible memory leak here....
PlaylistSoundListModel *playlistSoundModel = new PlaylistSoundListModel(soundStorage, this);
int selectedPlaylistId = ((ListModelBase*)index.model())->getItem(index).getId();
Playlist selectedPlaylist = soundStorage->getPlaylistById(selectedPlaylistId);
playlistSoundModel->updateSoundIds(selectedPlaylist.getSounds());
this->setModel(playlistSoundModel);
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPlaylist(QModelIndex)));
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(soundSelected(QModelIndex)));
}
void SoundListView::selectActivity(QModelIndex activityIndex) {
if (activityModel->isPlaylistSelected(activityIndex.row())) {
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectActivity(QModelIndex)));
selectPlaylist(activityIndex);
} else {
emit soundSelected(activityIndex);
}
}