1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Added an editor gadget for pathactions and waypoints - based on James

waypointeditor - no storing or loading yet
This commit is contained in:
Corvus Corax 2012-05-29 22:48:17 +02:00
parent 1ad2b19d28
commit 7586a55fd6
21 changed files with 1747 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<plugin name="PathActionEditor" version="0.0.1" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2012 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>Allows editing a list of pathactions</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,75 @@
/**
******************************************************************************
*
* @file browseritemdelegate.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 "fieldtreeitem.h"
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
Q_UNUSED(option)
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QWidget *editor = item->createEditor(parent);
Q_ASSERT(editor);
return editor;
}
void BrowserItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QVariant value = index.model()->data(index, Qt::EditRole);
item->setEditorValue(editor, value);
}
void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
FieldTreeItem *item = static_cast<FieldTreeItem*>(index.internalPointer());
QVariant value = item->getEditorValue(editor);
model->setData(index, value, Qt::EditRole);
}
void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return QSpinBox().sizeHint();
}

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
*
* @file browseritemdelegate.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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;
QSize sizeHint(const QStyleOptionViewItem & option,
const QModelIndex &index) const;
signals:
public slots:
};
#endif // BROWSERITEMDELEGATE_H

View File

@ -0,0 +1,29 @@
/**
******************************************************************************
*
* @file fieldtreeitem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 "fieldtreeitem.h"

View File

@ -0,0 +1,273 @@
/**
******************************************************************************
*
* @file fieldtreeitem.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 FIELDTREEITEM_H
#define FIELDTREEITEM_H
#include "treeitem.h"
#include <QtCore/QStringList>
#include <QtGui/QWidget>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <qscispinbox/QScienceSpinBox.h>
#include <QtGui/QComboBox>
#include <limits>
#define QINT8MIN std::numeric_limits<qint8>::min()
#define QINT8MAX std::numeric_limits<qint8>::max()
#define QUINTMIN std::numeric_limits<quint8>::min()
#define QUINT8MAX std::numeric_limits<quint8>::max()
#define QINT16MIN std::numeric_limits<qint16>::min()
#define QINT16MAX std::numeric_limits<qint16>::max()
#define QUINT16MAX std::numeric_limits<quint16>::max()
#define QINT32MIN std::numeric_limits<qint32>::min()
#define QINT32MAX std::numeric_limits<qint32>::max()
#define QUINT32MAX std::numeric_limits<qint32>::max()
//#define USE_SCIENTIFIC_NOTATION
class FieldTreeItem : public TreeItem
{
Q_OBJECT
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 QWidget *createEditor(QWidget *parent) = 0;
virtual QVariant getEditorValue(QWidget *editor) = 0;
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
virtual void apply() { }
protected:
int m_index;
};
class EnumFieldTreeItem : public FieldTreeItem
{
Q_OBJECT
public:
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
void setData(QVariant value, int column) {
QStringList options = m_field->getOptions();
QVariant tmpValue = m_field->getValue(m_index);
int tmpValIndex = options.indexOf(tmpValue.toString());
TreeItem::setData(value, column);
setChanged(tmpValIndex != value);
}
QString enumOptions(int index) {
if((index < 0) || (index >= m_enumOptions.length())) {
return QString("Invalid Value (") + QString().setNum(index) + QString(")");
}
return m_enumOptions.at(index);
}
void apply() {
int value = data(dataColumn).toInt();
QStringList options = m_field->getOptions();
m_field->setValue(options[value], m_index);
setChanged(false);
}
void update() {
QStringList options = m_field->getOptions();
QVariant value = m_field->getValue(m_index);
int valIndex = options.indexOf(value.toString());
if (data() != valIndex || changed()) {
TreeItem::setData(valIndex);
setHighlight(true);
}
}
QWidget *createEditor(QWidget *parent) {
QComboBox *editor = new QComboBox(parent);
foreach (QString option, m_enumOptions)
editor->addItem(option);
return editor;
}
QVariant getEditorValue(QWidget *editor) {
QComboBox *comboBox = static_cast<QComboBox*>(editor);
return comboBox->currentIndex();
}
void setEditorValue(QWidget *editor, QVariant value) {
QComboBox *comboBox = static_cast<QComboBox*>(editor);
comboBox->setCurrentIndex(value.toInt());
}
private:
QStringList m_enumOptions;
UAVObjectField *m_field;
};
class IntFieldTreeItem : public FieldTreeItem
{
Q_OBJECT
public:
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) {
setMinMaxValues();
}
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) {
setMinMaxValues();
}
void setMinMaxValues() {
switch (m_field->getType()) {
case UAVObjectField::INT8:
m_minValue = QINT8MIN;
m_maxValue = QINT8MAX;
break;
case UAVObjectField::INT16:
m_minValue = QINT16MIN;
m_maxValue = QINT16MAX;
break;
case UAVObjectField::INT32:
m_minValue = QINT32MIN;
m_maxValue = QINT32MAX;
break;
case UAVObjectField::UINT8:
m_minValue = QUINTMIN;
m_maxValue = QUINT8MAX;
break;
case UAVObjectField::UINT16:
m_minValue = QUINTMIN;
m_maxValue = QUINT16MAX;
break;
case UAVObjectField::UINT32:
m_minValue = QUINTMIN;
m_maxValue = QUINT32MAX;
break;
default:
Q_ASSERT(false);
break;
}
}
QWidget *createEditor(QWidget *parent) {
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(m_minValue);
editor->setMaximum(m_maxValue);
return editor;
}
QVariant getEditorValue(QWidget *editor) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
return spinBox->value();
}
void setEditorValue(QWidget *editor, QVariant value) {
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value.toInt());
}
void setData(QVariant value, int column) {
QVariant old=m_field->getValue(m_index);
TreeItem::setData(value, column);
setChanged(old != value);
}
void apply() {
m_field->setValue(data(dataColumn).toInt(), m_index);
setChanged(false);
}
void update() {
int value = m_field->getValue(m_index).toInt();
if (data() != value || changed()) {
TreeItem::setData(value);
setHighlight(true);
}
}
private:
UAVObjectField *m_field;
int m_minValue;
int m_maxValue;
};
class FloatFieldTreeItem : public FieldTreeItem
{
Q_OBJECT
public:
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { }
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { }
void setData(QVariant value, int column) {
QVariant old=m_field->getValue(m_index);
TreeItem::setData(value, column);
setChanged(old != value);
}
void apply() {
m_field->setValue(data(dataColumn).toDouble(), m_index);
setChanged(false);
}
void update() {
double value = m_field->getValue(m_index).toDouble();
if (data() != value || changed()) {
TreeItem::setData(value);
setHighlight(true);
}
}
QWidget *createEditor(QWidget *parent) {
#ifdef USE_SCIENTIFIC_NOTATION
QScienceSpinBox *editor = new QScienceSpinBox(parent);
editor->setDecimals(6);
#else
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setDecimals(8);
#endif
editor->setMinimum(-std::numeric_limits<float>::max());
editor->setMaximum(std::numeric_limits<float>::max());
return editor;
}
QVariant getEditorValue(QWidget *editor) {
#ifdef USE_SCIENTIFIC_NOTATION
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
#else
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
#endif
spinBox->interpretText();
return spinBox->value();
}
void setEditorValue(QWidget *editor, QVariant value) {
#ifdef USE_SCIENTIFIC_NOTATION
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
#else
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
#endif
spinBox->setValue(value.toDouble());
}
private:
UAVObjectField *m_field;
};
#endif // FIELDTREEITEM_H

View File

@ -0,0 +1,32 @@
TEMPLATE = lib
TARGET = PathActionEditor
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
HEADERS += pathactioneditorgadget.h
HEADERS += pathactioneditorgadgetwidget.h
HEADERS += pathactioneditorgadgetfactory.h
HEADERS += pathactioneditorplugin.h
HEADERS += pathactioneditortreemodel.h
HEADERS += treeitem.h
HEADERS += fieldtreeitem.h
HEADERS += browseritemdelegate.h
SOURCES += pathactioneditorgadget.cpp
SOURCES += pathactioneditorgadgetwidget.cpp
SOURCES += pathactioneditorgadgetfactory.cpp
SOURCES += pathactioneditorplugin.cpp
SOURCES += pathactioneditortreemodel.cpp
SOURCES += treeitem.cpp
SOURCES += fieldtreeitem.cpp
SOURCES += browseritemdelegate.cpp
OTHER_FILES += pathactioneditor.pluginspec
FORMS += pathactioneditor.ui
RESOURCES += pathactioneditor.qrc

View File

@ -0,0 +1,3 @@
<RCC>
<qresource prefix="/pathactioneditor"/>
</RCC>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PathActionEditor</class>
<widget class="QWidget" name="PathActionEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>296</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeView" name="pathactions">
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonNewPathAction">
<property name="text">
<string>New PathAction</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,48 @@
/**
******************************************************************************
* @file pathactioneditorgadget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 "pathactioneditorgadget.h"
#include "pathactioneditorgadgetwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QDebug>
PathActionEditorGadget::PathActionEditorGadget(QString classId, PathActionEditorGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
PathActionEditorGadget::~PathActionEditorGadget()
{
delete m_widget;
}
void PathActionEditorGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
Q_UNUSED(config);
}

View File

@ -0,0 +1,59 @@
/**
******************************************************************************
* @file pathactioneditorgadget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 PathActionEditorGADGET_H_
#define PathActionEditorGADGET_H_
#include <coreplugin/iuavgadget.h>
namespace Core {
class IUAVGadget;
}
//class QWidget;
//class QString;
class PathActionEditorGadgetWidget;
using namespace Core;
class PathActionEditorGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
PathActionEditorGadget(QString classId, PathActionEditorGadgetWidget *widget, QWidget *parent = 0);
~PathActionEditorGadget();
QList<int> context() const { return m_context; }
QWidget *widget() { return m_widget; }
QString contextHelpId() const { return QString(); }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
QWidget *m_widget;
QList<int> m_context;
};
#endif // PathActionEditorGADGET_H_

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
* @file pathactioneditorgadgetfactor.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 "pathactioneditorgadgetfactory.h"
#include "pathactioneditorgadgetwidget.h"
#include "pathactioneditorgadget.h"
#include <coreplugin/iuavgadget.h>
#include <QDebug>
PathActionEditorGadgetFactory::PathActionEditorGadgetFactory(QObject *parent) :
IUAVGadgetFactory(QString("PathActionEditorGadget"),
tr("PathAction Editor"),
parent)
{
}
PathActionEditorGadgetFactory::~PathActionEditorGadgetFactory()
{
}
IUAVGadget* PathActionEditorGadgetFactory::createGadget(QWidget *parent) {
PathActionEditorGadgetWidget* gadgetWidget = new PathActionEditorGadgetWidget(parent);
return new PathActionEditorGadget(QString("PathActionEditorGadget"), gadgetWidget, parent);
}

View File

@ -0,0 +1,49 @@
/**
******************************************************************************
* @file pathactioneditorgadgetfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 PathActionEditorGADGETFACTORY_H_
#define PathActionEditorGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class PathActionEditorGadgetFactory : public IUAVGadgetFactory
{
Q_OBJECT
public:
PathActionEditorGadgetFactory(QObject *parent = 0);
~PathActionEditorGadgetFactory();
IUAVGadget *createGadget(QWidget *parent);
};
#endif // PathActionEditorGADGETFACTORY_H_

View File

@ -0,0 +1,93 @@
/**
******************************************************************************
* @file pathactioneditorgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 "pathactioneditorgadgetwidget.h"
#include "ui_pathactioneditor.h"
#include <QDebug>
#include <QString>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include "browseritemdelegate.h"
#include "extensionsystem/pluginmanager.h"
PathActionEditorGadgetWidget::PathActionEditorGadgetWidget(QWidget *parent) : QLabel(parent)
{
m_pathactioneditor = new Ui_PathActionEditor();
m_pathactioneditor->setupUi(this);
m_model = new PathActionEditorTreeModel();
m_pathactioneditor->pathactions->setModel(m_model);
m_pathactioneditor->pathactions->setColumnWidth(0, 300);
m_pathactioneditor->pathactions->expandAll();
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
m_pathactioneditor->pathactions->setItemDelegate(m_delegate);
m_pathactioneditor->pathactions->setEditTriggers(QAbstractItemView::AllEditTriggers);
m_pathactioneditor->pathactions->setSelectionBehavior(QAbstractItemView::SelectItems);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
pathactionObj = PathAction::GetInstance(objManager);
Q_ASSERT(pathactionObj != NULL);
// Connect the signals
connect(m_pathactioneditor->buttonNewPathAction, SIGNAL(clicked()),
this, SLOT(addInstance()));
}
PathActionEditorGadgetWidget::~PathActionEditorGadgetWidget()
{
// Do nothing
}
void PathActionEditorGadgetWidget::pathactionChanged(UAVObject *)
{
}
void PathActionEditorGadgetWidget::addInstance()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
qDebug() << "Instances before: " << objManager->getNumInstances(pathactionObj->getObjID());
PathAction *obj = new PathAction();
quint32 newInstId = objManager->getNumInstances(pathactionObj->getObjID());
obj->initialize(newInstId,obj->getMetaObject());
objManager->registerObject(obj);
qDebug() << "Instances after: " << objManager->getNumInstances(pathactionObj->getObjID());
}
/**
* @}
* @}
*/

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
* @file pathactioneditorgadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 PathActionEditorGADGETWIDGET_H_
#define PathActionEditorGADGETWIDGET_H_
#include <QtGui/QLabel>
#include <QtGui/QWidget>
#include <QtGui/QTreeView>
#include "pathaction.h"
#include "pathactioneditortreemodel.h"
class Ui_PathActionEditor;
class PathActionEditorGadgetWidget : public QLabel
{
Q_OBJECT
public:
PathActionEditorGadgetWidget(QWidget *parent = 0);
~PathActionEditorGadgetWidget();
signals:
protected slots:
void pathactionChanged(UAVObject *);
void addInstance();
private:
Ui_PathActionEditor * m_pathactioneditor;
PathActionEditorTreeModel *m_model;
PathAction *pathactionObj;
};
#endif /* PathActionEditorGADGETWIDGET_H_ */

View File

@ -0,0 +1,68 @@
/**
******************************************************************************
* @file pathactioneditorplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 "pathactioneditorplugin.h"
#include "pathactioneditorgadgetfactory.h"
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
PathActionEditorPlugin::PathActionEditorPlugin()
{
// Do nothing
}
PathActionEditorPlugin::~PathActionEditorPlugin()
{
// Do nothing
}
bool PathActionEditorPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new PathActionEditorGadgetFactory(this);
addAutoReleasedObject(mf);
return true;
}
void PathActionEditorPlugin::extensionsInitialized()
{
// Do nothing
}
void PathActionEditorPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(PathActionEditorPlugin)
/**
* @}
* @}
*/

View File

@ -0,0 +1,46 @@
/**
******************************************************************************
* @file pathactioneditorplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup PathAction Editor GCS Plugins
* @{
* @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
* @{
* @brief A gadget to edit a list of pathactions
*****************************************************************************/
/*
* 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 PathActionEditorPLUGIN_H_
#define PathActionEditorPLUGIN_H_
#include <extensionsystem/iplugin.h>
class PathActionEditorGadgetFactory;
class PathActionEditorPlugin : public ExtensionSystem::IPlugin
{
public:
PathActionEditorPlugin();
~PathActionEditorPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
PathActionEditorGadgetFactory *mf;
};
#endif /* PathActionEditorPLUGIN_H_ */

View File

@ -0,0 +1,359 @@
/**
******************************************************************************
*
* @file pathactioneditortreemodel.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 "pathactioneditortreemodel.h"
#include "pathactioneditorgadget.h"
#include "fieldtreeitem.h"
#include "uavobjectmanager.h"
#include "uavdataobject.h"
#include "uavmetaobject.h"
#include "uavobjectfield.h"
#include "extensionsystem/pluginmanager.h"
#include <QtGui/QColor>
//#include <QtGui/QIcon>
#include <QMessageBox>
#include <QtCore/QSignalMapper>
#include <QtCore/QDebug>
#include "waypoint.h"
#include "pathaction.h"
PathActionEditorTreeModel::PathActionEditorTreeModel(QObject *parent) :
QAbstractItemModel(parent),
m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255))
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
setupModelData(objManager);
}
PathActionEditorTreeModel::~PathActionEditorTreeModel()
{
delete m_rootItem;
}
void PathActionEditorTreeModel::setupModelData(UAVObjectManager *objManager)
{
// root
QList<QVariant> rootData;
rootData << tr("Property") << tr("Value") << tr("Unit");
m_rootItem = new TreeItem(rootData);
m_pathactionsTree = new TopTreeItem(tr("PathActions"), m_rootItem);
m_rootItem->appendChild(m_pathactionsTree);
m_waypointsTree = new TopTreeItem(tr("Waypoints"), m_rootItem);
m_rootItem->appendChild(m_waypointsTree);
connect(m_rootItem, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
connect(m_pathactionsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
connect(m_waypointsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
{
QList<UAVObject*> list = objManager->getObjectInstances("PathAction");
foreach (UAVObject* obj, list) {
addInstance(obj,m_pathactionsTree);
}
}
{
QList<UAVObject*> list = objManager->getObjectInstances("Waypoint");
foreach (UAVObject* obj, list) {
addInstance(obj,m_waypointsTree);
}
}
}
void PathActionEditorTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
{
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
TreeItem *item;
QString name = QString::number(obj->getInstID());
item = new InstanceTreeItem(obj, name);
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
parent->appendChild(item);
foreach (UAVObjectField *field, obj->getFields()) {
if (field->getNumElements() > 1) {
addArrayField(field, item);
} else {
addSingleField(0, field, item);
}
}
}
void PathActionEditorTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
{
TreeItem *item = new ArrayFieldTreeItem(field->getName());
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
for (uint i = 0; i < field->getNumElements(); ++i) {
addSingleField(i, field, item);
}
parent->appendChild(item);
}
void PathActionEditorTreeModel::addSingleField(int index, UAVObjectField *field, TreeItem *parent)
{
QList<QVariant> data;
if (field->getNumElements() == 1)
data.append(field->getName());
else
data.append( QString("[%1]").arg((field->getElementNames())[index]) );
FieldTreeItem *item;
UAVObjectField::FieldType type = field->getType();
switch (type) {
case UAVObjectField::ENUM: {
QStringList options = field->getOptions();
QVariant value = field->getValue();
data.append( options.indexOf(value.toString()) );
data.append(field->getUnits());
item = new EnumFieldTreeItem(field, index, data);
break;
}
case UAVObjectField::INT8:
case UAVObjectField::INT16:
case UAVObjectField::INT32:
case UAVObjectField::UINT8:
case UAVObjectField::UINT16:
case UAVObjectField::UINT32:
data.append(field->getValue(index));
data.append(field->getUnits());
item = new IntFieldTreeItem(field, index, data);
break;
case UAVObjectField::FLOAT32:
data.append(field->getValue(index));
data.append(field->getUnits());
item = new FloatFieldTreeItem(field, index, data);
break;
default:
Q_ASSERT(false);
}
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
parent->appendChild(item);
}
QModelIndex PathActionEditorTreeModel::index(int row, int column, const QModelIndex &parent)
const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
TreeItem *parentItem;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex PathActionEditorTreeModel::index(TreeItem *item)
{
if (item->parent() == 0)
return QModelIndex();
QModelIndex root = index(item->parent());
for (int i = 0; i < rowCount(root); ++i) {
QModelIndex childIndex = index(i, 0, root);
TreeItem *child = static_cast<TreeItem*>(childIndex.internalPointer());
if (child == item)
return childIndex;
}
Q_ASSERT(false);
return QModelIndex();
}
QModelIndex PathActionEditorTreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *parentItem = childItem->parent();
if (parentItem == m_rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int PathActionEditorTreeModel::rowCount(const QModelIndex &parent) const
{
TreeItem *parentItem;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
return parentItem->childCount();
}
int PathActionEditorTreeModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
else
return m_rootItem->columnCount();
}
QVariant PathActionEditorTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column());
}
// if (role == Qt::DecorationRole)
// return QIcon(":/core/images/openpilot_logo_128.png");
if (role == Qt::ToolTipRole) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->description();
}
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (index.column() == 0 && role == Qt::BackgroundRole) {
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item);
if (objItem && objItem->highlighted())
return QVariant(m_recentlyUpdatedColor);
}
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
if (fieldItem && fieldItem->highlighted())
return QVariant(m_recentlyUpdatedColor);
if (fieldItem && fieldItem->changed())
return QVariant(m_manuallyChangedColor);
}
if (role != Qt::DisplayRole)
return QVariant();
if (index.column() == TreeItem::dataColumn) {
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
if (fieldItem) {
int enumIndex = fieldItem->data(index.column()).toInt();
return fieldItem->enumOptions(enumIndex);
}
}
return item->data(index.column());
}
bool PathActionEditorTreeModel::setData(const QModelIndex &index, const QVariant & value, int role)
{
Q_UNUSED(role)
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setData(value, index.column());
return true;
}
Qt::ItemFlags PathActionEditorTreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
if (index.column() == TreeItem::dataColumn) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item->isEditable())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant PathActionEditorTreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return m_rootItem->data(section);
return QVariant();
}
void PathActionEditorTreeModel::updateHighlight(TreeItem *item)
{
QModelIndex itemIndex = index(item);
Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
// update uavobject if any - go up the tree until there is
ObjectTreeItem *objItem = 0;
TreeItem *searchItem = item;
while (searchItem) {
objItem = dynamic_cast<ObjectTreeItem*>(searchItem);
if (objItem)
break;
searchItem = searchItem->parent();
}
if (objItem) {
item->apply();
objItem->apply();
UAVObject *obj = objItem->object();
Q_ASSERT(obj);
obj->updated();
}
}
void PathActionEditorTreeModel::highlightUpdatedObject(UAVObject *obj)
{
Q_ASSERT(obj);
if (obj->getName().compare("Waypoint")==0) {
m_waypointsTree->update();
//emit dataChanged(index(m_waypointsTree), index(m_waypointsTree));
} else if (obj->getName().compare("PathAction")==0) {
m_pathactionsTree->update();
//emit dataChanged(index(m_pathactionsTree), index(m_pathactionsTree));
}
}
void PathActionEditorTreeModel::newInstance(UAVObject *obj)
{
if (obj->getName().compare("Waypoint")==0) {
addInstance(obj,m_waypointsTree);
m_waypointsTree->update();
} else if (obj->getName().compare("PathAction")==0) {
addInstance(obj,m_pathactionsTree);
m_pathactionsTree->update();
}
emit layoutChanged();
}

View File

@ -0,0 +1,93 @@
/**
******************************************************************************
*
* @file pathactioneditortreemodel.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 PATHACTIONEDITORTREEMODEL_H
#define PATHACTIONEDITORTREEMODEL_H
#include "treeitem.h"
#include <QAbstractItemModel>
#include <QtCore/QMap>
#include <QtGui/QColor>
class TopTreeItem;
class ObjectTreeItem;
class DataObjectTreeItem;
class UAVObject;
class UAVDataObject;
class UAVMetaObject;
class UAVObjectField;
class UAVObjectManager;
class QSignalMapper;
class QTimer;
class PathActionEditorTreeModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit PathActionEditorTreeModel(QObject *parent = 0);
~PathActionEditorTreeModel();
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;
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
signals:
public slots:
void newInstance(UAVObject *obj);
private slots:
void highlightUpdatedObject(UAVObject *obj);
void updateHighlight(TreeItem*);
private:
QModelIndex index(TreeItem *item);
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 *m_rootItem;
TopTreeItem *m_pathactionsTree;
TopTreeItem *m_waypointsTree;
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;
};
#endif // PATHACTIONEDITORTREEMODEL_H

View File

@ -0,0 +1,115 @@
/**
******************************************************************************
*
* @file treeitem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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) :
QObject(0),
m_data(data),
m_parent(parent),
m_highlight(false),
m_changed(false)
{
}
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
QObject(0),
m_parent(parent),
m_highlight(false),
m_changed(false)
{
m_data << data << "" << "";
}
TreeItem::~TreeItem()
{
qDeleteAll(m_children);
}
void TreeItem::appendChild(TreeItem *child)
{
m_children.append(child);
child->setParentTree(this);
}
void TreeItem::insert(int index, TreeItem *child)
{
m_children.insert(index, child);
child->setParentTree(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(QVariant value, int column)
{
m_data.replace(column, value);
}
void TreeItem::update() {
foreach(TreeItem *child, treeChildren())
child->update();
}
void TreeItem::apply() {
foreach(TreeItem *child, treeChildren())
child->apply();
}
void TreeItem::setHighlight(bool highlight) {
m_highlight = highlight;
m_changed = false;
}
void TreeItem::removeHighlight() {
m_highlight = false;
update();
}

View File

@ -0,0 +1,187 @@
/**
******************************************************************************
*
* @file treeitem.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
* @{
* @brief The UAVObject Browser gadget plugin
*****************************************************************************/
/*
* 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 "uavobject.h"
#include "uavmetaobject.h"
#include "uavobjectfield.h"
#include <QtCore/QList>
#include <QtCore/QVariant>
#include <QtCore/QObject>
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);
void insert(int index, TreeItem *child);
TreeItem *child(int row);
inline QList<TreeItem*> treeChildren() const { return m_children; }
int childCount() const;
int columnCount() const;
QVariant data(int column = 1) const;
QString description() { return m_description; }
void setDescription(QString d) { // Split around 40 characters
int idx = d.indexOf(" ",40);
d.insert(idx,QString("<br>"));
d.remove("@Ref", Qt::CaseInsensitive);
m_description = d;
}
// 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);
inline bool changed() { return m_changed; }
inline void setChanged(bool changed) { m_changed = changed; if(changed) emit updateHighlight(this); }
signals:
void updateHighlight(TreeItem*);
private slots:
void removeHighlight();
private:
QList<TreeItem*> m_children;
// m_data contains: [0] property name, [1] value, [2] unit
QList<QVariant> m_data;
QString m_description;
TreeItem *m_parent;
bool m_highlight;
bool m_changed;
public:
static const int dataColumn = 1;
private:
};
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) { }
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 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) { }
void setObject(UAVObject *obj) { m_obj = obj; setDescription(obj->getDescription()); }
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

View File

@ -134,6 +134,12 @@ plugin_qmlview.depends = plugin_coreplugin
plugin_qmlview.depends += plugin_uavobjects
SUBDIRS += plugin_qmlview
# PathAction Editor gadget
plugin_pathactioneditor.subdir = pathactioneditor
plugin_pathactioneditor.depends = plugin_coreplugin
plugin_pathactioneditor.depends += plugin_uavobjects
SUBDIRS += plugin_pathactioneditor
# Waypoint Editor gadget
plugin_waypointeditor.subdir = waypointeditor
plugin_waypointeditor.depends = plugin_coreplugin