mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
cf4d32c6e8
commit
32df0ab0da
2 changed files with 255 additions and 445 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue