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;
27 WeightDataModel(QString &datafile, QObject *parent = 0);
28 int rowCount(const QModelIndex &/**/) const { return weights.size(); }
29 int columnCount(const QModelIndex &/**/) const { return 2; }
30 Qt::ItemFlags flags(const QModelIndex &index) const;
31 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
32 bool setData(const QModelIndex &index, const QVariant &value, int role);
33 bool setDataForRow(int row, const DateWeight &dw);
34 void setWeightForDate(const QDate &date, double weight);
35 void setWeightForDate(const DateWeight &dw);
36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
37 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
38 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
39 int rowOfDate(const QDate &date) const;
40 bool dateExists(const QDate &date) const;
41 int rowForNewDate(const QDate &date) const;
44 int size() const { return weights.size(); }
45 const WeightList &getWeights() const { return weights; }
55 typedef WeightDataModel::DateWeight DW;
57 #endif // WEIGHTDATA_H