1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

LP-419 xmlconfig: cleanup and remove dead code

This commit is contained in:
Philippe Renon 2016-10-02 17:13:35 +02:00
parent d031352cdd
commit 38005e3881
5 changed files with 34 additions and 48 deletions

View File

@ -392,7 +392,7 @@ void loadFactoryDefaults(QSettings &settings, AppOptionValues &appOptionValues)
}
// create settings from file
QSettings qs(fileName, XmlConfig::XmlSettingsFormat);
QSettings qs(fileName, XmlConfig::XmlFormat);
// transfer loaded settings to application settings
QStringList keys = qs.allKeys();
@ -454,7 +454,7 @@ int runApplication(int argc, char * *argv)
QCoreApplication::setApplicationName(APP_NAME);
QCoreApplication::setOrganizationName(ORG_NAME);
QSettings::setDefaultFormat(XmlConfig::XmlSettingsFormat);
QSettings::setDefaultFormat(XmlConfig::XmlFormat);
// initialize the plugin manager
ExtensionSystem::PluginManager pluginManager;
@ -485,7 +485,7 @@ int runApplication(int argc, char * *argv)
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
QString settingsPath = Utils::GetDataPath();
qDebug() << "Loading system settings from" << settingsPath;
QSettings::setPath(XmlConfig::XmlSettingsFormat, QSettings::SystemScope, settingsPath);
QSettings::setPath(XmlConfig::XmlFormat, QSettings::SystemScope, settingsPath);
QSettings settings;
qDebug() << "Loading user settings from" << settings.fileName();

View File

