Changeset View
Changeset View
Standalone View
Standalone View
src/models/datamodel.cpp
Show All 28 Lines | |||||
29 | #include <algorithm> | 29 | #include <algorithm> | ||
30 | 30 | | |||
31 | class DataModelPrivate | 31 | class DataModelPrivate | ||
32 | { | 32 | { | ||
33 | public: | 33 | public: | ||
34 | 34 | | |||
35 | DataModel::ListTrackDataType mAllTrackData; | 35 | DataModel::ListTrackDataType mAllTrackData; | ||
36 | 36 | | |||
37 | DataModel::ListTrackDataType mAllRadiosData; | ||||
mgallien: It would better (safer) if you add one more type like DataModel::ListRadioDataType. Online… | |||||
38 | | ||||
37 | DataModel::ListAlbumDataType mAllAlbumData; | 39 | DataModel::ListAlbumDataType mAllAlbumData; | ||
38 | 40 | | |||
39 | DataModel::ListArtistDataType mAllArtistData; | 41 | DataModel::ListArtistDataType mAllArtistData; | ||
40 | 42 | | |||
41 | DataModel::ListGenreDataType mAllGenreData; | 43 | DataModel::ListGenreDataType mAllGenreData; | ||
42 | 44 | | |||
43 | ModelDataLoader mDataLoader; | 45 | ModelDataLoader mDataLoader; | ||
44 | 46 | | |||
Show All 40 Lines | 86 | { | |||
85 | auto roles = QAbstractListModel::roleNames(); | 87 | auto roles = QAbstractListModel::roleNames(); | ||
86 | 88 | | |||
87 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::TitleRole)] = "title"; | 89 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::TitleRole)] = "title"; | ||
88 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; | 90 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; | ||
89 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ImageUrlRole)] = "imageUrl"; | 91 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ImageUrlRole)] = "imageUrl"; | ||
90 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::DatabaseIdRole)] = "databaseId"; | 92 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::DatabaseIdRole)] = "databaseId"; | ||
91 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ElementTypeRole)] = "dataType"; | 93 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ElementTypeRole)] = "dataType"; | ||
92 | 94 | | |||
95 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::HttpAddressRole)] = "httpAddress"; | ||||
96 | | ||||
93 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ArtistRole)] = "artist"; | 97 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::ArtistRole)] = "artist"; | ||
94 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AllArtistsRole)] = "allArtists"; | 98 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AllArtistsRole)] = "allArtists"; | ||
95 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::HighestTrackRating)] = "highestTrackRating"; | 99 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::HighestTrackRating)] = "highestTrackRating"; | ||
96 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::GenreRole)] = "genre"; | 100 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::GenreRole)] = "genre"; | ||
97 | 101 | | |||
98 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AlbumRole)] = "album"; | 102 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AlbumRole)] = "album"; | ||
99 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AlbumArtistRole)] = "albumArtist"; | 103 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::AlbumArtistRole)] = "albumArtist"; | ||
100 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::DurationRole)] = "duration"; | 104 | roles[static_cast<int>(DatabaseInterface::ColumnsRoles::DurationRole)] = "duration"; | ||
Show All 17 Lines | |||||
118 | QVariant DataModel::data(const QModelIndex &index, int role) const | 122 | QVariant DataModel::data(const QModelIndex &index, int role) const | ||
119 | { | 123 | { | ||
120 | auto result = QVariant(); | 124 | auto result = QVariant(); | ||
121 | 125 | | |||
122 | const auto dataCount = d->mAllTrackData.size() + d->mAllAlbumData.size() + d->mAllArtistData.size() + d->mAllGenreData.size(); | 126 | const auto dataCount = d->mAllTrackData.size() + d->mAllAlbumData.size() + d->mAllArtistData.size() + d->mAllGenreData.size(); | ||
123 | 127 | | |||
124 | Q_ASSERT(index.isValid()); | 128 | Q_ASSERT(index.isValid()); | ||
125 | Q_ASSERT(index.column() == 0); | 129 | Q_ASSERT(index.column() == 0); | ||
126 | Q_ASSERT(index.row() >= 0 && index.row() < dataCount); | | |||
127 | Q_ASSERT(!index.parent().isValid()); | 130 | Q_ASSERT(!index.parent().isValid()); | ||
128 | Q_ASSERT(index.model() == this); | 131 | Q_ASSERT(index.model() == this); | ||
129 | Q_ASSERT(index.internalId() == 0); | 132 | Q_ASSERT(index.internalId() == 0); | ||
130 | 133 | | |||
134 | if(d->mModelType != ElisaUtils::Radio){ | ||||
135 | Q_ASSERT(index.row() >= 0 && index.row() < dataCount); | ||||
136 | } | ||||
137 | | ||||
mgallien: What is the reason for that ?
It does not look good. | |||||
The dataCount did not make sense for radios, I reintegrated the check and added a different dataCount on line 128. jguidon: The dataCount did not make sense for radios, I reintegrated the check and added a different… | |||||
131 | switch(role) | 138 | switch(role) | ||
132 | { | 139 | { | ||
133 | case Qt::DisplayRole: | 140 | case Qt::DisplayRole: | ||
134 | switch(d->mModelType) | 141 | switch(d->mModelType) | ||
135 | { | 142 | { | ||
136 | case ElisaUtils::Track: | 143 | case ElisaUtils::Track: | ||
137 | result = d->mAllTrackData[index.row()][TrackDataType::key_type::TitleRole]; | 144 | result = d->mAllTrackData[index.row()][TrackDataType::key_type::TitleRole]; | ||
138 | break; | 145 | break; | ||
139 | case ElisaUtils::Album: | 146 | case ElisaUtils::Album: | ||
140 | result = d->mAllAlbumData[index.row()][AlbumDataType::key_type::TitleRole]; | 147 | result = d->mAllAlbumData[index.row()][AlbumDataType::key_type::TitleRole]; | ||
141 | break; | 148 | break; | ||
142 | case ElisaUtils::Artist: | 149 | case ElisaUtils::Artist: | ||
143 | result = d->mAllArtistData[index.row()][ArtistDataType::key_type::TitleRole]; | 150 | result = d->mAllArtistData[index.row()][ArtistDataType::key_type::TitleRole]; | ||
144 | break; | 151 | break; | ||
145 | case ElisaUtils::Genre: | 152 | case ElisaUtils::Genre: | ||
146 | result = d->mAllGenreData[index.row()][GenreDataType::key_type::TitleRole]; | 153 | result = d->mAllGenreData[index.row()][GenreDataType::key_type::TitleRole]; | ||
147 | break; | 154 | break; | ||
155 | case ElisaUtils::Radio: | ||||
156 | result = d->mAllRadiosData[index.row()][GenreDataType::key_type::TitleRole]; | ||||
157 | break; | ||||
148 | case ElisaUtils::Lyricist: | 158 | case ElisaUtils::Lyricist: | ||
149 | case ElisaUtils::Composer: | 159 | case ElisaUtils::Composer: | ||
150 | case ElisaUtils::FileName: | 160 | case ElisaUtils::FileName: | ||
151 | case ElisaUtils::Unknown: | 161 | case ElisaUtils::Unknown: | ||
152 | break; | 162 | break; | ||
153 | } | 163 | } | ||
154 | break; | 164 | break; | ||
155 | case DatabaseInterface::ColumnsRoles::DurationRole: | 165 | case DatabaseInterface::ColumnsRoles::DurationRole: | ||
156 | { | 166 | { | ||
157 | if (d->mModelType == ElisaUtils::Track) { | 167 | if (d->mModelType == ElisaUtils::Track) { | ||
158 | auto trackDuration = d->mAllTrackData[index.row()][TrackDataType::key_type::DurationRole].toTime(); | 168 | auto trackDuration = d->mAllTrackData[index.row()][TrackDataType::key_type::DurationRole].toTime(); | ||
159 | if (trackDuration.hour() == 0) { | 169 | if (trackDuration.hour() == 0) { | ||
160 | result = trackDuration.toString(QStringLiteral("mm:ss")); | 170 | result = trackDuration.toString(QStringLiteral("mm:ss")); | ||
161 | } else { | 171 | } else { | ||
162 | result = trackDuration.toString(); | 172 | result = trackDuration.toString(); | ||
163 | } | 173 | } | ||
164 | } | 174 | } | ||
165 | break; | 175 | break; | ||
166 | } | 176 | } | ||
167 | default: | 177 | default: | ||
astippich: use QString instead of QStringLiteral(""), it is a little bit cheaper | |||||
No need for that. If the data is missing, the view should handle that (i.e. an empty/invalid QVariant). This is the same in most places where fallback is an empty/invalid QVariant when the data is missing or unavailable. mgallien: No need for that. If the data is missing, the view should handle that (i.e. an empty/invalid… | |||||
168 | switch(d->mModelType) | 178 | switch(d->mModelType) | ||
169 | { | 179 | { | ||
170 | case ElisaUtils::Track: | 180 | case ElisaUtils::Track: | ||
171 | result = d->mAllTrackData[index.row()][static_cast<TrackDataType::key_type>(role)]; | 181 | result = d->mAllTrackData[index.row()][static_cast<TrackDataType::key_type>(role)]; | ||
172 | break; | 182 | break; | ||
173 | case ElisaUtils::Album: | 183 | case ElisaUtils::Album: | ||
174 | result = d->mAllAlbumData[index.row()][static_cast<AlbumDataType::key_type>(role)]; | 184 | result = d->mAllAlbumData[index.row()][static_cast<AlbumDataType::key_type>(role)]; | ||
175 | break; | 185 | break; | ||
176 | case ElisaUtils::Artist: | 186 | case ElisaUtils::Artist: | ||
177 | result = d->mAllArtistData[index.row()][static_cast<ArtistDataType::key_type>(role)]; | 187 | result = d->mAllArtistData[index.row()][static_cast<ArtistDataType::key_type>(role)]; | ||
178 | break; | 188 | break; | ||
179 | case ElisaUtils::Genre: | 189 | case ElisaUtils::Genre: | ||
180 | result = d->mAllGenreData[index.row()][static_cast<GenreDataType::key_type>(role)]; | 190 | result = d->mAllGenreData[index.row()][static_cast<GenreDataType::key_type>(role)]; | ||
181 | break; | 191 | break; | ||
192 | case ElisaUtils::Radio: | ||||
193 | result = d->mAllRadiosData[index.row()][static_cast<TrackDataType::key_type>(role)]; | ||||
194 | break; | ||||
182 | case ElisaUtils::Lyricist: | 195 | case ElisaUtils::Lyricist: | ||
183 | case ElisaUtils::Composer: | 196 | case ElisaUtils::Composer: | ||
184 | case ElisaUtils::FileName: | 197 | case ElisaUtils::FileName: | ||
185 | case ElisaUtils::Unknown: | 198 | case ElisaUtils::Unknown: | ||
186 | break; | 199 | break; | ||
187 | } | 200 | } | ||
188 | } | 201 | } | ||
189 | 202 | | |||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Line(s) | 400 | for (result = 0; result < d->mAllTrackData.size(); ++result) { | |||
390 | } | 403 | } | ||
391 | } | 404 | } | ||
392 | 405 | | |||
393 | result = -1; | 406 | result = -1; | ||
394 | 407 | | |||
395 | return result; | 408 | return result; | ||
396 | } | 409 | } | ||
397 | 410 | | |||
411 | int DataModel::radioIndexFromId(qulonglong id) const | ||||
412 | { | ||||
413 | int result; | ||||
414 | | ||||
415 | for (result = 0; result < d->mAllRadiosData.size(); ++result) { | ||||
416 | if (d->mAllRadiosData[result].databaseId() == id) { | ||||
417 | return result; | ||||
418 | } | ||||
419 | } | ||||
420 | | ||||
421 | result = -1; | ||||
422 | | ||||
423 | return result; | ||||
424 | } | ||||
425 | | ||||
This is too much specific to one usecase of DataModel. mgallien: This is too much specific to one usecase of DataModel.
Why do you need this when other views do… | |||||
I just copied trackIndexFromId, in the first case we get mAllTrackData[result] and mAllRadiosData[result] in the other. I will integrate both methods. jguidon: I just copied trackIndexFromId, in the first case we get mAllTrackData[result] and… | |||||
398 | void DataModel::connectModel(DatabaseInterface *database) | 426 | void DataModel::connectModel(DatabaseInterface *database) | ||
399 | { | 427 | { | ||
400 | d->mDataLoader.setDatabase(database); | 428 | d->mDataLoader.setDatabase(database); | ||
401 | 429 | | |||
402 | connect(&d->mDataLoader, &ModelDataLoader::allTracksData, | 430 | connect(&d->mDataLoader, &ModelDataLoader::allTracksData, | ||
403 | this, &DataModel::tracksAdded); | 431 | this, &DataModel::tracksAdded); | ||
432 | connect(&d->mDataLoader, &ModelDataLoader::allRadiosData, | ||||
433 | this, &DataModel::radiosAdded); | ||||
434 | connect(&d->mDataLoader, &ModelDataLoader::allRadiosDataUIUpdate, | ||||
435 | this, &DataModel::radiosModifiedUI); | ||||
404 | connect(&d->mDataLoader, &ModelDataLoader::allAlbumsData, | 436 | connect(&d->mDataLoader, &ModelDataLoader::allAlbumsData, | ||
405 | this, &DataModel::albumsAdded); | 437 | this, &DataModel::albumsAdded); | ||
406 | connect(&d->mDataLoader, &ModelDataLoader::allArtistsData, | 438 | connect(&d->mDataLoader, &ModelDataLoader::allArtistsData, | ||
407 | this, &DataModel::artistsAdded); | 439 | this, &DataModel::artistsAdded); | ||
408 | connect(&d->mDataLoader, &ModelDataLoader::allGenresData, | 440 | connect(&d->mDataLoader, &ModelDataLoader::allGenresData, | ||
409 | this, &DataModel::genresAdded); | 441 | this, &DataModel::genresAdded); | ||
410 | connect(&d->mDataLoader, &ModelDataLoader::genresAdded, | 442 | connect(&d->mDataLoader, &ModelDataLoader::genresAdded, | ||
411 | this, &DataModel::genresAdded); | 443 | this, &DataModel::genresAdded); | ||
412 | connect(&d->mDataLoader, &ModelDataLoader::albumsAdded, | 444 | connect(&d->mDataLoader, &ModelDataLoader::albumsAdded, | ||
413 | this, &DataModel::albumsAdded); | 445 | this, &DataModel::albumsAdded); | ||
414 | connect(&d->mDataLoader, &ModelDataLoader::albumModified, | 446 | connect(&d->mDataLoader, &ModelDataLoader::albumModified, | ||
415 | this, &DataModel::albumModified); | 447 | this, &DataModel::albumModified); | ||
416 | connect(&d->mDataLoader, &ModelDataLoader::albumRemoved, | 448 | connect(&d->mDataLoader, &ModelDataLoader::albumRemoved, | ||
417 | this, &DataModel::albumRemoved); | 449 | this, &DataModel::albumRemoved); | ||
418 | connect(&d->mDataLoader, &ModelDataLoader::tracksAdded, | 450 | connect(&d->mDataLoader, &ModelDataLoader::tracksAdded, | ||
419 | this, &DataModel::tracksAdded); | 451 | this, &DataModel::tracksAdded); | ||
420 | connect(&d->mDataLoader, &ModelDataLoader::trackModified, | 452 | connect(&d->mDataLoader, &ModelDataLoader::trackModified, | ||
421 | this, &DataModel::trackModified); | 453 | this, &DataModel::trackModified); | ||
454 | connect(&d->mDataLoader, &ModelDataLoader::radioModified, | ||||
455 | this, &DataModel::radioModified); | ||||
422 | connect(&d->mDataLoader, &ModelDataLoader::trackRemoved, | 456 | connect(&d->mDataLoader, &ModelDataLoader::trackRemoved, | ||
423 | this, &DataModel::trackRemoved); | 457 | this, &DataModel::trackRemoved); | ||
424 | connect(&d->mDataLoader, &ModelDataLoader::artistsAdded, | 458 | connect(&d->mDataLoader, &ModelDataLoader::artistsAdded, | ||
425 | this, &DataModel::artistsAdded); | 459 | this, &DataModel::artistsAdded); | ||
426 | connect(&d->mDataLoader, &ModelDataLoader::artistRemoved, | 460 | connect(&d->mDataLoader, &ModelDataLoader::artistRemoved, | ||
427 | this, &DataModel::artistRemoved); | 461 | this, &DataModel::artistRemoved); | ||
462 | connect(&d->mDataLoader, &ModelDataLoader::radioRemoved, | ||||
463 | this, &DataModel::radioRemoved); | ||||
428 | } | 464 | } | ||
429 | 465 | | |||
430 | void DataModel::tracksAdded(ListTrackDataType newData) | 466 | void DataModel::tracksAdded(ListTrackDataType newData) | ||
431 | { | 467 | { | ||
432 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Track) { | 468 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Track) { | ||
433 | setBusy(false); | 469 | setBusy(false); | ||
434 | } | 470 | } | ||
435 | 471 | | |||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 512 | } else { | |||
483 | } else { | 519 | } else { | ||
484 | beginInsertRows({}, d->mAllTrackData.size(), d->mAllTrackData.size() + newData.size() - 1); | 520 | beginInsertRows({}, d->mAllTrackData.size(), d->mAllTrackData.size() + newData.size() - 1); | ||
485 | d->mAllTrackData.append(newData); | 521 | d->mAllTrackData.append(newData); | ||
486 | endInsertRows(); | 522 | endInsertRows(); | ||
487 | } | 523 | } | ||
488 | } | 524 | } | ||
489 | } | 525 | } | ||
490 | 526 | | |||
527 | void DataModel::radiosAdded(ListTrackDataType newData) | ||||
528 | { | ||||
529 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Radio) { | ||||
530 | setBusy(false); | ||||
531 | } | ||||
532 | | ||||
533 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Radio) { | ||||
534 | return; | ||||
535 | } | ||||
536 | | ||||
537 | if (d->mFilterType == FilterById && !d->mAllRadiosData.isEmpty()) { | ||||
538 | for (const auto &newTrack : newData) { | ||||
539 | auto trackIndex = trackIndexFromId(newTrack.databaseId()); | ||||
540 | | ||||
541 | if (trackIndex != -1) { | ||||
542 | continue; | ||||
543 | } | ||||
544 | | ||||
545 | bool trackInserted = false; | ||||
546 | for (int trackIndex = 0; trackIndex < d->mAllRadiosData.count(); ++trackIndex) { | ||||
547 | const auto &oneTrack = d->mAllRadiosData[trackIndex]; | ||||
548 | | ||||
549 | if (oneTrack.trackNumber() > newTrack.trackNumber()) { | ||||
550 | beginInsertRows({}, trackIndex, trackIndex); | ||||
551 | d->mAllRadiosData.insert(trackIndex, newTrack); | ||||
552 | endInsertRows(); | ||||
553 | | ||||
554 | if (d->mAllRadiosData.size() == 1) { | ||||
555 | setBusy(false); | ||||
556 | } | ||||
557 | | ||||
558 | trackInserted = true; | ||||
559 | break; | ||||
560 | } | ||||
561 | } | ||||
562 | | ||||
563 | if (!trackInserted) { | ||||
564 | beginInsertRows({}, d->mAllRadiosData.count(), d->mAllRadiosData.count()); | ||||
565 | d->mAllRadiosData.insert(d->mAllRadiosData.count(), newTrack); | ||||
566 | endInsertRows(); | ||||
567 | | ||||
568 | if (d->mAllRadiosData.size() == 1) { | ||||
569 | setBusy(false); | ||||
570 | } | ||||
571 | } | ||||
572 | } | ||||
573 | } else { | ||||
574 | if (d->mAllRadiosData.isEmpty()) { | ||||
575 | beginInsertRows({}, 0, newData.size() - 1); | ||||
576 | d->mAllRadiosData.swap(newData); | ||||
577 | endInsertRows(); | ||||
578 | | ||||
579 | setBusy(false); | ||||
580 | } else { | ||||
581 | beginInsertRows({}, d->mAllRadiosData.size(), d->mAllRadiosData.size() + newData.size() - 1); | ||||
582 | d->mAllRadiosData.append(newData); | ||||
583 | endInsertRows(); | ||||
584 | } | ||||
585 | } | ||||
586 | } | ||||
587 | | ||||
491 | void DataModel::trackModified(const TrackDataType &modifiedTrack) | 588 | void DataModel::trackModified(const TrackDataType &modifiedTrack) | ||
492 | { | 589 | { | ||
493 | if (d->mModelType != ElisaUtils::Track) { | 590 | if (d->mModelType != ElisaUtils::Track) { | ||
494 | return; | 591 | return; | ||
495 | } | 592 | } | ||
496 | 593 | | |||
497 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | 594 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | ||
498 | if (modifiedTrack.album() != d->mAlbumTitle) { | 595 | if (modifiedTrack.album() != d->mAlbumTitle) { | ||
Show All 21 Lines | 607 | } else { | |||
520 | auto position = itTrack - d->mAllTrackData.begin(); | 617 | auto position = itTrack - d->mAllTrackData.begin(); | ||
521 | 618 | | |||
522 | d->mAllTrackData[position] = modifiedTrack; | 619 | d->mAllTrackData[position] = modifiedTrack; | ||
523 | 620 | | |||
524 | Q_EMIT dataChanged(index(position, 0), index(position, 0)); | 621 | Q_EMIT dataChanged(index(position, 0), index(position, 0)); | ||
525 | } | 622 | } | ||
526 | } | 623 | } | ||
527 | 624 | | |||
625 | void DataModel::radioModified(const TrackDataType &modifiedRadio) | ||||
626 | { | ||||
627 | if (d->mModelType != ElisaUtils::Radio) { | ||||
628 | return; | ||||
629 | } | ||||
630 | | ||||
631 | auto trackIndex = radioIndexFromId(modifiedRadio.databaseId()); | ||||
632 | | ||||
633 | if (trackIndex == -1) { | ||||
634 | return; | ||||
635 | } | ||||
636 | | ||||
637 | d->mAllRadiosData[trackIndex] = modifiedRadio; | ||||
638 | Q_EMIT dataChanged(index(trackIndex, 0), index(trackIndex, 0)); | ||||
639 | } | ||||
640 | | ||||
528 | void DataModel::trackRemoved(qulonglong removedTrackId) | 641 | void DataModel::trackRemoved(qulonglong removedTrackId) | ||
529 | { | 642 | { | ||
530 | if (d->mModelType != ElisaUtils::Track) { | 643 | if (d->mModelType != ElisaUtils::Track) { | ||
531 | return; | 644 | return; | ||
532 | } | 645 | } | ||
533 | 646 | | |||
534 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | 647 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | ||
535 | auto trackIndex = trackIndexFromId(removedTrackId); | 648 | auto trackIndex = trackIndexFromId(removedTrackId); | ||
Show All 16 Lines | 657 | } else { | |||
552 | auto position = itTrack - d->mAllTrackData.begin(); | 665 | auto position = itTrack - d->mAllTrackData.begin(); | ||
553 | 666 | | |||
554 | beginRemoveRows({}, position, position); | 667 | beginRemoveRows({}, position, position); | ||
555 | d->mAllTrackData.erase(itTrack); | 668 | d->mAllTrackData.erase(itTrack); | ||
556 | endRemoveRows(); | 669 | endRemoveRows(); | ||
557 | } | 670 | } | ||
558 | } | 671 | } | ||
559 | 672 | | |||
673 | void DataModel::radioRemoved(qulonglong removedRadioId) | ||||
674 | { | ||||
675 | if (d->mModelType != ElisaUtils::Radio) { | ||||
676 | return; | ||||
677 | } | ||||
678 | | ||||
679 | | ||||
680 | auto itRadio = std::find_if(d->mAllRadiosData.begin(), d->mAllRadiosData.end(), | ||||
681 | [removedRadioId](auto track) {return track.databaseId() == removedRadioId;}); | ||||
682 | | ||||
683 | if (itRadio == d->mAllRadiosData.end()) { | ||||
684 | return; | ||||
685 | } | ||||
686 | | ||||
687 | auto position = itRadio - d->mAllRadiosData.begin(); | ||||
688 | | ||||
689 | beginRemoveRows({}, position, position); | ||||
690 | d->mAllRadiosData.erase(itRadio); | ||||
691 | endRemoveRows(); | ||||
692 | } | ||||
693 | | ||||
694 | void DataModel::radiosModifiedUI(const DataModel::TrackDataType radioData, bool isInsertion){ | ||||
695 | if (d->mModelType != ElisaUtils::Radio) { | ||||
696 | return; | ||||
697 | } | ||||
698 | | ||||
699 | if(isInsertion){ | ||||
700 | ListTrackDataType list; | ||||
701 | list.append(radioData); | ||||
702 | radiosAdded(list); | ||||
703 | }else{ | ||||
704 | radioModified(radioData); | ||||
705 | } | ||||
706 | } | ||||
707 | | ||||
708 | void DataModel::removeRadios() | ||||
709 | { | ||||
710 | if (d->mModelType != ElisaUtils::Radio) { | ||||
711 | return; | ||||
712 | } | ||||
713 | | ||||
714 | beginRemoveRows({}, 0, d->mAllRadiosData.size()); | ||||
715 | d->mAllRadiosData.clear(); | ||||
716 | endRemoveRows(); | ||||
717 | } | ||||
718 | | ||||
560 | void DataModel::genresAdded(DataModel::ListGenreDataType newData) | 719 | void DataModel::genresAdded(DataModel::ListGenreDataType newData) | ||
561 | { | 720 | { | ||
562 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Genre) { | 721 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Genre) { | ||
563 | setBusy(false); | 722 | setBusy(false); | ||
564 | } | 723 | } | ||
565 | 724 | | |||
566 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Genre) { | 725 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Genre) { | ||
567 | return; | 726 | return; | ||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |
It would better (safer) if you add one more type like DataModel::ListRadioDataType. Online radios are similar to tracks but by doing that, the compiler will help avoid mistakes when connecting signals to slots.