int TimerModel::rowFor(QTimer *timer) { for (int i = 0; i < rowCount(); i++) { const TimerInfoPtr timerInfo = findOrCreateTimerInfo(index(i, 0)); if (timerInfo->timer() == timer) { return i; } } return -1; }
void TimerModel::postSignalActivate(QObject *caller, int methodIndex) { if (methodIndex != m_timeoutIndex) { return; } QHash<QObject*, TimerInfoPtr>::iterator it = m_currentSignals.find(caller); if (it == m_currentSignals.end()) { // Ok, likely a GammaRay timer //cout << "TimerModel::postSignalActivate(): Unable to find timer " // << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; return; } const TimerInfoPtr timerInfo = *it; Q_ASSERT(timerInfo); m_currentSignals.erase(it); if (!timerInfo->timer()) { // timer got killed in a slot return; } Q_ASSERT(static_cast<QTimer*>(caller) == timerInfo->timer()); if (!timerInfo->functionCallTimer()->active()) { cout << "TimerModel::postSignalActivate(): Timer not active: " << (void*)caller << " (" << caller->objectName().toStdString() << ")!" << endl; return; } TimerInfo::TimeoutEvent event; event.timeStamp = QTime::currentTime(); event.executionTime = timerInfo->functionCallTimer()->stop(); timerInfo->addEvent(event); const int row = rowFor(timerInfo->timer()); if (row != -1) { emit dataChanged(index(row, 0), index(row, columnCount() - 1)); } }
TimerInfoPtr TimerModel::findOrCreateQTimerTimerInfo(QTimer *timer) { if (!timer) { return TimerInfoPtr(); } QVariant timerInfoVariant = timer->property(timerInfoPropertyName); if (!timerInfoVariant.isValid()) { timerInfoVariant.setValue(TimerInfoPtr(new TimerInfo(timer))); timer->setProperty(timerInfoPropertyName, timerInfoVariant); } const TimerInfoPtr timerInfo = timerInfoVariant.value<TimerInfoPtr>(); Q_ASSERT(timerInfo->timer() == timer); return timerInfo; }
TimerInfoPtr TimerModel::findOrCreateQTimerTimerInfo(QTimer *timer) { if (!timer) { return TimerInfoPtr(); } QVariant timerInfoVariant = timer->property(timerInfoPropertyName); if (!timerInfoVariant.isValid()) { timerInfoVariant.setValue(TimerInfoPtr(new TimerInfo(timer))); if (timer->thread() == QThread::currentThread()) // ### FIXME: we shouldn't use setProperty() in the first place... timer->setProperty(timerInfoPropertyName, timerInfoVariant); } const TimerInfoPtr timerInfo = timerInfoVariant.value<TimerInfoPtr>(); Q_ASSERT(timerInfo->timer() == timer); return timerInfo; }