1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-369 Settings Import/Export for the Airframe. Also sanitized UAV Object saving in flash in one central location in the uavobjectutils library.

This commit is contained in:
elafargue 2011-06-02 16:08:19 +02:00
parent f8b945401d
commit f4b19fe65a
31 changed files with 322 additions and 895 deletions

View File

@ -568,8 +568,7 @@ void ConfigAHRSWidget::saveAHRSCalibration()
UAVObjectField *field = obj->getField(QString("measure_var"));
field->setValue("SET");
obj->updated();
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}
FORCE_ALIGN_FUNC

View File

@ -1524,7 +1524,7 @@ bool ConfigAirframeWidget::setupMixer(double mixerFactors[8][3])
setupQuadMotor(channel, mixerFactors[i][0]*pFactor,
rFactor*mixerFactors[i][1], yFactor*mixerFactors[i][2]);
}
obj->updated();
// obj->updated();
return true;
}
@ -1568,7 +1568,7 @@ void ConfigAirframeWidget::setupMotors(QList<QString> motorList)
field = obj->getField(motor);
field->setValue(mmList.takeFirst()->currentText());
}
obj->updated(); // Save...
//obj->updated(); // Save...
}
@ -2026,14 +2026,12 @@ void ConfigAirframeWidget::sendAircraftUpdate()
m_aircraft->mrStatusLabel->setText("Error: Assign a Yaw channel");
return;
}
motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS";
setupMotors(motorList);
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorSettings")));
Q_ASSERT(obj);
field = obj->getField("FixedWingYaw1");
field->setValue(m_aircraft->triYawChannel->currentText());
// No need to send a obj->updated() here because setupMotors
// will do it.
motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS";
setupMotors(motorList);
// Motor 1 to 6, Y6 Layout:
// pitch roll yaw
@ -2112,10 +2110,13 @@ void ConfigAirframeWidget::sendAircraftUpdate()
field->setValue(m_aircraft->customMixerTable->item(5,i)->text(),ti);
}
obj->updated();
}
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("SystemSettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorSettings")));
obj->updated();
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
obj->updated();
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("SystemSettings")));
UAVObjectField* field = obj->getField(QString("AirframeType"));
field->setValue(airframeType);
obj->updated();

View File

@ -1195,11 +1195,9 @@ void ConfigccpmWidget::saveccpmUpdate()
ShowDisclaimer(0);
// Send update so that the latest value is saved
sendccpmUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("MixerSettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}
void ConfigccpmWidget::resizeEvent(QResizeEvent* event)
@ -1506,8 +1504,7 @@ void ConfigccpmWidget::SwashLvlFinishButtonPressed()
}
obj->updated();
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
//restore Flight control of ActuatorCommand
enableSwashplateLevellingControl(false);

View File

@ -508,11 +508,9 @@ void ConfigInputWidget::saveRCInputObject()
{
// Send update so that the latest value is saved
sendRCInputUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ManualControlSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}

View File

@ -534,11 +534,9 @@ void ConfigOutputWidget::saveRCOutputObject()
{
// Send update so that the latest value is saved
sendRCOutputUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ActuatorSettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}

View File

