summaryrefslogtreecommitdiffstats
path: root/qt-ui/divetripmodel.h
diff options
context:
space:
mode:
authorGravatar Amit Chaudhuri <amit.k.chaudhuri@gmail.com>2013-04-12 08:24:07 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-12 12:54:08 -0700
commit76f71b4ca07dbef1069aec3db1138c199927b1bb (patch)
tree4ef068b3d60dc497c7549019f95425ee4ef7076e /qt-ui/divetripmodel.h
parent9dbda9f62aca314aa7cb7ef588b1ce5ec43a01b9 (diff)
downloadsubsurface-76f71b4ca07dbef1069aec3db1138c199927b1bb.tar.gz
Add dive list view to main window
Add files for dive list model/view implementation. Replace TableView with the custom list view. Amendments to makefile to match. Note: we don't yet handle trips and may want to add additional columns to describe the dive. A single, dummy dive is added to show how this works (get root; item is child of root). Purely to illustrate - needs proper integration etc. Amend member names for dive list view components Various naming changes to conform to coding style. Required changes to members (remove prefix) and methods (avoid clash with members). Clean up indentation (swap spaces for tabs). Code for model/view was written with a different editor which had different settings :-/ [Dirk Hohndel: minor whitespace cleanup] Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divetripmodel.h')
-rw-r--r--qt-ui/divetripmodel.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/qt-ui/divetripmodel.h b/qt-ui/divetripmodel.h
new file mode 100644
index 000000000..8c8a829e2
--- /dev/null
+++ b/qt-ui/divetripmodel.h
@@ -0,0 +1,80 @@
+#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