MailTransport

transporttreedelegate.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "transporttreedelegate.h"
7#include "transportmodel.h"
8#include <QLineEdit>
9using namespace MailTransport;
10TransportTreeDelegate::TransportTreeDelegate(QObject *parent)
11 : QStyledItemDelegate{parent}
12{
13}
14
15TransportTreeDelegate::~TransportTreeDelegate() = default;
16
17QWidget *TransportTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
18{
19 Q_UNUSED(index);
20 Q_UNUSED(option);
21 auto *lineEdit = new QLineEdit(parent);
22 auto *that = const_cast<TransportTreeDelegate *>(this);
23 connect(lineEdit, &QLineEdit::editingFinished, this, [this, that]() {
24 Q_EMIT that->commitData(mLineEdit);
25 Q_EMIT that->closeEditor(mLineEdit);
26 });
27 const_cast<TransportTreeDelegate *>(this)->mLineEdit = lineEdit;
28 return lineEdit;
29}
30
31void TransportTreeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
32{
33 auto loggingIndex = index.model()->index(index.row(), MailTransport::TransportModel::NameRole);
34 qobject_cast<QLineEdit *>(editor)->setText(loggingIndex.data().toString());
35}
36
37void TransportTreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
38{
39 auto loggingIndex = index.model()->index(index.row(), MailTransport::TransportModel::NameRole);
40 model->setData(loggingIndex, qobject_cast<QLineEdit *>(editor)->text());
41}
42
43void TransportTreeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /*index*/) const
44{
45 editor->setGeometry(option.rect);
46}
47
48#include "moc_transporttreedelegate.cpp"
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
void editingFinished()
const QAbstractItemModel * model() const const
int row() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
void setGeometry(const QRect &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.