@ -262,11 +262,9 @@ void ConfigStabilizationWidget::saveStabilizationUpdate()
{
// Send update so that the latest value is saved
sendStabilizationUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("StabilizationSettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("StabilizationSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}

View File

@ -30,8 +30,6 @@
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent)
{
saveState = IDLE;
queue.clear();
}
ConfigTaskWidget::~ConfigTaskWidget()
@ -41,100 +39,13 @@ ConfigTaskWidget::~ConfigTaskWidget()
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
{
// Add to queue
queue.enqueue(obj);
// If queue length is one, then start sending (call sendNextObject)
// Otherwise, do nothing, it's sending anyway
if (queue.length()==1)
saveNextObject();
// saveObjectToSD is now handled by the UAVUtils plugin in one
// central place (and one central queue)
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectUtilManager* utilMngr = pm->getObject<UAVObjectUtilManager>();
utilMngr->saveObjectToSD(obj);
}
void ConfigTaskWidget::saveNextObject()
{
if ( queue.isEmpty() )
{
return;
}
Q_ASSERT(saveState == IDLE);
// Get next object from the queue
UAVObject* obj = queue.head();
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *)));
saveState = AWAITING_ACK;
if (obj != NULL)
{
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_SAVE;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID();
objper->setData(data);
objper->updated();
}
}
/**
* @brief Process the transactionCompleted message from Telemetry indicating request sent successfully
* @param[in] The object just transsacted. Must be ObjectPersistance
* @param[in] success Indicates that the transaction did not time out
*
* After a failed transaction (usually timeout) resends the save request. After a succesful
* transaction will then wait for a save completed update from the autopilot.
*/
void ConfigTaskWidget::objectPersistenceTransactionCompleted(UAVObject* obj, bool success)
{
if(success) {
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
Q_ASSERT(saveState == AWAITING_ACK);
saveState = AWAITING_COMPLETED;
disconnect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
} else if (!success) {
// Can be caused by timeout errors on sending. Send again.
saveNextObject();
}
}
/**
* @brief Process the ObjectPersistence updated message to confirm the right object saved
* then requests next object be saved.
* @param[in] The object just received. Must be ObjectPersistance
*/
void ConfigTaskWidget::objectPersistenceUpdated(UAVObject * obj)
{
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
if(saveState == AWAITING_COMPLETED) {
// Check flight is saying it completed. This is the only thing flight should do to trigger an update.
Q_ASSERT( obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 );
// Check right object saved
UAVObject* savingObj = queue.head();
Q_ASSERT( obj->getField("ObjectID")->getValue() == savingObj->getObjID() );
obj->disconnect(this);
queue.dequeue(); // We can now remove the object, it's done.
saveState = IDLE;
saveNextObject();
}
}
void ConfigTaskWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj)
{
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
if (obj != NULL)
{
ObjectPersistence::DataFields data;
data.Operation = op;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID();
objper->setData(data);
objper->updated();
}
}
UAVObjectManager* ConfigTaskWidget::getObjectManager() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();

View File

@ -31,7 +31,7 @@
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "objectpersistence.h"
#include "uavobjectutilmanager.h"
#include <QQueue>
#include <QtGui/QWidget>
#include <QList>
@ -45,20 +45,12 @@ public:
ConfigTaskWidget(QWidget *parent = 0);
~ConfigTaskWidget();
void saveObjectToSD(UAVObject *obj);
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
UAVObjectManager* getObjectManager();
static double listMean(QList<double> list);
private slots:
void objectPersistenceTransactionCompleted(UAVObject* obj, bool success);
void objectPersistenceUpdated(UAVObject * obj);
private:
QQueue<UAVObject*> queue;
void saveNextObject();
enum {IDLE, AWAITING_ACK, AWAITING_COMPLETED} saveState;
};

View File

@ -84,9 +84,7 @@ void ConfigTelemetryWidget::requestTelemetryUpdate()
*/
void ConfigTelemetryWidget::sendTelemetryUpdate()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("TelemetrySettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("TelemetrySettings")));
Q_ASSERT(obj);
UAVObjectField* field = obj->getField(QString("Speed"));
field->setValue(m_telemetry->telemetrySpeed->currentText());
@ -100,11 +98,9 @@ void ConfigTelemetryWidget::saveTelemetryUpdate()
{
// Send update so that the latest value is saved
sendTelemetryUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("TelemetrySettings")));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("TelemetrySettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
}

View File

@ -7,18 +7,9 @@ include(importexport_dependencies.pri)
HEADERS += importexportplugin.h \
importexportgadgetwidget.h \
importexportdialog.h
HEADERS += importexportgadget.h
HEADERS += importexportgadgetfactory.h
HEADERS += importexportgadgetconfiguration.h
HEADERS += importexportgadgetoptionspage.h
SOURCES += importexportplugin.cpp \
importexportgadgetwidget.cpp \
importexportdialog.cpp
SOURCES += importexportgadget.cpp
SOURCES += importexportgadgetfactory.cpp
SOURCES += importexportgadgetconfiguration.cpp
SOURCES += importexportgadgetoptionspage.cpp
OTHER_FILES += ImportExportGadget.pluginspec
FORMS += importexportgadgetoptionspage.ui \
importexportgadgetwidget.ui \
FORMS += importexportgadgetwidget.ui \
importexportdialog.ui

View File

