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); | ||
428 | } | 462 | } | ||
429 | 463 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 510 | } else { | |||
483 | } else { | 517 | } else { | ||
484 | beginInsertRows({}, d->mAllTrackData.size(), d->mAllTrackData.size() + newData.size() - 1); | 518 | beginInsertRows({}, d->mAllTrackData.size(), d->mAllTrackData.size() + newData.size() - 1); | ||
485 | d->mAllTrackData.append(newData); | 519 | d->mAllTrackData.append(newData); | ||
486 | endInsertRows(); | 520 | endInsertRows(); | ||
487 | } | 521 | } | ||
488 | } | 522 | } | ||
489 | } | 523 | } | ||
490 | 524 | | |||
525 | void DataModel::radiosAdded(ListTrackDataType newData) | ||||
526 | { | ||||
527 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Radio) { | ||||
528 | setBusy(false); | ||||
529 | } | ||||
530 | | ||||
531 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Radio) { | ||||
532 | return; | ||||
533 | } | ||||
534 | | ||||
535 | if (d->mFilterType == FilterById && !d->mAllRadiosData.isEmpty()) { | ||||
536 | for (const auto &newTrack : newData) { | ||||
537 | auto trackIndex = trackIndexFromId(newTrack.databaseId()); | ||||
538 | | ||||
539 | if (trackIndex != -1) { | ||||
540 | continue; | ||||
541 | } | ||||
542 | | ||||
543 | bool trackInserted = false; | ||||
544 | for (int trackIndex = 0; trackIndex < d->mAllRadiosData.count(); ++trackIndex) { | ||||
545 | const auto &oneTrack = d->mAllRadiosData[trackIndex]; | ||||
546 | | ||||
547 | if (oneTrack.trackNumber() > newTrack.trackNumber()) { | ||||
548 | beginInsertRows({}, trackIndex, trackIndex); | ||||
549 | d->mAllRadiosData.insert(trackIndex, newTrack); | ||||
550 | endInsertRows(); | ||||
551 | | ||||
552 | if (d->mAllRadiosData.size() == 1) { | ||||
553 | setBusy(false); | ||||
554 | } | ||||
555 | | ||||
556 | trackInserted = true; | ||||
557 | break; | ||||
558 | } | ||||
559 | } | ||||
560 | | ||||
561 | if (!trackInserted) { | ||||
562 | beginInsertRows({}, d->mAllRadiosData.count(), d->mAllRadiosData.count()); | ||||
563 | d->mAllRadiosData.insert(d->mAllRadiosData.count(), newTrack); | ||||
564 | endInsertRows(); | ||||
565 | | ||||
566 | if (d->mAllRadiosData.size() == 1) { | ||||
567 | setBusy(false); | ||||
568 | } | ||||
569 | } | ||||
570 | } | ||||
571 | } else { | ||||
572 | if (d->mAllRadiosData.isEmpty()) { | ||||
573 | beginInsertRows({}, 0, newData.size() - 1); | ||||
574 | d->mAllRadiosData.swap(newData); | ||||
575 | endInsertRows(); | ||||
576 | | ||||
577 | setBusy(false); | ||||
578 | } else { | ||||
579 | beginInsertRows({}, d->mAllRadiosData.size(), d->mAllRadiosData.size() + newData.size() - 1); | ||||
580 | d->mAllRadiosData.append(newData); | ||||
581 | endInsertRows(); | ||||
582 | } | ||||
583 | } | ||||
584 | } | ||||
585 | | ||||
491 | void DataModel::trackModified(const TrackDataType &modifiedTrack) | 586 | void DataModel::trackModified(const TrackDataType &modifiedTrack) | ||
492 | { | 587 | { | ||
493 | if (d->mModelType != ElisaUtils::Track) { | 588 | if (d->mModelType != ElisaUtils::Track) { | ||
494 | return; | 589 | return; | ||
495 | } | 590 | } | ||
496 | 591 | | |||
497 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | 592 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | ||
498 | if (modifiedTrack.album() != d->mAlbumTitle) { | 593 | if (modifiedTrack.album() != d->mAlbumTitle) { | ||
Show All 21 Lines | 605 | } else { | |||
520 | auto position = itTrack - d->mAllTrackData.begin(); | 615 | auto position = itTrack - d->mAllTrackData.begin(); | ||
521 | 616 | | |||
522 | d->mAllTrackData[position] = modifiedTrack; | 617 | d->mAllTrackData[position] = modifiedTrack; | ||
523 | 618 | | |||
524 | Q_EMIT dataChanged(index(position, 0), index(position, 0)); | 619 | Q_EMIT dataChanged(index(position, 0), index(position, 0)); | ||
525 | } | 620 | } | ||
526 | } | 621 | } | ||
527 | 622 | | |||
623 | void DataModel::radioModified(const TrackDataType &modifiedRadio) | ||||
624 | { | ||||
625 | if (d->mModelType != ElisaUtils::Radio) { | ||||
626 | return; | ||||
627 | } | ||||
628 | | ||||
629 | auto trackIndex = radioIndexFromId(modifiedRadio.databaseId()); | ||||
630 | | ||||
631 | if (trackIndex == -1) { | ||||
632 | return; | ||||
633 | } | ||||
634 | | ||||
635 | d->mAllRadiosData[trackIndex] = modifiedRadio; | ||||
636 | Q_EMIT dataChanged(index(trackIndex, 0), index(trackIndex, 0)); | ||||
637 | } | ||||
638 | | ||||
528 | void DataModel::trackRemoved(qulonglong removedTrackId) | 639 | void DataModel::trackRemoved(qulonglong removedTrackId) | ||
529 | { | 640 | { | ||
530 | if (d->mModelType != ElisaUtils::Track) { | 641 | if (d->mModelType != ElisaUtils::Track) { | ||
531 | return; | 642 | return; | ||
532 | } | 643 | } | ||
533 | 644 | | |||
534 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | 645 | if (!d->mAlbumTitle.isEmpty() && !d->mAlbumArtist.isEmpty()) { | ||
535 | auto trackIndex = trackIndexFromId(removedTrackId); | 646 | auto trackIndex = trackIndexFromId(removedTrackId); | ||
Show All 16 Lines | 655 | } else { | |||
552 | auto position = itTrack - d->mAllTrackData.begin(); | 663 | auto position = itTrack - d->mAllTrackData.begin(); | ||
553 | 664 | | |||
554 | beginRemoveRows({}, position, position); | 665 | beginRemoveRows({}, position, position); | ||
555 | d->mAllTrackData.erase(itTrack); | 666 | d->mAllTrackData.erase(itTrack); | ||
556 | endRemoveRows(); | 667 | endRemoveRows(); | ||
557 | } | 668 | } | ||
558 | } | 669 | } | ||
559 | 670 | | |||
671 | void DataModel::radiosModifiedUI(const DataModel::TrackDataType radioData, bool isInsertion){ | ||||
672 | if (d->mModelType != ElisaUtils::Radio) { | ||||
673 | return; | ||||
674 | } | ||||
675 | | ||||
676 | if(isInsertion){ | ||||
677 | ListTrackDataType list; | ||||
678 | list.append(radioData); | ||||
679 | radiosAdded(list); | ||||
680 | }else{ | ||||
681 | radioModified(radioData); | ||||
682 | } | ||||
683 | } | ||||
684 | | ||||
685 | void DataModel::removeRadios() | ||||
686 | { | ||||
687 | if (d->mModelType != ElisaUtils::Radio) { | ||||
688 | return; | ||||
689 | } | ||||
690 | | ||||
691 | beginRemoveRows({}, 0, d->mAllRadiosData.size()); | ||||
692 | d->mAllRadiosData.clear(); | ||||
693 | endRemoveRows(); | ||||
694 | } | ||||
695 | | ||||
560 | void DataModel::genresAdded(DataModel::ListGenreDataType newData) | 696 | void DataModel::genresAdded(DataModel::ListGenreDataType newData) | ||
561 | { | 697 | { | ||
562 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Genre) { | 698 | if (newData.isEmpty() && d->mModelType == ElisaUtils::Genre) { | ||
563 | setBusy(false); | 699 | setBusy(false); | ||
564 | } | 700 | } | ||
565 | 701 | | |||
566 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Genre) { | 702 | if (newData.isEmpty() || d->mModelType != ElisaUtils::Genre) { | ||
567 | return; | 703 | 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.