summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-14 08:56:53 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-14 15:57:14 -0400
commit32df0ab0daa8551e24d93082ad182673bbf37cdf (patch)
tree1abf1003eeafcaf894329089a5582278a6a796d0 /qt-models/divetripmodel.h
parentcf4d32c6e8bd60b5e825535702f3e2701b40716b (diff)
downloadsubsurface-32df0ab0daa8551e24d93082ad182673bbf37cdf.tar.gz
Cleanup: remove DiveItem and TripItem classes
The DiveItem and TripItem classes were wrappers around dive * and dive_trip * used to extract tabular data. With the rework of DiveTripModel they lost all their state besides the pointer itself. The usage was: DiveItem item(d); item.data(...); This can now be simplified to the much more idiomatic diveData(d, ...); and analoguously for TripItem. While adapting the data() function to be part of DiveTripModel, change the QVariant ret switch(...) { ... case ...: ret = ...; break; ... } return ret; style to switch(...) { ... case ...: return ...; } Not only is this shorter and easier to reason about, it generally also improves the generated code. The compiler can directly construct the return value in the buffer provided by the caller. Though modern compilers start to be very good at avoiding unnecessary copies. In total this cleanup results in a net-reduction of 190 lines of code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.h')
-rw-r--r--qt-models/divetripmodel.h57
1 files changed, 4 insertions, 53 deletions
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index fb3c3395d..d75926f9e 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -4,59 +4,6 @@
#include "core/dive.h"
#include <QAbstractItemModel>
-#include <QCoreApplication> // For Q_DECLARE_TR_FUNCTIONS
-
-struct DiveItem {
- Q_DECLARE_TR_FUNCTIONS(TripItem) // Is that TripItem on purpose?
-public:
- enum Column {
- NR,
- DATE,
- RATING,
- DEPTH,
- DURATION,
- TEMPERATURE,
- TOTALWEIGHT,
- SUIT,
- CYLINDER,
- GAS,
- SAC,
- OTU,
- MAXCNS,
- TAGS,
- PHOTOS,
- BUDDIES,
- COUNTRY,
- LOCATION,
- COLUMNS
- };
-
- QVariant data(int column, int role) const;
- dive *d;
- DiveItem(dive *dIn) : d(dIn) {} // Trivial constructor
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- QString displayDate() const;
- QString displayDuration() const;
- QString displayDepth() const;
- QString displayDepthWithUnit() const;
- QString displayTemperature() const;
- QString displayTemperatureWithUnit() const;
- QString displayWeight() const;
- QString displayWeightWithUnit() const;
- QString displaySac() const;
- QString displaySacWithUnit() const;
- QString displayTags() const;
- int countPhotos() const;
- int weight() const;
-};
-
-struct TripItem {
- Q_DECLARE_TR_FUNCTIONS(TripItem)
-public:
- QVariant data(int column, int role) const;
- dive_trip_t *trip;
- TripItem(dive_trip_t *tIn) : trip(tIn) {} // Trivial constructor
-};
class DiveTripModel : public QAbstractItemModel {
Q_OBJECT
@@ -165,6 +112,10 @@ private:
int findDiveInTrip(int tripIdx, const dive *d) const; // Find dive inside trip. Second parameter is index of trip
int findInsertionIndex(timestamp_t when) const; // Where to insert item with timestamp "when"
+ // Access trip and dive data
+ static QVariant diveData(const struct dive *d, int column, int role);
+ static QVariant tripData(const dive_trip *trip, int column, int role);
+
// Select or deselect dives
void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select);