mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 06:53:25 +00:00
Mobile: move tripId from DiveObjectHelper to DiveListModel
The canonical way of displaying lists in Qt is via models. Thus, return the tripId directly from the DiveListModel instead of going indirectly via a DiveObjectHelper. In the future, this will allow us to make the DiveObjectHelper value-based, as it is not generated numerous times for every list item. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b7cddcc737
commit
1b9581369a
5 changed files with 8 additions and 11 deletions
|
@ -315,11 +315,6 @@ QVector<CylinderObjectHelper> DiveObjectHelper::cylinderObjects() const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiveObjectHelper::tripId() const
|
|
||||||
{
|
|
||||||
return m_dive->divetrip ? QString::number((quint64)m_dive->divetrip, 16) : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DiveObjectHelper::tripNrDives() const
|
int DiveObjectHelper::tripNrDives() const
|
||||||
{
|
{
|
||||||
struct dive_trip *dt = m_dive->divetrip;
|
struct dive_trip *dt = m_dive->divetrip;
|
||||||
|
|
|
@ -40,7 +40,6 @@ class DiveObjectHelper : public QObject {
|
||||||
Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT)
|
Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT)
|
||||||
Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
|
Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
|
||||||
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects READ cylinderObjects CONSTANT)
|
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects READ cylinderObjects CONSTANT)
|
||||||
Q_PROPERTY(QString tripId READ tripId CONSTANT)
|
|
||||||
Q_PROPERTY(int tripNrDives READ tripNrDives CONSTANT)
|
Q_PROPERTY(int tripNrDives READ tripNrDives CONSTANT)
|
||||||
Q_PROPERTY(int maxcns READ maxcns CONSTANT)
|
Q_PROPERTY(int maxcns READ maxcns CONSTANT)
|
||||||
Q_PROPERTY(int otu READ otu CONSTANT)
|
Q_PROPERTY(int otu READ otu CONSTANT)
|
||||||
|
@ -83,7 +82,6 @@ public:
|
||||||
QStringList cylinders() const;
|
QStringList cylinders() const;
|
||||||
QString cylinder(int idx) const;
|
QString cylinder(int idx) const;
|
||||||
QVector<CylinderObjectHelper> cylinderObjects() const;
|
QVector<CylinderObjectHelper> cylinderObjects() const;
|
||||||
QString tripId() const;
|
|
||||||
int tripNrDives() const;
|
int tripNrDives() const;
|
||||||
int maxcns() const;
|
int maxcns() const;
|
||||||
int otu() const;
|
int otu() const;
|
||||||
|
|
|
@ -57,7 +57,7 @@ Kirigami.ScrollablePage {
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "isHidden";
|
name: "isHidden";
|
||||||
when: dive.tripId !== activeTrip && ! diveOutsideTrip
|
when: tripId !== activeTrip && ! diveOutsideTrip
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: innerListItem
|
target: innerListItem
|
||||||
height: 0
|
height: 0
|
||||||
|
@ -66,7 +66,7 @@ Kirigami.ScrollablePage {
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "isVisible";
|
name: "isVisible";
|
||||||
when: dive.tripId === activeTrip || diveOutsideTrip
|
when: tripId === activeTrip || diveOutsideTrip
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: innerListItem
|
target: innerListItem
|
||||||
height: diveListEntry.height + Kirigami.Units.smallSpacing
|
height: diveListEntry.height + Kirigami.Units.smallSpacing
|
||||||
|
@ -129,7 +129,7 @@ Kirigami.ScrollablePage {
|
||||||
Item {
|
Item {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: leftBarDive
|
id: leftBarDive
|
||||||
width: dive.tripId == "" ? 0 : Kirigami.Units.smallSpacing
|
width: tripId == "" ? 0 : Kirigami.Units.smallSpacing
|
||||||
height: diveListEntry.height * 0.8
|
height: diveListEntry.height * 0.8
|
||||||
color: subsurfaceTheme.lightPrimaryColor
|
color: subsurfaceTheme.lightPrimaryColor
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -524,7 +524,7 @@ Kirigami.ScrollablePage {
|
||||||
maximumFlickVelocity: parent.height * 5
|
maximumFlickVelocity: parent.height * 5
|
||||||
bottomMargin: Kirigami.Units.iconSizes.medium + Kirigami.Units.gridUnit
|
bottomMargin: Kirigami.Units.iconSizes.medium + Kirigami.Units.gridUnit
|
||||||
cacheBuffer: 40 // this will increase memory use, but should help with scrolling
|
cacheBuffer: 40 // this will increase memory use, but should help with scrolling
|
||||||
section.property: "dive.tripId"
|
section.property: "tripId"
|
||||||
section.criteria: ViewSection.FullString
|
section.criteria: ViewSection.FullString
|
||||||
section.delegate: tripHeading
|
section.delegate: tripHeading
|
||||||
section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
|
section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
|
||||||
|
|
|
@ -240,9 +240,11 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
DiveObjectHelper *curr_dive = m_dives[index.row()];
|
DiveObjectHelper *curr_dive = m_dives[index.row()];
|
||||||
|
const dive *d = curr_dive->getDive();
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
||||||
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
||||||
|
case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
|
@ -253,6 +255,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[DiveRole] = "dive";
|
roles[DiveRole] = "dive";
|
||||||
roles[DiveDateRole] = "date";
|
roles[DiveDateRole] = "date";
|
||||||
|
roles[TripIdRole] = "tripId";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
enum DiveListRoles {
|
enum DiveListRoles {
|
||||||
DiveRole = Qt::UserRole + 1,
|
DiveRole = Qt::UserRole + 1,
|
||||||
DiveDateRole,
|
DiveDateRole,
|
||||||
|
TripIdRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
static DiveListModel *instance();
|
static DiveListModel *instance();
|
||||||
|
|
Loading…
Add table
Reference in a new issue