| 634 | } |
| 635 | |
| 636 | void TimerModel::applyChanges(const TimerIdInfoContainer &changes) |
| 637 | { |
| 638 | QSet<TimerId> updatedIds; |
| 639 | QVector<QPair<int, int>> dataChangedRanges; // pair of first/last |
| 640 | |
| 641 | // Update QQmlTimer / QTimer entries |
| 642 | for (int i = 0; i < m_sourceModel->rowCount(); ++i) { |
| 643 | const QModelIndex sourceIndex = m_sourceModel->index(i, 0); |
| 644 | QObject *const timerObject = sourceIndex.data(ObjectModel::ObjectRole).value<QObject *>(); |
| 645 | |
| 646 | // The object might have already be deleted even if our index is valid |
| 647 | if (!timerObject) |
| 648 | return; |
| 649 | |
| 650 | const TimerId id(timerObject); |
| 651 | const auto cit = changes.constFind(id); |
| 652 | auto it = m_timersInfo.find(id); |
| 653 | |
| 654 | if (it == m_timersInfo.end()) { |
| 655 | it = m_timersInfo.insert(id, TimerIdInfo()); |
| 656 | |
| 657 | if (cit == changes.constEnd()) |
| 658 | // safe, validated by the source model |
| 659 | it.value().update(id); |
| 660 | } |
| 661 | |
| 662 | if (cit != changes.constEnd()) { |
| 663 | updatedIds << id; |
| 664 | it.value() = cit.value(); |
| 665 | |
| 666 | if (dataChangedRanges.isEmpty() || dataChangedRanges.last().second != i - 1) { |
| 667 | dataChangedRanges << qMakePair(i, i); |
| 668 | } else { |
| 669 | dataChangedRanges.last().second = i; |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | // Update existing free timers entries |
| 675 | for (auto it = m_freeTimersInfo.begin(), end = m_freeTimersInfo.end(); it != end; ++it) { |
| 676 | const TimerId id((*it).timerId, (*it).lastReceiverAddress); |
| 677 | const auto cit = changes.constFind(id); |
| 678 | |
| 679 | if (cit != changes.constEnd()) { |
| 680 | const int i = m_sourceModel->rowCount() + std::distance(m_freeTimersInfo.begin(), it); |
| 681 | updatedIds << id; |
| 682 | (*it) = cit.value(); |
| 683 | |
| 684 | if (dataChangedRanges.isEmpty() || dataChangedRanges.last().second != i - 1) { |
| 685 | dataChangedRanges << qMakePair(i, i); |
| 686 | } else { |
| 687 | dataChangedRanges.last().second = i; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | // Fill new free timers to insert |
| 693 | QVector<TimerIdInfo> freeTimersToInsert; |
nothing calls this directly
no test coverage detected