@ -1,12 +1,11 @@
#include "importexportdialog.h"
#include "ui_importexportdialog.h"
ImportExportDialog::ImportExportDialog( ImportExportGadgetConfiguration *config, QWidget *parent) :
ImportExportDialog::ImportExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportExportDialog)
{
ui->setupUi(this);
ui->widget->loadConfiguration(config);
setWindowTitle(tr("Import Export Settings"));
connect( ui->widget, SIGNAL(done()), this, SLOT(close()));

View File

@ -27,7 +27,6 @@
#define IMPORTEXPORTDIALOG_H
#include <QDialog>
#include "importexportgadgetconfiguration.h"
namespace Ui {
class ImportExportDialog;
@ -38,7 +37,7 @@ class ImportExportDialog : public QDialog
Q_OBJECT
public:
explicit ImportExportDialog( ImportExportGadgetConfiguration *config, QWidget *parent = 0);
explicit ImportExportDialog(QWidget *parent = 0);
~ImportExportDialog();
protected:

View File

@ -23,7 +23,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>

View File

@ -1,76 +0,0 @@
/**
******************************************************************************
*
* @file importexportgadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @brief Configuration for Import/Export Plugin
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*
*****************************************************************************/
/*
* 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 "importexportgadgetconfiguration.h"
static const QString VERSION = "1.0.1";
/**
* Loads a saved configuration or defaults if non exist.
*
*/
ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, QSettings* qSettings, UAVConfigInfo *configInfo, QObject *parent) :
IUAVGadgetConfiguration(classId, parent)
{
if ( ! qSettings )
return;
if ( configInfo->version() == UAVConfigVersion() )
configInfo->setVersion("1.0.0");
if ( !configInfo->standardVersionHandlingOK(VERSION))
return;
iniFile = qSettings->value("iniFile", "gcs.xml").toString();
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
{
ImportExportGadgetConfiguration *m = new ImportExportGadgetConfiguration(this->classId());
m->iniFile = iniFile;
return m;
}
/**
* Saves a configuration.
*
*/
void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) const {
configInfo->setVersion(VERSION);
qSettings->setValue("iniFile", iniFile);
}
/**
* @}
* @}
*/

View File

@ -1,65 +0,0 @@
/**
******************************************************************************
* @file
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*****************************************************************************/
/*
* 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 IMPORTEXPORTGADGETCONFIGURATION_H
#define IMPORTEXPORTGADGETCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
#include "importexport_global.h"
using namespace Core;
/* This is a generic bargraph dial
supporting one indicator.
*/
class IMPORTEXPORT_EXPORT ImportExportGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
ImportExportGadgetConfiguration(QString classId, QSettings* qSettings = 0, UAVConfigInfo *configInfo = 0, QObject *parent = 0);
//set dial configuration functions
void setIniFile(QString filename) {
iniFile = filename;
}
//get dial configuration functions
QString getIniFile() const{
return iniFile;
}
void saveConfig(QSettings* settings, Core::UAVConfigInfo *configInfo) const;
IUAVGadgetConfiguration *clone();
private:
QString iniFile;
};
#endif // IMPORTEXPORTGADGETCONFIGURATION_H
/**
* @}
* @}
*/

View File

@ -1,67 +0,0 @@
/**
******************************************************************************
*
* @file importexportgadgetfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @brief Factory for Import/Export Plugin
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*
*****************************************************************************/
/*
* 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 "importexportgadgetfactory.h"
#include "importexportgadgetwidget.h"
#include "importexportgadget.h"
#include "importexportgadgetconfiguration.h"
#include "importexportgadgetoptionspage.h"
#include <coreplugin/iuavgadget.h>
ImportExportGadgetFactory::ImportExportGadgetFactory(QObject *parent) :
IUAVGadgetFactory(QString("ImportExportGadget"),
tr("Import/Export GCS Config"),
parent)
{
}
ImportExportGadgetFactory::~ImportExportGadgetFactory()
{
}
Core::IUAVGadget* ImportExportGadgetFactory::createGadget(QWidget *parent)
{
ImportExportGadgetWidget* gadgetWidget = new ImportExportGadgetWidget(parent);
return new ImportExportGadget(QString("ImportExportGadget"), gadgetWidget, parent);
}
IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(QSettings* qSettings, UAVConfigInfo *configInfo)
{
lastConfig = new ImportExportGadgetConfiguration(QString("ImportExportGadget"), qSettings, configInfo);
return lastConfig;
}
IOptionsPage *ImportExportGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{
return new ImportExportGadgetOptionsPage(qobject_cast<ImportExportGadgetConfiguration*>(config));
}
/**
* @}
* @}
*/

View File

@ -1,61 +0,0 @@
/**
******************************************************************************
* @file
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*****************************************************************************/
/*
* 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 IMPORTEXPORTGADGETFACTORY_H_
#define IMPORTEXPORTGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
#include "importexportgadgetconfiguration.h"
namespace Core
{
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class IMPORTEXPORT_EXPORT ImportExportGadgetFactory : public IUAVGadgetFactory
{
Q_OBJECT
public:
ImportExportGadgetFactory(QObject *parent = 0);
~ImportExportGadgetFactory();
ImportExportGadgetConfiguration *getLastConfig(){ return lastConfig;}
Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(QSettings *qSettings, UAVConfigInfo *configInfo);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
private:
ImportExportGadgetConfiguration *lastConfig;
};
#endif // IMPORTEXPORTGADGETFACTORY_H_
/**
* @}
* @}
*/

View File

@ -1,81 +0,0 @@
/**
******************************************************************************
*
* @file importexportgadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @brief Option page for Import/Export Plugin
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*
*****************************************************************************/
/*
* 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 "importexportgadgetoptionspage.h"
#include "importexportgadgetconfiguration.h"
#include "ui_importexportgadgetoptionspage.h"
#include <QFileDialog>
#include <QtDebug>
ImportExportGadgetOptionsPage::ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
//creates options page widget (uses the UI file)
QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
{
options_page = new Ui::ImportExportGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
// Restore the contents from the settings:
options_page->iniFile->setExpectedKind(Utils::PathChooser::File);
options_page->iniFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)"));
options_page->iniFile->setPromptDialogTitle(tr("Choose configuration file"));
options_page->iniFile->setPath(m_config->getIniFile());
return optionsPageWidget;
}
/**
* Called when the user presses apply or OK.
*
* Saves the current values
*
*/
void ImportExportGadgetOptionsPage::apply()
{
m_config->setIniFile(options_page->iniFile->path());
}
void ImportExportGadgetOptionsPage::finish()
{
}
/**
* @}
* @}
*/

View File

@ -1,74 +0,0 @@
/**
******************************************************************************
* @file
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @{
*****************************************************************************/
/*
* 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 IMPORTEXPORTGADGETOPTIONSPAGE_H
#define IMPORTEXPORTGADGETOPTIONSPAGE_H
#include "importexport_global.h"
#include "coreplugin/dialogs/ioptionspage.h"
#include <QString>
#include <QFont>
#include <QStringList>
#include <QDebug>
namespace Core
{
class IUAVGadgetConfiguration;
}
class ImportExportGadgetConfiguration;
namespace Ui
{
class ImportExportGadgetOptionsPage;
}
using namespace Core;
class IMPORTEXPORT_EXPORT ImportExportGadgetOptionsPage : public IOptionsPage
{
Q_OBJECT
public:
explicit ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent);
void apply();
void finish();
private:
Ui::ImportExportGadgetOptionsPage *options_page;
ImportExportGadgetConfiguration *m_config;
QFont font;
private slots:
};
#endif // IMPORTEXPORTGADGETOPTIONSPAGE_H
/**
* @}
* @}
*/

View File

