Ejemplo n.º 1
0
bool TimerModel::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::Timer) {
        QTimerEvent * const timerEvent = static_cast<QTimerEvent *>(event);

        // If there is a QTimer associated with this timer ID, don't handle it here, it will be handled
        // by the signal hooks for QTimer::timeout()
        if (findOrCreateQTimerTimerInfo(timerEvent->timerId()))
            return false;

        // check if object is owned by GammaRay itself
        if (m_probe && m_probe->filterObject(watched))
            return false;

        const TimerInfoPtr timerInfo = findOrCreateFreeTimerInfo(timerEvent->timerId());
        TimerInfo::TimeoutEvent timeoutEvent;
        timeoutEvent.timeStamp = QTime::currentTime();
        timeoutEvent.executionTime = -1;
        timerInfo->addEvent(timeoutEvent);

        timerInfo->setLastReceiver(watched);
        emitFreeTimerChanged(m_freeTimers.indexOf(timerInfo));
    }
    return false;
}
Ejemplo n.º 2
0
void TimerModel::preSignalActivate(QObject *caller, int methodIndex)
{
  if (!(methodIndex == m_timeoutIndex && qobject_cast<QTimer*>(caller)) &&
      !(methodIndex == m_qmlTimerTriggeredIndex && caller->inherits("QQmlTimer")))
  {
    return;
  }

  const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(caller);

  if (!timerInfo) {
    // Ok, likely a GammaRay timer
    //cout << "TimerModel::preSignalActivate(): Unable to find timer "
    //     << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
    return;
  }

  if (!timerInfo->functionCallTimer()->start()) {
    cout << "TimerModel::preSignalActivate(): Recursive timeout for timer "
         << (void*)caller << " (" << caller->objectName().toStdString() << ")!" << endl;
    return;
  }

  Q_ASSERT(!m_currentSignals.contains(caller));
  m_currentSignals[caller] = timerInfo;
}
Ejemplo n.º 3
0
bool TimerModel::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::Timer) {

        QTimerEvent * const timerEvent = dynamic_cast<QTimerEvent*>(event);
        Q_ASSERT(timerEvent);

        // If there is a QTimer associated with this timer ID, don't handle it here, it will be handled
        // by the signal hooks for QTimer::timeout()
        if (findOrCreateQTimerTimerInfo(timerEvent->timerId())) {
            return false;
        }

        if (Probe::instance()->filterObject(watched)) {
            return false;
        }

        const TimerInfoPtr timerInfo = findOrCreateFreeTimerInfo(timerEvent->timerId());
        TimerInfo::TimeoutEvent timeoutEvent;
        timeoutEvent.timeStamp = QTime::currentTime();
        timeoutEvent.executionTime = -1;
        timerInfo->addEvent(timeoutEvent);

        timerInfo->setLastReceiver(watched);
    }
    return false;
}
Ejemplo n.º 4
0
void TimerModel::preSignalActivate(QObject *caller, int methodIndex)
{
  if (methodIndex != m_timeoutIndex) {
    return;
  }

  QTimer *timer = qobject_cast<QTimer*>(caller);
  if (!timer || timer->objectName().toLower().startsWith(QLatin1String("gammaray"))) {
    return;
  }

  const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(timer);

  if (!timerInfo) {
    // Ok, likely a GammaRay timer
    //cout << "TimerModel::preSignalActivate(): Unable to find timer "
    //     << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
    return;
  }

  if (!timerInfo->functionCallTimer()->start()) {
    cout << "TimerModel::preSignalActivate(): Recursive timeout for timer "
         << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
    return;
  }

  Q_ASSERT(!m_currentSignals.contains(caller));
  m_currentSignals[caller] = timerInfo;
}
Ejemplo n.º 5
0
QVariant TimerModel::data(const QModelIndex &index, int role) const
{
    if (!m_sourceModel || !index.isValid())
        return QVariant();

    if (role == Qt::DisplayRole) {
        const TimerInfoPtr timerInfo = const_cast<TimerModel *>(this)->findOrCreateTimerInfo(index);
        switch (index.column()) {
        case ObjectNameColumn:
            return timerInfo->displayName();
        case StateColumn:
            return timerInfo->state();
        case TotalWakeupsColumn:
            return timerInfo->totalWakeups();
        case WakeupsPerSecColumn:
            return timerInfo->wakeupsPerSec();
        case TimePerWakeupColumn:
            return timerInfo->timePerWakeup();
        case MaxTimePerWakeupColumn:
            return timerInfo->maxWakeupTime();
        case TimerIdColumn:
            return timerInfo->timerId();
        case ColumnCount:
            break;
        }
    }

    if (role == ObjectIdRole && index.column() == 0) {
        const TimerInfoPtr timerInfo = const_cast<TimerModel*>(this)->findOrCreateTimerInfo(index);
        return QVariant::fromValue(ObjectId(timerInfo->timerObject()));
    }

    return QVariant();
}
Ejemplo n.º 6
0
int TimerModel::rowFor(QObject *timer)
{
    for (int i = 0; i < rowCount(); i++) {
        const TimerInfoPtr timerInfo = findOrCreateTimerInfo(index(i, 0));
        if (timerInfo && timerInfo->timerObject() == timer)
            return i;
    }
    return -1;
}
Ejemplo n.º 7
0
QVariant TimerModel::data(const QModelIndex &index, int role) const
{
    if (!m_sourceModel)
        return QVariant();

    if (role == Qt::DisplayRole && index.isValid()
        && index.column() >= 0 && index.column() < columnCount()) {
        const TimerInfoPtr timerInfo = const_cast<TimerModel *>(this)->findOrCreateTimerInfo(index);
        switch ((Roles)(index.column() + FirstRole + 1)) {
        case ObjectNameRole:
            return timerInfo->displayName();
        case StateRole:
            return timerInfo->state();
        case TotalWakeupsRole:
            return timerInfo->totalWakeups();
        case WakeupsPerSecRole:
            return timerInfo->wakeupsPerSec();
        case TimePerWakeupRole:
            return timerInfo->timePerWakeup();
        case MaxTimePerWakeupRole:
            return timerInfo->maxWakeupTime();
        case TimerIdRole:
            return timerInfo->timerId();
        case FirstRole:
        case LastRole:
            break;
        }
    }
    return QVariant();
}
Ejemplo n.º 8
0
void TimerModel::preSignalActivate(QTimer *timer)
{
    const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(timer);
    if (timerInfo) {
        if (!timerInfo->functionCallTimer()->start()) {
            cout << "TimerModel::preSignalActivate(): Recursive timeout for timer "
                 << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
        }
    } else {
        // Ok, likely a GammaRay timer
        //cout << "TimerModel::preSignalActivate(): Unable to find timer "
        //     << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
    }
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
TimerInfoPtr TimerModel::findOrCreateQTimerTimerInfo(QObject *timer)
{
    if (!timer)
        return TimerInfoPtr();

    QVariant timerInfoVariant = timer->property(timerInfoPropertyName);
    if (!timerInfoVariant.isValid()) {
        const TimerInfoPtr info = TimerInfoPtr(new TimerInfo(timer));
        if (m_qmlTimerTriggeredIndex < 0 && info->type() == TimerInfo::QQmlTimerType)
            m_qmlTimerTriggeredIndex = timer->metaObject()->indexOfMethod("triggered()");
        timerInfoVariant.setValue(info);
        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->timerObject() == timer);
    return timerInfo;
}
Ejemplo n.º 12
0
void TimerModel::postSignalActivate(QTimer *timer)
{
    const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(timer);
    if (timerInfo) {
        if (!timerInfo->functionCallTimer()->active()) {
            cout << "TimerModel::postSignalActivate(): Timer not active: "
                 << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
        } else {
            TimerInfo::TimeoutEvent event;
            event.timeStamp = QTime::currentTime();
            event.executionTime = timerInfo->functionCallTimer()->stop();
            timerInfo->addEvent(event);
            const int row = rowFor(timer);
            if (row != -1) {
                emit dataChanged(index(row, 0), index(row, columnCount() - 1));
            }
        }
    } else {
        // Ok, likely a GammaRay timer
        //cout << "TimerModel::postSignalActivate(): Unable to find timer "
        //     << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl;
    }
}
Ejemplo n.º 13
0
void TimerModel::postSignalActivate(QObject *caller, int methodIndex)
{
    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*)caller << " (" << caller->objectName().toStdString() << ")!" << endl;
        return;
    }

    const TimerInfoPtr timerInfo = *it;
    Q_ASSERT(timerInfo);

    if (!(timerInfo->type() == TimerInfo::QTimerType && methodIndex == m_timeoutIndex)
        && !(timerInfo->type() == TimerInfo::QQmlTimerType
             && methodIndex == m_qmlTimerTriggeredIndex))
        return;

    m_currentSignals.erase(it);

    if (!timerInfo->timerObject()) {
        // timer got killed in a slot
        return;
    }

    Q_ASSERT(caller == timerInfo->timerObject());

    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->timerObject());
    emitTimerObjectChanged(row);
}
Ejemplo n.º 14
0
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));
  }
}