NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
intnumericdelegate.h
Go to the documentation of this file.
1
18#ifndef INTNUMERICDELEGATE_H
19#define INTNUMERICDELEGATE_H
20
21#include <QItemDelegate>
22#include <QSpinBox>
23
28class IntNumericDelegate : public QItemDelegate {
29 Q_OBJECT
30
31private:
32 int maxValue;
33 int minValue;
34 int stepSize;
35 int value;
36
37public:
45 IntNumericDelegate(QWidget *parent = nullptr, int maxValue = 1000000000, int minValue = -1000000000, int stepSize = 1, int value = 0)
46 : QItemDelegate(parent), maxValue(maxValue), minValue(minValue), stepSize(stepSize), value(value) {}
47
55 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
56 QSpinBox *editor = new QSpinBox(parent);
57 editor->setMaximum(maxValue);
58 editor->setMinimum(minValue);
59 editor->setSingleStep(stepSize);
60 editor->setValue(value);
61 return editor;
62 }
63
70 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override {
71 QSpinBox *spinBox = qobject_cast<QSpinBox *>(editor);
72 int value = spinBox->value();
73 model->setData(index, value, Qt::EditRole);
74 }
75};
76
77#endif // INTNUMERICDELEGATE_H
The IntNumericDelegate class provides a spin box editor for integer numeric data in a view.
Definition intnumericdelegate.h:28
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Creates an editor widget for the given parent, style option, and model index.
Definition intnumericdelegate.h:55
IntNumericDelegate(QWidget *parent=nullptr, int maxValue=1000000000, int minValue=-1000000000, int stepSize=1, int value=0)
Constructor for the IntNumericDelegate class.
Definition intnumericdelegate.h:45
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets the model data based on the data of the editor widget.
Definition intnumericdelegate.h:70