X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fstatsmodel.cpp;fp=src%2Fstatsmodel.cpp;h=b6a2ef8199b3a1566df13922f6087ff71ddab9d5;hp=52090c43e6d1fd4246f97e206f0271dfccefa49a;hb=dc14479d561196e19417c4ecf78e847ec4b43b7c;hpb=76b5f460f9a5052571d730918b2ee778753f4c59 diff --git a/src/statsmodel.cpp b/src/statsmodel.cpp index 52090c4..b6a2ef8 100644 --- a/src/statsmodel.cpp +++ b/src/statsmodel.cpp @@ -1,12 +1,17 @@ #include "statsmodel.h" StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) { + roles[TitleRole] = "title"; roles[ValuesRole] = "values"; roles[LabelsRole] = "labels"; + roles[UnitsRole] = "units"; + roles[MinValRole] = "minval"; + roles[MaxValRole] = "maxval"; + roles[StepRole] = "step"; } -void StatsModel::addStats(const Stats &stats) { - this->stats.append(stats); +void StatsModel::addStats(Stats &stats) { + this->stats.append(&stats); } QHash StatsModel::roleNames() const { @@ -22,11 +27,21 @@ QVariant StatsModel::data(const QModelIndex & index, int role) const { if (index.row() < 0 || index.row() > stats.count()) return QVariant(); - const Stats &stat = stats[index.row()]; - if (role == ValuesRole) - return QVariant::fromValue>(stat.getValues()); + const Stats *stat = stats[index.row()]; + if (role == TitleRole) + return stat->getTitle(); + else if (role == ValuesRole) + return QVariant::fromValue>(stat->getValues()); else if (role == LabelsRole) - return stat.getLabels(); + return stat->getLabels(); + else if (role == UnitsRole) + return stat->getUnits(); + else if (role == MinValRole) + return stat->getMinVal(); + else if (role == MaxValRole) + return stat->getMaxVal(); + else if (role == StepRole) + return stat->getStep(); return QVariant(); } @@ -34,3 +49,8 @@ void StatsModel::clear() { stats.clear(); } +void StatsModel::updateAll() { + foreach (Stats * stat, stats) { + stat->update(); + } +}