diff --git a/ground/src/plugins/config/configgadgetconfiguration.cpp b/ground/src/plugins/config/configgadgetconfiguration.cpp index 160433482..cb1f75ec0 100644 --- a/ground/src/plugins/config/configgadgetconfiguration.cpp +++ b/ground/src/plugins/config/configgadgetconfiguration.cpp @@ -34,15 +34,18 @@ ConfigGadgetConfiguration::ConfigGadgetConfiguration(QString classId, const QByt } +ConfigGadgetConfiguration::ConfigGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent) +{ + +} + IUAVGadgetConfiguration *ConfigGadgetConfiguration::clone() { ConfigGadgetConfiguration *m = new ConfigGadgetConfiguration(this->classId()); return m; } -QByteArray ConfigGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - return bytes; +void ConfigGadgetConfiguration::saveConfig(QSettings* settings) const { + } diff --git a/ground/src/plugins/config/configgadgetconfiguration.h b/ground/src/plugins/config/configgadgetconfiguration.h index 7216d4319..d7f801414 100644 --- a/ground/src/plugins/config/configgadgetconfiguration.h +++ b/ground/src/plugins/config/configgadgetconfiguration.h @@ -36,8 +36,9 @@ class ConfigGadgetConfiguration : public IUAVGadgetConfiguration Q_OBJECT public: - explicit ConfigGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); - QByteArray saveState() const; + explicit ConfigGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit ConfigGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); }; diff --git a/ground/src/plugins/config/configgadgetfactory.cpp b/ground/src/plugins/config/configgadgetfactory.cpp index 1db928409..f48e7ce9e 100644 --- a/ground/src/plugins/config/configgadgetfactory.cpp +++ b/ground/src/plugins/config/configgadgetfactory.cpp @@ -51,6 +51,11 @@ IUAVGadgetConfiguration *ConfigGadgetFactory::createConfiguration(const QByteArr return new ConfigGadgetConfiguration(QString("ConfigGadget"), state); } +IUAVGadgetConfiguration *ConfigGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new ConfigGadgetConfiguration(QString("ConfigGadget"), qSettings); +} + IOptionsPage *ConfigGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new ConfigGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/config/configgadgetfactory.h b/ground/src/plugins/config/configgadgetfactory.h index d4a8f3275..14c39c4c1 100644 --- a/ground/src/plugins/config/configgadgetfactory.h +++ b/ground/src/plugins/config/configgadgetfactory.h @@ -46,6 +46,7 @@ public: IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/coreplugin/iuavgadgetconfiguration.h b/ground/src/plugins/coreplugin/iuavgadgetconfiguration.h index 1ce764839..edb50bca9 100644 --- a/ground/src/plugins/coreplugin/iuavgadgetconfiguration.h +++ b/ground/src/plugins/coreplugin/iuavgadgetconfiguration.h @@ -30,6 +30,7 @@ #include #include +#include namespace Core { @@ -46,7 +47,8 @@ public: bool locked() const { return m_locked; } void setLocked(bool locked) { m_locked = locked; } - virtual QByteArray saveState() const = 0; + virtual void saveConfig(QSettings* settings) const = 0; + virtual IUAVGadgetConfiguration *clone() = 0; signals: diff --git a/ground/src/plugins/coreplugin/iuavgadgetfactory.h b/ground/src/plugins/coreplugin/iuavgadgetfactory.h index 63f2b9a08..f62f19fbb 100644 --- a/ground/src/plugins/coreplugin/iuavgadgetfactory.h +++ b/ground/src/plugins/coreplugin/iuavgadgetfactory.h @@ -31,6 +31,7 @@ #include "core_global.h" #include +#include QT_BEGIN_NAMESPACE class QStringList; @@ -54,6 +55,7 @@ public: virtual IUAVGadget *createGadget(QWidget *parent) = 0; virtual IUAVGadgetConfiguration *createConfiguration(const QByteArray &/*state*/) { return 0; } + virtual IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings) { return 0; } virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; } QString classId() const { return m_classId; } QString name() const { return m_name; } diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index e42c44092..b5143eb4e 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -96,29 +96,63 @@ void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs) { IUAVGadgetFactory *f = factory(classId); qs->beginGroup(classId); - QStringList configs = qs->childKeys(); - foreach (QString configName, configs) { - QByteArray ba = QByteArray::fromBase64(qs->value(configName).toByteArray()); - QDataStream stream(ba); - bool locked; - stream >> locked; - QByteArray state; - stream >> state; - IUAVGadgetConfiguration *config = f->createConfiguration(state); - if (config){ - config->setName(configName); - config->setProvisionalName(configName); - config->setLocked(locked); - int idx = indexForConfig(m_configurations, classId, configName); - if ( idx >= 0 ){ - // We should replace the config, but it might be used, so just - // throw it out of the list. The GCS should be reinitialised soon. - m_configurations[idx] = config; + // New style: each config is a group, old style: each config is a value + QStringList groups = qs->childGroups(); + bool oldStyle = groups.size() == 0; + QStringList configs = QStringList(); + if(oldStyle) { + // Old style configuration + configs = qs->childKeys(); + + foreach (QString configName, configs) { + QByteArray ba = QByteArray::fromBase64(qs->value(configName).toByteArray()); + QDataStream stream(ba); + bool locked; + stream >> locked; + QByteArray state; + stream >> state; + IUAVGadgetConfiguration *config = f->createConfiguration(state); + if (config){ + config->setName(configName); + config->setProvisionalName(configName); + config->setLocked(locked); + int idx = indexForConfig(m_configurations, classId, configName); + if ( idx >= 0 ){ + // We should replace the config, but it might be used, so just + // throw it out of the list. The GCS should be reinitialised soon. + m_configurations[idx] = config; + } + else{ + m_configurations.append(config); + } } - else{ - m_configurations.append(config); + } + } else { + // New style configuration + configs = qs->childGroups(); + + foreach (QString configName, configs) { + qDebug() << "Loading config: " << classId << "," << configName; + qs->beginGroup(configName); + bool locked = qs->value("config.locked").toBool(); + IUAVGadgetConfiguration *config = f->createConfiguration(qs); + if (config){ + config->setName(configName); + config->setProvisionalName(configName); + config->setLocked(locked); + int idx = indexForConfig(m_configurations, classId, configName); + if ( idx >= 0 ){ + // We should replace the config, but it might be used, so just + // throw it out of the list. The GCS should be reinitialised soon. + m_configurations[idx] = config; + } + else{ + m_configurations.append(config); + } } + + qs->endGroup(); } } @@ -145,11 +179,11 @@ void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs) foreach (IUAVGadgetConfiguration *config, m_configurations) { qs->beginGroup(config->classId()); - QByteArray ba; - QDataStream stream(&ba, QIODevice::WriteOnly); - stream << config->locked(); - stream << config->saveState(); - qs->setValue(config->name(), ba.toBase64()); + qs->beginGroup(config->name()); + // TODO: Someone could accidentially use the same name? + qs->setValue("config.locked", config->locked()); + config->saveConfig(qs); + qs->endGroup(); qs->endGroup(); } qs->endGroup(); diff --git a/ground/src/plugins/dial/dialgadgetconfiguration.cpp b/ground/src/plugins/dial/dialgadgetconfiguration.cpp index fab159d4e..da98e3336 100644 --- a/ground/src/plugins/dial/dialgadgetconfiguration.cpp +++ b/ground/src/plugins/dial/dialgadgetconfiguration.cpp @@ -88,6 +88,65 @@ DialGadgetConfiguration::DialGadgetConfiguration(QString classId, const QByteArr } } + + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +DialGadgetConfiguration::DialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_defaultDial("Unknown"), + dialBackgroundID("background"), + dialForegroundID("foreground"), + dialNeedleID1("needle"), + dialNeedleID2("needle2"), + dialNeedleID3("needle3"), + needle1MinValue(0), + needle1MaxValue(100), + needle2MinValue(0), + needle2MaxValue(100), + needle3MinValue(0), + needle3MaxValue(100), + needle1Factor(1), + needle2Factor(1), + needle3Factor(1), + needle1Move("Rotate"), + needle2Move("Rotate"), + needle3Move("Rotate") +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QString dialFile = qSettings->value("dialFile").toString(); + + m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile); + dialBackgroundID = qSettings->value("dialBackgroundID").toString(); + dialForegroundID = qSettings->value("dialForegroundID").toString(); + dialNeedleID1 = qSettings->value("dialNeedleID1").toString(); + dialNeedleID2 = qSettings->value("dialNeedleID2").toString(); + dialNeedleID3 = qSettings->value("dialNeedleID3").toString(); + needle1MinValue = qSettings->value("needle1MinValue").toDouble(); + needle1MaxValue = qSettings->value("needle1MaxValue").toDouble(); + needle2MinValue = qSettings->value("needle2MinValue").toDouble(); + needle2MaxValue = qSettings->value("needle2MaxValue").toDouble(); + needle3MinValue = qSettings->value("needle3MinValue").toDouble(); + needle3MaxValue = qSettings->value("needle3MaxValue").toDouble(); + needle1DataObject = qSettings->value("needle1DataObject").toString(); + needle1ObjectField = qSettings->value("needle1ObjectField").toString(); + needle2DataObject = qSettings->value("needle2DataObject").toString(); + needle2ObjectField = qSettings->value("needle2ObjectField").toString(); + needle3DataObject = qSettings->value("needle3DataObject").toString(); + needle3ObjectField = qSettings->value("needle3ObjectField").toString(); + needle1Factor = qSettings->value("needle1Factor").toDouble(); + needle2Factor = qSettings->value("needle2Factor").toDouble(); + needle3Factor = qSettings->value("needle3Factor").toDouble(); + needle1Move = qSettings->value("needle1Move").toString(); + needle2Move = qSettings->value("needle2Move").toString(); + needle3Move = qSettings->value("needle3Move").toString(); + font = qSettings->value("font").toString(); + } +} + /** * Clones a configuration. * @@ -123,40 +182,43 @@ IUAVGadgetConfiguration *DialGadgetConfiguration::clone() return m; } + /** * Saves a configuration. * */ -QByteArray DialGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); +void DialGadgetConfiguration::saveConfig(QSettings* settings) const { QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial); - stream << dialFile; - stream << dialBackgroundID; - stream << dialForegroundID; - stream << dialNeedleID1; - stream << dialNeedleID2; - stream << dialNeedleID3; - stream << needle1MinValue; - stream << needle1MaxValue; - stream << needle2MinValue; - stream << needle2MaxValue; - stream << needle3MinValue; - stream << needle3MaxValue; - stream << needle1DataObject; - stream << needle1ObjectField; - stream << needle2DataObject; - stream << needle2ObjectField; - stream << needle3DataObject; - stream << needle3ObjectField; - stream << needle1Factor; - stream << needle2Factor; - stream << needle3Factor; - stream << needle1Move; - stream << needle2Move; - stream << needle3Move; - stream << font; + settings->setValue("dialFile", dialFile); - return bytes; + settings->setValue("dialBackgroundID", dialBackgroundID); + settings->setValue("dialForegroundID", dialForegroundID); + + settings->setValue("dialNeedleID1", dialNeedleID1); + settings->setValue("dialNeedleID2", dialNeedleID2); + settings->setValue("dialNeedleID3", dialNeedleID3); + + settings->setValue("needle1MinValue", needle1MinValue); + settings->setValue("needle1MaxValue", needle1MaxValue); + settings->setValue("needle2MinValue", needle2MinValue); + settings->setValue("needle2MaxValue", needle2MaxValue); + settings->setValue("needle3MinValue", needle3MinValue); + settings->setValue("needle3MaxValue", needle3MaxValue); + + settings->setValue("needle1DataObject", needle1DataObject); + settings->setValue("needle1ObjectField", needle1ObjectField); + settings->setValue("needle2DataObject", needle2DataObject); + settings->setValue("needle2ObjectField", needle2ObjectField); + settings->setValue("needle3DataObject", needle3DataObject); + settings->setValue("needle3ObjectField", needle3ObjectField); + + settings->setValue("needle1Factor", needle1Factor); + settings->setValue("needle2Factor", needle2Factor); + settings->setValue("needle3Factor", needle3Factor); + + settings->setValue("needle1Move", needle1Move); + settings->setValue("needle2Move", needle2Move); + settings->setValue("needle3Move", needle3Move); + + settings->setValue("font", font); } diff --git a/ground/src/plugins/dial/dialgadgetconfiguration.h b/ground/src/plugins/dial/dialgadgetconfiguration.h index 22b1d752d..35d6339b8 100644 --- a/ground/src/plugins/dial/dialgadgetconfiguration.h +++ b/ground/src/plugins/dial/dialgadgetconfiguration.h @@ -40,7 +40,9 @@ class DialGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit DialGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit DialGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit DialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + //set dial configuration functions void setDialFile(QString dialFile){m_defaultDial=dialFile;} @@ -97,7 +99,7 @@ public: QString getN3Move() { return needle3Move; } QString getFont() { return font;} - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/dial/dialgadgetfactory.cpp b/ground/src/plugins/dial/dialgadgetfactory.cpp index 35293a743..dd71a7501 100644 --- a/ground/src/plugins/dial/dialgadgetfactory.cpp +++ b/ground/src/plugins/dial/dialgadgetfactory.cpp @@ -54,6 +54,11 @@ IUAVGadgetConfiguration *DialGadgetFactory::createConfiguration(const QByteArray return new DialGadgetConfiguration(QString("DialGadget"), state); } +IUAVGadgetConfiguration *DialGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new DialGadgetConfiguration(QString("DialGadget"), qSettings); +} + IOptionsPage *DialGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new DialGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/dial/dialgadgetfactory.h b/ground/src/plugins/dial/dialgadgetfactory.h index ed7622f4d..1905bc782 100644 --- a/ground/src/plugins/dial/dialgadgetfactory.h +++ b/ground/src/plugins/dial/dialgadgetfactory.h @@ -47,6 +47,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.cpp b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.cpp index fbe32d82d..a046ab09d 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.cpp +++ b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.cpp @@ -84,6 +84,53 @@ GpsDisplayGadgetConfiguration::GpsDisplayGadgetConfiguration(QString classId, co } +/** + * Loads a saved configuration or defaults if non exist. + * + */ +GpsDisplayGadgetConfiguration::GpsDisplayGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_connectionMode("Serial"), + m_defaultPort("Unknown"), + m_defaultSpeed(BAUD4800), + m_defaultDataBits(DATA_8), + m_defaultFlow(FLOW_OFF), + m_defaultParity(PAR_NONE), + m_defaultStopBits(STOP_1), + m_defaultTimeOut(5000) +{ + //if a saved configuration exists load it + if(qSettings != 0) { + BaudRateType speed; + DataBitsType databits; + FlowType flow; + ParityType parity; + StopBitsType stopbits; + + int ispeed = qSettings->value("defaultSpeed").toInt(); + int idatabits = qSettings->value("defaultDataBits").toInt(); + int iflow = qSettings->value("defaultFlow").toInt(); + int iparity = qSettings->value("defaultParity").toInt(); + int istopbits = qSettings->value("defaultStopBits").toInt(); + QString port = qSettings->value("defaultPort").toString(); + QString conMode = qSettings->value("connectionMode").toString(); + + databits = (DataBitsType) idatabits; + flow = (FlowType)iflow; + parity = (ParityType)iparity; + stopbits = (StopBitsType)istopbits; + speed = (BaudRateType)ispeed; + m_defaultPort = port; + m_defaultSpeed = speed; + m_defaultDataBits = databits; + m_defaultFlow = flow; + m_defaultParity = parity; + m_defaultStopBits = stopbits; + m_connectionMode = conMode; + } + +} + /** * Clones a configuration. * @@ -106,16 +153,13 @@ IUAVGadgetConfiguration *GpsDisplayGadgetConfiguration::clone() * Saves a configuration. * */ -QByteArray GpsDisplayGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << (int)m_defaultSpeed; - stream << (int)m_defaultDataBits; - stream << (int)m_defaultFlow; - stream << (int)m_defaultParity; - stream << (int)m_defaultStopBits; - stream << m_defaultPort; - stream << m_connectionMode; - return bytes; +void GpsDisplayGadgetConfiguration::saveConfig(QSettings* settings) const { + settings->setValue("defaultSpeed", m_defaultSpeed); + settings->setValue("defaultDataBits", m_defaultDataBits); + settings->setValue("defaultFlow", m_defaultFlow); + settings->setValue("defaultParity", m_defaultParity); + settings->setValue("defaultStopBits", m_defaultStopBits); + settings->setValue("defaultPort", m_defaultPort); + settings->setValue("connectionMode", m_connectionMode); + } diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.h b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.h index d1d2ef3a5..7d1eae0a1 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.h +++ b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetconfiguration.h @@ -37,7 +37,8 @@ class GpsDisplayGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit GpsDisplayGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit GpsDisplayGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit GpsDisplayGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); void setConnectionMode(QString mode) { m_connectionMode = mode; } QString connectionMode() { return m_connectionMode; } @@ -60,7 +61,7 @@ class GpsDisplayGadgetConfiguration : public IUAVGadgetConfiguration ParityType parity() {return m_defaultParity;} long timeOut(){return m_defaultTimeOut;} - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.cpp b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.cpp index 4713ed033..257f7911a 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.cpp +++ b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.cpp @@ -53,6 +53,11 @@ IUAVGadgetConfiguration *GpsDisplayGadgetFactory::createConfiguration(const QByt return new GpsDisplayGadgetConfiguration(QString("GpsDisplayGadget"), state); } +IUAVGadgetConfiguration *GpsDisplayGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new GpsDisplayGadgetConfiguration(QString("GpsDisplayGadget"), qSettings); +} + IOptionsPage *GpsDisplayGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new GpsDisplayGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.h b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.h index 7ad1f0b61..4e476db8c 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.h +++ b/ground/src/plugins/gpsdisplay/gpsdisplaygadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/hitlnew/hitlconfiguration.cpp b/ground/src/plugins/hitlnew/hitlconfiguration.cpp index 42b8b987e..10b0b6ed0 100644 --- a/ground/src/plugins/hitlnew/hitlconfiguration.cpp +++ b/ground/src/plugins/hitlnew/hitlconfiguration.cpp @@ -56,6 +56,33 @@ HITLConfiguration::HITLConfiguration(QString classId, const QByteArray &state, Q } } +HITLConfiguration::HITLConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent) +{ + settings.simulatorId = ""; + settings.binPath = ""; + settings.dataPath = ""; + settings.manual = false; + settings.hostAddress = "127.0.0.1"; + settings.outPort = 0; + settings.inPort = 0; + settings.latitude = ""; + settings.longitude = ""; + + //if a saved configuration exists load it + if(qSettings != 0) { + settings.simulatorId = qSettings->value("simulatorId").toString(); + settings.binPath = qSettings->value("binPath").toString(); + settings.dataPath = qSettings->value("dataPath").toString(); + settings.manual = qSettings->value("manual").toBool(); + settings.hostAddress = qSettings->value("hostAddress").toString(); + settings.outPort = qSettings->value("outPort").toInt(); + settings.inPort = qSettings->value("inPort").toInt(); + settings.latitude = qSettings->value("latitude").toString(); + settings.longitude = qSettings->value("longitude").toString(); + } +} + IUAVGadgetConfiguration *HITLConfiguration::clone() { HITLConfiguration *m = new HITLConfiguration(this->classId()); @@ -64,20 +91,19 @@ IUAVGadgetConfiguration *HITLConfiguration::clone() return m; } -QByteArray HITLConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - - stream << settings.simulatorId; - stream << settings.binPath; - stream << settings.dataPath; - stream << settings.manual; - stream << settings.hostAddress; - stream << settings.outPort; - stream << settings.inPort; - stream << settings.latitude; - stream << settings.longitude; - return bytes; + /** + * Saves a configuration. + * + */ +void HITLConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("simulatorId", settings.simulatorId); + qSettings->setValue("binPath", settings.binPath); + qSettings->setValue("dataPath", settings.dataPath); + qSettings->setValue("manual", settings.manual); + qSettings->setValue("hostAddress", settings.hostAddress); + qSettings->setValue("outPort", settings.outPort); + qSettings->setValue("inPort", settings.inPort); + qSettings->setValue("latitude", settings.latitude); + qSettings->setValue("longitude", settings.longitude); } diff --git a/ground/src/plugins/hitlnew/hitlconfiguration.h b/ground/src/plugins/hitlnew/hitlconfiguration.h index 15ec2d38a..e4c208912 100644 --- a/ground/src/plugins/hitlnew/hitlconfiguration.h +++ b/ground/src/plugins/hitlnew/hitlconfiguration.h @@ -44,8 +44,10 @@ class HITLConfiguration : public IUAVGadgetConfiguration Q_PROPERTY(SimulatorSettings settings READ Settings WRITE setSimulatorSettings) public: - explicit HITLConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); - QByteArray saveState() const; + explicit HITLConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit HITLConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); SimulatorSettings Settings() const { return settings; } diff --git a/ground/src/plugins/hitlnew/hitlfactory.cpp b/ground/src/plugins/hitlnew/hitlfactory.cpp index 94af029e3..249ef61cf 100644 --- a/ground/src/plugins/hitlnew/hitlfactory.cpp +++ b/ground/src/plugins/hitlnew/hitlfactory.cpp @@ -54,6 +54,11 @@ IUAVGadgetConfiguration *HITLFactory::createConfiguration(const QByteArray &stat return new HITLConfiguration(QString("HITL"), state); } +IUAVGadgetConfiguration *HITLFactory::createConfiguration(QSettings* qSettings) +{ + return new HITLConfiguration(QString("HITL"), qSettings); +} + IOptionsPage *HITLFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new HITLOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/hitlnew/hitlfactory.h b/ground/src/plugins/hitlnew/hitlfactory.h index 5b44e8480..90c3e92d3 100644 --- a/ground/src/plugins/hitlnew/hitlfactory.h +++ b/ground/src/plugins/hitlnew/hitlfactory.h @@ -46,6 +46,7 @@ public: IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/importexport/importexportgadgetconfiguration.cpp b/ground/src/plugins/importexport/importexportgadgetconfiguration.cpp index 4c8830b5a..6a4dc4277 100644 --- a/ground/src/plugins/importexport/importexportgadgetconfiguration.cpp +++ b/ground/src/plugins/importexport/importexportgadgetconfiguration.cpp @@ -44,6 +44,21 @@ ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId stream >> dialFile; } } + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + dialFile("gcs.ini") +{ + //if a saved configuration exists load it + if(qSettings != 0) { + dialFile = qSettings->value("dialFile").toString(); + } +} + /** * Clones a configuration. * @@ -54,16 +69,13 @@ IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone() m->dialFile = dialFile; return m; } + /** * Saves a configuration. * */ -QByteArray ImportExportGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << dialFile; - return bytes; +void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("dialFile", dialFile); } /** diff --git a/ground/src/plugins/importexport/importexportgadgetconfiguration.h b/ground/src/plugins/importexport/importexportgadgetconfiguration.h index 9c68f7ca4..eaae914ca 100644 --- a/ground/src/plugins/importexport/importexportgadgetconfiguration.h +++ b/ground/src/plugins/importexport/importexportgadgetconfiguration.h @@ -39,7 +39,8 @@ class IMPORTEXPORT_EXPORT ImportExportGadgetConfiguration : public IUAVGadgetCon { Q_OBJECT public: - explicit ImportExportGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit ImportExportGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit ImportExportGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); //set dial configuration functions void setDialFile(QString filename) { @@ -51,7 +52,7 @@ public: return dialFile; } - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/importexport/importexportgadgetfactory.cpp b/ground/src/plugins/importexport/importexportgadgetfactory.cpp index 338d1b15e..143d64d63 100644 --- a/ground/src/plugins/importexport/importexportgadgetfactory.cpp +++ b/ground/src/plugins/importexport/importexportgadgetfactory.cpp @@ -56,6 +56,12 @@ IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(const QB return lastConfig; } +IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(QSettings* qSettings) +{ + lastConfig = new ImportExportGadgetConfiguration(QString("ImportExportGadget"), qSettings); + return lastConfig; +} + IOptionsPage *ImportExportGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new ImportExportGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/importexport/importexportgadgetfactory.h b/ground/src/plugins/importexport/importexportgadgetfactory.h index b93f3a836..f4915619f 100644 --- a/ground/src/plugins/importexport/importexportgadgetfactory.h +++ b/ground/src/plugins/importexport/importexportgadgetfactory.h @@ -48,6 +48,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); private: diff --git a/ground/src/plugins/ipconnection/ipconnectionconfiguration.cpp b/ground/src/plugins/ipconnection/ipconnectionconfiguration.cpp index c92ce9367..d193e0130 100644 --- a/ground/src/plugins/ipconnection/ipconnectionconfiguration.cpp +++ b/ground/src/plugins/ipconnection/ipconnectionconfiguration.cpp @@ -37,9 +37,20 @@ IPconnectionConfiguration::IPconnectionConfiguration(QString classId, const QByt { settings = Core::ICore::instance()->settings(); } + +IPconnectionConfiguration::IPconnectionConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_HostName("127.0.0.1"), + m_Port(1000), + m_UseTCP(1) +{ + settings = Core::ICore::instance()->settings(); +} + IPconnectionConfiguration::~IPconnectionConfiguration() { } + IUAVGadgetConfiguration *IPconnectionConfiguration::clone() { IPconnectionConfiguration *m = new IPconnectionConfiguration(this->classId()); @@ -49,18 +60,16 @@ IUAVGadgetConfiguration *IPconnectionConfiguration::clone() return m; } -QByteArray IPconnectionConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << m_Port; - stream << m_HostName; - stream << m_UseTCP; - return bytes; - +/** + * Saves a configuration. + * + */ +void IPconnectionConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("port", m_Port); + qSettings->setValue("hostName", m_HostName); + qSettings->setValue("useTCP", m_UseTCP); } - void IPconnectionConfiguration::savesettings() const { settings->beginGroup(QLatin1String("IPconnection")); diff --git a/ground/src/plugins/ipconnection/ipconnectionconfiguration.h b/ground/src/plugins/ipconnection/ipconnectionconfiguration.h index 86ae4cc68..3f33cf4e2 100644 --- a/ground/src/plugins/ipconnection/ipconnectionconfiguration.h +++ b/ground/src/plugins/ipconnection/ipconnectionconfiguration.h @@ -42,9 +42,11 @@ Q_PROPERTY(int Port READ Port WRITE setPort) Q_PROPERTY(int UseTCP READ UseTCP WRITE setUseTCP) public: - explicit IPconnectionConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit IPconnectionConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit IPconnectionConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + virtual ~IPconnectionConfiguration(); - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; //void savesettings(QSettings* settings) const; //void restoresettings(QSettings* settings); void savesettings() const; diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp index ef7d1e3ff..6db9b3b9e 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp @@ -70,6 +70,47 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co stream >> factor; } } + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + dialFile("Unknown"), + sourceDataObject("Unknown"), + sourceObjectField("Unknown"), + minValue(0), + maxValue(100), + redMin(0), + redMax(33), + yellowMin(33), + yellowMax(66), + greenMin(66), + greenMax(100), + factor(1.00), + decimalPlaces(0) +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QString dFile = qSettings->value("dFile").toString(); + dialFile = Utils::PathUtils().InsertDataPath(dFile); + sourceDataObject = qSettings->value("sourceDataObject").toString(); + sourceObjectField = qSettings->value("sourceObjectField").toString(); + minValue = qSettings->value("minValue").toDouble(); + maxValue = qSettings->value("maxValue").toDouble(); + redMin = qSettings->value("redMin").toDouble(); + redMax = qSettings->value("redMax").toDouble(); + yellowMin = qSettings->value("yellowMin").toDouble(); + yellowMax = qSettings->value("yellowMax").toDouble(); + greenMin = qSettings->value("greenMin").toDouble(); + greenMax = qSettings->value("greenMax").toDouble(); + font = qSettings->value("font").toString(); + decimalPlaces = qSettings->value("decimalPlaces").toInt(); + factor = qSettings->value("factor").toDouble(); + } +} + /** * Clones a configuration. * @@ -94,29 +135,25 @@ IUAVGadgetConfiguration *LineardialGadgetConfiguration::clone() return m; } + /** * Saves a configuration. * */ -QByteArray LineardialGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - QString dFile = Utils::PathUtils().RemoveDataPath(dialFile); - stream << dFile; - stream << sourceDataObject; - stream << sourceObjectField; - stream << minValue; - stream << maxValue; - stream << redMin; - stream << redMax; - stream << yellowMin; - stream << yellowMax; - stream << greenMin; - stream << greenMax; - stream << font; - stream << decimalPlaces; - stream << factor; - - return bytes; +void LineardialGadgetConfiguration::saveConfig(QSettings* qSettings) const { + QString dFile = Utils::PathUtils().RemoveDataPath(dialFile); + qSettings->setValue("dFile", dFile); + qSettings->setValue("sourceDataObject", sourceDataObject); + qSettings->setValue("sourceObjectField", sourceObjectField); + qSettings->setValue("minValue", minValue); + qSettings->setValue("maxValue", maxValue); + qSettings->setValue("redMin", redMin); + qSettings->setValue("redMax", redMax); + qSettings->setValue("yellowMin", yellowMin); + qSettings->setValue("yellowMax", yellowMax); + qSettings->setValue("greenMin", greenMin); + qSettings->setValue("greenMax", greenMax); + qSettings->setValue("font", font); + qSettings->setValue("decimalPlaces", decimalPlaces); + qSettings->setValue("factor", factor); } diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h index b5e8fc1d6..157bebe93 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h @@ -39,7 +39,8 @@ class LineardialGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit LineardialGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit LineardialGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit LineardialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); //set dial configuration functions void setDialFile(QString filename){dialFile=filename;} @@ -72,7 +73,7 @@ public: int getDecimalPlaces() { return decimalPlaces; } double getFactor() { return factor; } - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp b/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp index 3c341c163..fe4b43c2b 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp @@ -53,6 +53,11 @@ IUAVGadgetConfiguration *LineardialGadgetFactory::createConfiguration(const QByt return new LineardialGadgetConfiguration(QString("LineardialGadget"), state); } +IUAVGadgetConfiguration *LineardialGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new LineardialGadgetConfiguration(QString("LineardialGadget"), qSettings); +} + IOptionsPage *LineardialGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new LineardialGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/lineardial/lineardialgadgetfactory.h b/ground/src/plugins/lineardial/lineardialgadgetfactory.h index 9ae6bd463..158435ebd 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetfactory.h +++ b/ground/src/plugins/lineardial/lineardialgadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/modelview/modelviewgadgetconfiguration.cpp b/ground/src/plugins/modelview/modelviewgadgetconfiguration.cpp index 4fdb312d5..12822cd2b 100644 --- a/ground/src/plugins/modelview/modelviewgadgetconfiguration.cpp +++ b/ground/src/plugins/modelview/modelviewgadgetconfiguration.cpp @@ -47,6 +47,22 @@ ModelViewGadgetConfiguration::ModelViewGadgetConfiguration(QString classId, cons } } +ModelViewGadgetConfiguration::ModelViewGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_acFilename("../share/models/Easystar/EasyStar.3ds"), + m_bgFilename(""), + m_enableVbo(false) +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QString modelFile = qSettings->value("acFilename").toString(); + QString bgFile = qSettings->value("bgFilename").toString(); + m_enableVbo = qSettings->value("enableVbo").toBool(); + m_acFilename = Utils::PathUtils().InsertDataPath(modelFile); + m_bgFilename = Utils::PathUtils().InsertDataPath(bgFile); + } +} + IUAVGadgetConfiguration *ModelViewGadgetConfiguration::clone() { ModelViewGadgetConfiguration *mv = new ModelViewGadgetConfiguration(this->classId()); @@ -56,14 +72,12 @@ IUAVGadgetConfiguration *ModelViewGadgetConfiguration::clone() return mv; } -QByteArray ModelViewGadgetConfiguration::saveState() const -{ - - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << Utils::PathUtils().RemoveDataPath(m_acFilename); - stream << Utils::PathUtils().RemoveDataPath(m_bgFilename); - stream << m_enableVbo; - return bytes; +/** + * Saves a configuration. + * + */ +void ModelViewGadgetConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("acFilename", Utils::PathUtils().RemoveDataPath(m_acFilename)); + qSettings->setValue("bgFilename", Utils::PathUtils().RemoveDataPath(m_bgFilename)); + qSettings->setValue("enableVbo", m_enableVbo); } - diff --git a/ground/src/plugins/modelview/modelviewgadgetconfiguration.h b/ground/src/plugins/modelview/modelviewgadgetconfiguration.h index 6ffcf0738..b90d2261a 100644 --- a/ground/src/plugins/modelview/modelviewgadgetconfiguration.h +++ b/ground/src/plugins/modelview/modelviewgadgetconfiguration.h @@ -36,8 +36,10 @@ class ModelViewGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit ModelViewGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); - QByteArray saveState() const; + explicit ModelViewGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit ModelViewGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); QString acFilename() {return m_acFilename;} void setAcFilename(QString acFile) { m_acFilename = acFile; } diff --git a/ground/src/plugins/modelview/modelviewgadgetfactory.cpp b/ground/src/plugins/modelview/modelviewgadgetfactory.cpp index 4ef9986e6..60109185c 100644 --- a/ground/src/plugins/modelview/modelviewgadgetfactory.cpp +++ b/ground/src/plugins/modelview/modelviewgadgetfactory.cpp @@ -52,6 +52,11 @@ IUAVGadgetConfiguration *ModelViewGadgetFactory::createConfiguration(const QByte return new ModelViewGadgetConfiguration(QString("ModelViewGadget"), state); } +IUAVGadgetConfiguration *ModelViewGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new ModelViewGadgetConfiguration(QString("ModelViewGadget"), qSettings); +} + IOptionsPage *ModelViewGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new ModelViewGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/modelview/modelviewgadgetfactory.h b/ground/src/plugins/modelview/modelviewgadgetfactory.h index 750c78798..0f9007b1d 100644 --- a/ground/src/plugins/modelview/modelviewgadgetfactory.h +++ b/ground/src/plugins/modelview/modelviewgadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp b/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp index 460c45a1a..2bb957756 100644 --- a/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp +++ b/ground/src/plugins/opmap/opmapgadgetconfiguration.cpp @@ -78,6 +78,44 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, const QByteA } } +OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_mapProvider("GoogleHybrid"), + m_defaultZoom(2), + m_defaultLatitude(0), + m_defaultLongitude(0), + m_useOpenGL(false), + m_showTileGridLines(false), + m_accessMode("ServerAndCache"), + m_useMemoryCache(true), + m_cacheLocation(QDir::currentPath() + QDir::separator() + "mapscache" + QDir::separator()) +{ + + //if a saved configuration exists load it + if(qSettings != 0) { + QString mapProvider = qSettings->value("mapProvider").toString(); + int zoom = qSettings->value("defaultZoom").toInt(); + double latitude= qSettings->value("defaultLatitude").toDouble(); + double longitude= qSettings->value("defaultLongitude").toDouble(); + bool useOpenGL= qSettings->value("useOpenGL").toBool(); + bool showTileGridLines= qSettings->value("showTileGridLines").toBool(); + QString accessMode= qSettings->value("accessMode").toString(); + bool useMemoryCache= qSettings->value("useMemoryCache").toBool(); + QString cacheLocation= qSettings->value("cacheLocation").toString(); + + if (!mapProvider.isEmpty()) m_mapProvider = mapProvider; + m_defaultZoom = zoom; + m_defaultLatitude = latitude; + m_defaultLongitude = longitude; + m_useOpenGL = useOpenGL; + m_showTileGridLines = showTileGridLines; + + if (!accessMode.isEmpty()) m_accessMode = accessMode; + m_useMemoryCache = useMemoryCache; + if (!cacheLocation.isEmpty()) m_cacheLocation = cacheLocation; + } +} + IUAVGadgetConfiguration * OPMapGadgetConfiguration::clone() { OPMapGadgetConfiguration *m = new OPMapGadgetConfiguration(this->classId()); @@ -95,20 +133,14 @@ IUAVGadgetConfiguration * OPMapGadgetConfiguration::clone() return m; } -QByteArray OPMapGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - - stream << m_mapProvider; - stream << m_defaultZoom; - stream << m_defaultLatitude; - stream << m_defaultLongitude; - stream << m_useOpenGL; - stream << m_showTileGridLines; - stream << m_accessMode; - stream << m_useMemoryCache; - stream << m_cacheLocation; - - return bytes; +void OPMapGadgetConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("mapProvider", m_mapProvider); + qSettings->setValue("defaultZoom", m_defaultZoom); + qSettings->setValue("defaultLatitude", m_defaultLatitude); + qSettings->setValue("defaultLongitude", m_defaultLongitude); + qSettings->setValue("useOpenGL", m_useOpenGL); + qSettings->setValue("showTileGridLines", m_showTileGridLines); + qSettings->setValue("accessMode", m_accessMode); + qSettings->setValue("useMemoryCache", m_useMemoryCache); + qSettings->setValue("cacheLocation", m_cacheLocation); } diff --git a/ground/src/plugins/opmap/opmapgadgetconfiguration.h b/ground/src/plugins/opmap/opmapgadgetconfiguration.h index 7a3bba734..effa5afe8 100644 --- a/ground/src/plugins/opmap/opmapgadgetconfiguration.h +++ b/ground/src/plugins/opmap/opmapgadgetconfiguration.h @@ -48,8 +48,10 @@ Q_PROPERTY(bool useMemoryCache READ useMemoryCache WRITE setUseMemoryCache) Q_PROPERTY(QString cacheLocation READ cacheLocation WRITE setCacheLocation) public: - explicit OPMapGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); - QByteArray saveState() const; + explicit OPMapGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit OPMapGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); QString mapProvider() const { return m_mapProvider; } diff --git a/ground/src/plugins/opmap/opmapgadgetfactory.cpp b/ground/src/plugins/opmap/opmapgadgetfactory.cpp index c8c3e3ba2..79067944f 100644 --- a/ground/src/plugins/opmap/opmapgadgetfactory.cpp +++ b/ground/src/plugins/opmap/opmapgadgetfactory.cpp @@ -51,6 +51,11 @@ IUAVGadgetConfiguration * OPMapGadgetFactory::createConfiguration(const QByteArr return new OPMapGadgetConfiguration(QString("OPMapGadget"), state); } +IUAVGadgetConfiguration *OPMapGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new OPMapGadgetConfiguration(QString("OPMapGadget"), qSettings); +} + IOptionsPage * OPMapGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new OPMapGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/opmap/opmapgadgetfactory.h b/ground/src/plugins/opmap/opmapgadgetfactory.h index a5391477d..f6118605f 100644 --- a/ground/src/plugins/opmap/opmapgadgetfactory.h +++ b/ground/src/plugins/opmap/opmapgadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/pfd/pfdgadgetconfiguration.cpp b/ground/src/plugins/pfd/pfdgadgetconfiguration.cpp index 1b3b03ecd..f8d769430 100644 --- a/ground/src/plugins/pfd/pfdgadgetconfiguration.cpp +++ b/ground/src/plugins/pfd/pfdgadgetconfiguration.cpp @@ -47,6 +47,24 @@ PFDGadgetConfiguration::PFDGadgetConfiguration(QString classId, const QByteArray m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile); } } + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +PFDGadgetConfiguration::PFDGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_defaultDial("Unknown") +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QString dialFile = qSettings->value("dialFile").toString(); + useOpenGLFlag = qSettings->value("useOpenGLFlag").toBool(); + hqFonts = qSettings->value("hqFonts").toBool(); + m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile); + } +} + /** * Clones a configuration. * @@ -59,18 +77,14 @@ IUAVGadgetConfiguration *PFDGadgetConfiguration::clone() m->hqFonts = hqFonts; return m; } + /** * Saves a configuration. * */ -QByteArray PFDGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); +void PFDGadgetConfiguration::saveConfig(QSettings* qSettings) const { QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial); - stream << dialFile; - stream << useOpenGLFlag; - stream << hqFonts; - - return bytes; + qSettings->setValue("dialFile", dialFile); + qSettings->setValue("useOpenGLFlag", useOpenGLFlag); + qSettings->setValue("hqFonts", hqFonts); } diff --git a/ground/src/plugins/pfd/pfdgadgetconfiguration.h b/ground/src/plugins/pfd/pfdgadgetconfiguration.h index 559738f5e..865b53d23 100644 --- a/ground/src/plugins/pfd/pfdgadgetconfiguration.h +++ b/ground/src/plugins/pfd/pfdgadgetconfiguration.h @@ -36,7 +36,8 @@ class PFDGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit PFDGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit PFDGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit PFDGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); //set dial configuration functions void setDialFile(QString dialFile){m_defaultDial=dialFile;} @@ -47,7 +48,7 @@ public: bool useOpenGL() { return useOpenGLFlag; } bool getHqFonts() { return hqFonts; } - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/pfd/pfdgadgetfactory.cpp b/ground/src/plugins/pfd/pfdgadgetfactory.cpp index accb818c3..ca91cb3d9 100644 --- a/ground/src/plugins/pfd/pfdgadgetfactory.cpp +++ b/ground/src/plugins/pfd/pfdgadgetfactory.cpp @@ -53,6 +53,11 @@ IUAVGadgetConfiguration *PFDGadgetFactory::createConfiguration(const QByteArray return new PFDGadgetConfiguration(QString("PFDGadget"), state); } +IUAVGadgetConfiguration *PFDGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new PFDGadgetConfiguration(QString("PFDGadget"), qSettings); +} + IOptionsPage *PFDGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new PFDGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/pfd/pfdgadgetfactory.h b/ground/src/plugins/pfd/pfdgadgetfactory.h index 088e398df..24c45146a 100644 --- a/ground/src/plugins/pfd/pfdgadgetfactory.h +++ b/ground/src/plugins/pfd/pfdgadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/scope/scopegadgetconfiguration.cpp b/ground/src/plugins/scope/scopegadgetconfiguration.cpp index b7b4167da..bb996f7d0 100644 --- a/ground/src/plugins/scope/scopegadgetconfiguration.cpp +++ b/ground/src/plugins/scope/scopegadgetconfiguration.cpp @@ -78,6 +78,58 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, const QByteA } +ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_plotType((int)ChronoPlot), + m_dataSize(60), + m_refreshInterval(1000) +{ + uint currentStreamVersion = 0; + int plotCurveCount = 0; + + + //if a saved configuration exists load it + if(qSettings != 0) { + currentStreamVersion = qSettings->value("configurationStreamVersion").toUInt(); + + if(currentStreamVersion != m_configurationStreamVersion) + return; + + m_plotType = qSettings->value("plotType").toInt(); + m_dataSize = qSettings->value("dataSize").toInt(); + m_refreshInterval = qSettings->value("refreshInterval").toInt(); + plotCurveCount = qSettings->value("plotCurveCount").toInt(); + + for(int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) + { + QString uavObject; + QString uavField; + QRgb color; + + qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex)); + + PlotCurveConfiguration* plotCurveConf = new PlotCurveConfiguration(); + uavObject = qSettings->value("uavObject").toString(); + plotCurveConf->uavObject = uavObject; + uavField = qSettings->value("uavField").toString(); + plotCurveConf->uavField = uavField; + color = qSettings->value("color").value(); + plotCurveConf->color = color; + plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); + plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); + plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble(); + + m_PlotCurveConfigs.append(plotCurveConf); + + qSettings->endGroup(); + } + + //The value is converted to milliseconds, so if it is < 100, it is still seconds + if(m_refreshInterval < 100) + m_refreshInterval *= 1000; + } +} + void ScopeGadgetConfiguration::clearPlotData() { PlotCurveConfiguration* poltCurveConfig; @@ -129,31 +181,31 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone() * Saves a configuration. * */ -QByteArray ScopeGadgetConfiguration::saveState() const -{ +void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const { + int plotCurveCount = m_PlotCurveConfigs.size(); int plotDatasLoadIndex = 0; - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << m_configurationStreamVersion; - stream << m_plotType; - stream << m_dataSize; - stream << m_refreshInterval; - stream << plotCurveCount; + + qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion); + qSettings->setValue("plotType", m_plotType); + qSettings->setValue("dataSize", m_dataSize); + qSettings->setValue("refreshInterval", m_refreshInterval); + qSettings->setValue("plotCurveCount", plotCurveCount); for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) { + qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex)); + PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex); + qSettings->setValue("uavObject", plotCurveConf->uavObject); + qSettings->setValue("uavField", plotCurveConf->uavField); + qSettings->setValue("color", plotCurveConf->color); + qSettings->setValue("yScalePower", plotCurveConf->yScalePower); + qSettings->setValue("yMinimum", plotCurveConf->yMinimum); + qSettings->setValue("yMaximum", plotCurveConf->yMaximum); - stream << plotCurveConf->uavObject; - stream << plotCurveConf->uavField; - stream << plotCurveConf->color; - stream << plotCurveConf->yScalePower; - stream << plotCurveConf->yMinimum; - stream << plotCurveConf->yMaximum; + qSettings->endGroup(); } - - return bytes; } void ScopeGadgetConfiguration::replacePlotCurveConfig(QList newPlotCurveConfigs) diff --git a/ground/src/plugins/scope/scopegadgetconfiguration.h b/ground/src/plugins/scope/scopegadgetconfiguration.h index 024681676..707d00a52 100644 --- a/ground/src/plugins/scope/scopegadgetconfiguration.h +++ b/ground/src/plugins/scope/scopegadgetconfiguration.h @@ -49,7 +49,9 @@ class ScopeGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit ScopeGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit ScopeGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit ScopeGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + ~ScopeGadgetConfiguration(); //configuration setter functions @@ -66,7 +68,7 @@ public: int refreshInterval(){return m_refreshInterval;} QList plotCurveConfigs(){return m_PlotCurveConfigs;} - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/scope/scopegadgetfactory.cpp b/ground/src/plugins/scope/scopegadgetfactory.cpp index d68e0e844..73d6ae687 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.cpp +++ b/ground/src/plugins/scope/scopegadgetfactory.cpp @@ -53,6 +53,11 @@ IUAVGadgetConfiguration *ScopeGadgetFactory::createConfiguration(const QByteArra return new ScopeGadgetConfiguration(QString("ScopeGadget"), state); } +IUAVGadgetConfiguration *ScopeGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new ScopeGadgetConfiguration(QString("ScopeGadget"), qSettings); +} + IOptionsPage *ScopeGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new ScopeGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/scope/scopegadgetfactory.h b/ground/src/plugins/scope/scopegadgetfactory.h index 6404dcc0b..15fe32eb5 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.h +++ b/ground/src/plugins/scope/scopegadgetfactory.h @@ -47,6 +47,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.cpp b/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.cpp index 71d572ccb..2c102a580 100644 --- a/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.cpp +++ b/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.cpp @@ -45,6 +45,22 @@ SystemHealthGadgetConfiguration::SystemHealthGadgetConfiguration(QString classId systemFile = Utils::PathUtils().InsertDataPath(diagram); } } + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +SystemHealthGadgetConfiguration::SystemHealthGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + systemFile("Unknown") +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QString diagram= qSettings->value("diagram").toString(); + systemFile = Utils::PathUtils().InsertDataPath(diagram); + } +} + /** * Clones a configuration. * @@ -55,16 +71,12 @@ IUAVGadgetConfiguration *SystemHealthGadgetConfiguration::clone() m->systemFile=systemFile; return m; } + /** * Saves a configuration. * */ -QByteArray SystemHealthGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); +void SystemHealthGadgetConfiguration::saveConfig(QSettings* qSettings) const { QString diagram = Utils::PathUtils().RemoveDataPath(systemFile); - stream << diagram; - - return bytes; + qSettings->setValue("diagram", diagram); } diff --git a/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.h b/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.h index 35a8705a7..ad3ff1428 100644 --- a/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.h +++ b/ground/src/plugins/systemhealth/systemhealthgadgetconfiguration.h @@ -39,7 +39,8 @@ class SystemHealthGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit SystemHealthGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit SystemHealthGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit SystemHealthGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); //set system health configuration functions void setSystemFile(QString filename){systemFile=filename;} @@ -47,7 +48,7 @@ public: //get dial configuration functions QString getSystemFile() {return systemFile;} - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/systemhealth/systemhealthgadgetfactory.cpp b/ground/src/plugins/systemhealth/systemhealthgadgetfactory.cpp index 456069514..557897bf6 100644 --- a/ground/src/plugins/systemhealth/systemhealthgadgetfactory.cpp +++ b/ground/src/plugins/systemhealth/systemhealthgadgetfactory.cpp @@ -53,6 +53,11 @@ IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(const QB return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), state); } +IUAVGadgetConfiguration *SystemHealthGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new SystemHealthGadgetConfiguration(QString("SystemHealthGadget"), qSettings); +} + IOptionsPage *SystemHealthGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new SystemHealthGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/systemhealth/systemhealthgadgetfactory.h b/ground/src/plugins/systemhealth/systemhealthgadgetfactory.h index 78aa66079..f11108729 100644 --- a/ground/src/plugins/systemhealth/systemhealthgadgetfactory.h +++ b/ground/src/plugins/systemhealth/systemhealthgadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.cpp b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.cpp index d9f81402a..56314b845 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.cpp +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.cpp @@ -48,6 +48,24 @@ UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, co } } +UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_recentlyUpdatedColor(QColor(255, 230, 230)), + m_manuallyChangedColor(QColor(230, 230, 255)), + m_recentlyUpdatedTimeout(500) +{ + //if a saved configuration exists load it + if(qSettings != 0) { + QColor recent = qSettings->value("recentlyUpdatedColor").value(); + QColor manual = qSettings->value("manuallyChangedColor").value(); + int timeout = qSettings->value("recentlyUpdatedTimeout").toInt(); + + m_recentlyUpdatedColor = recent; + m_manuallyChangedColor = manual; + m_recentlyUpdatedTimeout = timeout; + } +} + IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone() { UAVObjectBrowserConfiguration *m = new UAVObjectBrowserConfiguration(this->classId()); @@ -57,13 +75,12 @@ IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone() return m; } -QByteArray UAVObjectBrowserConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << m_recentlyUpdatedColor; - stream << m_manuallyChangedColor; - stream << m_recentlyUpdatedTimeout; - return bytes; +/** + * Saves a configuration. + * + */ +void UAVObjectBrowserConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("recentlyUpdatedColor", m_recentlyUpdatedColor); + qSettings->setValue("manuallyChangedColor", m_manuallyChangedColor); + qSettings->setValue("recentlyUpdatedTimeout", m_recentlyUpdatedTimeout); } - diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.h b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.h index 139b89741..251ebfcb2 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.h +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserconfiguration.h @@ -40,8 +40,10 @@ Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRece Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor) Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout) public: - explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); - QByteArray saveState() const; + explicit UAVObjectBrowserConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit UAVObjectBrowserConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; } diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.cpp b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.cpp index 15a03833a..995c98dd3 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.cpp +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.cpp @@ -51,6 +51,12 @@ IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(const QByt return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), state); } +IUAVGadgetConfiguration *UAVObjectBrowserFactory::createConfiguration(QSettings* qSettings) +{ + return new UAVObjectBrowserConfiguration(QString("UAVObjectBrowser"), qSettings); +} + + IOptionsPage *UAVObjectBrowserFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new UAVObjectBrowserOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.h b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.h index 64cab413e..fdf8ca8b7 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.h +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; diff --git a/ground/src/plugins/uploader/uploadergadgetconfiguration.cpp b/ground/src/plugins/uploader/uploadergadgetconfiguration.cpp index 21278333a..84a308018 100755 --- a/ground/src/plugins/uploader/uploadergadgetconfiguration.cpp +++ b/ground/src/plugins/uploader/uploadergadgetconfiguration.cpp @@ -80,6 +80,54 @@ UploaderGadgetConfiguration::UploaderGadgetConfiguration(QString classId, const } } + + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +UploaderGadgetConfiguration::UploaderGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_defaultPort("Unknown"), + m_defaultSpeed(BAUD19200), + m_defaultDataBits(DATA_8), + m_defaultFlow(FLOW_OFF), + m_defaultParity(PAR_NONE), + m_defaultStopBits(STOP_1), + m_defaultTimeOut(5000) + +{ + //if a saved configuration exists load it + if(qSettings != 0) { + BaudRateType speed; + DataBitsType databits; + FlowType flow; + ParityType parity; + StopBitsType stopbits; + + int ispeed = qSettings->value("defaultSpeed").toInt(); + int idatabits = qSettings->value("defaultDataBits").toInt(); + int iflow = qSettings->value("defaultFlow").toInt(); + int iparity = qSettings->value("defaultParity").toInt(); + int istopbits = qSettings->value("defaultStopBits").toInt(); + QString port = qSettings->value("defaultPort").toString(); + + databits=(DataBitsType) idatabits; + flow=(FlowType)iflow; + parity=(ParityType)iparity; + stopbits=(StopBitsType)istopbits; + speed=(BaudRateType)ispeed; + m_defaultPort=port; + m_defaultSpeed=speed; + m_defaultDataBits=databits; + m_defaultFlow=flow; + m_defaultParity=parity; + m_defaultStopBits=stopbits; + + } + +} + /** * Clones a configuration. * @@ -96,20 +144,16 @@ IUAVGadgetConfiguration *UploaderGadgetConfiguration::clone() m->m_defaultPort=m_defaultPort; return m; } + /** * Saves a configuration. * */ -QByteArray UploaderGadgetConfiguration::saveState() const -{ - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << (int)m_defaultSpeed; - stream << (int)m_defaultDataBits; - stream << (int)m_defaultFlow; - stream << (int)m_defaultParity; - stream << (int)m_defaultStopBits; - stream << m_defaultPort; - return bytes; +void UploaderGadgetConfiguration::saveConfig(QSettings* qSettings) const { + qSettings->setValue("defaultSpeed", m_defaultSpeed); + qSettings->setValue("defaultDataBits", m_defaultDataBits); + qSettings->setValue("defaultFlow", m_defaultFlow); + qSettings->setValue("defaultParity", m_defaultParity); + qSettings->setValue("defaultStopBits", m_defaultStopBits); + qSettings->setValue("defaultPort", m_defaultPort); } - diff --git a/ground/src/plugins/uploader/uploadergadgetconfiguration.h b/ground/src/plugins/uploader/uploadergadgetconfiguration.h index 1f8e1c864..e58eac47d 100755 --- a/ground/src/plugins/uploader/uploadergadgetconfiguration.h +++ b/ground/src/plugins/uploader/uploadergadgetconfiguration.h @@ -37,7 +37,8 @@ class UploaderGadgetConfiguration : public IUAVGadgetConfiguration { Q_OBJECT public: - explicit UploaderGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + explicit UploaderGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent = 0); + explicit UploaderGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); //set port configuration functions void setSpeed(BaudRateType speed) {m_defaultSpeed=speed;} @@ -57,7 +58,7 @@ public: QString Port(){return m_defaultPort;} long TimeOut(){return m_defaultTimeOut;} - QByteArray saveState() const; + void saveConfig(QSettings* settings) const; IUAVGadgetConfiguration *clone(); private: diff --git a/ground/src/plugins/uploader/uploadergadgetfactory.cpp b/ground/src/plugins/uploader/uploadergadgetfactory.cpp index cfb46e46c..36229125d 100755 --- a/ground/src/plugins/uploader/uploadergadgetfactory.cpp +++ b/ground/src/plugins/uploader/uploadergadgetfactory.cpp @@ -52,6 +52,11 @@ IUAVGadgetConfiguration *UploaderGadgetFactory::createConfiguration(const QByteA return new UploaderGadgetConfiguration(QString("Uploader"), state); } +IUAVGadgetConfiguration *UploaderGadgetFactory::createConfiguration(QSettings* qSettings) +{ + return new UploaderGadgetConfiguration(QString("Uploader"), qSettings); +} + IOptionsPage *UploaderGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { return new UploaderGadgetOptionsPage(qobject_cast(config)); diff --git a/ground/src/plugins/uploader/uploadergadgetfactory.h b/ground/src/plugins/uploader/uploadergadgetfactory.h index 93167097c..5a4cb9fb8 100755 --- a/ground/src/plugins/uploader/uploadergadgetfactory.h +++ b/ground/src/plugins/uploader/uploadergadgetfactory.h @@ -46,6 +46,7 @@ public: Core::IUAVGadget *createGadget(QWidget *parent); IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings); IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); };