2 ******************************************************************************
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
31 #include "uavobject.h"
32 #include "uavmetaobject.h"
33 #include "uavobjectfield.h"
34 #include <QtCore/QList>
35 #include <QtCore/QVariant>
36 #include <QtCore/QObject>
39 class TreeItem
: public QObject
{
42 TreeItem(const QList
<QVariant
> &data
, TreeItem
*parent
= 0);
43 TreeItem(const QVariant
&data
, TreeItem
*parent
= 0);
46 void appendChild(TreeItem
*child
);
47 void insert(int index
, TreeItem
*child
);
49 TreeItem
*child(int row
);
50 inline QList
<TreeItem
*> treeChildren() const
54 int childCount() const;
55 int columnCount() const;
56 QVariant
data(int column
= 1) const;
61 void setDescription(QString d
) // Split around 40 characters
63 int idx
= d
.indexOf(" ", 40);
65 d
.insert(idx
, QString("<br>"));
66 d
.remove("@Ref", Qt::CaseInsensitive
);
69 // only column 1 (TreeItem::dataColumn) is changed with setData currently
70 // other columns are initialized in constructor
71 virtual void setData(QVariant value
, int column
= 1);
77 void setParentTree(TreeItem
*parent
)
81 inline virtual bool isEditable()
85 virtual void update();
88 inline bool highlighted()
92 void setHighlight(bool highlight
);
93 void setActive(bool highlight
);
99 inline void setChanged(bool changed
)
101 m_changed
= changed
; if (changed
) {
102 emit
updateHighlight(this);
107 void updateHighlight(TreeItem
*);
110 void removeHighlight();
113 QList
<TreeItem
*> m_children
;
114 // m_data contains: [0] property name, [1] value, [2] unit
115 QList
<QVariant
> m_data
;
116 QString m_description
;
121 static const int dataColumn
= 1;
125 class TopTreeItem
: public TreeItem
{
128 TopTreeItem(const QList
<QVariant
> &data
, TreeItem
*parent
= 0) : TreeItem(data
, parent
) {}
129 TopTreeItem(const QVariant
&data
, TreeItem
*parent
= 0) : TreeItem(data
, parent
) {}
131 QList
<quint32
> objIds()
135 void addObjId(quint32 objId
)
137 m_objIds
.append(objId
);
139 void insertObjId(int index
, quint32 objId
)
141 m_objIds
.insert(index
, objId
);
143 int nameIndex(QString name
)
145 for (int i
= 0; i
< childCount(); ++i
) {
146 if (name
< child(i
)->data(0).toString()) {
154 QList
<quint32
> m_objIds
;
157 class ObjectTreeItem
: public TreeItem
{
160 ObjectTreeItem(const QList
<QVariant
> &data
, TreeItem
*parent
= 0) :
161 TreeItem(data
, parent
), m_obj(0) {}
162 ObjectTreeItem(const QVariant
&data
, TreeItem
*parent
= 0) :
163 TreeItem(data
, parent
), m_obj(0) {}
164 void setObject(UAVObject
*obj
)
166 m_obj
= obj
; setDescription(obj
->getDescription());
168 inline UAVObject
*object()
176 class MetaObjectTreeItem
: public ObjectTreeItem
{
179 MetaObjectTreeItem(UAVObject
*obj
, const QList
<QVariant
> &data
, TreeItem
*parent
= 0) :
180 ObjectTreeItem(data
, parent
)
184 MetaObjectTreeItem(UAVObject
*obj
, const QVariant
&data
, TreeItem
*parent
= 0) :
185 ObjectTreeItem(data
, parent
)
191 class DataObjectTreeItem
: public ObjectTreeItem
{
194 DataObjectTreeItem(const QList
<QVariant
> &data
, TreeItem
*parent
= 0) :
195 ObjectTreeItem(data
, parent
) {}
196 DataObjectTreeItem(const QVariant
&data
, TreeItem
*parent
= 0) :
197 ObjectTreeItem(data
, parent
) {}
200 foreach(TreeItem
* child
, treeChildren()) {
201 MetaObjectTreeItem
*metaChild
= dynamic_cast<MetaObjectTreeItem
*>(child
);
208 virtual void update()
210 foreach(TreeItem
* child
, treeChildren()) {
211 MetaObjectTreeItem
*metaChild
= dynamic_cast<MetaObjectTreeItem
*>(child
);
220 class InstanceTreeItem
: public DataObjectTreeItem
{
223 InstanceTreeItem(UAVObject
*obj
, const QList
<QVariant
> &data
, TreeItem
*parent
= 0) :
224 DataObjectTreeItem(data
, parent
)
228 InstanceTreeItem(UAVObject
*obj
, const QVariant
&data
, TreeItem
*parent
= 0) :
229 DataObjectTreeItem(data
, parent
)
237 virtual void update()
243 class ArrayFieldTreeItem
: public TreeItem
{
246 ArrayFieldTreeItem(const QList
<QVariant
> &data
, TreeItem
*parent
= 0) : TreeItem(data
, parent
) {}
247 ArrayFieldTreeItem(const QVariant
&data
, TreeItem
*parent
= 0) : TreeItem(data
, parent
) {}