@ -1,103 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportExportGadgetOptionsPage</class>
<widget class="QWidget" name="ImportExportGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<height>300</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>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>485</width>
<height>339</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Default Config File </string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="iniFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -48,10 +48,9 @@ ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) :
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
ui->setupUi(this);
ui->configFile->setExpectedKind(Utils::PathChooser::File);
ui->configFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)"));
ui->configFile->setPromptDialogFilter(tr("XML file (*.xml)"));
ui->configFile->setPromptDialogTitle(tr("Choose configuration file"));
}
ImportExportGadgetWidget::~ImportExportGadgetWidget()
@ -70,17 +69,22 @@ void ImportExportGadgetWidget::changeEvent(QEvent *e)
break;
}
}
void ImportExportGadgetWidget::loadConfiguration(const ImportExportGadgetConfiguration* config)
{
if ( !config )
return;
ui->configFile->setPath(config->getIniFile());
}
void ImportExportGadgetWidget::on_exportButton_clicked()
{
QString file = ui->configFile->path();
if (file.isEmpty()) {
QMessageBox msgBox;
msgBox.setText(tr("Empty File name."));
msgBox.setInformativeText(tr("Please choose an export file name."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
// Add a "XML" extension to the file in case it does not exist:
if (!file.endsWith(".xml"))
file.append(".xml");
qDebug() << "Export pressed! Write to file " << QFileInfo(file).absoluteFilePath();
if ( QFileInfo(file).exists() ){
@ -133,18 +137,7 @@ void ImportExportGadgetWidget::exportConfiguration(const QString& fileName)
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings::Format format;
if ( ui->radioButtonIniFormat->isChecked() ){
format = QSettings::IniFormat;
}
else if ( ui->radioButtonXmlFormat->isChecked() ){
format = XmlConfig::XmlSettingsFormat;
}
else {
qWarning() << "Program Error in ImportExportGadgetWidget::exportConfiguration: unknown format. Assume XML!";
format = XmlConfig::XmlSettingsFormat;
}
QSettings::Format format = XmlConfig::XmlSettingsFormat;
QSettings qs(fileName, format);
if (doGeneral) {
@ -193,19 +186,7 @@ void ImportExportGadgetWidget::importConfiguration(const QString& fileName)
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings::Format format;
if ( ui->radioButtonIniFormat->isChecked() ){
format = QSettings::IniFormat;
}
else if ( ui->radioButtonXmlFormat->isChecked() ){
format = XmlConfig::XmlSettingsFormat;
}
else {
qWarning() << "Program Error in ImportExportGadgetWidget::exportConfiguration: unknown format. Assume XML!";
format = XmlConfig::XmlSettingsFormat;
}
QSettings qs(fileName, format);
QSettings qs(fileName, XmlConfig::XmlSettingsFormat);
if ( doAllGadgets ) {
Core::ICore::instance()->uavGadgetInstanceManager()->readSettings(&qs);

View File

@ -13,8 +13,8 @@
#include <QWidget>
#include <QString>
#include "importexport_global.h"
#include <coreplugin/iconfigurableplugin.h>
#include "importexportgadgetconfiguration.h"
namespace Ui
{
@ -28,8 +28,6 @@ public:
ImportExportGadgetWidget(QWidget *parent = 0);
~ImportExportGadgetWidget();
void loadConfiguration(const ImportExportGadgetConfiguration* config);
signals:
void done();

View File

@ -82,8 +82,50 @@
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="helpButton">
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/helpicon.svg</normaloff>:/core/images/helpicon.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="toolTip">
<string>Export the GCS settings selected in the checkboxes above.</string>
</property>
<property name="text">
<string>Export</string>
</property>
@ -91,6 +133,9 @@
</item>
<item>
<widget class="QPushButton" name="importButton">
<property name="toolTip">
<string>Import settings from the config file, only for the items checked above.</string>
</property>
<property name="text">
<string>Import</string>
</property>
@ -98,46 +143,16 @@
</item>
<item>
<widget class="QPushButton" name="resetButton">
<property name="toolTip">
<string>Resets your GCS configuration to its default configuration.</string>
</property>
<property name="text">
<string>Reset Config</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="helpButton">
<property name="text">
<string>Help</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBoxFormat">
<property name="title">
<string>Format</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="radioButtonXmlFormat">
<property name="text">
<string>XML Format</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonIniFormat">
<property name="text">
<string>INI Format</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -148,6 +163,8 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../coreplugin/core.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -4,7 +4,7 @@
* @file importexportplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @brief Import/Export Plugin
* @brief Import/Export Plugin for GCS Settings
* @addtogroup GCSPlugins GCS Plugins
* @{
* @defgroup importexportplugin
@ -28,7 +28,6 @@
*/
#include "importexportplugin.h"
#include "importexportgadgetfactory.h"
#include "importexportdialog.h"
#include <QDebug>
#include <QtPlugin>
@ -55,8 +54,6 @@ bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new ImportExportGadgetFactory(this);
addAutoReleasedObject(mf);
// Add Menu entry
Core::ActionManager* am = Core::ICore::instance()->actionManager();
@ -82,7 +79,7 @@ bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg)
void ImportExportPlugin::importExport()
{
ImportExportDialog(mf->getLastConfig()).exec();
ImportExportDialog().exec();
}
void ImportExportPlugin::extensionsInitialized()

View File

@ -30,8 +30,6 @@
#include <extensionsystem/iplugin.h>
#include "importexport_global.h"
class ImportExportGadgetFactory;
class IMPORTEXPORT_EXPORT ImportExportPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
@ -44,7 +42,6 @@ public:
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
ImportExportGadgetFactory *mf;
private slots:
void importExport();

View File

@ -58,64 +58,101 @@ UAVObjectUtilManager::~UAVObjectUtilManager()
}
}
UAVObjectManager* UAVObjectUtilManager::getObjectManager() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
Q_ASSERT(objMngr);
return objMngr;
}
// ******************************
// SD card saving
//
void UAVObjectUtilManager::saveObjectToSD(UAVObject *obj)
{
QMutexLocker locker(mutex);
// Add to queue
queue.enqueue(obj);
// If queue length is one, then start sending (call sendNextObject)
// Otherwise, do nothing, it's sending anyway
if (queue.length()==1)
saveNextObject();
if (!obj) return;
// Add to queue
queue.enqueue(obj);
// If queue length is one, then start sending (call sendNextObject)
// Otherwise, do nothing, it's sending anyway
if (queue.length() <= 1)
saveNextObject();
}
void UAVObjectUtilManager::saveNextObject()
{
if (queue.isEmpty()) return;
if ( queue.isEmpty() )
{
return;
}
// Get next object from the queue
UAVObject *obj = queue.head();
if (!obj) return;
Q_ASSERT(saveState == IDLE);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
if (!pm) return;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
if (!om) return;
ObjectPersistence *objper = dynamic_cast<ObjectPersistence *>(om->getObject(ObjectPersistence::NAME));
connect(objper, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transactionCompleted(UAVObject *, bool)));
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_SAVE;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID();
objper->setData(data);
objper->updated();
// Get next object from the queue
UAVObject* obj = queue.head();
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *)));
saveState = AWAITING_ACK;
if (obj != NULL)
{
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_SAVE;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID();
objper->setData(data);
objper->updated();
}
}
void UAVObjectUtilManager::transactionCompleted(UAVObject *obj, bool success)
/**
* @brief Process the transactionCompleted message from Telemetry indicating request sent successfully
* @param[in] The object just transsacted. Must be ObjectPersistance
* @param[in] success Indicates that the transaction did not time out
*
* After a failed transaction (usually timeout) resends the save request. After a succesful
* transaction will then wait for a save completed update from the autopilot.
*/
void UAVObjectUtilManager::objectPersistenceTransactionCompleted(UAVObject* obj, bool success)
{
Q_UNUSED(success);
QMutexLocker locker(mutex);
if (!obj) return;
// Disconnect from sending object
obj->disconnect(this);
queue.dequeue(); // We can now remove the object, it's done.
saveNextObject();
if(success) {
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
Q_ASSERT(saveState == AWAITING_ACK);
saveState = AWAITING_COMPLETED;
disconnect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
} else if (!success) {
// Can be caused by timeout errors on sending. Send again.
saveNextObject();
}
}
/**
* @brief Process the ObjectPersistence updated message to confirm the right object saved
* then requests next object be saved.
* @param[in] The object just received. Must be ObjectPersistance
*/
void UAVObjectUtilManager::objectPersistenceUpdated(UAVObject * obj)
{
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
if(saveState == AWAITING_COMPLETED) {
// Check flight is saying it completed. This is the only thing flight should do to trigger an update.
Q_ASSERT( obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 );
// Check right object saved
UAVObject* savingObj = queue.head();
Q_ASSERT( obj->getField("ObjectID")->getValue() == savingObj->getObjID() );
obj->disconnect(this);
queue.dequeue(); // We can now remove the object, it's done.
saveState = IDLE;
saveNextObject();
}
}
/**
* Get the UAV Board model, for anyone interested. Return format is:
* (Board Type << 8) + BoardRevision.

View File

@ -63,17 +63,21 @@ public:
int getBoardModel();
QByteArray getBoardCPUSerial();
QString getBoardDescription();
UAVObjectManager* getObjectManager();
void saveObjectToSD(UAVObject *obj);
private:
QMutex *mutex;
QQueue<UAVObject *> queue;
enum {IDLE, AWAITING_ACK, AWAITING_COMPLETED} saveState;
void saveNextObject();
void saveObjectToSD(UAVObject *obj);
private slots:
void transactionCompleted(UAVObject *obj, bool success);
//void transactionCompleted(UAVObject *obj, bool success);
void objectPersistenceTransactionCompleted(UAVObject* obj, bool success);
void objectPersistenceUpdated(UAVObject * obj);
};

View File

@ -36,6 +36,7 @@
#include <QtPlugin>
#include <QStringList>
#include <QDebug>
// for menu item
#include <coreplugin/coreconstants.h>
@ -74,20 +75,21 @@ bool UAVSettingsImportExportPlugin::initialize(const QStringList& args, QString
Core::ActionManager* am = Core::ICore::instance()->actionManager();
Core::ActionContainer* ac = am->actionContainer(Core::Constants::M_FILE);
Core::Command* cmd = am->registerAction(new QAction(this),
"UAVSettingsImportExportPlugin.UAVSettingsImportExport",
"UAVSettingsImportExportPlugin.UAVSettingsExport",
QList<int>() <<
Core::Constants::C_GLOBAL_ID);
cmd->setDefaultKeySequence(QKeySequence("Ctrl+E"));
cmd->setDefaultKeySequence(QKeySequence("Ctrl+E"));
cmd->action()->setText(tr("Export UAV Settings..."));
ac->addAction(cmd, Core::Constants::G_FILE_SAVE);
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportUAVSettings()));
// cmd->action()->setText(tr("UAV Settings Import/Export..."));
cmd->action()->setText(tr("UAV Settings Export..."));
// ac->menu()->addSeparator();
// ac->appendGroup("ImportExport");
// ac->addAction(cmd, "ImportExport");
ac->addAction(cmd, Core::Constants::G_FILE_SAVE);
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importExport()));
cmd = am->registerAction(new QAction(this),
"UAVSettingsImportExportPlugin.UAVSettingsImport",
QList<int>() <<
Core::Constants::C_GLOBAL_ID);
cmd->action()->setText(tr("Import UAV Settings..."));
ac->addAction(cmd, Core::Constants::G_FILE_SAVE);
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importUAVSettings()));
return true;
}
@ -97,39 +99,106 @@ void UAVSettingsImportExportPlugin::extensionsInitialized()
// Do nothing
}
// Slot called by the menu manager on user action
// TODO: import function is not implemented yet
void UAVSettingsImportExportPlugin::importExport()
void UAVSettingsImportExportPlugin::importUAVSettings()
{
// available formats
enum { UNDEF, UAV, XML, INI } fileFormat = UNDEF;
// ask for file name and export format
// ask for file name
QString fileName;
QString filters = tr("UAV Settings files (*.uav)")
+ ";;" + tr("Simple XML files (*.xml)")
+ ";;" + tr("INI files (*.ini)");
fileName = QFileDialog::getSaveFileName(0, tr("Save UAV Settings File As"), "", filters);
QString filters = tr("UAVSettings XML files (*.xml)");
fileName = QFileDialog::getOpenFileName(0, tr("Import UAV Settings"), "", filters);
if (fileName.isEmpty()) {
return;
}
// check export file format
QFileInfo fileInfo(fileName);
QString fileType = fileInfo.suffix().toLower();
// Now open the file
QFile file(fileName);
QDomDocument doc("UAVSettings");
file.open(QFile::ReadOnly|QFile::Text);
if (!doc.setContent(file.readAll())) {
QMessageBox msgBox;
msgBox.setText(tr("File Parsing Failed."));
msgBox.setInformativeText(tr("This file is not a correct XML file"));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
file.close();
if (fileType == "uav") {
fileFormat = UAV;
} else if (fileType == "xml") {
fileFormat = XML;
} else if (fileType == "ini") {
fileFormat = INI;
} else {
QMessageBox::critical(0,
tr("UAV Settings Export"),
tr("Unsupported export file format: ") + fileType,
QMessageBox::Ok);
QDomElement root = doc.documentElement();
if (root.tagName() != "settings") {
QMessageBox msgBox;
msgBox.setText(tr("Wrong file contents."));
msgBox.setInformativeText(tr("This file is not a correct UAVSettings file"));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVObjectUtilManager *utilManager = pm->getObject<UAVObjectUtilManager>();
QDomNode node = root.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
if (e.tagName() == "object") {
// - Read each object
QString uavObjectName = e.attribute("name");
uint uavObjectID = e.attribute("id").toUInt(NULL,16);
// Sanity Check:
UAVObject* obj = objManager->getObject(uavObjectName);
if (uavObjectID != obj->getObjID()) {
qDebug() << "Mismatch for Object " << uavObjectName << uavObjectID << " - " << obj->getObjID();
QMessageBox msgBox;
msgBox.setText(tr("File Object Mismatch: aborting."));
msgBox.setInformativeText(tr("Found a mismatch between file object definition and current object definition."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
} else {
// - Update each field
// - Issue and "updated" command
QDomNode field = node.firstChild();
while(!field.isNull()) {
QDomElement f = field.toElement();
if (f.tagName() == "field") {
UAVObjectField *uavfield = obj->getField(f.attribute("name"));
if (f.attribute("elements").toInt() == 1) {
uavfield->setValue(f.attribute("values"));
} else {
// This is an enum:
int i=0;
QStringList list = f.attribute("values").split(",");
foreach (QString element, list) {
uavfield->setValue(element,i++);
}
}
}
field = field.nextSibling();
}
obj->updated();
utilManager->saveObjectToSD(obj);
}
}
node = node.nextSibling();
}
QMessageBox msgBox;
msgBox.setText(tr("Settings restored."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
// Slot called by the menu manager on user action
void UAVSettingsImportExportPlugin::exportUAVSettings()
{
// ask for file name
QString fileName;
QString filters = tr("UAVSettings XML files (*.xml)");
fileName = QFileDialog::getSaveFileName(0, tr("Save UAV Settings File As"), "", filters);
if (fileName.isEmpty()) {
return;
}
@ -152,12 +221,10 @@ void UAVSettingsImportExportPlugin::importExport()
QDomElement o = doc.createElement("object");
o.setAttribute("name", obj->getName());
o.setAttribute("id", QString("0x")+ QString().setNum(obj->getObjID(),16).toUpper());
if (fileFormat == UAV) {
QDomElement d = doc.createElement("description");
QDomText t = doc.createTextNode(obj->getDescription().remove("@Ref ", Qt::CaseInsensitive));
d.appendChild(t);
o.appendChild(d);
}
QDomElement d = doc.createElement("description");
QDomText t = doc.createTextNode(obj->getDescription().remove("@Ref ", Qt::CaseInsensitive));
d.appendChild(t);
o.appendChild(d);
// iterate over fields
QList<UAVObjectField*> fieldList = obj->getFields();
@ -175,13 +242,11 @@ void UAVSettingsImportExportPlugin::importExport()
f.setAttribute("name", field->getName());
f.setAttribute("values", vals);
if (fileFormat == UAV) {
f.setAttribute("type", field->getTypeAsString());
f.setAttribute("units", field->getUnits());
f.setAttribute("elements", nelem);
if (field->getType() == UAVObjectField::ENUM) {
f.setAttribute("options", field->getOptions().join(","));
}
f.setAttribute("type", field->getTypeAsString());
f.setAttribute("units", field->getUnits());
f.setAttribute("elements", nelem);
if (field->getType() == UAVObjectField::ENUM) {
f.setAttribute("options", field->getOptions().join(","));
}
o.appendChild(f);
}
@ -189,48 +254,23 @@ void UAVSettingsImportExportPlugin::importExport()
}
}
}
// save file
if ((fileFormat == UAV) || (fileFormat == XML)) {
QFile file(fileName);
if (file.open(QIODevice::WriteOnly) &&
(file.write(doc.toString(4).toAscii()) != -1)) {
file.close();
} else {
QMessageBox::critical(0,
tr("UAV Settings Export"),
tr("Unable to save settings: ") + fileName,
QMessageBox::Ok);
return;
}
} else if (fileFormat == INI) {
if (QFile::exists(fileName) && !QFile::remove(fileName)) {
QMessageBox::critical(0,
tr("UAV Settings Export"),
tr("Unable to remove existing file: ") + fileName,
QMessageBox::Ok);
return;
}
QSettings ini(fileName, QSettings::IniFormat);
QDomElement docElem = doc.documentElement();
QDomNodeList nodeList = docElem.elementsByTagName("object");
for (int i = 0; i < nodeList.count(); i++) {
QDomElement e = nodeList.at(i).toElement();
if (!e.isNull()) {
ini.beginGroup(e.attribute("name", "undefined"));
ini.setValue("id", e.attribute("id"));
QDomNodeList n = e.elementsByTagName("field");
for (int j = 0; j < n.count(); j++) {
QDomElement f = n.at(j).toElement();
if (!f.isNull()) {
ini.setValue(f.attribute("name", "unknown"), f.attribute("values"));
}
}
ini.endGroup();
}
}
QFile file(fileName);
if (file.open(QIODevice::WriteOnly) &&
(file.write(doc.toString(4).toAscii()) != -1)) {
file.close();
} else {
QMessageBox::critical(0,
tr("UAV Settings Export"),
tr("Unable to save settings: ") + fileName,
QMessageBox::Ok);
return;
}
QMessageBox msgBox;
msgBox.setText(tr("Settings saved."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
void UAVSettingsImportExportPlugin::shutdown()

View File

@ -28,6 +28,7 @@
#define UAVSETTINGSIMPORTEXPORT_H
#include <extensionsystem/iplugin.h>
#include "uavobjectutil/uavobjectutilmanager.h"
class UAVSettingsImportExportPlugin : public ExtensionSystem::IPlugin
{
@ -42,7 +43,8 @@ public:
void shutdown();
private slots:
void importExport();
void importUAVSettings();
void exportUAVSettings();
};

View File

@ -7,5 +7,6 @@
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
<dependency name="UAVObjectUtil" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -1,2 +1,3 @@
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/uavobjectutil/uavobjectutil.pri)