mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
DiveObjectHelper: Turn DiveObjectHelper into Q_GADGET based object
DiveObjectHelper is a tiny wrapper around dive * to allow access to dive data from QML and grantlee. It doesn't have to be a full-fledged QObject with support for signals, etc. Therefore, turn it into a Q_GADGET based object. This allows us passing the object around as object, not as pointer to DiveObjectHelper. This makes memory-management distinctly easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
a79c45e401
commit
be763452ad
5 changed files with 101 additions and 20 deletions
|
@ -64,8 +64,8 @@ int DiveListSortModel::getIdxForId(int id)
|
|||
{
|
||||
for (int i = 0; i < rowCount(); i++) {
|
||||
QVariant v = data(index(i, 0), DiveListModel::DiveRole);
|
||||
DiveObjectHelper *d = v.value<DiveObjectHelper *>();
|
||||
if (d->id() == id)
|
||||
DiveObjectHelper d = v.value<DiveObjectHelper>();
|
||||
if (d.id() == id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
|
@ -239,13 +239,13 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
|
|||
if(index.row() < 0 || index.row() >= m_dives.count())
|
||||
return QVariant();
|
||||
|
||||
DiveObjectHelper *curr_dive = m_dives[index.row()];
|
||||
const dive *d = curr_dive->getDive();
|
||||
DiveObjectHelper &curr_dive = *m_dives[index.row()];
|
||||
const dive *d = curr_dive.getDive();
|
||||
if (!d)
|
||||
return QVariant();
|
||||
switch(role) {
|
||||
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
||||
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
||||
case DiveRole: return QVariant::fromValue<DiveObjectHelper>(curr_dive);
|
||||
case DiveDateRole: return (qlonglong)d->when;
|
||||
case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString();
|
||||
case TripNrDivesRole: return d->divetrip ? d->divetrip->dives.nr : 0;
|
||||
case DateTimeRole: {
|
||||
|
@ -305,7 +305,7 @@ DiveListModel *DiveListModel::instance()
|
|||
return m_instance;
|
||||
}
|
||||
|
||||
DiveObjectHelper* DiveListModel::at(int i)
|
||||
DiveObjectHelper *DiveListModel::at(int i)
|
||||
{
|
||||
return m_dives.at(i);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue