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

GCS/UAVObjectBrowser: Implemented settings save/load actions and created the SettingsPersistence object

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@469 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-10 05:09:56 +00:00 committed by vassilis
parent bf792a8058
commit ad9227d7a4
15 changed files with 381 additions and 176 deletions

View File

@ -673,7 +673,7 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
}
enums.append( QString(" } %1Enum;\n")
.arg( info->fields[n]->name.toUpper() ) );
.arg( info->fields[n]->name ) );
}
}
outInclude.replace(QString("$(DATAENUM)"), enums);

View File

@ -1,155 +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>
<?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>476</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

@ -28,6 +28,7 @@
#include "uavobjecttreemodel.h"
#include "browseritemdelegate.h"
#include "ui_uavobjectbrowser.h"
#include "uavobjects/uavobjectmanager.h"
#include <QStringList>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
@ -35,6 +36,7 @@
#include <QtGui/QComboBox>
#include <QtCore/QDebug>
#include <QtGui/QItemEditorFactory>
#include "extensionsystem/pluginmanager.h"
UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent)
{
@ -50,6 +52,8 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
showMetaData(m_browser->metaCheckBox->isChecked());
connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(readSettings()));
}
UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
@ -79,4 +83,27 @@ void UAVObjectBrowserWidget::requestUpdate()
}
void UAVObjectBrowserWidget::saveSettings()
{
updateSettings(SettingsPersistence::OPERATION_SAVE);
}
void UAVObjectBrowserWidget::readSettings()
{
updateSettings(SettingsPersistence::OPERATION_LOAD);
}
void UAVObjectBrowserWidget::updateSettings(SettingsPersistence::OperationEnum op)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
SettingsPersistence* obj = dynamic_cast<SettingsPersistence*>( objManager->getObject(SettingsPersistence::NAME) );
if (obj != NULL)
{
SettingsPersistence::DataFields data;
data.Operation = op;
obj->setData(data);
obj->updated();
}
}

View File

@ -30,6 +30,7 @@
#include <QtGui/QWidget>
#include <QtGui/QTreeView>
#include "uavobjects/settingspersistence.h"
class QPushButton;
class Ui_UAVObjectBrowser;
@ -47,6 +48,8 @@ private slots:
void sendUpdate();
void requestUpdate();
void showMetaData(bool show);
void saveSettings();
void readSettings();
private:
@ -54,6 +57,8 @@ private:
QPushButton *m_sendUpdate;
Ui_UAVObjectBrowser *m_browser;
QAbstractItemModel *m_model;
void updateSettings(SettingsPersistence::OperationEnum op);
};
#endif /* UAVOBJECTBROWSERWIDGET_H_ */

View File

@ -33,8 +33,10 @@
#include "uavdataobject.h"
class ExampleObject1: public UAVDataObject
class UAVOBJECTS_EXPORT ExampleObject1: public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {
@ -50,7 +52,7 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } FIELD8Enum;
typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } Field8Enum;
// Constants

View File

@ -33,8 +33,10 @@
#include "uavdataobject.h"
class ExampleObject2: public UAVDataObject
class UAVOBJECTS_EXPORT ExampleObject2: public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {

View File

@ -33,8 +33,10 @@
#include "uavdataobject.h"
class ExampleSettings: public UAVDataObject
class UAVOBJECTS_EXPORT ExampleSettings: public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {
@ -45,7 +47,7 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } STEPDIRECTIONEnum;
typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } StepDirectionEnum;
// Constants

View File

@ -0,0 +1,82 @@
/**
******************************************************************************
*
* @file settingspersistence.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the SettingsPersistence object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: settingspersistence.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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 "settingspersistence.h"
#include "uavobjectfields.h"
const QString SettingsPersistence::NAME = QString("SettingsPersistence");
SettingsPersistence::SettingsPersistence(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
{
// Create fields
QList<UAVObjectField*> fields;
QStringList OperationEnumOptions;
OperationEnumOptions.append("Load");
OperationEnumOptions.append("Save");
fields.append(new UAVObjectFieldEnum(QString("Operation"), QString(""), 1, OperationEnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);
}
UAVObject::Metadata SettingsPersistence::getDefaultMetadata()
{
UAVObject::Metadata metadata;
metadata.gcsTelemetryAcked = 1;
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.flightTelemetryAcked = 1;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL;
metadata.flightTelemetryUpdatePeriod = 0;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER;
metadata.loggingUpdatePeriod = 0;
return metadata;
}
SettingsPersistence::DataFields SettingsPersistence::getData()
{
QMutexLocker locker(mutex);
return data;
}
void SettingsPersistence::setData(DataFields& data)
{
QMutexLocker locker(mutex);
this->data = data;
emit objectUpdatedAuto(this); // trigger object updated event
emit objectUpdated(this);
}
UAVDataObject* SettingsPersistence::clone(quint32 instID)
{
SettingsPersistence* obj = new SettingsPersistence();
obj->initialize(instID, this->getMetaObject());
return obj;
}

View File

@ -0,0 +1,71 @@
/**
******************************************************************************
*
* @file settingspersistence.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the SettingsPersistence object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: settingspersistence.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* 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 SETTINGSPERSISTENCE_H
#define SETTINGSPERSISTENCE_H
#include "uavdataobject.h"
class UAVOBJECTS_EXPORT SettingsPersistence: public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {
quint8 Operation;
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { OPERATION_LOAD=0, OPERATION_SAVE=1, } OperationEnum;
// Constants
static const quint32 OBJID = 3652432370U;
static const QString NAME;
static const bool ISSINGLEINST = 1;
static const bool ISSETTINGS = 0;
static const quint32 NUMBYTES = sizeof(DataFields);
// Functions
SettingsPersistence();
DataFields getData();
void setData(DataFields& data);
Metadata getDefaultMetadata();
UAVDataObject* clone(quint32 instID);
private:
DataFields data;
};
#endif // SETTINGSPERSISTENCE_H

View File

@ -220,7 +220,7 @@ QList <QList<UAVMetaObject*> > UAVObjectManager::getMetaObjects()
* Get a specific object given its name and instance ID
* @returns The object is found or NULL if not
*/
UAVObject* UAVObjectManager::getObject(QString& name, quint32 instId)
UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId)
{
return getObject(&name, 0, instId);
}
@ -237,7 +237,7 @@ UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId)
/**
* Helper function for the public getObject() functions.
*/
UAVObject* UAVObjectManager::getObject(QString* name, quint32 objId, quint32 instId)
UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId)
{
QMutexLocker locker(mutex);
// Check if this object type is already in the list
@ -266,7 +266,7 @@ UAVObject* UAVObjectManager::getObject(QString* name, quint32 objId, quint32 ins
/**
* Get all the instances of the object specified by name
*/
QList<UAVObject*> UAVObjectManager::getObjectInstances(QString& name)
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString& name)
{
return getObjectInstances(&name, 0);
}
@ -282,7 +282,7 @@ QList<UAVObject*> UAVObjectManager::getObjectInstances(quint32 objId)
/**
* Helper function for the public getObjectInstances()
*/
QList<UAVObject*> UAVObjectManager::getObjectInstances(QString* name, quint32 objId)
QList<UAVObject*> UAVObjectManager::getObjectInstances(const QString* name, quint32 objId)
{
QMutexLocker locker(mutex);
// Check if this object type is already in the list
@ -304,7 +304,7 @@ QList<UAVObject*> UAVObjectManager::getObjectInstances(QString* name, quint32 ob
/**
* Get the number of instances for an object given its name
*/
qint32 UAVObjectManager::getNumInstances(QString& name)
qint32 UAVObjectManager::getNumInstances(const QString& name)
{
return getNumInstances(&name, 0);
}
@ -320,7 +320,7 @@ qint32 UAVObjectManager::getNumInstances(quint32 objId)
/**
* Helper function for public getNumInstances
*/
qint32 UAVObjectManager::getNumInstances(QString* name, quint32 objId)
qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId)
{
QMutexLocker locker(mutex);
// Check if this object type is already in the list

View File

@ -48,11 +48,11 @@ public:
QList< QList<UAVObject*> > getObjects();
QList< QList<UAVDataObject*> > getDataObjects();
QList< QList<UAVMetaObject*> > getMetaObjects();
UAVObject* getObject(QString& name, quint32 instId = 0);
UAVObject* getObject(const QString& name, quint32 instId = 0);
UAVObject* getObject(quint32 objId, quint32 instId = 0);
QList<UAVObject*> getObjectInstances(QString& name);
QList<UAVObject*> getObjectInstances(const QString& name);
QList<UAVObject*> getObjectInstances(quint32 objId);
qint32 getNumInstances(QString& name);
qint32 getNumInstances(const QString& name);
qint32 getNumInstances(quint32 objId);
signals:
@ -66,9 +66,9 @@ private:
QMutex* mutex;
void addObject(UAVObject* obj);
UAVObject* getObject(QString* name, quint32 objId, quint32 instId);
QList<UAVObject*> getObjectInstances(QString* name, quint32 objId);
qint32 getNumInstances(QString* name, quint32 objId);
UAVObject* getObject(const QString* name, quint32 objId, quint32 instId);
QList<UAVObject*> getObjectInstances(const QString* name, quint32 objId);
qint32 getNumInstances(const QString* name, quint32 objId);
};

View File

@ -22,7 +22,8 @@ HEADERS += uavobjects_global.h \
uavobjectfielduint8.h \
uavobjectfielduint16.h \
uavobjectfielduint32.h \
uavobjectfields.h
uavobjectfields.h \
settingspersistence.h
SOURCES += uavobject.cpp \
uavmetaobject.cpp \
uavobjectmanager.cpp \
@ -41,6 +42,7 @@ SOURCES += uavobject.cpp \
uavobjectfieldfloat.cpp \
uavobjectfielduint8.cpp \
uavobjectfielduint16.cpp \
uavobjectfielduint32.cpp
uavobjectfielduint32.cpp \
settingspersistence.cpp
DEFINES += UAVOBJECTS_LIBRARY
OTHER_FILES += UAVObjects.pluginspec

View File

@ -33,6 +33,7 @@
#include "exampleobject1.h"
#include "exampleobject2.h"
#include "examplesettings.h"
#include "settingspersistence.h"
/**
@ -44,5 +45,6 @@ void UAVObjectsInitialize(UAVObjectManager* objMngr)
objMngr->registerObject( new ExampleObject1() );
objMngr->registerObject( new ExampleObject2() );
objMngr->registerObject( new ExampleSettings() );
objMngr->registerObject( new SettingsPersistence() );
}

View File

@ -33,8 +33,10 @@
#include "uavdataobject.h"
class $(NAME): public UAVDataObject
class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {

View File

@ -0,0 +1,8 @@
<xml>
<object name="SettingsPersistence" singleinstance="true" settings="false">
<field name="Operation" units="" type="enum" elements="1" options="Load,Save"/>
<telemetrygcs acked="true" updatemode="manual" period="0"/>
<telemetryflight acked="true" updatemode="manual" period="0"/>
<logging updatemode="never" period="0"/>
</object>
</xml>