2
* WaterTableModel.h is part of Brewtarget, and is Copyright Philip G. Lee
3
* (rocketman768@gmail.com), 2009.
5
* Brewtarget is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Brewtarget is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#ifndef _WATERTABLEMODEL_H
20
#define _WATERTABLEMODEL_H
22
class WaterTableModel;
23
class WaterItemDelegate;
25
#include <QAbstractTableModel>
27
#include <QModelIndex>
30
#include <QItemDelegate>
33
#include "observable.h"
34
#include "WaterTableWidget.h"
36
enum{ WATERNAMECOL, WATERAMOUNTCOL, WATERCALCIUMCOL, WATERBICARBONATECOL,
37
WATERSULFATECOL, WATERCHLORIDECOL, WATERSODIUMCOL, WATERMAGNESIUMCOL,
38
WATERNUMCOLS /*This one MUST be last*/};
40
class WaterTableModel : public QAbstractTableModel, public MultipleObserver
45
WaterTableModel(WaterTableWidget* parent=0);
46
void addWater(Water* water);
47
bool removeWater(Water* water); // Returns true if "water" is successfully found and removed.
49
virtual void notify(Observable* notifier, QVariant info = QVariant()); // Inherited from Observer via MultipleObserver.
51
// Inherit the following from QAbstractItemModel via QAbstractTableModel
52
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
53
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
54
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
55
virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
56
virtual Qt::ItemFlags flags(const QModelIndex& index ) const;
57
virtual bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
60
std::vector<Water*> waterObs;
61
WaterTableWidget* parentTableWidget;
64
class WaterItemDelegate : public QItemDelegate
69
WaterItemDelegate(QObject* parent = 0);
71
// Inherited functions.
72
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
73
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
74
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
75
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
80
#endif /* _WATERTABLEMODEL_H */