Chrysalis - CLO3D Extensions
Toggle main menu visibility
Loading...
Searching...
No Matches
BaseDelegate.h
Go to the documentation of this file.
1
#ifndef CHRYSALIS_BASEDELEGATE_H
2
#define CHRYSALIS_BASEDELEGATE_H
3
4
#include <QStyledItemDelegate>
5
6
namespace
CLO3D::UI
{
7
template
<
typename
W,
typename
C>
8
requires
std::is_base_of_v<QWidget, W>
9
class
BaseDelegate
:
public
QStyledItemDelegate {
10
public
:
11
explicit
BaseDelegate
(QObject* parent): QStyledItemDelegate(parent) {}
12
13
QSize
sizeHint
(
const
QStyleOptionViewItem& option,
const
QModelIndex& index)
const override
{
14
static
int
height = W().height();
15
return
{0, height};
16
}
17
void
updateEditorGeometry
(QWidget* editor,
const
QStyleOptionViewItem& option,
const
QModelIndex& index)
const override
{
18
static
int
height = editor->sizeHint().height();
19
const
int
y = option.rect.y() + (option.rect.height() - height) / 2;
20
editor->setGeometry(option.rect.x(), y, option.rect.width(), height);
21
}
22
23
void
setEditorData
(QWidget* editor,
const
QModelIndex& index)
const override
{
24
qobject_cast<W*>(editor)->set(index.data(Qt::UserRole).value<C*>());
25
}
26
QWidget*
createEditor
(QWidget* parent,
const
QStyleOptionViewItem& option,
const
QModelIndex& index)
const override
{
27
return
new
W(parent);
28
}
29
};
30
}
31
32
#endif
//CHRYSALIS_BASEDELEGATE_H
CLO3D::UI::BaseDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition
BaseDelegate.h:26
CLO3D::UI::BaseDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition
BaseDelegate.h:23
CLO3D::UI::BaseDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition
BaseDelegate.h:13
CLO3D::UI::BaseDelegate::BaseDelegate
BaseDelegate(QObject *parent)
Definition
BaseDelegate.h:11
CLO3D::UI::BaseDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition
BaseDelegate.h:17
CLO3D::UI
Definition
BaseCommandArgumentsWidget.h:10
integrations
clo3d
include
BaseDelegate.h
Generated by
1.17.0