source: subsurface/desktop-widgets/modeldelegates.h @ 99351b7

Last change on this file since 99351b7 was 99351b7, checked in by Dirk Hohndel <dirk@…>, 9 months ago

Allow cylinder names to be edited

The same ComboBoxDelegate? is used for picking a cylinder model
and picking a gas in the planner waypoint table. In the former
case we want to allow the user to edit the string in the second
we don't.

The difference is not if we are in the planner but which use of
the class. So add a bool allowEdit to the constructor.

Fixes #272

Signed-off-by: Robert C. Helling <helling@…>

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#ifndef MODELDELEGATES_H
2#define MODELDELEGATES_H
3
4#include <QStyledItemDelegate>
5#include <QComboBox>
6class QPainter;
7
8class DiveListDelegate : public QStyledItemDelegate {
9public:
10        explicit DiveListDelegate(QObject *parent = 0)
11            : QStyledItemDelegate(parent)
12        {
13        }
14        QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
15};
16
17class StarWidgetsDelegate : public QStyledItemDelegate {
18        Q_OBJECT
19public:
20        explicit StarWidgetsDelegate(QWidget *parent = 0);
21        virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
22        virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
23        const QSize& starSize() const;
24
25private:
26        QWidget *parentWidget;
27        QSize minStarSize;
28};
29
30class ComboBoxDelegate : public QStyledItemDelegate {
31        Q_OBJECT
32public:
33        explicit ComboBoxDelegate(QAbstractItemModel *model, QObject *parent = 0, bool allowEdit = true);
34        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
35        virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
36        virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
37        virtual bool eventFilter(QObject *object, QEvent *event);
38public
39slots:
40        void testActivation(const QString &currString = QString());
41        void testActivation(const QModelIndex &currIndex);
42        //HACK: try to get rid of this in the future.
43        void fakeActivation();
44        void fixTabBehavior();
45        virtual void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0;
46private:
47        bool editable;
48protected:
49        QAbstractItemModel *model;
50};
51
52class TankInfoDelegate : public ComboBoxDelegate {
53        Q_OBJECT
54public:
55        explicit TankInfoDelegate(QObject *parent = 0);
56        virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
57        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
58public
59slots:
60        void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
61        void reenableReplot(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
62};
63
64class TankUseDelegate : public QStyledItemDelegate {
65        Q_OBJECT
66public:
67        explicit TankUseDelegate(QObject *parent = 0);
68        virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
69        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
70        virtual void setEditorData(QWidget * editor, const QModelIndex & index) const;
71};
72
73class WSInfoDelegate : public ComboBoxDelegate {
74        Q_OBJECT
75public:
76        explicit WSInfoDelegate(QObject *parent = 0);
77        virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
78        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
79public
80slots:
81        void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
82};
83
84class AirTypesDelegate : public ComboBoxDelegate {
85        Q_OBJECT
86public:
87        explicit AirTypesDelegate(QObject *parent = 0);
88        virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
89public
90slots:
91        void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
92};
93
94class SpinBoxDelegate : public QStyledItemDelegate {
95        Q_OBJECT
96public:
97        SpinBoxDelegate(int min, int max, int step, QObject *parent = 0);
98        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
99private:
100        int min;
101        int max;
102        int step;
103};
104
105class DoubleSpinBoxDelegate : public QStyledItemDelegate {
106        Q_OBJECT
107public:
108        DoubleSpinBoxDelegate(double min, double max, double step, QObject *parent = 0);
109        virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
110private:
111        double min;
112        double max;
113        double step;
114};
115
116class LocationFilterDelegate : public QStyledItemDelegate {
117        Q_OBJECT
118public:
119        LocationFilterDelegate(QObject *parent = 0);
120        void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
121        QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
122};
123
124#endif // MODELDELEGATES_H
Note: See TracBrowser for help on using the repository browser.