Warning, file /plasma/plasma-nm/libs/editor/widgets/delegate.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "delegate.h"
0008 
0009 #include <QLineEdit>
0010 #include <QStandardItem>
0011 #include <QStandardItemModel>
0012 
0013 Delegate::Delegate(QObject *parent)
0014     : QStyledItemDelegate(parent)
0015 {
0016 }
0017 Delegate::~Delegate() = default;
0018 
0019 QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
0020 {
0021     auto editor = new QLineEdit(parent);
0022 
0023     return editor;
0024 }
0025 
0026 void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
0027 {
0028     QString value = index.model()->data(index, Qt::EditRole).toString();
0029 
0030     auto le = static_cast<QLineEdit *>(editor);
0031     le->setText(value);
0032 }
0033 
0034 void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
0035 {
0036     auto le = static_cast<QLineEdit *>(editor);
0037 
0038     model->setData(index, le->text(), Qt::EditRole);
0039 }
0040 
0041 void Delegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
0042 {
0043     editor->setGeometry(option.rect);
0044 }