2010-06-23 02:33:53 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file treeitem.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
2010-07-16 16:01:53 +00:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
2010-06-23 02:33:53 +00:00
|
|
|
* @{
|
2010-07-16 16:01:53 +00:00
|
|
|
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The UAVObject Browser gadget plugin
|
2010-06-23 02:33:53 +00:00
|
|
|
*****************************************************************************/
|
2010-07-16 16:01:53 +00:00
|
|
|
/*
|
2010-06-23 02:33:53 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TREEITEM_H
|
|
|
|
#define TREEITEM_H
|
|
|
|
|
2011-01-22 17:38:22 +00:00
|
|
|
#include "uavobject.h"
|
|
|
|
#include "uavmetaobject.h"
|
|
|
|
#include "uavobjectfield.h"
|
2010-06-23 02:33:53 +00:00
|
|
|
#include <QtCore/QList>
|
2012-06-16 17:38:05 +02:00
|
|
|
#include <QtCore/QLinkedList>
|
2012-06-30 16:45:08 +02:00
|
|
|
#include <QtCore/QMap>
|
2010-06-23 02:33:53 +00:00
|
|
|
#include <QtCore/QVariant>
|
2012-06-20 22:07:14 -04:00
|
|
|
#include <QtCore/QTime>
|
2010-06-23 02:33:53 +00:00
|
|
|
#include <QtCore/QTimer>
|
|
|
|
#include <QtCore/QObject>
|
2012-06-16 17:38:05 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-06-23 02:33:53 +00:00
|
|
|
|
2012-06-16 17:38:05 +02:00
|
|
|
class TreeItem;
|
|
|
|
|
2012-06-17 12:46:45 +02:00
|
|
|
/*
|
|
|
|
* Small utility class that handles the higlighting of
|
|
|
|
* tree grid items.
|
|
|
|
* Basicly it maintains all items due to be restored to
|
|
|
|
* non highlighted state in a linked list.
|
|
|
|
* A timer traverses this list periodically to find out
|
|
|
|
* if any of the items should be restored. All items are
|
|
|
|
* updated withan expiration timestamp when they expires.
|
|
|
|
* An item that is beeing restored is removed from the
|
|
|
|
* list and its removeHighlight() method is called. Items
|
|
|
|
* that are not expired are left in the list til next time.
|
|
|
|
* Items that are updated during the expiration time are
|
|
|
|
* left untouched in the list. This reduces unwanted emits
|
|
|
|
* of signals to the repaint/update function.
|
|
|
|
*/
|
2012-06-16 17:38:05 +02:00
|
|
|
class HighLightManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-06-17 12:46:45 +02:00
|
|
|
// Constructor taking the checking interval in ms.
|
2012-06-16 17:38:05 +02:00
|
|
|
HighLightManager(long checkingInterval);
|
2012-06-17 12:46:45 +02:00
|
|
|
|
|
|
|
// This is called when an item has been set to
|
|
|
|
// highlighted = true.
|
2012-06-16 17:38:05 +02:00
|
|
|
bool add(TreeItem* itemToAdd);
|
2012-06-17 12:46:45 +02:00
|
|
|
|
|
|
|
//This is called when an item is set to highlighted = false;
|
2012-06-16 17:38:05 +02:00
|
|
|
bool remove(TreeItem* itemToRemove);
|
|
|
|
|
|
|
|
private slots:
|
2012-06-17 12:46:45 +02:00
|
|
|
// Timer callback method.
|
2012-06-16 17:38:05 +02:00
|
|
|
void checkItemsExpired();
|
|
|
|
|
|
|
|
private:
|
2012-06-17 12:46:45 +02:00
|
|
|
// The timer checking highlight expiration.
|
2012-06-16 17:38:05 +02:00
|
|
|
QTimer m_expirationTimer;
|
2012-06-17 12:46:45 +02:00
|
|
|
|
|
|
|
// The list holding all items due to be updated.
|
2012-06-16 17:38:05 +02:00
|
|
|
QLinkedList<TreeItem*> m_itemsList;
|
2012-06-17 12:46:45 +02:00
|
|
|
|
|
|
|
//Mutex to lock when accessing list.
|
2012-06-16 17:38:05 +02:00
|
|
|
QMutex m_listMutex;
|
|
|
|
};
|
2010-06-23 02:33:53 +00:00
|
|
|
|
|
|
|
class TreeItem : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
|
|
|
|
TreeItem(const QVariant &data, TreeItem *parent = 0);
|
|
|
|
virtual ~TreeItem();
|
|
|
|
|
|
|
|
void appendChild(TreeItem *child);
|
2012-06-30 16:45:08 +02:00
|
|
|
void insertChild(TreeItem *child);
|
2010-06-23 02:33:53 +00:00
|
|
|
|
2012-06-30 16:45:08 +02:00
|
|
|
TreeItem *getChild(int index);
|
2010-06-23 02:33:53 +00:00
|
|
|
inline QList<TreeItem*> treeChildren() const { return m_children; }
|
|
|
|
int childCount() const;
|
|
|
|
int columnCount() const;
|
|
|
|
QVariant data(int column = 1) const;
|
2010-12-22 21:29:23 +00:00
|
|
|
QString description() { return m_description; }
|
|
|
|
void setDescription(QString d) { // Split around 40 characters
|
|
|
|
int idx = d.indexOf(" ",40);
|
|
|
|
d.insert(idx,QString("<br>"));
|
2011-01-11 09:02:57 +00:00
|
|
|
d.remove("@Ref", Qt::CaseInsensitive);
|
2010-12-22 21:29:23 +00:00
|
|
|
m_description = d;
|
|
|
|
}
|
2010-06-23 02:33:53 +00:00
|
|
|
// only column 1 (TreeItem::dataColumn) is changed with setData currently
|
|
|
|
// other columns are initialized in constructor
|
|
|
|
virtual void setData(QVariant value, int column = 1);
|
|
|
|
int row() const;
|
|
|
|
TreeItem *parent() { return m_parent; }
|
|
|
|
void setParentTree(TreeItem *parent) { m_parent = parent; }
|
|
|
|
inline virtual bool isEditable() { return false; }
|
|
|
|
virtual void update();
|
|
|
|
virtual void apply();
|
|
|
|
|
|
|
|
inline bool highlighted() { return m_highlight; }
|
|
|
|
void setHighlight(bool highlight);
|
|
|
|
static void setHighlightTime(int time) { m_highlightTimeMs = time; }
|
|
|
|
|
|
|
|
inline bool changed() { return m_changed; }
|
|
|
|
inline void setChanged(bool changed) { m_changed = changed; }
|
|
|
|
|
2012-06-16 17:38:05 +02:00
|
|
|
virtual void setHighlightManager(HighLightManager* mgr);
|
|
|
|
|
|
|
|
QTime getHiglightExpires();
|
|
|
|
|
|
|
|
virtual void removeHighlight();
|
|
|
|
|
2012-06-30 16:45:08 +02:00
|
|
|
int nameIndex(QString name) {
|
|
|
|
for (int i = 0; i < childCount(); ++i) {
|
|
|
|
if (name < getChild(i)->data(0).toString())
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return childCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem* findChildByName(QString name)
|
|
|
|
{
|
|
|
|
foreach (TreeItem* child, m_children) {
|
|
|
|
if (name == child->data(0).toString()) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-23 02:33:53 +00:00
|
|
|
signals:
|
|
|
|
void updateHighlight(TreeItem*);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<TreeItem*> m_children;
|
2010-12-22 21:29:23 +00:00
|
|
|
// m_data contains: [0] property name, [1] value, [2] unit
|
2010-06-23 02:33:53 +00:00
|
|
|
QList<QVariant> m_data;
|
2010-12-22 21:29:23 +00:00
|
|
|
QString m_description;
|
2010-06-23 02:33:53 +00:00
|
|
|
TreeItem *m_parent;
|
|
|
|
bool m_highlight;
|
|
|
|
bool m_changed;
|
2012-06-16 17:38:05 +02:00
|
|
|
QTime m_highlightExpires;
|
|
|
|
HighLightManager* m_highlightManager;
|
2012-07-07 12:57:11 +02:00
|
|
|
static int m_highlightTimeMs;
|
2010-06-23 02:33:53 +00:00
|
|
|
public:
|
|
|
|
static const int dataColumn = 1;
|
|
|
|
};
|
|
|
|
|
2012-06-30 16:45:08 +02:00
|
|
|
class DataObjectTreeItem;
|
|
|
|
class MetaObjectTreeItem;
|
|
|
|
|
2010-06-23 02:33:53 +00:00
|
|
|
class TopTreeItem : public TreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
|
|
|
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
|
|
|
|
2012-06-30 16:45:08 +02:00
|
|
|
void addObjectTreeItem(quint32 objectId, DataObjectTreeItem* oti) {
|
|
|
|
m_objectTreeItemsPerObjectIds[objectId] = oti;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataObjectTreeItem* findDataObjectTreeItemByObjectId(quint32 objectId) {
|
|
|
|
return m_objectTreeItemsPerObjectIds.contains(objectId) ? m_objectTreeItemsPerObjectIds[objectId] : 0;
|
2010-06-23 02:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-30 16:45:08 +02:00
|
|
|
void addMetaObjectTreeItem(quint32 objectId, MetaObjectTreeItem* oti) {
|
|
|
|
m_metaObjectTreeItemsPerObjectIds[objectId] = oti;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaObjectTreeItem* findMetaObjectTreeItemByObjectId(quint32 objectId) {
|
|
|
|
return m_metaObjectTreeItemsPerObjectIds.contains(objectId) ? m_metaObjectTreeItemsPerObjectIds[objectId] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<MetaObjectTreeItem*> getMetaObjectItems();
|
|
|
|
|
2010-06-23 02:33:53 +00:00
|
|
|
private:
|
2012-06-30 16:45:08 +02:00
|
|
|
QMap<quint32, DataObjectTreeItem*> m_objectTreeItemsPerObjectIds;
|
|
|
|
QMap<quint32, MetaObjectTreeItem*> m_metaObjectTreeItemsPerObjectIds;
|
2010-06-23 02:33:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ObjectTreeItem : public TreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
|
|
|
TreeItem(data, parent), m_obj(0) { }
|
|
|
|
ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
|
|
|
TreeItem(data, parent), m_obj(0) { }
|
2010-12-22 21:29:23 +00:00
|
|
|
void setObject(UAVObject *obj) { m_obj = obj; setDescription(obj->getDescription()); }
|
2010-06-23 02:33:53 +00:00
|
|
|
inline UAVObject *object() { return m_obj; }
|
|
|
|
private:
|
|
|
|
UAVObject *m_obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MetaObjectTreeItem : public ObjectTreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
|
|
|
ObjectTreeItem(data, parent) { setObject(obj); }
|
|
|
|
MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
|
|
|
ObjectTreeItem(data, parent) { setObject(obj); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataObjectTreeItem : public ObjectTreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
|
|
|
|
ObjectTreeItem(data, parent) { }
|
|
|
|
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
|
|
|
|
ObjectTreeItem(data, parent) { }
|
|
|
|
virtual void apply() {
|
|
|
|
foreach(TreeItem *child, treeChildren()) {
|
|
|
|
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
|
|
|
if (!metaChild)
|
|
|
|
child->apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void update() {
|
|
|
|
foreach(TreeItem *child, treeChildren()) {
|
|
|
|
MetaObjectTreeItem *metaChild = dynamic_cast<MetaObjectTreeItem*>(child);
|
|
|
|
if (!metaChild)
|
|
|
|
child->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class InstanceTreeItem : public DataObjectTreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
|
|
|
|
DataObjectTreeItem(data, parent) { setObject(obj); }
|
|
|
|
InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
|
|
|
|
DataObjectTreeItem(data, parent) { setObject(obj); }
|
|
|
|
virtual void apply() { TreeItem::apply(); }
|
|
|
|
virtual void update() { TreeItem::update(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArrayFieldTreeItem : public TreeItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
|
|
|
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TREEITEM_H
|