~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to FermentableTableModel.h

  • Committer: Philip Greggory Lee
  • Date: 2009-08-23 16:53:43 UTC
  • Revision ID: git-v1:f8d1a25135bd92f06c46c562293800e4faa42c61
Made a src/ and ui/ directory and moved everything.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * FermentableTableModel.h is part of Brewtarget, and is Copyright Philip G. Lee
3
 
 * (rocketman768@gmail.com), 2009.
4
 
 *
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.
9
 
 
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.
14
 
 
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/>.
17
 
 */
18
 
 
19
 
#ifndef _FERMENTABLETABLEMODEL_H
20
 
#define _FERMENTABLETABLEMODEL_H
21
 
 
22
 
class FermentableTableModel;
23
 
class FermentableItemDelegate;
24
 
 
25
 
#include <QAbstractTableModel>
26
 
#include <QWidget>
27
 
#include <QModelIndex>
28
 
#include <QVariant>
29
 
#include <Qt>
30
 
#include <QStringList>
31
 
#include <QStyledItemDelegate>
32
 
#include <QAbstractItemDelegate>
33
 
#include <vector>
34
 
#include "fermentable.h"
35
 
#include "FermentableTableWidget.h"
36
 
#include "observable.h"
37
 
 
38
 
enum{FERMNAMECOL, FERMTYPECOL, FERMAMOUNTCOL, FERMISMASHEDCOL, FERMYIELDCOL, FERMCOLORCOL, FERMNUMCOLS /*This one MUST be last*/};
39
 
 
40
 
class FermentableTableModel : public QAbstractTableModel, public MultipleObserver
41
 
{
42
 
   Q_OBJECT
43
 
           
44
 
public:
45
 
   FermentableTableModel(FermentableTableWidget* parent=0);
46
 
   void addFermentable(Fermentable* ferm);
47
 
   bool removeFermentable(Fermentable* ferm); // Returns true if "ferm" is successfully found and removed.
48
 
   void removeAll();
49
 
   Fermentable* getFermentable(unsigned int i);
50
 
   void setDisplayPercentages( bool var );
51
 
   virtual void notify(Observable* notifier, QVariant info = QVariant()); // Inherited from Observer via MultipleObserver.
52
 
   
53
 
   // Inherit the following from QAbstractItemModel via QAbstractTableModel
54
 
   virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
55
 
   virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
56
 
   virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
57
 
   virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
58
 
   virtual Qt::ItemFlags flags(const QModelIndex& index ) const;
59
 
   virtual bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
60
 
   
61
 
   FermentableTableWidget* parentTableWidget;
62
 
   
63
 
private:
64
 
   void updateTotalGrains();
65
 
   
66
 
   std::vector<Fermentable*> fermObs;
67
 
   bool displayPercentages; // True if you want to display percent of each grain in the row header.
68
 
   double totalFermMass_kg;
69
 
};
70
 
 
71
 
class FermentableItemDelegate : public QStyledItemDelegate
72
 
{
73
 
   Q_OBJECT
74
 
           
75
 
public:
76
 
   FermentableItemDelegate(QObject* parent = 0);
77
 
   
78
 
   // Inherited functions.
79
 
   virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
80
 
   virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
81
 
   virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
82
 
   virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
83
 
   //virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
84
 
   
85
 
public slots:
86
 
   void destroyWidget(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
87
 
private:
88
 
};
89
 
 
90
 
#endif  /* _FERMENTABLETABLEMODEL_H */
91