Kstars

filterdelegate.cpp
1/* Ekos Filter Delegates
2
3 Collection of delegates assigned to each individual column
4 in the table view.
5
6 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "filterdelegate.h"
12#include <QCheckBox>
13#include <QSpinBox>
14#include <QDoubleSpinBox>
15#include <QComboBox>
16#include <QApplication>
17
18QWidget * UseAutoFocusDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
19{
20 cb = new QCheckBox(parent);
21 return cb;
22}
23
24
25void UseAutoFocusDelegate::setEditorData(QWidget *, const QModelIndex &index) const
26{
27 int value = index.model()->data(index, Qt::EditRole).toInt();
28 cb->setChecked(value == 1);
29}
30
31void UseAutoFocusDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
32 const QModelIndex &) const
33{
36
37 //center
38 checkboxstyle.rect = option.rect;
39 checkboxstyle.rect.setLeft(option.rect.x() + option.rect.width() / 2 - checkbox_rect.width() / 2);
40
41 editor->setGeometry(checkboxstyle.rect);
42}
43
44void UseAutoFocusDelegate::setModelData(QWidget *, QAbstractItemModel *model, const QModelIndex &index) const
45{
46 int value = cb->isChecked() ? 1 : 0;
47 model->setData(index, value, Qt::EditRole);
48}
49
50void UseAutoFocusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
51{
54
55 QRect rect(option.rect.x() + option.rect.width() / 2 - checkbox_rect.width() / 2,
56 option.rect.y() + option.rect.height() / 2 - checkbox_rect.height() / 2,
57 checkbox_rect.width(), checkbox_rect.height());
58
59 drawCheck(painter, option, rect, index.data().toBool() ? Qt::Checked : Qt::Unchecked);
60 //drawFocus(painter, option, checkboxstyle.rect);
61}
62
63bool UseAutoFocusDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &,
64 const QModelIndex &index)
65{
66 if (event->type() == QEvent::MouseButtonRelease)
67 {
68 bool checked = index.model()->data(index, Qt::DisplayRole).toBool();
69 // Toggle value
70 int value = checked ? 0 : 1;
71 return model->setData(index, value, Qt::EditRole);
72 }
73
74 return false;
75}
76
77/////////////////////////////////////////////////////////
78// Exposure Delegate
79/////////////////////////////////////////////////////////
80
81QWidget * ExposureDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
82{
83 spinbox = new QDoubleSpinBox(parent);
84 spinbox->setFrame(false);
85 spinbox->setDecimals(3);
86 spinbox->setMinimum(0.001);
87 spinbox->setMaximum(120);
88 spinbox->setSingleStep(1);
89 return spinbox;
90}
91
92
93void ExposureDelegate::setEditorData(QWidget *, const QModelIndex &index) const
94{
95 double value = index.model()->data(index, Qt::EditRole).toDouble();
96 spinbox->setValue(value);
97}
98
99void ExposureDelegate::setModelData(QWidget *, QAbstractItemModel *model, const QModelIndex &index) const
100{
101 double value = spinbox->value();
102 model->setData(index, value, Qt::EditRole);
103}
104
105void ExposureDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
106{
107 editor->setGeometry(option.rect);
108}
109
110/////////////////////////////////////////////////////////
111// Offset Delegate
112/////////////////////////////////////////////////////////
113
114QWidget * OffsetDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
115{
116 spinbox = new QSpinBox(parent);
117 spinbox->setFrame(false);
118 spinbox->setMinimum(-10000);
119 spinbox->setMaximum(10000);
120 return spinbox;
121}
122
123
124void OffsetDelegate::setEditorData(QWidget *, const QModelIndex &index) const
125{
126 int value = index.model()->data(index, Qt::EditRole).toInt();
127 spinbox->setValue(value);
128}
129
130void OffsetDelegate::setModelData(QWidget *, QAbstractItemModel *model, const QModelIndex &index) const
131{
132 int value = spinbox->value();
133 model->setData(index, value, Qt::EditRole);
134}
135
136void OffsetDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
137{
138 editor->setGeometry(option.rect);
139}
140
141/////////////////////////////////////////////////////////
142// Lock Delegate
143/////////////////////////////////////////////////////////
144
145LockDelegate::LockDelegate(QStringList filterList, QObject *parent) : QStyledItemDelegate(parent)
146{
147 m_FilterList = filterList;
148 m_FilterList.insert(0, "--");
149}
150
151QWidget * LockDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
152{
153 lockbox = new QComboBox(parent);
154 lockbox->addItems(m_FilterList);
155 return lockbox;
156}
157
158
159void LockDelegate::setEditorData(QWidget *, const QModelIndex &index) const
160{
161 QString currentLockFilter = index.model()->data(index, Qt::EditRole).toString();
163}
164
165void LockDelegate::setModelData(QWidget *, QAbstractItemModel *model, const QModelIndex &index) const
166{
167 QString value = lockbox->currentText();
168 model->setData(index, value, Qt::EditRole);
169}
170
171void LockDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
172{
173 editor->setGeometry(option.rect);
174}
175
176void LockDelegate::setCurrentFilterList(const QStringList &list)
177{
178 m_FilterList = list;
179 m_FilterList.insert(0, "--");
180}
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void setChecked(bool)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
void setFrame(bool)
QStyle * style()
void addItems(const QStringList &texts)
void setCurrentText(const QString &text)
void setDecimals(int prec)
void setMaximum(double max)
void setMinimum(double min)
void setSingleStep(double val)
void setValue(double val)
MouseButtonRelease
Int toInt() const const
virtual void drawCheck(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, Qt::CheckState state) const const
iterator insert(const_iterator before, parameter_type value)
QVariant data(int role) const const
const QAbstractItemModel * model() const const
virtual bool event(QEvent *e)
QObject * parent() const const
void setMaximum(int max)
void setMinimum(int min)
void setValue(int val)
SE_CheckBoxIndicator
virtual QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const const=0
EditRole
bool toBool() const const
void setGeometry(const QRect &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:25 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.