1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/uavobjectbrowser: First addition of UAVObject browser gadget. Work in progress.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@436 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-04-07 18:38:20 +00:00 committed by ephy
parent 23aa2ea1cd
commit 85aef7c757
22 changed files with 1716 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<plugin name="UAVObjectBrowser" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>UAVObject Browser</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="0.0.1"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,100 @@
/**
******************************************************************************
*
* @file browseritemdelegate.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "browseritemdelegate.h"
#include "treeitem.h"
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QComboBox>
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
if (item->isIntType()) {
IntFieldTreeItem *intItem = static_cast<IntFieldTreeItem*>(item);
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(intItem->MIN);
editor->setMaximum(intItem->MAX);
return editor;
} else if (item->isEnum()) {
EnumFieldTreeItem *enumItem = static_cast<EnumFieldTreeItem*>(item);
QComboBox *editor = new QComboBox(parent);
foreach (QString option, enumItem->enumOptions)
editor->addItem(option);
return editor;
}
return QStyledItemDelegate::createEditor(parent, option, index);
}
void BrowserItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
if (item->isIntType()) {
int value = index.model()->data(index, Qt::EditRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);
} else if (item->isEnum()) {
int value = index.model()->data(index, Qt::EditRole).toInt();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
comboBox->setCurrentIndex(value);
} else {
QStyledItemDelegate::setEditorData(editor, index);
}
}
void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
if (item->isIntType()) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value, Qt::EditRole);
} else if (item->isEnum()) {
QComboBox *comboBox = static_cast<QComboBox*>(editor);
int value = comboBox->currentIndex();
model->setData(index, value, Qt::EditRole);
} else {
QStyledItemDelegate::setModelData(editor, model, index);
}
}
void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}

View File

@ -0,0 +1,55 @@
/**
******************************************************************************
*
* @file browseritemdelegate.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 BROWSERITEMDELEGATE_H
#define BROWSERITEMDELEGATE_H
#include <QStyledItemDelegate>
class BrowserItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit BrowserItemDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
signals:
public slots:
};
#endif // BROWSERITEMDELEGATE_H

View File

@ -0,0 +1,63 @@
/**
******************************************************************************
*
* @file mapplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "browserplugin.h"
#include "uavobjectbrowserfactory.h"
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
BrowserPlugin::BrowserPlugin()
{
// Do nothing
}
BrowserPlugin::~BrowserPlugin()
{
// Do nothing
}
bool BrowserPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new UAVObjectBrowserFactory(this);
addAutoReleasedObject(mf);
return true;
}
void BrowserPlugin::extensionsInitialized()
{
// Do nothing
}
void BrowserPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(BrowserPlugin)

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file browserplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSERPLUGIN_H_
#define UAVOBJECTBROWSERPLUGIN_H_
#include <extensionsystem/iplugin.h>
class UAVObjectBrowserFactory;
class BrowserPlugin : public ExtensionSystem::IPlugin
{
public:
BrowserPlugin();
~BrowserPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
UAVObjectBrowserFactory *mf;
};
#endif /* UAVOBJECTBROWSERPLUGIN_H_ */

View File

