QVariant GpsListModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() > m_gpsFixes.count()) return QVariant(); const gpsTracker > = m_gpsFixes[index.row()]; if (role == GpsDateRole) return get_short_dive_date_string(gt.when); else if (role == GpsWhenRole) return gt.when; else if (role == GpsNameRole) return gt.name; else if (role == GpsLatitudeRole) return QString::number(gt.location.lat.udeg / 1000000.0, 'f', 6); else if (role == GpsLongitudeRole) return QString::number(gt.location.lon.udeg / 1000000.0, 'f', 6); return QVariant(); }
QVariant DiveImportedModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() + firstIndex > lastIndex) return QVariant(); struct dive *d = get_dive_from_table(index.row() + firstIndex, diveTable); if (!d) return QVariant(); // widgets access the model via index.column(), qml via role. int column = index.column(); if (role >= DateTime) { column = role - DateTime; role = Qt::DisplayRole; } if (role == Qt::DisplayRole) { switch (column) { case 0: return QVariant(get_short_dive_date_string(d->when)); case 1: return QVariant(get_dive_duration_string(d->duration.seconds, tr("h"), tr("min"))); case 2: return QVariant(get_depth_string(d->maxdepth.mm, true, false)); case 3: return checkStates[index.row()]; } } if (role == Qt::CheckStateRole) { if (index.column() == 0) return checkStates[index.row()] ? Qt::Checked : Qt::Unchecked; } return QVariant(); }