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 override
50 {
51 Q_UNUSED(locale)
52 QString str = QString::number(value.toDouble(), 'f', 2);
53 return str;
54 }
55
56 protected:
57 bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, const QModelIndex &) override
58 {
59 return false;
60 }
61 QWidget* createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
62 {
63 return nullptr;
64 }
65};
66
67class ToggleDelegate : public QItemDelegate
68{
70 public:
71 explicit ToggleDelegate(QObject *parent = nullptr) : QItemDelegate(parent) {}
72
73 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
74 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
75 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
76 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
77 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
78 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, const QModelIndex &index) override;
79};
80
81class DoubleDelegate : public QStyledItemDelegate
82{
84 public:
85 explicit DoubleDelegate(QObject *parent = nullptr, double min = -1, double max = -1,
86 double step = -1) : QStyledItemDelegate(parent)
87 {
88 this->min = min;
89 this->max = max;
90 this->step = step;
91 }
92
93 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
94 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
95 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
96 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
97 protected:
98 double min {-1}, max {-1}, step {-1};
99};
100
101class IntegerDelegate : public QStyledItemDelegate
102{
104 public:
105 explicit IntegerDelegate(QObject *parent = nullptr, int min = -1, int max = -1, int step = -1) : QStyledItemDelegate(parent)
106 {
107 this->min = min;
108 this->max = max;
109 this->step = step;
110 }
111
112 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
113 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
114 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
115 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
116 void setMinMaxStep(int min, int max, int step);
117 protected:
118 int min {-1}, max {-1}, step {-1};
119};
120
121class ComboDelegate : public QStyledItemDelegate
122{
124 public:
125 explicit ComboDelegate(QObject *parent = nullptr);
126
127 QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
128 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
129 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
130 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
131 void setValues(const QStringList &values);
132 const QStringList &values() const
133 {
134 return m_Values;
135 }
136
137 private:
138 mutable QStringList m_Values;
139};
140
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 Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.