@ -0,0 +1,90 @@
/**
******************************************************************************
*
* @file treeitem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "treeitem.h"
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
m_data(data),
m_parent(parent)
{
}
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
m_parent(parent)
{
m_data << data << "" << "";
}
TreeItem::~TreeItem()
{
qDeleteAll(m_children);
}
void TreeItem::appendChild(TreeItem *child)
{
m_children.append(child);
child->setParent(this);
}
void TreeItem::insert(int index, TreeItem *child)
{
m_children.insert(index, child);
child->setParent(this);
}
TreeItem *TreeItem::child(int row)
{
return m_children.value(row);
}
int TreeItem::childCount() const
{
return m_children.count();
}
int TreeItem::row() const
{
if (m_parent)
return m_parent->m_children.indexOf(const_cast<TreeItem*>(this));
return 0;
}
int TreeItem::columnCount() const
{
return m_data.count();
}
QVariant TreeItem::data(int column) const
{
return m_data.value(column);
}
void TreeItem::setData(int column, QVariant value)
{
m_data.replace(column, value);
}

View File

@ -0,0 +1,159 @@
/**
******************************************************************************
*
* @file treeitem.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
#include <QtCore/QList>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
class TreeItem
{
public:
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
TreeItem(const QVariant &data, TreeItem *parent = 0);
~TreeItem();
void appendChild(TreeItem *child);
void insert(int index, TreeItem *child);
TreeItem *child(int row);
QList<TreeItem*> children() const { return m_children; }
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
void setData(int column, QVariant value);
int row() const;
TreeItem *parent() { return m_parent; }
void setParent(TreeItem *parent) { m_parent = parent; }
virtual bool isEditable() { return false; }
private:
QList<TreeItem*> m_children;
QList<QVariant> m_data;
TreeItem *m_parent;
};
class TopTreeItem : public TreeItem
{
public:
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
QList<quint32> objIds() { return m_objIds; }
void addObjId(quint32 objId) { m_objIds.append(objId); }
void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); }
int nameIndex(QString name) {
for (int i = 0; i < childCount(); ++i) {
if (name < child(i)->data(0).toString())
return i;
}
return childCount();
}
private:
QList<quint32> m_objIds;
};
class DataObjectTreeItem : public TreeItem
{
public:
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
};
class MetaObjectTreeItem : public TreeItem
{
public:
MetaObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
MetaObjectTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
};
class InstanceTreeItem : public TreeItem
{
public:
InstanceTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
InstanceTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
};
class ArrayFieldTreeItem : public TreeItem
{
public:
ArrayFieldTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
};
class FieldTreeItem : public TreeItem
{
public:
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) { }
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) { }
bool isEditable() { return true; }
virtual bool isIntType() { return false; }
virtual bool isEnum() { return false; }
private:
int m_index;
};
class EnumFieldTreeItem : public FieldTreeItem
{
public:
EnumFieldTreeItem(int index, const QList<QVariant> &data, QStringList enumOptions, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), enumOptions(enumOptions) { }
EnumFieldTreeItem(int index, const QVariant &data, QStringList enumOptions, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), enumOptions(enumOptions) { }
bool isEnum() { return true; }
QStringList enumOptions;
};
class IntFieldTreeItem : public FieldTreeItem
{
public:
IntFieldTreeItem(int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), MIN(min), MAX(max) { }
IntFieldTreeItem(int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), MIN(min), MAX(max) { }
bool isIntType() { return true; }
int MIN;
int MAX;
};
class FloatFieldTreeItem : public FieldTreeItem
{
public:
FloatFieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent) { }
FloatFieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent) { }
virtual bool isIntType() { return false; }
};
#endif // TREEITEM_H

View File

@ -0,0 +1,46 @@
/**
******************************************************************************
*
* @file uavobjectbrowser.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjectbrowser.h"
#include "uavobjectbrowserwidget.h"
#include "uavobjectbrowserconfiguration.h"
UAVObjectBrowser::UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
UAVObjectBrowser::~UAVObjectBrowser()
{
}
void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
{
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration*>(config);
}

View File

@ -0,0 +1,56 @@
/**
******************************************************************************
*
* @file uavobjectbrowser.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSER_H_
#define UAVOBJECTBROWSER_H_
#include <coreplugin/iuavgadget.h>
#include "uavobjectbrowserwidget.h"
class IUAVGadget;
class QWidget;
class QString;
class UAVObjectBrowserWidget;
using namespace Core;
class UAVObjectBrowser : public Core::IUAVGadget
{
Q_OBJECT
public:
UAVObjectBrowser(QString classId, UAVObjectBrowserWidget *widget, QWidget *parent = 0);
~UAVObjectBrowser();
QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
UAVObjectBrowserWidget *m_widget;
};
#endif // UAVOBJECTBROWSER_H_

View File

@ -0,0 +1,24 @@
TEMPLATE = lib
TARGET = UAVObjectBrowser
include(../../openpilotgcsplugin.pri)
include(uavobjectbrowser_dependencies.pri)
HEADERS += browserplugin.h \
uavobjectbrowserconfiguration.h \
uavobjectbrowser.h \
uavobjectbrowserwidget.h \
uavobjectbrowserfactory.h \
uavobjectbrowseroptionspage.h \
uavobjecttreemodel.h \
treeitem.h \
browseritemdelegate.h
SOURCES += browserplugin.cpp \
uavobjectbrowserconfiguration.cpp \
uavobjectbrowser.cpp \
uavobjectbrowserfactory.cpp \
uavobjectbrowserwidget.cpp \
uavobjectbrowseroptionspage.cpp \
uavobjecttreemodel.cpp \
treeitem.cpp \
browseritemdelegate.cpp
OTHER_FILES += UAVObjectBrowser.pluginspec
FORMS += uavobjectbrowser.ui

View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UAVObjectBrowser</class>
<widget class="QWidget" name="UAVObjectBrowser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="requestButton">
<property name="toolTip">
<string>Request update</string>
</property>
<property name="text">
<string>Request</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="sendButton">
<property name="toolTip">
<string>Send update</string>
</property>
<property name="text">
<string>Send</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="saveSDButton">
<property name="toolTip">
<string>Save to SD Card</string>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="readSDButton">
<property name="toolTip">
<string>Read from SD Card</string>
</property>
<property name="text">
<string>Read</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="metaCheckBox">
<property name="toolTip">
<string>Show Meta Data</string>
</property>
<property name="text">
<string>Show Meta Data</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="treeView"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,3 @@
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/utils/utils.pri)

View File

@ -0,0 +1,53 @@
/**
******************************************************************************
*
* @file uavobjectbrowserconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjectbrowserconfiguration.h"
#include <QtCore/QDataStream>
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent)
{
if (state.count() > 0) {
QDataStream stream(state);
}
}
IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
{
UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId());
return m;
}
QByteArray UAVObjectBrowserConfiguration::saveState() const
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
return bytes;
}

View File

@ -0,0 +1,50 @@
/**
******************************************************************************
*
* @file uavobjectbrowserconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSERCONFIGURATION_H
#define UAVOBJECTBROWSERCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
using namespace Core;
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
signals:
public slots:
private:
};
#endif // UAVOBJECTBROWSERCONFIGURATION_H

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
*
* @file uavobjectbrowserfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjectbrowserfactory.h"
#include "uavobjectbrowserwidget.h"
#include "uavobjectbrowser.h"
#include "uavobjectbrowserconfiguration.h"
#include "uavobjectbrowseroptionspage.h"
#include <coreplugin/iuavgadget.h>
UAVObjectBrowserFactory::UAVObjectBrowserFactory(QObject *parent) :
IUAVGadgetFactory(QString("UAVObjectBrowser"), tr("UAVObject Browser"), parent)
{
}
UAVObjectBrowserFactory::~UAVObjectBrowserFactory()
{
}
Core::IUAVGadget* UAVObjectBrowserFactory::createGadget(QWidget *parent)
{
UAVObjectBrowserWidget* gadgetWidget = new UAVObjectBrowserWidget(parent);
return new UAVObjectBrowser(QString("UAVObjectBrowser"), gadgetWidget, parent);
}
IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByteArray &state)
{
return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state);
}
IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{
return new UAVObjectBrowserOptionsPage(qobject_cast<UAVObjectBrowserConfiguration*>(config));
}

View File

@ -0,0 +1,52 @@
/**
******************************************************************************
*
* @file uavobjectbrowserfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSERFACTORY_H_
#define UAVOBJECTBROWSERFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class UAVObjectBrowserFactory : public Core::IUAVGadgetFactory
{
Q_OBJECT
public:
UAVObjectBrowserFactory(QObject *parent = 0);
~UAVObjectBrowserFactory();
Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
};
#endif // UAVOBJECTBROWSERFACTORY_H_

View File

@ -0,0 +1,59 @@
/**
******************************************************************************
*
* @file uavobjectbrowseroptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjectbrowseroptionspage.h"
#include "uavobjectbrowserconfiguration.h"
#include <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
UAVObjectBrowserOptionsPage::UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
{
QWidget *widget = new QWidget;
return widget;
}
void UAVObjectBrowserOptionsPage::apply()
{
}
void UAVObjectBrowserOptionsPage::finish()
{
}

View File

@ -0,0 +1,60 @@
/**
******************************************************************************
*
* @file uavobjectbrowseroptionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSEROPTIONSPAGE_H
#define UAVOBJECTBROWSEROPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h"
namespace Core {
class IUAVGadgetConfiguration;
}
class UAVObjectBrowserConfiguration;
class QSpinBox;
class QDoubleSpinBox;
using namespace Core;
class UAVObjectBrowserOptionsPage : public IOptionsPage
{
Q_OBJECT
public:
explicit UAVObjectBrowserOptionsPage(UAVObjectBrowserConfiguration *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent);
void apply();
void finish();
signals:
public slots:
private:
UAVObjectBrowserConfiguration *m_config;
};
#endif // UAVOBJECTBROWSEROPTIONSPAGE_H

View File

@ -0,0 +1,82 @@
/**
******************************************************************************
*
* @file uavobjectbrowserwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjectbrowserwidget.h"
#include "uavobjecttreemodel.h"
#include "browseritemdelegate.h"
#include "ui_uavobjectbrowser.h"
#include <QStringList>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QComboBox>
#include <QtCore/QDebug>
#include <QtGui/QItemEditorFactory>
UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent)
{
m_browser = new Ui_UAVObjectBrowser();
m_browser->setupUi(this);
m_model = new UAVObjectTreeModel();
m_browser->treeView->setModel(m_model);
m_browser->treeView->setColumnWidth(0, 300);
m_browser->treeView->setAllColumnsShowFocus(false);
m_browser->treeView->expandAll();
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
m_browser->treeView->setItemDelegate(m_delegate);
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
showMetaData(m_browser->metaCheckBox->isChecked());
}
UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
{
delete m_browser;
}
void UAVObjectBrowserWidget::showMetaData(bool show)
{
int topRowCount = m_model->rowCount(QModelIndex());
for (int i = 0; i < topRowCount; ++i) {
QModelIndex index = m_model->index(i, 0, QModelIndex());
int subRowCount = m_model->rowCount(index);
for (int j = 0; j < subRowCount; ++j) {
m_browser->treeView->setRowHidden(0, index.child(j,0), !show);
}
}
}
void UAVObjectBrowserWidget::sendUpdate()
{
}
void UAVObjectBrowserWidget::requestUpdate()
{
}

View File

@ -0,0 +1,59 @@
/**
******************************************************************************
*
* @file uavobjectbrowserwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTBROWSERWIDGET_H_
#define UAVOBJECTBROWSERWIDGET_H_
#include <QtGui/QWidget>
#include <QtGui/QTreeView>
class QPushButton;
class Ui_UAVObjectBrowser;
class UAVObjectBrowserWidget : public QWidget
{
Q_OBJECT
public:
UAVObjectBrowserWidget(QWidget *parent = 0);
~UAVObjectBrowserWidget();
private slots:
void sendUpdate();
void requestUpdate();
void showMetaData(bool show);
private:
QPushButton *m_requestUpdate;
QPushButton *m_sendUpdate;
Ui_UAVObjectBrowser *m_browser;
QAbstractItemModel *m_model;
};
#endif /* UAVOBJECTBROWSERWIDGET_H_ */

View File

@ -0,0 +1,354 @@
/**
******************************************************************************
*
* @file uavobjecttreemodel.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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
*/
#include "uavobjecttreemodel.h"
#include "treeitem.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavdataobject.h"
#include "uavobjects/uavmetaobject.h"
#include "uavobjects/uavobjectfieldenum.h"
#include "uavobjects/uavobjectfielduint8.h"
#include "uavobjects/uavobjectfielduint16.h"
#include "uavobjects/uavobjectfielduint32.h"
#include "uavobjects/uavobjectfieldint8.h"
#include "uavobjects/uavobjectfieldint16.h"
#include "uavobjects/uavobjectfieldint32.h"
#include "uavobjects/uavobjectfieldfloat.h"
#include "extensionsystem/pluginmanager.h"
#include <QtGui/QColor>
#include <QtCore/QDebug>
#define QINT8MIN -128
#define QINT8MAX 127
#define QUINTMIN 0
#define QUINT8MAX 255
#define QINT16MIN -32768
#define QINT16MAX 32767
#define QUINT16MAX 65535
#define QINT32MIN -2147483648
#define QINT32MAX 2147483647
#define QUINT32MAX 2147483647
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
QAbstractItemModel(parent)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
setupModelData(objManager);
}
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
{
// root
QList<QVariant> rootData;
rootData << tr("Property") << tr("Value") << tr("Unit");
rootItem = new TreeItem(rootData);
m_settingsTree = new TopTreeItem(tr("Settings"), rootItem);
rootItem->appendChild(m_settingsTree);
m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), rootItem);
rootItem->appendChild(m_nonSettingsTree);
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
addDataObject(obj);
}
}
}
void UAVObjectTreeModel::newObject(UAVObject *obj)
{
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj);
if (dobj)
addDataObject(dobj);
}
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
{
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
if (root->objIds().contains(obj->getObjID())) {
int index = root->objIds().indexOf(obj->getObjID());
addInstance(obj, root->child(index));
} else {
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName());
int index = root->nameIndex(obj->getName());
root->insert(index, data);
root->insertObjId(index, obj->getObjID());
UAVMetaObject *meta = obj->getMetaObject();
addMetaObject(meta, data);
addInstance(obj, data);
}
}
void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
{
MetaObjectTreeItem *meta = new MetaObjectTreeItem(tr("Meta Data"));
UAVObject::Metadata md = obj->getMetadata();
QStringList boolList;
boolList << tr("False") << tr("True");
QStringList updateModeList;
updateModeList << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never");
QList<QVariant> data;
QString msUnit = tr("ms");
data << tr("Flight Telemetry Acked") << md.flightTelemetryAcked;
meta->appendChild(new EnumFieldTreeItem(0, data, boolList));
data.clear();
data << tr("Flight Telemetry Update Mode") << md.flightTelemetryUpdateMode;
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
data.clear();
data << tr("Flight Telemetry Update Period") << md.flightTelemetryUpdatePeriod << msUnit;
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
data.clear();
data << tr("GCS Telemetry Acked") << md.gcsTelemetryAcked;
meta->appendChild(new EnumFieldTreeItem(0, data, boolList));
data.clear();
data << tr("GCS Telemetry Update Mode") << md.gcsTelemetryUpdateMode;
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
data.clear();
data << tr("GCS Telemetry Update Period") << md.gcsTelemetryUpdatePeriod << msUnit;
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
data.clear();
data << tr("Logging Update Mode") << md.loggingUpdateMode;
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
data.clear();
data << tr("Logging Update Period") << md.loggingUpdatePeriod << msUnit;
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
parent->appendChild(meta);
}
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
{
TreeItem *item;
if (!obj->isSingleInstance()) {
QString name = tr("Instance") + " " + QString::number(obj->getInstID());
item = new InstanceTreeItem(name);
} else {
item = parent;
}
foreach (UAVObjectField *field, obj->getFields()) {
if (field->getNumElements() > 1) {
addArrayField(field, item);
} else {
addSingleField(0, field, item);
}
}
if (item != parent)
parent->appendChild(item);
}
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
{
TreeItem *item = new ArrayFieldTreeItem(field->getName());
// UAVObjectFieldEnum *enumField = qobject_cast<UAVObjectFieldEnum*>(field);
for (uint i = 0; i < field->getNumElements(); ++i) {
addSingleField(i, field, item);
}
parent->appendChild(item);
}
void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent)
{
QList<QVariant> data;
if (field->getNumElements() == 1)
data.append(field->getName());
else
data.append(QString("[%1]").arg(index));
UAVObjectFieldEnum *enumField = dynamic_cast<UAVObjectFieldEnum*>(field);
UAVObjectFieldInt8 *int8Field = dynamic_cast<UAVObjectFieldInt8*>(field);
UAVObjectFieldInt16 *int16Field = dynamic_cast<UAVObjectFieldInt16*>(field);
UAVObjectFieldInt32 *int32Field = dynamic_cast<UAVObjectFieldInt32*>(field);
UAVObjectFieldUInt8 *uInt8Field = dynamic_cast<UAVObjectFieldUInt8*>(field);
UAVObjectFieldUInt16 *uInt16Field = dynamic_cast<UAVObjectFieldUInt16*>(field);
UAVObjectFieldUInt32 *uInt32Field = dynamic_cast<UAVObjectFieldUInt32*>(field);
UAVObjectFieldFloat *floatField = dynamic_cast<UAVObjectFieldFloat*>(field);
FieldTreeItem *item;
if (enumField) {
data.append(enumField->getSelectedIndex());
data.append(field->getUnits());
item = new EnumFieldTreeItem(index, data, enumField->getOptions());
} else if (int8Field) {
data.append(int8Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QINT8MIN, QINT8MAX);
} else if (int16Field) {
data.append(int16Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QINT16MIN, QINT16MAX);
} else if (int32Field) {
data.append(int32Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QINT32MIN, QINT32MAX);
} else if (uInt8Field) {
data.append(uInt8Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT8MAX);
} else if (uInt16Field) {
data.append(uInt16Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT16MAX);
} else if (uInt32Field) {
data.append(uInt32Field->getValue());
data.append(field->getUnits());
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT32MAX);
} else if (floatField) {
data.append(floatField->getValue());
data.append(field->getUnits());
item = new FloatFieldTreeItem(index, data);
} else {
data.append("Data Error");
data.append(field->getUnits());
item = new FieldTreeItem(index, data);
}
parent->appendChild(item);
}
QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent)
const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
TreeItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *parentItem = childItem->parent();
if (parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int UAVObjectTreeModel::rowCount(const QModelIndex &parent) const
{
TreeItem *parentItem;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
return parentItem->childCount();
}
int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
else
return rootItem->columnCount();
}
QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.column() == 1 && role == Qt::EditRole) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column());
}
//XXX
// if (index.column() == 1 && role == Qt::ForegroundRole)
// return QVariant( QColor( Qt::red ) );
if (role != Qt::DisplayRole)
return QVariant();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (index.column() == 1) {
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
if (fieldItem) {
int enumIndex = fieldItem->data(index.column()).toInt();
return fieldItem->enumOptions.at(enumIndex);
}
}
return item->data(index.column());
}
bool UAVObjectTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
{
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setData(index.column(), value);
return true;
}
Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
if (index.column() == 1) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item->isEditable())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant UAVObjectTreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
return QVariant();
}

View File

@ -0,0 +1,80 @@
/**
******************************************************************************
*
* @file uavobjecttreemodel.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup uavobjectbrowser
* @{
*
*****************************************************************************/
/*
* 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 UAVOBJECTTREEMODEL_H
#define UAVOBJECTTREEMODEL_H
#include <QAbstractItemModel>
class TreeItem;
class TopTreeItem;
class UAVObject;
class UAVDataObject;
class UAVMetaObject;
class UAVObjectField;
class UAVObjectManager;
class UAVObjectTreeModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit UAVObjectTreeModel(QObject *parent = 0);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant & value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
signals:
public slots:
void newObject(UAVObject *obj);
private:
void addDataObject(UAVDataObject *obj);
void addMetaObject(UAVMetaObject *obj, TreeItem *parent);
void addArrayField(UAVObjectField *field, TreeItem *parent);
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
void addInstance(UAVObject *obj, TreeItem *parent);
QString updateMode(quint8 updateMode);
void setupModelData(UAVObjectManager *objManager);
TreeItem *rootItem;
TopTreeItem *m_settingsTree;
TopTreeItem *m_nonSettingsTree;
};
#endif // UAVOBJECTTREEMODEL_H