Added code base.
[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   class WeightEditCreator : public QItemEditorCreatorBase
34   {
35   public:
36     WeightEditCreator() : QItemEditorCreatorBase() { }
37     virtual QWidget *createWidget(QWidget *parent) const
38     {
39       return new WeightSpinBox(parent);
40     }
41     virtual QByteArray valuePropertyName() const { return "value"; }
42   };
43   private:
44     QStyledItemDelegate delegate;
45 };
46
47 #endif // WEIGHTVIEW_H