Kstars

tabledelegate.h
1/* Optical Train Delegates
2
3 Collection of delegates assigned to each individual column
4 in the table view.
5
6 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#pragma once
12
13#include <QStyledItemDelegate>
14#include <QItemDelegate>
15
16class QCheckBox;
17class QSpinBox;
18class QDoubleSpinBox;
19class QComboBox;
20
21class NotEditableDelegate : public QStyledItemDelegate
22{
24 public:
25 explicit NotEditableDelegate(QObject *parent = nullptr)
27 {}
28
29 protected:
30 bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, const QModelIndex &) override
31 {
32 return false;
33 }
34 QWidget* createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
35 {
36 return nullptr;
37 }
38};
39
40// Not editable delegate to display numbers to 2 decimal places
41class NotEditableDelegate2dp : public QStyledItemDelegate
42{
44 public:
45 explicit NotEditableDelegate2dp(QObject *parent = nullptr)
47 {}
48
49 QString displayText(const QVariant &value, const QLocale &locale) const
50 {
51 QString str = QString::number(value.toDouble(), 'f', 2);
52 return str;
53 }
54
55 protected:
56 bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, const QModelIndex &) override
57 {
58 return false;
59 }
60 QWidget* createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
61 {
62 return nullptr;
63 }
64};
65
66class ToggleDelegate : public QItemDelegate
67{
69 public:
70 explicit ToggleDelegate(QObject *parent = nullptr) : QItemDelegate(parent) {}
71
72 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
73 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
74 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
75 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
76 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
77 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, const QModelIndex &index) override;
78};
79
80class DoubleDelegate : public QStyledItemDelegate
81{
83 public:
84 explicit DoubleDelegate(QObject *parent = nullptr, double min = -1, double max = -1,
85 double step = -1) : QStyledItemDelegate(parent)
86 {
87 this->min = min;
88 this->max = max;
89 this->step = step;
90 }
91
92 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
93 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
94 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
95 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
96 protected:
97 double min {-1}, max {-1}, step {-1};
98};
99
100class IntegerDelegate : public QStyledItemDelegate
101{
103 public:
104 explicit IntegerDelegate(QObject *parent = nullptr, int min = -1, int max = -1, int step = -1) : QStyledItemDelegate(parent)
105 {
106 this->min = min;
107 this->max = max;
108 this->step = step;
109 }
110
111 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
112 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
113 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
114 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
115 void setMinMaxStep(int min, int max, int step);
116 protected:
117 int min {-1}, max {-1}, step {-1};
118};
119
120class ComboDelegate : public QStyledItemDelegate
121{
123 public:
124 explicit ComboDelegate(QObject *parent = nullptr);
125
126 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
127 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
128 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
129 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
130 void setValues(const QStringList &values);
131 const QStringList &values() const
132 {
133 return m_Values;
134 }
135
136 private:
137 mutable QStringList m_Values;
138};
139
Q_OBJECTQ_OBJECT
virtual bool event(QEvent *e)
QObject * parent() const const
QString number(double n, char format, int precision)
double toDouble(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.