mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-99 Ground Import/Export Plugin: Add version-number to plugin configuration.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1771 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
a46b46f939
commit
9d5f82727f
@ -29,11 +29,14 @@
|
|||||||
#define IUAVGADGETCONFIGURATION_H
|
#define IUAVGADGETCONFIGURATION_H
|
||||||
|
|
||||||
#include <coreplugin/core_global.h>
|
#include <coreplugin/core_global.h>
|
||||||
|
#include <coreplugin/uavconfiginfo.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
class UAVConfigInfo;
|
||||||
|
|
||||||
class CORE_EXPORT IUAVGadgetConfiguration : public QObject
|
class CORE_EXPORT IUAVGadgetConfiguration : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -47,7 +50,8 @@ public:
|
|||||||
bool locked() const { return m_locked; }
|
bool locked() const { return m_locked; }
|
||||||
void setLocked(bool locked) { m_locked = locked; }
|
void setLocked(bool locked) { m_locked = locked; }
|
||||||
|
|
||||||
virtual void saveConfig(QSettings* settings) const = 0;
|
virtual void saveConfig(QSettings* /*settings*/) const {};
|
||||||
|
virtual void saveConfig(QSettings* settings, UAVConfigInfo* /*configInfo*/) const { saveConfig(settings); }
|
||||||
|
|
||||||
virtual IUAVGadgetConfiguration *clone() = 0;
|
virtual IUAVGadgetConfiguration *clone() = 0;
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include "uavconfiginfo.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QStringList;
|
class QStringList;
|
||||||
@ -55,6 +56,7 @@ public:
|
|||||||
|
|
||||||
virtual IUAVGadget *createGadget(QWidget *parent) = 0;
|
virtual IUAVGadget *createGadget(QWidget *parent) = 0;
|
||||||
virtual IUAVGadgetConfiguration *createConfiguration(QSettings* /*qSettings*/) { return 0; }
|
virtual IUAVGadgetConfiguration *createConfiguration(QSettings* /*qSettings*/) { return 0; }
|
||||||
|
virtual IUAVGadgetConfiguration *createConfiguration(QSettings* qs, UAVConfigInfo */*configInfo*/) { return createConfiguration(qs); }
|
||||||
virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
|
virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
|
||||||
QString classId() const { return m_classId; }
|
QString classId() const { return m_classId; }
|
||||||
QString name() const { return m_name; }
|
QString name() const { return m_name; }
|
||||||
|
@ -24,6 +24,85 @@
|
|||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
/*!
|
||||||
|
\class Core::UAVConfigInfo
|
||||||
|
\mainclass
|
||||||
|
|
||||||
|
\brief The Config Info is a helper-class to handle version changes in GCS
|
||||||
|
configuration files.
|
||||||
|
|
||||||
|
The UAVConfigInfo provides version-information for the configuration-data
|
||||||
|
and callback functions to ask the user how to handle incompatble
|
||||||
|
(old or newer) configurations.
|
||||||
|
|
||||||
|
When the config is created from a \l{QSettings} instance, an UAVConfigInfo
|
||||||
|
object is passed to the factory-method. With the version-data it can decide whether
|
||||||
|
the presented config-data is compatible to the current implementation. It may
|
||||||
|
migrate old data to the current format or abort the import.
|
||||||
|
|
||||||
|
When the config is written to the \l{QSettings} instance, an UAVConfigInfo object
|
||||||
|
is passed to the writer-function. The version of the config-format should
|
||||||
|
be written to the UAVConfigInfo object. This version will be passed to
|
||||||
|
factory-method when creating the config-object from this configuration.
|
||||||
|
|
||||||
|
|
||||||
|
Typically a plugin can handle version-changes like this:
|
||||||
|
\code
|
||||||
|
MyGadgetConfiguration::MyGadgetConfiguration(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(CURRENT_VERSION))
|
||||||
|
return;
|
||||||
|
|
||||||
|
... read the config ...
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyGadgetConfiguration::saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) const {
|
||||||
|
|
||||||
|
configInfo->setVersion(CURRENT_VERSION);
|
||||||
|
|
||||||
|
... write the config ...
|
||||||
|
}
|
||||||
|
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
|
||||||
|
\section1 Version Conventions
|
||||||
|
|
||||||
|
The Version numbers are in the form "major.minor.patch" (e.g. "3.1.4") with the
|
||||||
|
following meaning:
|
||||||
|
\list
|
||||||
|
\o major: Differences in this number indicate completely incompatible formats. The
|
||||||
|
config can't be imported.
|
||||||
|
\o minor: Differences in this number indicate backwards compatible formats. Old
|
||||||
|
configs can be imported or will be automatically migrated by the new program
|
||||||
|
but configs written by this plugin can't be reasonably read by old versions of
|
||||||
|
the plugin.
|
||||||
|
\o patch: Differences in this number indicate backwards and forward compatible formats.
|
||||||
|
Configs written by this plugin can be read by old versions of the plugin. Old configs
|
||||||
|
are extended by defaults by the new plugin.
|
||||||
|
\endlist
|
||||||
|
|
||||||
|
All parts (major, minor, patch) must be numeric values.
|
||||||
|
|
||||||
|
\section1 Utility Functions
|
||||||
|
|
||||||
|
\fn bool UAVConfigInfo::standardVersionHandlingOK(UAVConfigVersion programVersion)
|
||||||
|
\brief Default version handling.
|
||||||
|
|
||||||
|
With this function the plugin can test compatiblility of the current version
|
||||||
|
with the imported version. If there are differences, the user is asked whether
|
||||||
|
he or she wants to import the settings or abort the import.
|
||||||
|
|
||||||
|
Returns true when the import should be done, false otherwise.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#include "uavconfiginfo.h"
|
#include "uavconfiginfo.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -47,27 +126,51 @@ by your version of the plugin. You should upgrade the plugin to import these set
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
|
UAVConfigInfo::UAVConfigInfo(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_version(VERSION_DEFAULT),
|
||||||
|
m_locked(false),
|
||||||
|
m_nameOfConfigurable("")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
UAVConfigInfo::UAVConfigInfo(QSettings *qs, QObject *parent) :
|
UAVConfigInfo::UAVConfigInfo(QSettings *qs, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_version(VERSION_DEFAULT)
|
m_version(VERSION_DEFAULT)
|
||||||
{
|
{
|
||||||
qs->beginGroup("configInfo");
|
read(qs);
|
||||||
m_version = UAVConfigVersion( qs->value("version", VERSION_DEFAULT ).toString());
|
|
||||||
qs->endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UAVConfigInfo::UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent) :
|
UAVConfigInfo::UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_version(version),
|
m_version(version),
|
||||||
|
m_locked(false),
|
||||||
m_nameOfConfigurable(nameOfConfigurable)
|
m_nameOfConfigurable(nameOfConfigurable)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UAVConfigInfo::UAVConfigInfo(IUAVGadgetConfiguration *config, QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_locked = config->locked();
|
||||||
|
m_nameOfConfigurable = config->classId() + "-" + config->name();
|
||||||
|
}
|
||||||
|
|
||||||
void UAVConfigInfo::save(QSettings *qs)
|
void UAVConfigInfo::save(QSettings *qs)
|
||||||
{
|
{
|
||||||
qs->beginGroup("configInfo");
|
qs->beginGroup("configInfo");
|
||||||
qs->setValue("version", m_version.toString());
|
qs->setValue("version", m_version.toString());
|
||||||
|
qs->setValue("locked", m_locked);
|
||||||
|
qs->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAVConfigInfo::read(QSettings *qs)
|
||||||
|
{
|
||||||
|
qs->beginGroup("configInfo");
|
||||||
|
m_version = UAVConfigVersion( qs->value("version", VERSION_DEFAULT ).toString());
|
||||||
|
m_locked = qs->value("locked", false ).toBool();
|
||||||
qs->endGroup();
|
qs->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +207,7 @@ bool UAVConfigInfo::askToAbort(int compat, QString message)
|
|||||||
|
|
||||||
case NotCompatible:
|
case NotCompatible:
|
||||||
msgBox.setText("ERROR: " + message + TEXT_NOT_COMPATIBLE);
|
msgBox.setText("ERROR: " + message + TEXT_NOT_COMPATIBLE);
|
||||||
|
msgBox.setInformativeText(tr(""));
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return true;
|
return true;
|
||||||
@ -118,7 +222,7 @@ bool UAVConfigInfo::askToAbort(int compat, QString message)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVConfigInfo::notifyAbort(QString message)
|
void UAVConfigInfo::notify(QString message)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setText(message);
|
msgBox.setText(message);
|
||||||
@ -139,9 +243,9 @@ int UAVConfigInfo::checkCompatibilityWith(UAVConfigVersion programVersion)
|
|||||||
return FullyCompatible;
|
return FullyCompatible;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UAVConfigInfo::standardVersionHandlingIsNotOK(UAVConfigVersion programVersion)
|
bool UAVConfigInfo::standardVersionHandlingOK(UAVConfigVersion programVersion)
|
||||||
{
|
{
|
||||||
return askToAbort(
|
return !askToAbort(
|
||||||
checkCompatibilityWith(programVersion),
|
checkCompatibilityWith(programVersion),
|
||||||
"("+m_nameOfConfigurable+")");
|
"("+m_nameOfConfigurable+")");
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,15 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include "iuavgadgetconfiguration.h"
|
||||||
|
#include "core_global.h"
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
|
|
||||||
class UAVConfigVersion{
|
class IUAVGadgetConfiguration;
|
||||||
|
|
||||||
|
class CORE_EXPORT UAVConfigVersion{
|
||||||
public:
|
public:
|
||||||
UAVConfigVersion(QString versionString = "0.0.0");
|
UAVConfigVersion(QString versionString = "0.0.0");
|
||||||
UAVConfigVersion(int major, int minor, int patch);
|
UAVConfigVersion(int major, int minor, int patch);
|
||||||
@ -47,26 +51,34 @@ public:
|
|||||||
bool operator==(const UAVConfigVersion &other);
|
bool operator==(const UAVConfigVersion &other);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UAVConfigInfo : public QObject
|
class CORE_EXPORT UAVConfigInfo : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UAVConfigInfo(QSettings *qs, QObject *parent = 0);
|
explicit UAVConfigInfo(QObject *parent = 0);
|
||||||
|
explicit UAVConfigInfo(QSettings *qs, QObject *parent = 0);
|
||||||
|
explicit UAVConfigInfo(IUAVGadgetConfiguration* config, QObject *parent = 0);
|
||||||
UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent = 0);
|
UAVConfigInfo(UAVConfigVersion version, QString nameOfConfigurable, QObject *parent = 0);
|
||||||
|
|
||||||
enum Compatibility { FullyCompatible, MinorLossOfConfiguration, MissingConfiguration, MajorLossOfConfiguration, NotCompatible };
|
enum Compatibility { FullyCompatible, MinorLossOfConfiguration, MissingConfiguration, MajorLossOfConfiguration, NotCompatible };
|
||||||
void setNameOfConfigurable(const QString nameOfConfigurable){m_nameOfConfigurable = nameOfConfigurable;}
|
void setNameOfConfigurable(const QString nameOfConfigurable){m_nameOfConfigurable = nameOfConfigurable;}
|
||||||
|
|
||||||
void save(QSettings *qs);
|
void save(QSettings *qs);
|
||||||
|
void read(QSettings *qs);
|
||||||
|
|
||||||
void setVersion(int major, int minor, int patch){m_version = UAVConfigVersion(major, minor, patch);}
|
void setVersion(int major, int minor, int patch){m_version = UAVConfigVersion(major, minor, patch);}
|
||||||
void setVersion(const QString version){m_version = UAVConfigVersion(version);}
|
void setVersion(const QString version){m_version = UAVConfigVersion(version);}
|
||||||
|
void setVersion(const UAVConfigVersion version){m_version = version;}
|
||||||
UAVConfigVersion version(){ return m_version;}
|
UAVConfigVersion version(){ return m_version;}
|
||||||
|
bool locked(){ return m_locked; }
|
||||||
|
void setLocked(bool locked){ m_locked = locked; }
|
||||||
|
|
||||||
int checkCompatibilityWith(UAVConfigVersion programVersion);
|
int checkCompatibilityWith(UAVConfigVersion programVersion);
|
||||||
bool askToAbort(int compat, QString message);
|
bool askToAbort(int compat, QString message);
|
||||||
void notifyAbort(QString message);
|
void notify(QString message);
|
||||||
bool standardVersionHandlingIsNotOK(UAVConfigVersion programVersion);
|
bool standardVersionHandlingOK(UAVConfigVersion programVersion);
|
||||||
|
bool standardVersionHandlingOK(QString programVersion){ return standardVersionHandlingOK(UAVConfigVersion(programVersion));}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -74,6 +86,7 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
UAVConfigVersion m_version;
|
UAVConfigVersion m_version;
|
||||||
|
bool m_locked;
|
||||||
QString m_nameOfConfigurable;
|
QString m_nameOfConfigurable;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -44,9 +44,10 @@
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
|
static const UAVConfigVersion m_versionUAVGadgetConfigurations = UAVConfigVersion("1.2.0");
|
||||||
|
|
||||||
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent)
|
||||||
m_versionUAVGadgetConfigurations("1.1.0")
|
|
||||||
{
|
{
|
||||||
m_pm = ExtensionSystem::PluginManager::instance();
|
m_pm = ExtensionSystem::PluginManager::instance();
|
||||||
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
|
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
|
||||||
@ -77,23 +78,86 @@ void UAVGadgetInstanceManager::readConfigurations(QSettings *qs)
|
|||||||
UAVConfigInfo configInfo(qs);
|
UAVConfigInfo configInfo(qs);
|
||||||
configInfo.setNameOfConfigurable("UAVGadgetConfigurations");
|
configInfo.setNameOfConfigurable("UAVGadgetConfigurations");
|
||||||
if ( configInfo.version() == UAVConfigVersion() ){
|
if ( configInfo.version() == UAVConfigVersion() ){
|
||||||
// If version is not set, assume its a old version before readable config.
|
// If version is not set, assume its a old version before readable config (1.0.0).
|
||||||
|
// however compatibility to 1.0.0 is broken.
|
||||||
configInfo.setVersion("1.0.0");
|
configInfo.setVersion("1.0.0");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if ( configInfo.standardVersionHandlingIsNotOK(m_versionUAVGadgetConfigurations) ){
|
if ( configInfo.version() == UAVConfigVersion("1.1.0") ){
|
||||||
// We are in trouble now. User wants us to quit the import.
|
configInfo.notify(tr("Migrating UAVGadgetConfigurations from version 1.1.0 to ")
|
||||||
qs->endGroup();
|
+ m_versionUAVGadgetConfigurations.toString());
|
||||||
return;
|
readConfigs_1_1_0(qs); // this is fully compatible with 1.2.0
|
||||||
}
|
}
|
||||||
*/
|
else if ( !configInfo.standardVersionHandlingOK(m_versionUAVGadgetConfigurations) ){
|
||||||
readConfigs_1_0_0(qs);
|
// We are in trouble now. User wants us to quit the import, but when he saves
|
||||||
|
// the GCS, his old config will be lost.
|
||||||
|
configInfo.notify(
|
||||||
|
tr("You might want to save your old config NOW since it might be replaced by broken one when you exit the GCS!")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
readConfigs_1_2_0(qs);
|
||||||
|
}
|
||||||
|
|
||||||
qs->endGroup();
|
qs->endGroup();
|
||||||
createOptionsPages();
|
createOptionsPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs)
|
void UAVGadgetInstanceManager::readConfigs_1_2_0(QSettings *qs)
|
||||||
{
|
{
|
||||||
|
UAVConfigInfo configInfo;
|
||||||
|
|
||||||
|
foreach (QString classId, m_classIds.keys())
|
||||||
|
{
|
||||||
|
IUAVGadgetFactory *f = factory(classId);
|
||||||
|
qs->beginGroup(classId);
|
||||||
|
|
||||||
|
QStringList configs = QStringList();
|
||||||
|
|
||||||
|
configs = qs->childGroups();
|
||||||
|
foreach (QString configName, configs) {
|
||||||
|
qDebug() << "Loading config: " << classId << "," << configName;
|
||||||
|
qs->beginGroup(configName);
|
||||||
|
configInfo.read(qs);
|
||||||
|
configInfo.setNameOfConfigurable(classId+"-"+configName);
|
||||||
|
qs->beginGroup("data");
|
||||||
|
IUAVGadgetConfiguration *config = f->createConfiguration(qs, &configInfo);
|
||||||
|
if (config){
|
||||||
|
config->setName(configName);
|
||||||
|
config->setProvisionalName(configName);
|
||||||
|
config->setLocked(configInfo.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();
|
||||||
|
qs->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configs.count() == 0) {
|
||||||
|
IUAVGadgetConfiguration *config = f->createConfiguration(0, 0);
|
||||||
|
// it is not mandatory for uavgadgets to have any configurations (settings)
|
||||||
|
// and therefore we have to check for that
|
||||||
|
if (config) {
|
||||||
|
config->setName(tr("default"));
|
||||||
|
config->setProvisionalName(tr("default"));
|
||||||
|
m_configurations.append(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qs->endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAVGadgetInstanceManager::readConfigs_1_1_0(QSettings *qs)
|
||||||
|
{
|
||||||
|
UAVConfigInfo configInfo;
|
||||||
|
|
||||||
foreach (QString classId, m_classIds.keys())
|
foreach (QString classId, m_classIds.keys())
|
||||||
{
|
{
|
||||||
IUAVGadgetFactory *f = factory(classId);
|
IUAVGadgetFactory *f = factory(classId);
|
||||||
@ -106,7 +170,8 @@ void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs)
|
|||||||
qDebug() << "Loading config: " << classId << "," << configName;
|
qDebug() << "Loading config: " << classId << "," << configName;
|
||||||
qs->beginGroup(configName);
|
qs->beginGroup(configName);
|
||||||
bool locked = qs->value("config.locked").toBool();
|
bool locked = qs->value("config.locked").toBool();
|
||||||
IUAVGadgetConfiguration *config = f->createConfiguration(qs);
|
configInfo.setNameOfConfigurable(classId+"-"+configName);
|
||||||
|
IUAVGadgetConfiguration *config = f->createConfiguration(qs, &configInfo);
|
||||||
if (config){
|
if (config){
|
||||||
config->setName(configName);
|
config->setName(configName);
|
||||||
config->setProvisionalName(configName);
|
config->setProvisionalName(configName);
|
||||||
@ -125,7 +190,7 @@ void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configs.count() == 0) {
|
if (configs.count() == 0) {
|
||||||
IUAVGadgetConfiguration *config = f->createConfiguration(0);
|
IUAVGadgetConfiguration *config = f->createConfiguration(0, 0);
|
||||||
// it is not mandatory for uavgadgets to have any configurations (settings)
|
// it is not mandatory for uavgadgets to have any configurations (settings)
|
||||||
// and therefore we have to check for that
|
// and therefore we have to check for that
|
||||||
if (config) {
|
if (config) {
|
||||||
@ -140,19 +205,24 @@ void UAVGadgetInstanceManager::readConfigs_1_0_0(QSettings *qs)
|
|||||||
|
|
||||||
void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs)
|
void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs)
|
||||||
{
|
{
|
||||||
|
UAVConfigInfo *configInfo;
|
||||||
qs->beginGroup("UAVGadgetConfigurations");
|
qs->beginGroup("UAVGadgetConfigurations");
|
||||||
qs->remove(""); // Remove existing configurations
|
qs->remove(""); // Remove existing configurations
|
||||||
UAVConfigInfo configInfo(m_versionUAVGadgetConfigurations, "UAVGadgetConfigurations");
|
configInfo = new UAVConfigInfo(m_versionUAVGadgetConfigurations, "UAVGadgetConfigurations");
|
||||||
configInfo.save(qs);
|
configInfo->save(qs);
|
||||||
|
delete configInfo;
|
||||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||||
{
|
{
|
||||||
|
configInfo = new UAVConfigInfo(config);
|
||||||
qs->beginGroup(config->classId());
|
qs->beginGroup(config->classId());
|
||||||
qs->beginGroup(config->name());
|
qs->beginGroup(config->name());
|
||||||
// TODO: Someone could accidentially use the same name?
|
qs->beginGroup("data");
|
||||||
qs->setValue("config.locked", config->locked());
|
config->saveConfig(qs, configInfo);
|
||||||
config->saveConfig(qs);
|
qs->endGroup();
|
||||||
|
configInfo->save(qs);
|
||||||
qs->endGroup();
|
qs->endGroup();
|
||||||
qs->endGroup();
|
qs->endGroup();
|
||||||
|
delete configInfo;
|
||||||
}
|
}
|
||||||
qs->endGroup();
|
qs->endGroup();
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,10 @@ private:
|
|||||||
QList<IOptionsPage*> m_provisionalOptionsPages;
|
QList<IOptionsPage*> m_provisionalOptionsPages;
|
||||||
Core::Internal::SettingsDialog *m_settingsDialog;
|
Core::Internal::SettingsDialog *m_settingsDialog;
|
||||||
ExtensionSystem::PluginManager *m_pm;
|
ExtensionSystem::PluginManager *m_pm;
|
||||||
UAVConfigVersion m_versionUAVGadgetConfigurations;
|
|
||||||
int indexForConfig(QList<IUAVGadgetConfiguration*> configurations,
|
int indexForConfig(QList<IUAVGadgetConfiguration*> configurations,
|
||||||
QString classId, QString configName);
|
QString classId, QString configName);
|
||||||
void readConfigs_1_0_0(QSettings *qs);
|
void readConfigs_1_1_0(QSettings *qs);
|
||||||
|
void readConfigs_1_2_0(QSettings *qs);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -29,18 +29,26 @@
|
|||||||
|
|
||||||
#include "importexportgadgetconfiguration.h"
|
#include "importexportgadgetconfiguration.h"
|
||||||
|
|
||||||
|
static const QString VERSION = "1.0.1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a saved configuration or defaults if non exist.
|
* Loads a saved configuration or defaults if non exist.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
|
ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, QSettings* qSettings, UAVConfigInfo *configInfo, QObject *parent) :
|
||||||
IUAVGadgetConfiguration(classId, parent),
|
IUAVGadgetConfiguration(classId, parent)
|
||||||
dialFile("gcs.ini")
|
|
||||||
{
|
{
|
||||||
//if a saved configuration exists load it
|
if ( ! qSettings )
|
||||||
if(qSettings != 0) {
|
return;
|
||||||
dialFile = qSettings->value("dialFile").toString();
|
|
||||||
}
|
if ( configInfo->version() == UAVConfigVersion() )
|
||||||
|
configInfo->setVersion("1.0.0");
|
||||||
|
|
||||||
|
if ( !configInfo->standardVersionHandlingOK(VERSION))
|
||||||
|
return;
|
||||||
|
|
||||||
|
iniFile = qSettings->value("dialFile", "gcs.ini").toString(); // TODO Delete with next minor version.
|
||||||
|
iniFile = qSettings->value("iniFile", iniFile).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +58,7 @@ ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId
|
|||||||
IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
|
IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
|
||||||
{
|
{
|
||||||
ImportExportGadgetConfiguration *m = new ImportExportGadgetConfiguration(this->classId());
|
ImportExportGadgetConfiguration *m = new ImportExportGadgetConfiguration(this->classId());
|
||||||
m->dialFile = dialFile;
|
m->iniFile = iniFile;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +66,10 @@ IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
|
|||||||
* Saves a configuration.
|
* Saves a configuration.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings) const {
|
void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) const {
|
||||||
qSettings->setValue("dialFile", dialFile);
|
configInfo->setVersion(VERSION);
|
||||||
|
qSettings->setValue("dialFile", iniFile);
|
||||||
|
qSettings->setValue("iniFile", iniFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,23 +39,23 @@ class IMPORTEXPORT_EXPORT ImportExportGadgetConfiguration : public IUAVGadgetCon
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ImportExportGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
|
ImportExportGadgetConfiguration(QString classId, QSettings* qSettings = 0, UAVConfigInfo *configInfo = 0, QObject *parent = 0);
|
||||||
|
|
||||||
//set dial configuration functions
|
//set dial configuration functions
|
||||||
void setDialFile(QString filename) {
|
void setIniFile(QString filename) {
|
||||||
dialFile = filename;
|
iniFile = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get dial configuration functions
|
//get dial configuration functions
|
||||||
QString getDialFile() const{
|
QString getIniFile() const{
|
||||||
return dialFile;
|
return iniFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfig(QSettings* settings) const;
|
void saveConfig(QSettings* settings, Core::UAVConfigInfo *configInfo) const;
|
||||||
IUAVGadgetConfiguration *clone();
|
IUAVGadgetConfiguration *clone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString dialFile;
|
QString iniFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMPORTEXPORTGADGETCONFIGURATION_H
|
#endif // IMPORTEXPORTGADGETCONFIGURATION_H
|
||||||
|
@ -50,9 +50,9 @@ Core::IUAVGadget* ImportExportGadgetFactory::createGadget(QWidget *parent)
|
|||||||
return new ImportExportGadget(QString("ImportExportGadget"), gadgetWidget, parent);
|
return new ImportExportGadget(QString("ImportExportGadget"), gadgetWidget, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(QSettings* qSettings)
|
IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(QSettings* qSettings, UAVConfigInfo *configInfo)
|
||||||
{
|
{
|
||||||
lastConfig = new ImportExportGadgetConfiguration(QString("ImportExportGadget"), qSettings);
|
lastConfig = new ImportExportGadgetConfiguration(QString("ImportExportGadget"), qSettings, configInfo);
|
||||||
return lastConfig;
|
return lastConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
ImportExportGadgetConfiguration *getLastConfig(){ return lastConfig;}
|
ImportExportGadgetConfiguration *getLastConfig(){ return lastConfig;}
|
||||||
|
|
||||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||||
IUAVGadgetConfiguration *createConfiguration(QSettings* qSettings);
|
IUAVGadgetConfiguration *createConfiguration(QSettings *qSettings, UAVConfigInfo *configInfo);
|
||||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -51,10 +51,10 @@ QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
options_page->setupUi(optionsPageWidget);
|
options_page->setupUi(optionsPageWidget);
|
||||||
|
|
||||||
// Restore the contents from the settings:
|
// Restore the contents from the settings:
|
||||||
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
|
options_page->iniFile->setExpectedKind(Utils::PathChooser::File);
|
||||||
options_page->svgSourceFile->setPromptDialogFilter(tr("INI file (*.ini)"));
|
options_page->iniFile->setPromptDialogFilter(tr("INI file (*.ini)"));
|
||||||
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose configuration file"));
|
options_page->iniFile->setPromptDialogTitle(tr("Choose configuration file"));
|
||||||
options_page->svgSourceFile->setPath(m_config->getDialFile());
|
options_page->iniFile->setPath(m_config->getIniFile());
|
||||||
|
|
||||||
return optionsPageWidget;
|
return optionsPageWidget;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
*/
|
*/
|
||||||
void ImportExportGadgetOptionsPage::apply()
|
void ImportExportGadgetOptionsPage::apply()
|
||||||
{
|
{
|
||||||
m_config->setDialFile(options_page->svgSourceFile->path());
|
m_config->setIniFile(options_page->iniFile->path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
|
<widget class="Utils::PathChooser" name="iniFile" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -67,7 +67,7 @@ void ImportExportGadgetWidget::loadConfiguration(const ImportExportGadgetConfigu
|
|||||||
if ( !config )
|
if ( !config )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ui->configFile->setText(config->getDialFile());
|
ui->configFile->setText(config->getIniFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportExportGadgetWidget::on_exportButton_clicked()
|
void ImportExportGadgetWidget::on_exportButton_clicked()
|
||||||
|
@ -14,24 +14,6 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>This is experimental. Use at own risk.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Please report bugs!</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
|
@ -69,9 +69,11 @@ bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg)
|
|||||||
cmd->setDefaultKeySequence(QKeySequence("Ctrl+I"));
|
cmd->setDefaultKeySequence(QKeySequence("Ctrl+I"));
|
||||||
cmd->action()->setText("Import/Export...");
|
cmd->action()->setText("Import/Export...");
|
||||||
|
|
||||||
ac->menu()->addSeparator();
|
// ac->menu()->addSeparator();
|
||||||
ac->appendGroup("ImportExport");
|
// ac->appendGroup("ImportExport");
|
||||||
ac->addAction(cmd, "ImportExport");
|
// ac->addAction(cmd, "ImportExport");
|
||||||
|
ac->addAction(cmd, Core::Constants::G_FILE_SAVE);
|
||||||
|
|
||||||
|
|
||||||
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importExport()));
|
connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importExport()));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user