2013-04-13 20:44:02 -07:00
|
|
|
/*
|
|
|
|
* models.h
|
|
|
|
*
|
|
|
|
* header file for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-13 10:17:59 -03:00
|
|
|
#ifndef MODELS_H
|
|
|
|
#define MODELS_H
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
2013-05-01 23:51:34 -03:00
|
|
|
#include <QCoreApplication>
|
2013-05-23 15:33:20 -03:00
|
|
|
#include <QStringList>
|
2013-11-14 17:39:35 -02:00
|
|
|
#include <QStringListModel>
|
2014-09-17 16:18:37 -03:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-05-28 16:23:49 -03:00
|
|
|
#include <QPixmap>
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2014-10-15 15:30:50 +02:00
|
|
|
#include "metrics.h"
|
|
|
|
|
2013-04-13 10:17:59 -03:00
|
|
|
#include "../dive.h"
|
2013-04-27 12:27:27 -03:00
|
|
|
#include "../divelist.h"
|
2014-05-12 13:53:26 -03:00
|
|
|
#include "../divecomputer.h"
|
2015-05-28 15:00:58 -03:00
|
|
|
#include "cleanertablemodel.h"
|
2013-10-11 10:50:40 -03:00
|
|
|
|
2013-04-21 22:12:36 -03:00
|
|
|
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
|
|
|
*
|
|
|
|
*/
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
struct TreeItem {
|
2014-02-27 20:09:57 -08:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TreeItemDT);
|
|
|
|
|
2013-04-21 22:12:36 -03:00
|
|
|
public:
|
2013-06-17 18:59:50 -03:00
|
|
|
virtual ~TreeItem();
|
2013-06-18 13:29:37 -07:00
|
|
|
TreeItem();
|
2014-02-27 20:09:57 -08:00
|
|
|
virtual QVariant data(int column, int role) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
2013-11-18 22:33:01 -02:00
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
int row() const;
|
2014-02-27 20:09:57 -08:00
|
|
|
QList<TreeItem *> children;
|
2013-06-17 18:59:50 -03:00
|
|
|
TreeItem *parent;
|
2013-05-01 23:51:34 -03:00
|
|
|
};
|
2013-04-21 22:12:36 -03:00
|
|
|
|
2013-07-11 12:40:08 +03:00
|
|
|
struct DiveItem : public TreeItem {
|
2014-02-27 20:09:57 -08:00
|
|
|
enum Column {
|
|
|
|
NR,
|
|
|
|
DATE,
|
|
|
|
RATING,
|
|
|
|
DEPTH,
|
|
|
|
DURATION,
|
|
|
|
TEMPERATURE,
|
|
|
|
TOTALWEIGHT,
|
|
|
|
SUIT,
|
|
|
|
CYLINDER,
|
2014-07-20 15:07:56 +02:00
|
|
|
GAS,
|
2014-02-27 20:09:57 -08:00
|
|
|
SAC,
|
|
|
|
OTU,
|
|
|
|
MAXCNS,
|
|
|
|
LOCATION,
|
|
|
|
COLUMNS
|
|
|
|
};
|
2013-07-11 12:40:08 +03:00
|
|
|
|
|
|
|
virtual QVariant data(int column, int role) const;
|
2014-01-07 11:57:20 +08:00
|
|
|
int diveId;
|
2014-02-27 20:09:57 -08:00
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
2013-07-11 12:41:50 +03:00
|
|
|
QString displayDate() const;
|
2013-07-11 12:40:08 +03:00
|
|
|
QString displayDuration() const;
|
|
|
|
QString displayDepth() const;
|
2014-07-11 21:59:21 -07:00
|
|
|
QString displayDepthWithUnit() const;
|
2013-07-11 12:40:08 +03:00
|
|
|
QString displayTemperature() const;
|
|
|
|
QString displayWeight() const;
|
|
|
|
QString displaySac() const;
|
|
|
|
int weight() const;
|
|
|
|
};
|
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
struct TripItem;
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
class TreeModel : public QAbstractItemModel {
|
2013-05-01 23:51:34 -03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-17 18:59:50 -03:00
|
|
|
TreeModel(QObject *parent = 0);
|
|
|
|
virtual ~TreeModel();
|
2014-02-27 20:09:57 -08:00
|
|
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
2013-05-01 23:51:34 -03:00
|
|
|
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
2013-04-21 22:12:36 -03:00
|
|
|
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
/*reimp*/ QModelIndex parent(const QModelIndex &child) const;
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
protected:
|
|
|
|
int columns;
|
|
|
|
TreeItem *rootItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DiveTripModel : public TreeModel {
|
2013-06-17 19:41:05 -03:00
|
|
|
Q_OBJECT
|
2013-06-17 18:59:50 -03:00
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
enum Column {
|
|
|
|
NR,
|
|
|
|
DATE,
|
|
|
|
RATING,
|
|
|
|
DEPTH,
|
|
|
|
DURATION,
|
|
|
|
TEMPERATURE,
|
|
|
|
TOTALWEIGHT,
|
|
|
|
SUIT,
|
|
|
|
CYLINDER,
|
2014-07-20 15:07:56 +02:00
|
|
|
GAS,
|
2014-02-27 20:09:57 -08:00
|
|
|
SAC,
|
|
|
|
OTU,
|
|
|
|
MAXCNS,
|
|
|
|
LOCATION,
|
|
|
|
COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ExtraRoles {
|
|
|
|
STAR_ROLE = Qt::UserRole + 1,
|
|
|
|
DIVE_ROLE,
|
|
|
|
TRIP_ROLE,
|
|
|
|
SORT_ROLE,
|
|
|
|
DIVE_IDX
|
|
|
|
};
|
|
|
|
enum Layout {
|
|
|
|
TREE,
|
|
|
|
LIST,
|
|
|
|
CURRENT
|
|
|
|
};
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
2013-10-15 04:37:31 -07:00
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2014-02-27 20:09:57 -08:00
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
DiveTripModel(QObject *parent = 0);
|
2013-05-28 16:56:58 -03:00
|
|
|
Layout layout() const;
|
|
|
|
void setLayout(Layout layout);
|
2014-02-27 20:09:57 -08:00
|
|
|
|
2013-04-21 22:12:36 -03:00
|
|
|
private:
|
2013-05-01 23:51:34 -03:00
|
|
|
void setupModelData();
|
2014-02-27 20:09:57 -08:00
|
|
|
QMap<dive_trip_t *, TripItem *> trips;
|
2013-05-28 16:56:58 -03:00
|
|
|
Layout currentLayout;
|
2013-04-21 22:12:36 -03:00
|
|
|
};
|
|
|
|
|
2013-06-17 19:41:05 -03:00
|
|
|
class YearlyStatisticsModel : public TreeModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
enum {
|
|
|
|
YEAR,
|
|
|
|
DIVES,
|
|
|
|
TOTAL_TIME,
|
|
|
|
AVERAGE_TIME,
|
|
|
|
SHORTEST_TIME,
|
|
|
|
LONGEST_TIME,
|
|
|
|
AVG_DEPTH,
|
|
|
|
MIN_DEPTH,
|
|
|
|
MAX_DEPTH,
|
|
|
|
AVG_SAC,
|
|
|
|
MIN_SAC,
|
|
|
|
MAX_SAC,
|
|
|
|
AVG_TEMP,
|
|
|
|
MIN_TEMP,
|
|
|
|
MAX_TEMP,
|
|
|
|
COLUMNS
|
|
|
|
};
|
2013-06-17 19:41:05 -03:00
|
|
|
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2014-02-27 20:09:57 -08:00
|
|
|
YearlyStatisticsModel(QObject *parent = 0);
|
2013-06-17 21:05:17 -03:00
|
|
|
void update_yearly_stats();
|
2013-06-17 19:41:05 -03:00
|
|
|
};
|
2013-07-25 12:52:20 +03:00
|
|
|
|
|
|
|
/* TablePrintModel:
|
|
|
|
* for now we use a blank table model with row items TablePrintItem.
|
|
|
|
* these are pretty much the same as DiveItem, but have color
|
|
|
|
* properties, as well. perhaps later one a more unified model has to be
|
|
|
|
* considered, but the current TablePrintModel idea has to be extended
|
|
|
|
* to support variadic column lists and column list orders that can
|
|
|
|
* be controlled by the user.
|
|
|
|
*/
|
|
|
|
struct TablePrintItem {
|
|
|
|
QString number;
|
|
|
|
QString date;
|
|
|
|
QString depth;
|
|
|
|
QString duration;
|
|
|
|
QString divemaster;
|
|
|
|
QString buddy;
|
|
|
|
QString location;
|
|
|
|
unsigned int colorBackground;
|
|
|
|
};
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
class TablePrintModel : public QAbstractTableModel {
|
2013-07-25 12:52:20 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<struct TablePrintItem *> list;
|
|
|
|
|
|
|
|
public:
|
|
|
|
~TablePrintModel();
|
|
|
|
TablePrintModel();
|
|
|
|
|
|
|
|
int rows, columns;
|
|
|
|
void insertRow(int index = -1);
|
|
|
|
void callReset();
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
2013-07-25 12:52:20 +03:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
|
|
|
int rowCount(const QModelIndex &parent) const;
|
|
|
|
int columnCount(const QModelIndex &parent) const;
|
|
|
|
};
|
|
|
|
|
2013-10-03 17:50:40 +03:00
|
|
|
/* ProfilePrintModel:
|
|
|
|
* this model is used when printing a data table under a profile. it requires
|
|
|
|
* some exact usage of setSpan(..) on the target QTableView widget.
|
|
|
|
*/
|
2014-02-27 20:09:57 -08:00
|
|
|
class ProfilePrintModel : public QAbstractTableModel {
|
2013-10-03 17:50:40 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2014-01-07 11:57:20 +08:00
|
|
|
int diveId;
|
2014-07-11 21:30:40 -07:00
|
|
|
double fontSize;
|
2013-10-03 17:50:40 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
ProfilePrintModel(QObject *parent = 0);
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
void setDive(struct dive *divePtr);
|
2014-07-11 21:30:40 -07:00
|
|
|
void setFontsize(double size);
|
2013-10-03 17:50:40 +03:00
|
|
|
};
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
class GasSelectionModel : public QStringListModel {
|
2013-11-14 17:39:35 -02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
static GasSelectionModel *instance();
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
public
|
|
|
|
slots:
|
2013-11-14 17:39:35 -02:00
|
|
|
void repopulate();
|
|
|
|
};
|
|
|
|
|
2013-12-06 14:29:38 -02:00
|
|
|
|
|
|
|
class LanguageModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
static LanguageModel *instance();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
2013-12-06 14:29:38 -02:00
|
|
|
private:
|
2014-02-27 20:09:57 -08:00
|
|
|
LanguageModel(QObject *parent = 0);
|
2013-12-06 14:29:38 -02:00
|
|
|
|
|
|
|
QStringList languages;
|
|
|
|
};
|
2014-09-17 15:45:18 -03:00
|
|
|
|
2014-02-11 19:14:46 +01:00
|
|
|
#endif // MODELS_H
|