2 ******************************************************************************
4 * @file browseritemdelegate.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
11 * @brief The UAVObject Browser gadget plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "browseritemdelegate.h"
30 #include "fieldtreeitem.h"
32 BrowserItemDelegate::BrowserItemDelegate(QObject
*parent
) :
33 QStyledItemDelegate(parent
)
35 _sizeHint
= QSpinBox().sizeHint();
38 QWidget
*BrowserItemDelegate::createEditor(QWidget
*parent
,
39 const QStyleOptionViewItem
& option
,
40 const QModelIndex
&index
) const
43 FieldTreeItem
* item
= static_cast<FieldTreeItem
*>(index
.data(Qt::UserRole
).value
<void *>());
44 QWidget
*editor
= item
->createEditor(parent
);
49 void BrowserItemDelegate::setEditorData(QWidget
*editor
,
50 const QModelIndex
&index
) const
52 FieldTreeItem
*item
= static_cast<FieldTreeItem
*>(index
.data(Qt::UserRole
).value
<void *>());
53 QVariant value
= index
.model()->data(index
, Qt::EditRole
);
55 item
->setEditorValue(editor
, value
);
58 void BrowserItemDelegate::setModelData(QWidget
*editor
, QAbstractItemModel
*model
,
59 const QModelIndex
&index
) const
61 FieldTreeItem
*item
= static_cast<FieldTreeItem
*>(index
.data(Qt::UserRole
).value
<void *>());
62 QVariant value
= item
->getEditorValue(editor
);
64 bool ret
= model
->setData(index
, value
, Qt::EditRole
);
69 void BrowserItemDelegate::updateEditorGeometry(QWidget
*editor
,
70 const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
73 editor
->setGeometry(option
.rect
);
76 QSize
BrowserItemDelegate::sizeHint(const QStyleOptionViewItem
& option
, const QModelIndex
&index
) const