-
Notifications
You must be signed in to change notification settings - Fork 1
/
activitylistmodel.cpp
37 lines (30 loc) · 1.16 KB
/
activitylistmodel.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
#include "activitylistmodel.h"
ActivityListModel::ActivityListModel(const SoundStorage *storage, QObject *parent)
: ListModelBase(storage,parent) {
connect(soundStorage, SIGNAL(activitiesUpdated(QList<QPair<int,QString> >)),
this, SLOT(updateActivities(QList<QPair<int,QString> >)));
}
Sound ActivityListModel::getItem(const QModelIndex& index) const {
int idx = index.row();
if (idx < idsAndTypes.size()) {
if (isPlaylistSelected(idx)) {
return soundStorage->getPlaylistById(idsAndTypes.at(idx).first);
} else {
return soundStorage->getSoundById(idsAndTypes.at(idx).first);
}
}
}
int ActivityListModel::rowCount(const QModelIndex&) const {
return idsAndTypes.count();
}
bool ActivityListModel::isPlaylistSelected(const int &idx) const {
if (idsAndTypes.at(idx).second == QString("track")) {
return false;
} else if (idsAndTypes.at(idx).second == QString("playlist")) {
return true;
}
}
void ActivityListModel::updateActivities(QList< QPair<int, QString> > activities) {
idsAndTypes = activities;
emit dataChanged(QModelIndex(), QModelIndex());
}