Release 1.0.4
[weightgraph] / weightgraph / weightview.h
1 #ifndef WEIGHTVIEW_H
2 #define WEIGHTVIEW_H
3
4 #include <QTableView>
5 #include <QStyledItemDelegate>
6 #include <QItemEditorCreatorBase>
7 #include <QDoubleSpinBox>
8 #include <QItemEditorFactory>
9 #include <QFont>
10 #include <QHeaderView>
11 #include "weightspinbox.h"
12
13 class WeightView : public QTableView
14 {
15   Q_OBJECT
16 public:
17   explicit WeightView(QWidget *parent = 0) :
18         QTableView(parent)
19   {
20     QItemEditorFactory *editorFactory = new QItemEditorFactory;
21     editorFactory->registerEditor(QVariant::Double, new WeightView::WeightEditCreator);
22     delegate.setItemEditorFactory(editorFactory);
23     setItemDelegate(&delegate);
24     setSelectionMode(QAbstractItemView::SingleSelection);
25     this->verticalHeader()->hide();
26     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
27     this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
28     QFont f;
29     f.setPointSize(28);
30     setFont(f);
31   }
32
33   struct WeightEditCreator : public QItemEditorCreatorBase
34   {
35     QWidget *createWidget(QWidget *parent) const
36     {
37       return new WeightSpinBox(parent);
38     }
39     virtual QByteArray valuePropertyName() const {
40       return "value";
41     }
42   };
43
44 private:
45     QStyledItemDelegate delegate;
46 };
47
48 #endif // WEIGHTVIEW_H