diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-04-21 22:12:36 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-04-22 09:42:13 -0700 |
commit | a0280ae7d2cdd483bc53c7bc91a8aa438f9234de (patch) | |
tree | 1953e0422d8c714d4616f7266622b2b1fde3c185 /qt-ui/divetripmodel.h | |
parent | 5da11cbc6a1d3339cbb519cf74e4377b8cbaee5f (diff) | |
download | subsurface-a0280ae7d2cdd483bc53c7bc91a8aa438f9234de.tar.gz |
Move model related code from MainWindow and adjustments.
Moves the DiveTrip model related code to models.h
The DiveTripModel was implemented in three parts:
DiveTripModel.h
DiveTripModel.cpp
MainWindow.cpp (the code to populate the model)
This patch changes the DiveTripModel from it's original
implementation to the file models.h, wich should store
all models (Dirk requested the Qt developers to not create
2 files per class, but instead to use a file for functionality,
and data-models are one functionality.)
Besides that, this code cleans up a bit the style:
removed operator<< for .push_back, const references where they apply,
moved the internal DiveItem class to the .cpp since it should be visible
only to the DiveTripModel class, and redesigned the current interface of
the model to be identical of the GTK one (used the UTF8-star and 2
subscribed, for instance).
Amit (the creator of the original code) should comment here if it's ok
with my changes.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divetripmodel.h')
-rw-r--r-- | qt-ui/divetripmodel.h | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/qt-ui/divetripmodel.h b/qt-ui/divetripmodel.h deleted file mode 100644 index ad1815798..000000000 --- a/qt-ui/divetripmodel.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * divetripmodel.h - * - * header file for the divetrip model of Subsurface - * - */ -#ifndef DIVETRIPMODEL_H -#define DIVETRIPMODEL_H - -#include <QAbstractItemModel> - -/*! A DiveItem for use with a DiveTripModel - * - * A simple class which wraps basic stats for a dive (e.g. duration, depth) and - * tidies up after it's children. This is done manually as we don't inherit from - * QObject. - * -*/ -class DiveItem -{ -public: - explicit DiveItem(): number(0), dateTime(QString()), duration(0.0), depth(0.0), location(QString()) {parentItem = 0;} - explicit DiveItem(int num, QString dt, float, float, QString loc, DiveItem *parent = 0); - ~DiveItem() { qDeleteAll(childlist); } - - int diveNumber() const { return number; } - QString diveDateTime() const { return dateTime; } - float diveDuration() const { return duration; } - float diveDepth() const { return depth; } - QString diveLocation() const { return location; } - - DiveItem *parent() const { return parentItem; } - DiveItem *childAt(int row) const { return childlist.value(row); } - int rowOfChild(DiveItem *child) const { return childlist.indexOf(child); } - int childCount() const { return childlist.count(); } - bool hasChildren() const { return !childlist.isEmpty(); } - QList<DiveItem *> children() const { return childlist; } - void addChild(DiveItem* item) { item->parentItem = this; childlist << item; } /* parent = self */ - - -private: - - int number; - QString dateTime; - float duration; - float depth; - QString location; - - DiveItem *parentItem; - QList <DiveItem*> childlist; - -}; - - -enum Column {DIVE_NUMBER, DIVE_DATE_TIME, DIVE_DURATION, DIVE_DEPTH, DIVE_LOCATION, COLUMNS}; - - -/*! An AbstractItemModel for recording dive trip information such as a list of dives. -* -*/ -class DiveTripModel : public QAbstractItemModel -{ -public: - - DiveTripModel(const QString &filename, QObject *parent = 0); - - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int rowCount(const QModelIndex &parent) const; - - int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex &child) const; - - DiveItem *itemForIndex(const QModelIndex &) const; - -private: - - DiveItem *rootItem; - QString filename; - -}; - -#endif // DIVETRIPMODEL_H |