4 #include <QAbstractTableModel>
8 #include <QDoubleSpinBox>
9 #include <QItemEditorCreatorBase>
14 // A table model with 2 columns: Date | Weight
15 class WeightDataModel : public QAbstractTableModel
24 bool operator<(const DateWeight &o) const { return date < o.date; }
26 typedef QList<DateWeight> WeightList;
28 WeightDataModel(QString &datafile, QObject *parent = 0);
30 int size() const { return weights.size(); }
31 int rowCount(const QModelIndex& = QModelIndex()) const { return weights.size(); }
32 int columnCount(const QModelIndex& = QModelIndex()) const { return 2; }
33 Qt::ItemFlags flags(const QModelIndex &index) const;
34 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
36 bool dateExists(const QDate &date) const;
37 int rowOfDate(const QDate &date) const;
38 QModelIndex indexOfDate(const QDate &date) const;
39 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
40 const WeightList &getWeights() const { return weights; }
41 double minWeight() const;
42 double maxWeight() const;
44 bool setData(const QModelIndex &index, const QVariant &value, int role);
45 bool setDataForRow(int row, const DateWeight &dw);
46 void setWeightForDate(const QDate &date, double weight);
47 void setWeightForDate(const DateWeight &dw);
49 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
52 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
53 int rowForNewDate(const QDate &date) const;
61 typedef WeightDataModel::DateWeight DW;
63 #endif // WEIGHTDATA_H