2 ******************************************************************************
4 * @file browseritemdelegate.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
10 * @brief The UAVObject Browser gadget plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "browseritemdelegate.h"
29 #include "fieldtreeitem.h"
31 BrowserItemDelegate::BrowserItemDelegate(QObject
*parent
) :
32 QStyledItemDelegate(parent
)
35 QWidget
*BrowserItemDelegate::createEditor(QWidget
*parent
,
36 const QStyleOptionViewItem
& option
,
37 const QModelIndex
& index
) const
40 FieldTreeItem
* item
= static_cast<FieldTreeItem
*>(index
.internalPointer());
41 QWidget
*editor
= item
->createEditor(parent
);
47 void BrowserItemDelegate::setEditorData(QWidget
*editor
,
48 const QModelIndex
&index
) const
50 FieldTreeItem
*item
= static_cast<FieldTreeItem
*>(index
.internalPointer());
51 QVariant value
= index
.model()->data(index
, Qt::EditRole
);
53 item
->setEditorValue(editor
, value
);
56 void BrowserItemDelegate::setModelData(QWidget
*editor
, QAbstractItemModel
*model
,
57 const QModelIndex
&index
) const
59 FieldTreeItem
*item
= static_cast<FieldTreeItem
*>(index
.internalPointer());
60 QVariant value
= item
->getEditorValue(editor
);
62 model
->setData(index
, value
, Qt::EditRole
);
65 void BrowserItemDelegate::updateEditorGeometry(QWidget
*editor
,
66 const QStyleOptionViewItem
&option
, const QModelIndex
& /* index */) const
68 editor
->setGeometry(option
.rect
);
71 QSize
BrowserItemDelegate::sizeHint(const QStyleOptionViewItem
& option
, const QModelIndex
&index
) const
75 return QSpinBox().sizeHint();