2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* models.h
|
|
|
|
*
|
|
|
|
* header file for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-13 13:17:59 +00:00
|
|
|
#ifndef MODELS_H
|
|
|
|
#define MODELS_H
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
2013-05-02 02:51:34 +00:00
|
|
|
#include <QCoreApplication>
|
2013-05-23 18:33:20 +00:00
|
|
|
#include <QStringList>
|
2013-11-14 19:39:35 +00:00
|
|
|
#include <QStringListModel>
|
2014-09-17 19:18:37 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-05-28 19:23:49 +00:00
|
|
|
#include <QPixmap>
|
2013-05-02 02:51:34 +00:00
|
|
|
|
2014-10-15 13:30:50 +00:00
|
|
|
#include "metrics.h"
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
#include "../dive.h"
|
2013-04-27 15:27:27 +00:00
|
|
|
#include "../divelist.h"
|
2014-05-12 16:53:26 +00:00
|
|
|
#include "../divecomputer.h"
|
2015-05-28 18:00:58 +00:00
|
|
|
#include "cleanertablemodel.h"
|
2013-10-11 13:50:40 +00:00
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
|
|
|
*
|
|
|
|
*/
|
2013-05-02 02:51:34 +00:00
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
struct TreeItem {
|
2014-02-28 04:09:57 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TreeItemDT);
|
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
public:
|
2013-06-17 21:59:50 +00:00
|
|
|
virtual ~TreeItem();
|
2013-06-18 20:29:37 +00:00
|
|
|
TreeItem();
|
2014-02-28 04:09:57 +00:00
|
|
|
virtual QVariant data(int column, int role) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
2013-11-19 00:33:01 +00:00
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
int row() const;
|
2014-02-28 04:09:57 +00:00
|
|
|
QList<TreeItem *> children;
|
2013-06-17 21:59:50 +00:00
|
|
|
TreeItem *parent;
|
2013-05-02 02:51:34 +00:00
|
|
|
};
|
2013-04-22 01:12:36 +00:00
|
|
|
|
2013-07-11 09:40:08 +00:00
|
|
|
struct DiveItem : public TreeItem {
|
2014-02-28 04:09:57 +00:00
|
|
|
enum Column {
|
|
|
|
NR,
|
|
|
|
DATE,
|
|
|
|
RATING,
|
|
|
|
DEPTH,
|
|
|
|
DURATION,
|
|
|
|
TEMPERATURE,
|
|
|
|
TOTALWEIGHT,
|
|
|
|
SUIT,
|
|
|
|
CYLINDER,
|
2014-07-20 13:07:56 +00:00
|
|
|
GAS,
|
2014-02-28 04:09:57 +00:00
|
|
|
SAC,
|
|
|
|
OTU,
|
|
|
|
MAXCNS,
|
|
|
|
LOCATION,
|
|
|
|
COLUMNS
|
|
|
|
};
|
2013-07-11 09:40:08 +00:00
|
|
|
|
|
|
|
virtual QVariant data(int column, int role) const;
|
2014-01-07 03:57:20 +00:00
|
|
|
int diveId;
|
2014-02-28 04:09:57 +00: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 09:41:50 +00:00
|
|
|
QString displayDate() const;
|
2013-07-11 09:40:08 +00:00
|
|
|
QString displayDuration() const;
|
|
|
|
QString displayDepth() const;
|
2014-07-12 04:59:21 +00:00
|
|
|
QString displayDepthWithUnit() const;
|
2013-07-11 09:40:08 +00:00
|
|
|
QString displayTemperature() const;
|
|
|
|
QString displayWeight() const;
|
|
|
|
QString displaySac() const;
|
|
|
|
int weight() const;
|
|
|
|
};
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
struct TripItem;
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class TreeModel : public QAbstractItemModel {
|
2013-05-02 02:51:34 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-17 21:59:50 +00:00
|
|
|
TreeModel(QObject *parent = 0);
|
|
|
|
virtual ~TreeModel();
|
2014-02-28 04:09:57 +00:00
|
|
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
2013-05-02 02:51:34 +00:00
|
|
|
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
2013-04-22 01:12:36 +00: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 21:59:50 +00:00
|
|
|
protected:
|
|
|
|
int columns;
|
|
|
|
TreeItem *rootItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DiveTripModel : public TreeModel {
|
2013-06-17 22:41:05 +00:00
|
|
|
Q_OBJECT
|
2013-06-17 21:59:50 +00:00
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
enum Column {
|
|
|
|
NR,
|
|
|
|
DATE,
|
|
|
|
RATING,
|
|
|
|
DEPTH,
|
|
|
|
DURATION,
|
|
|
|
TEMPERATURE,
|
|
|
|
TOTALWEIGHT,
|
|
|
|
SUIT,
|
|
|
|
CYLINDER,
|
2014-07-20 13:07:56 +00:00
|
|
|
GAS,
|
2014-02-28 04:09:57 +00: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 21:59:50 +00:00
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
2013-10-15 11:37:31 +00:00
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2014-02-28 04:09:57 +00:00
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
DiveTripModel(QObject *parent = 0);
|
2013-05-28 19:56:58 +00:00
|
|
|
Layout layout() const;
|
|
|
|
void setLayout(Layout layout);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
private:
|
2013-05-02 02:51:34 +00:00
|
|
|
void setupModelData();
|
2014-02-28 04:09:57 +00:00
|
|
|
QMap<dive_trip_t *, TripItem *> trips;
|
2013-05-28 19:56:58 +00:00
|
|
|
Layout currentLayout;
|
2013-04-22 01:12:36 +00:00
|
|
|
};
|
|
|
|
|
2013-06-17 22:41:05 +00:00
|
|
|
class YearlyStatisticsModel : public TreeModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00: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 22:41:05 +00:00
|
|
|
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2014-02-28 04:09:57 +00:00
|
|
|
YearlyStatisticsModel(QObject *parent = 0);
|
2013-06-18 00:05:17 +00:00
|
|
|
void update_yearly_stats();
|
2013-06-17 22:41:05 +00:00
|
|
|
};
|
2013-07-25 09:52:20 +00: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-28 04:09:57 +00:00
|
|
|
class TablePrintModel : public QAbstractTableModel {
|
2013-07-25 09:52:20 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<struct TablePrintItem *> list;
|
|
|
|
|
|
|
|
public:
|
|
|
|
~TablePrintModel();
|
|
|
|
TablePrintModel();
|
|
|
|
|
|
|
|
int rows, columns;
|
|
|
|
void insertRow(int index = -1);
|
|
|
|
void callReset();
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
2013-07-25 09:52:20 +00: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 14:50:40 +00: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-28 04:09:57 +00:00
|
|
|
class ProfilePrintModel : public QAbstractTableModel {
|
2013-10-03 14:50:40 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2014-01-07 03:57:20 +00:00
|
|
|
int diveId;
|
2014-07-12 04:30:40 +00:00
|
|
|
double fontSize;
|
2013-10-03 14:50:40 +00: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-12 04:30:40 +00:00
|
|
|
void setFontsize(double size);
|
2013-10-03 14:50:40 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class GasSelectionModel : public QStringListModel {
|
2013-11-14 19:39:35 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00: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 19:39:35 +00:00
|
|
|
void repopulate();
|
|
|
|
};
|
|
|
|
|
2013-12-06 16:29:38 +00:00
|
|
|
|
|
|
|
class LanguageModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00: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 16:29:38 +00:00
|
|
|
private:
|
2014-02-28 04:09:57 +00:00
|
|
|
LanguageModel(QObject *parent = 0);
|
2013-12-06 16:29:38 +00:00
|
|
|
|
|
|
|
QStringList languages;
|
|
|
|
};
|
2014-09-17 18:45:18 +00:00
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // MODELS_H
|