@ -2,13 +2,14 @@
******************************************************************************
*
* @file xmlconfig.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @see The GNU Public License (GPL) Version 3
* @brief Widget for Import/Export Plugin
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @addtogroup utils
* @{
*
*****************************************************************************/
@ -30,24 +31,24 @@
/* Nokia Corporation */
#include "xmlconfig.h"
#include <QtDebug>
#include <QDebug>
#include <QStringList>
#include <QRegExp>
#include <QDataStream>
#include <QVariant>
#include <QRect>
#include <QSize>
#include <QPoint>
#include <QtCore/QUrl>
#include <QUrl>
#include <QDomElement>
#define NUM_PREFIX "arr_"
QString XmlConfig::rootName = "gcs";
const QString XmlConfig::RootName = "gcs";
const QSettings::Format XmlConfig::XmlSettingsFormat =
const QSettings::Format XmlConfig::XmlFormat =
QSettings::registerFormat("xml", XmlConfig::readXmlFile, XmlConfig::writeXmlFile);
bool XmlConfig::readXmlFile(QIODevice &device, QSettings::SettingsMap &map)
{
QDomDocument domDoc;
@ -90,7 +91,7 @@ void XmlConfig::handleNode(QDomElement *node, QSettings::SettingsMap &map, QStri
nodeName = nodeName.replace("__PCT__", "%");
nodeName = QUrl::fromPercentEncoding(nodeName.toLatin1());
if (nodeName == XmlConfig::rootName) {
if (nodeName == XmlConfig::RootName) {
;
} else if (path == "") {
path = nodeName;
@ -98,31 +99,31 @@ void XmlConfig::handleNode(QDomElement *node, QSettings::SettingsMap &map, QStri
path += "/" + nodeName;
}
// qDebug() << "Node: " << ": " << path << " Children: " << node->childNodes().length();
// qDebug() << "Node: " << ": " << path << " Children: " << node->childNodes().length();
for (int i = 0; i < node->childNodes().length(); ++i) {
QDomNode child = node->childNodes().item(i);
if (child.isElement()) {
handleNode(static_cast<QDomElement *>(&child), map, path);
} else if (child.isText()) {
// qDebug() << "Key: " << path << " Value:" << node->text();
// qDebug() << "Key: " << path << " Value:" << node->text();
map.insert(path, stringToVariant(node->text()));
} else {
qDebug() << "Child not Element or text!" << child.nodeType();
}
}
// qDebug() << "XmlConfig::handleNode end";
// qDebug() << "XmlConfig::handleNode end";
}
bool XmlConfig::writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map)
{
QDomDocument outDocument;
// qDebug() << "writeXmlFile start";
outDocument.appendChild(outDocument.createElement(XmlConfig::rootName));
// qDebug() << "writeXmlFile start";
outDocument.appendChild(outDocument.createElement(XmlConfig::RootName));
QMapIterator<QString, QVariant> iter(map);
while (iter.hasNext()) {
iter.next();
// qDebug() << "Entry: " << iter.key() << ": " << iter.value().toString() << endl;
// qDebug() << "Entry: " << iter.key() << ": " << iter.value().toString() << endl;
QDomNode node = outDocument.firstChild();
foreach(QString elem, iter.key().split('/')) {
if (elem == "") {
@ -149,27 +150,11 @@ bool XmlConfig::writeXmlFile(QIODevice &device, const QSettings::SettingsMap &ma
node.appendChild(outDocument.createTextNode(variantToString(iter.value())));
}
device.write(outDocument.toByteArray(2).constData());
// qDebug() << "Dokument:\n" << outDocument.toByteArray(2).constData();
// qDebug() << "writeXmlFile end";
// qDebug() << "Document:\n" << outDocument.toByteArray(2).constData();
// qDebug() << "writeXmlFile end";
return true;
}
QSettings::SettingsMap XmlConfig::settingsToMap(QSettings & qs)
{
qDebug() << "settingsToMap:---------------";
QSettings::SettingsMap map;
QStringList keys = qs.allKeys();
foreach(QString key, keys) {
QVariant val = qs.value(key);
qDebug() << key << val.toString();
map.insert(key, val);
}
qDebug() << "settingsToMap End --------";
return map;
}
QString XmlConfig::variantToString(const QVariant &v)
{
QString result;

View File

@ -1,11 +1,13 @@
/**
******************************************************************************
* @file
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
*
* @file xmlconfig.h
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup importexportplugin
* @addtogroup utils
* @{
*****************************************************************************/
/*
@ -34,29 +36,29 @@
#include <QtCore/qglobal.h>
#include <QSettings>
#include <QDomElement>
#include <QObject>
#include <QDataStream>
class QDomElement;
class XMLCONFIG_EXPORT XmlConfig : QObject {
Q_OBJECT
public:
static const QSettings::Format XmlSettingsFormat;
static const QSettings::Format XmlFormat;
static bool readXmlFile(QIODevice &device, QSettings::SettingsMap &map);
static bool writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map);
private:
static QString rootName;
static const QString RootName;
static void handleNode(QDomElement *node, QSettings::SettingsMap &map, QString path = "");
static QSettings::SettingsMap settingsToMap(QSettings & qs);
static QString variantToString(const QVariant &v);
static QVariant stringToVariant(const QString &s);
static QStringList splitArgs(const QString &s, int idx);
};
#endif // XMLCONFIG_H
/**
* @}
* @}

View File

@ -104,7 +104,7 @@ MainWindow::MainWindow() :
m_additionalContexts(m_globalContext),
// keep this in sync with main() in app/main.cpp
m_settings(new QSettings(this)),
m_globalSettings(new QSettings(XmlConfig::XmlSettingsFormat, QSettings::SystemScope,
m_globalSettings(new QSettings(XmlConfig::XmlFormat, QSettings::SystemScope,
m_settings->organizationName(), m_settings->applicationName(), this)),
m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
QFileInfo(m_settings->fileName()).baseName(),

View File

@ -125,8 +125,7 @@ void ImportExportGadgetWidget::exportConfiguration(const QString & fileName)
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings::Format format = XmlConfig::XmlSettingsFormat;
QSettings qs(fileName, format);
QSettings qs(fileName, XmlConfig::XmlFormat);
if (doGeneral) {
Core::ICore::instance()->saveMainSettings(&qs);
@ -184,7 +183,7 @@ void ImportExportGadgetWidget::importConfiguration(const QString & fileName)
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings qs(fileName, XmlConfig::XmlSettingsFormat);
QSettings qs(fileName, XmlConfig::XmlFormat);
if (doAllGadgets) {
Core::ICore::instance()->uavGadgetInstanceManager()->readSettings(&qs);