mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added Support for the Trips and Dives on the DiveList model.
Now the list and dives will work in the same way that the GTK version does. The code got changed heavly because the old one was just looking at the dives and didn't worked like a tree. small adaptations on the list view and model delegates because of the changes done on this model. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
0be521bb25
commit
764a863082
4 changed files with 285 additions and 217 deletions
|
@ -11,5 +11,5 @@
|
||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
|
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
setItemDelegateForColumn(DiveTripModel::RATING, new StarWidgetsDelegate());
|
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,16 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rating = index.model()->data(index, Qt::DisplayRole).toInt();
|
QVariant value = index.model()->data(index, Qt::DisplayRole);
|
||||||
|
|
||||||
if (option.state & QStyle::State_Selected)
|
if (!value.isValid()){
|
||||||
painter->fillRect(option.rect, option.palette.highlight());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rating = value.toInt();
|
||||||
|
|
||||||
|
if(option.state & QStyle::State_Selected)
|
||||||
|
painter->fillRect(option.rect, option.palette.highlight());
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
447
qt-ui/models.cpp
447
qt-ui/models.cpp
|
@ -5,7 +5,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "models.h"
|
#include "models.h"
|
||||||
#include <QtDebug>
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
extern struct tank_info tank_info[100];
|
extern struct tank_info tank_info[100];
|
||||||
|
|
||||||
|
@ -289,59 +290,162 @@ void TankInfoModel::update()
|
||||||
* QObject.
|
* QObject.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DiveItem
|
|
||||||
|
TreeItemDT::~TreeItemDT()
|
||||||
{
|
{
|
||||||
public:
|
qDeleteAll(childs);
|
||||||
DiveItem(): dive(NULL), parentItem(NULL) {}
|
}
|
||||||
|
|
||||||
DiveItem(struct dive *d, DiveItem *parent = NULL);
|
int TreeItemDT::row() const
|
||||||
|
{
|
||||||
|
if (parent)
|
||||||
|
return parent->childs.indexOf(const_cast<TreeItemDT*>(this));
|
||||||
|
|
||||||
~DiveItem() { qDeleteAll(childlist); }
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int diveNumber() const { return dive->number; }
|
QVariant TreeItemDT::data(int column, int role) const
|
||||||
const QString diveDateTime() const { return get_dive_date_string(dive->when); }
|
{
|
||||||
int diveDuration() const { return dive->duration.seconds; }
|
QVariant ret;
|
||||||
int diveDepth() const { return dive->maxdepth.mm; }
|
switch (column) {
|
||||||
int diveSac() const { return dive->sac; }
|
case NR:
|
||||||
int diveOtu() const { return dive->otu; }
|
ret = tr("#");
|
||||||
int diveMaxcns() const { return dive->maxcns; }
|
break;
|
||||||
|
case DATE:
|
||||||
|
ret = tr("Date");
|
||||||
|
break;
|
||||||
|
case RATING:
|
||||||
|
ret = UTF8_BLACKSTAR;
|
||||||
|
break;
|
||||||
|
case DEPTH:
|
||||||
|
ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft");
|
||||||
|
break;
|
||||||
|
case DURATION:
|
||||||
|
ret = tr("min");
|
||||||
|
break;
|
||||||
|
case TEMPERATURE:
|
||||||
|
ret = QString("%1%2").arg(UTF8_DEGREE).arg( (get_units()->temperature == units::CELSIUS) ? "C" : "F");
|
||||||
|
break;
|
||||||
|
case TOTALWEIGHT:
|
||||||
|
ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs");
|
||||||
|
break;
|
||||||
|
case SUIT:
|
||||||
|
ret = tr("Suit");
|
||||||
|
break;
|
||||||
|
case CYLINDER:
|
||||||
|
ret = tr("Cyl");
|
||||||
|
break;
|
||||||
|
case NITROX:
|
||||||
|
ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2);
|
||||||
|
break;
|
||||||
|
case SAC:
|
||||||
|
ret = tr("SAC");
|
||||||
|
break;
|
||||||
|
case OTU:
|
||||||
|
ret = tr("OTU");
|
||||||
|
break;
|
||||||
|
case MAXCNS:
|
||||||
|
ret = tr("maxCNS");
|
||||||
|
break;
|
||||||
|
case LOCATION:
|
||||||
|
ret = tr("Location");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int diveWeight() const
|
struct TripItem : public TreeItemDT {
|
||||||
{
|
virtual QVariant data(int column, int role) const;
|
||||||
weight_t tw = { total_weight(dive) };
|
dive_trip_t* trip;
|
||||||
return tw.grams;
|
};
|
||||||
|
|
||||||
|
QVariant TripItem::data(int column, int role) const
|
||||||
|
{
|
||||||
|
QVariant ret;
|
||||||
|
|
||||||
|
if (column != LOCATION) {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diveRating() const { return dive->rating; }
|
switch (role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
ret = QString(trip->location);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DiveItem : public TreeItemDT {
|
||||||
|
virtual QVariant data(int column, int role) const;
|
||||||
|
struct dive* dive;
|
||||||
|
|
||||||
QString displayDuration() const;
|
QString displayDuration() const;
|
||||||
QString displayDepth() const;
|
QString displayDepth() const;
|
||||||
QString displayTemperature() const;
|
QString displayTemperature() const;
|
||||||
QString displayWeight() const;
|
QString displayWeight() const;
|
||||||
QString displaySac() const;
|
QString displaySac() const;
|
||||||
const QString diveLocation() const { return dive->location; }
|
int weight() const;
|
||||||
const QString diveSuit() const { return dive->suit; }
|
|
||||||
DiveItem *parent() const { return parentItem; }
|
|
||||||
const QList<DiveItem *>& children() const { return childlist; }
|
|
||||||
|
|
||||||
void addChild(DiveItem* item) {
|
|
||||||
item->parentItem = this;
|
|
||||||
childlist.push_back(item);
|
|
||||||
} /* parent = self */
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct dive *dive;
|
|
||||||
DiveItem *parentItem;
|
|
||||||
QList <DiveItem*> childlist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QVariant DiveItem::data(int column, int role) const
|
||||||
DiveItem::DiveItem(struct dive *d, DiveItem *p):
|
|
||||||
dive(d),
|
|
||||||
parentItem(p)
|
|
||||||
{
|
{
|
||||||
if (parentItem)
|
QVariant retVal;
|
||||||
parentItem->addChild(this);
|
|
||||||
|
if (role == Qt::TextAlignmentRole) {
|
||||||
|
switch (column) {
|
||||||
|
case DATE: /* fall through */
|
||||||
|
case SUIT: /* fall through */
|
||||||
|
case LOCATION:
|
||||||
|
retVal = Qt::AlignLeft;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
retVal = Qt::AlignRight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch (column) {
|
||||||
|
case NR:
|
||||||
|
retVal = dive->number;
|
||||||
|
break;
|
||||||
|
case DATE:
|
||||||
|
retVal = QString(get_dive_date_string(dive->when));
|
||||||
|
break;
|
||||||
|
case DEPTH:
|
||||||
|
retVal = displayDepth();
|
||||||
|
break;
|
||||||
|
case DURATION:
|
||||||
|
retVal = displayDuration();
|
||||||
|
break;
|
||||||
|
case TEMPERATURE:
|
||||||
|
retVal = displayTemperature();
|
||||||
|
break;
|
||||||
|
case TOTALWEIGHT:
|
||||||
|
retVal = displayWeight();
|
||||||
|
break;
|
||||||
|
case SUIT:
|
||||||
|
retVal = QString(dive->suit);
|
||||||
|
break;
|
||||||
|
case SAC:
|
||||||
|
retVal = displaySac();
|
||||||
|
break;
|
||||||
|
case OTU:
|
||||||
|
retVal = dive->otu;
|
||||||
|
break;
|
||||||
|
case MAXCNS:
|
||||||
|
retVal = dive->maxcns;
|
||||||
|
break;
|
||||||
|
case LOCATION:
|
||||||
|
retVal = QString(dive->location);
|
||||||
|
break;
|
||||||
|
case RATING:
|
||||||
|
retVal = dive->rating;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiveItem::displayDepth() const
|
QString DiveItem::displayDepth() const
|
||||||
|
@ -361,7 +465,6 @@ QString DiveItem::displayDepth() const
|
||||||
QString DiveItem::displayDuration() const
|
QString DiveItem::displayDuration() const
|
||||||
{
|
{
|
||||||
int hrs, mins, secs;
|
int hrs, mins, secs;
|
||||||
|
|
||||||
secs = dive->duration.seconds % 60;
|
secs = dive->duration.seconds % 60;
|
||||||
mins = dive->duration.seconds / 60;
|
mins = dive->duration.seconds / 60;
|
||||||
hrs = mins / 60;
|
hrs = mins / 60;
|
||||||
|
@ -405,215 +508,147 @@ QString DiveItem::displayWeight() const
|
||||||
QString str;
|
QString str;
|
||||||
|
|
||||||
if (get_units()->weight == units::KG) {
|
if (get_units()->weight == units::KG) {
|
||||||
int gr = diveWeight() % 1000;
|
int gr = weight() % 1000;
|
||||||
int kg = diveWeight() / 1000;
|
int kg = weight() / 1000;
|
||||||
str = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100);
|
str = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100);
|
||||||
} else {
|
} else {
|
||||||
str = QString("%1").arg((unsigned)(grams_to_lbs(diveWeight()) + 0.5));
|
str = QString("%1").arg((unsigned)(grams_to_lbs(weight()) + 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiveTripModel::DiveTripModel(QObject *parent) : QAbstractItemModel(parent)
|
int DiveItem::weight() const
|
||||||
{
|
{
|
||||||
rootItem = new DiveItem;
|
weight_t tw = { total_weight(dive) };
|
||||||
int i;
|
return tw.grams;
|
||||||
struct dive *d;
|
|
||||||
|
|
||||||
for_each_dive(i, d) {
|
|
||||||
new DiveItem(d, rootItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Qt::ItemFlags DiveTripModel::flags(const QModelIndex &index) const
|
DiveTripModel::DiveTripModel(QObject* parent)
|
||||||
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
Qt::ItemFlags diveFlags = QAbstractItemModel::flags(index);
|
rootItem = new TreeItemDT();
|
||||||
if (index.isValid()) {
|
setupModelData();
|
||||||
diveFlags |= Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
|
||||||
}
|
|
||||||
return diveFlags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiveTripModel::~DiveTripModel()
|
||||||
|
{
|
||||||
|
delete rootItem;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant DiveTripModel::data(const QModelIndex &index, int role) const
|
int DiveTripModel::columnCount(const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
return static_cast<TreeItemDT*>(parent.internalPointer())->columnCount();
|
||||||
|
else
|
||||||
|
return rootItem->columnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DiveTripModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
DiveItem *item = static_cast<DiveItem*>(index.internalPointer());
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
QVariant retVal;
|
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
|
||||||
if (role == Qt::TextAlignmentRole) {
|
|
||||||
switch (index.column()) {
|
return item->data(index.column(), role);
|
||||||
case DATE: /* fall through */
|
|
||||||
case SUIT: /* fall through */
|
|
||||||
case LOCATION:
|
|
||||||
retVal = Qt::AlignLeft;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
retVal = Qt::AlignRight;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
switch (index.column()) {
|
|
||||||
case NR:
|
|
||||||
retVal = item->diveNumber();
|
|
||||||
break;
|
|
||||||
case DATE:
|
|
||||||
retVal = item->diveDateTime();
|
|
||||||
break;
|
|
||||||
case DEPTH:
|
|
||||||
retVal = item->displayDepth();
|
|
||||||
break;
|
|
||||||
case DURATION:
|
|
||||||
retVal = item->displayDuration();
|
|
||||||
break;
|
|
||||||
case TEMPERATURE:
|
|
||||||
retVal = item->displayTemperature();
|
|
||||||
break;
|
|
||||||
case TOTALWEIGHT:
|
|
||||||
retVal = item->displayWeight();
|
|
||||||
break;
|
|
||||||
case SUIT:
|
|
||||||
retVal = item->diveSuit();
|
|
||||||
break;
|
|
||||||
case SAC:
|
|
||||||
retVal = item->displaySac();
|
|
||||||
break;
|
|
||||||
case OTU:
|
|
||||||
retVal = item->diveOtu();
|
|
||||||
break;
|
|
||||||
case MAXCNS:
|
|
||||||
retVal = item->diveMaxcns();
|
|
||||||
break;
|
|
||||||
case LOCATION:
|
|
||||||
retVal = item->diveLocation();
|
|
||||||
break;
|
|
||||||
case RATING:
|
|
||||||
retVal = item->diveRating();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags DiveTripModel::flags(const QModelIndex& index) const
|
||||||
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
{
|
||||||
QVariant ret;
|
if (!index.isValid())
|
||||||
if (orientation != Qt::Horizontal)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
switch(section) {
|
|
||||||
case NR:
|
|
||||||
ret = tr("#");
|
|
||||||
break;
|
|
||||||
case DATE:
|
|
||||||
ret = tr("Date");
|
|
||||||
break;
|
|
||||||
case RATING:
|
|
||||||
ret = UTF8_BLACKSTAR;
|
|
||||||
break;
|
|
||||||
case DEPTH:
|
|
||||||
if (get_units()->length == units::METERS)
|
|
||||||
ret = tr("m");
|
|
||||||
else
|
|
||||||
ret = tr("ft");
|
|
||||||
break;
|
|
||||||
case DURATION:
|
|
||||||
ret = tr("min");
|
|
||||||
break;
|
|
||||||
case TEMPERATURE:
|
|
||||||
if (get_units()->temperature == units::CELSIUS)
|
|
||||||
ret = QString("%1%2").arg(UTF8_DEGREE).arg("C");
|
|
||||||
else
|
|
||||||
ret = QString("%1%2").arg(UTF8_DEGREE).arg("F");
|
|
||||||
break;
|
|
||||||
case TOTALWEIGHT:
|
|
||||||
if (get_units()->weight == units::KG)
|
|
||||||
ret = tr("kg");
|
|
||||||
else
|
|
||||||
ret = tr("lbs");
|
|
||||||
break;
|
|
||||||
case SUIT:
|
|
||||||
ret = tr("Suit");
|
|
||||||
break;
|
|
||||||
case CYLINDER:
|
|
||||||
ret = tr("Cyl");
|
|
||||||
break;
|
|
||||||
case NITROX:
|
|
||||||
ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2);
|
|
||||||
break;
|
|
||||||
case SAC:
|
|
||||||
ret = tr("SAC");
|
|
||||||
break;
|
|
||||||
case OTU:
|
|
||||||
ret = tr("OTU");
|
|
||||||
break;
|
|
||||||
case MAXCNS:
|
|
||||||
ret = tr("maxCNS");
|
|
||||||
break;
|
|
||||||
case LOCATION:
|
|
||||||
ret = tr("Location");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DiveTripModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
/* only allow kids in column 0 */
|
|
||||||
if (parent.isValid() && parent.column() > 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
DiveItem *item = itemForIndex(parent);
|
|
||||||
return item ? item->children().count() : 0;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DiveTripModel::columnCount(const QModelIndex &parent) const
|
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role) const
|
||||||
{
|
{
|
||||||
return parent.isValid() && parent.column() != 0 ? 0 : COLUMNS;
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
|
return rootItem->data(section, role);
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex DiveTripModel::index(int row, int column, const QModelIndex& parent)
|
||||||
QModelIndex DiveTripModel::index(int row, int column, const QModelIndex &parent) const
|
const
|
||||||
{
|
{
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
if (!rootItem || row < 0 || column < 0 || column >= COLUMNS ||
|
|
||||||
(parent.isValid() && parent.column() != 0))
|
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
DiveItem *parentItem = itemForIndex(parent);
|
TreeItemDT* parentItem = (!parent.isValid()) ? rootItem
|
||||||
Q_ASSERT(parentItem);
|
: static_cast<TreeItemDT*>(parent.internalPointer());
|
||||||
if (DiveItem *item = parentItem->children().at(row))
|
|
||||||
return createIndex(row, column, item);
|
TreeItemDT* childItem = parentItem->childs[row];
|
||||||
return QModelIndex();
|
|
||||||
|
return (childItem) ? createIndex(row, column, childItem)
|
||||||
|
: QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex DiveTripModel::parent(const QModelIndex& index) const
|
||||||
QModelIndex DiveTripModel::parent(const QModelIndex &childIndex) const
|
|
||||||
{
|
{
|
||||||
if (!childIndex.isValid())
|
if (!index.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
DiveItem *child = static_cast<DiveItem*>(childIndex.internalPointer());
|
TreeItemDT* childItem = static_cast<TreeItemDT*>(index.internalPointer());
|
||||||
DiveItem *parent = child->parent();
|
TreeItemDT* parentItem = childItem->parent;
|
||||||
|
|
||||||
if (parent == rootItem)
|
if (parentItem == rootItem)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(parent->children().indexOf(child), 0, parent);
|
return createIndex(parentItem->row(), 0, parentItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DiveTripModel::rowCount(const QModelIndex& parent) const
|
||||||
DiveItem* DiveTripModel::itemForIndex(const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
if (index.isValid()) {
|
TreeItemDT* parentItem;
|
||||||
DiveItem *item = static_cast<DiveItem*>(index.internalPointer());
|
|
||||||
return item;
|
if (parent.column() > 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = rootItem;
|
||||||
|
|
||||||
|
else
|
||||||
|
parentItem = static_cast<TreeItemDT*>(parent.internalPointer());
|
||||||
|
|
||||||
|
return parentItem->childs.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveTripModel::setupModelData()
|
||||||
|
{
|
||||||
|
int i = dive_table.nr;
|
||||||
|
|
||||||
|
while (--i >= 0) {
|
||||||
|
struct dive* dive = get_dive(i);
|
||||||
|
dive_trip_t* trip = dive->divetrip;
|
||||||
|
|
||||||
|
DiveItem* diveItem = new DiveItem();
|
||||||
|
diveItem->dive = dive;
|
||||||
|
|
||||||
|
if (!trip) {
|
||||||
|
diveItem->parent = rootItem;
|
||||||
|
rootItem->childs.push_back(diveItem);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!trips.keys().contains(trip)) {
|
||||||
|
TripItem* tripItem = new TripItem();
|
||||||
|
tripItem->trip = trip;
|
||||||
|
tripItem->parent = rootItem;
|
||||||
|
tripItem->childs.push_back(diveItem);
|
||||||
|
trips[trip] = tripItem;
|
||||||
|
rootItem->childs.push_back(tripItem);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TripItem* tripItem = trips[trip];
|
||||||
|
tripItem->childs.push_back(diveItem);
|
||||||
}
|
}
|
||||||
return rootItem;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,11 @@
|
||||||
#define MODELS_H
|
#define MODELS_H
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
|
|
||||||
/* Encapsulates the tank_info global variable
|
/* Encapsulates the tank_info global variable
|
||||||
* to show on Qt`s Model View System.*/
|
* to show on Qt`s Model View System.*/
|
||||||
class TankInfoModel : public QAbstractTableModel {
|
class TankInfoModel : public QAbstractTableModel {
|
||||||
|
@ -74,25 +77,49 @@ private:
|
||||||
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DiveItem;
|
|
||||||
class DiveTripModel : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
|
struct TreeItemDT {
|
||||||
|
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
|
||||||
public:
|
public:
|
||||||
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
||||||
|
virtual ~TreeItemDT();
|
||||||
|
int columnCount() const {
|
||||||
|
return COLUMNS;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual QVariant data ( int column, int role ) const;
|
||||||
|
int row() const;
|
||||||
|
QList<TreeItemDT *> childs;
|
||||||
|
TreeItemDT *parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct TripItem;
|
||||||
|
|
||||||
|
class DiveTripModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
DiveTripModel(QObject *parent = 0);
|
DiveTripModel(QObject *parent = 0);
|
||||||
|
~DiveTripModel();
|
||||||
|
|
||||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex &index) const;
|
/*reimp*/ Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
/*reimp*/ QVariant data(const QModelIndex &index, int role) const;
|
/*reimp*/ QVariant data(const QModelIndex &index, int role) const;
|
||||||
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
/*reimp*/ int rowCount(const QModelIndex &parent) const;
|
/*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
/*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
/*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
/*reimp*/ QModelIndex parent(const QModelIndex &child) const;
|
/*reimp*/ QModelIndex parent(const QModelIndex &child) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiveItem *itemForIndex(const QModelIndex& index) const;
|
void setupModelData();
|
||||||
DiveItem *rootItem;
|
|
||||||
|
TreeItemDT *rootItem;
|
||||||
|
QMap<dive_trip_t*, TripItem*> trips;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue