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(); }
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(); }