mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +01:00
GCS: Make [UAVGadgetManager] also human readable.
Makes the ini file a bit more verbose, but debuggable/hackable :) (Not to mention more robust). Again, I left in support for loading the binary version, so this shouldn't mess up people's configurations. Keep a backup handy anyways :) In the future, that needs to be removed though. Anyone with a 'old style' configuration may notice the binary versions are left in the ini file, I can't easily delete them without deleting the new groups also, but they won't cause any problems, and aren't read. Feel free to delete them for a clean ini file :) I left in the 'DefaultSettings' stuff, but I think it can be removed too ( or whatever it was meant to support should be added :) ). git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1664 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
e8d6e7c557
commit
96990b5f60
@ -32,6 +32,7 @@
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/core_global.h>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWidget;
|
||||
@ -61,8 +62,9 @@ public:
|
||||
|
||||
virtual IUAVGadgetConfiguration *activeConfiguration() { return 0; }
|
||||
virtual void loadConfiguration(IUAVGadgetConfiguration*) { }
|
||||
virtual QByteArray saveState() { return QByteArray(); }
|
||||
virtual void saveState(QSettings* qSettings) { }
|
||||
virtual void restoreState(QByteArray) { }
|
||||
virtual void restoreState(QSettings* qSettings) { }
|
||||
public slots:
|
||||
virtual void configurationChanged(IUAVGadgetConfiguration* ) { }
|
||||
virtual void configurationAdded(IUAVGadgetConfiguration*) { }
|
||||
|
@ -112,13 +112,22 @@ void UAVGadgetDecorator::updateToolbar()
|
||||
m_toolbar->setEnabled(m_toolbar->count() > 1);
|
||||
}
|
||||
|
||||
QByteArray UAVGadgetDecorator::saveState()
|
||||
void UAVGadgetDecorator::saveState(QSettings* qSettings)
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
if (m_activeConfiguration)
|
||||
stream << m_activeConfiguration->name().toLatin1();
|
||||
return bytes;
|
||||
if (m_activeConfiguration) {
|
||||
qSettings->setValue("activeConfiguration",m_activeConfiguration->name());
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::restoreState(QSettings* qSetting)
|
||||
{
|
||||
QString configName = qSetting->value("activeConfiguration").toString();
|
||||
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
|
||||
if (config->name() == configName) {
|
||||
m_activeConfiguration = config;
|
||||
loadConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::restoreState(QByteArray state)
|
||||
|
@ -44,8 +44,9 @@ public:
|
||||
QComboBox *toolBar() { return m_toolbar; }
|
||||
IUAVGadgetConfiguration *activeConfiguration() { return m_activeConfiguration; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration *config);
|
||||
QByteArray saveState();
|
||||
void saveState(QSettings* qSettings);
|
||||
void restoreState(QByteArray state);
|
||||
void restoreState(QSettings* qSettings);
|
||||
public slots:
|
||||
void configurationChanged(IUAVGadgetConfiguration* config);
|
||||
void configurationAdded(IUAVGadgetConfiguration* config);
|
||||
|
@ -422,18 +422,39 @@ void UAVGadgetManager::updateActions()
|
||||
m_d->m_gotoOtherSplitAction->setEnabled(shown && hasSplitter);
|
||||
}
|
||||
|
||||
QByteArray UAVGadgetManager::saveState() const
|
||||
void UAVGadgetManager::saveState(QSettings* qSettings) const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
qSettings->setValue("version","UAVGadgetManagerV1");
|
||||
qSettings->setValue("showToolbars",m_showToolbars);
|
||||
qSettings->beginGroup("splitter");
|
||||
m_d->m_splitterOrView->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
}
|
||||
|
||||
stream << QByteArray("UAVGadgetManagerV1");
|
||||
bool UAVGadgetManager::restoreState(QSettings* qSettings)
|
||||
{
|
||||
removeAllSplits();
|
||||
|
||||
stream << m_showToolbars;
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
IUAVGadget *gadget = m_d->m_splitterOrView->view()->gadget();
|
||||
emptyView(m_d->m_splitterOrView->view());
|
||||
im->removeGadget(gadget);
|
||||
|
||||
stream << m_d->m_splitterOrView->saveState();
|
||||
QString version = qSettings->value("version").toString();
|
||||
if (version != "UAVGadgetManagerV1") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
m_showToolbars = qSettings->value("showToolbars").toBool();
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
qSettings->beginGroup("splitter");
|
||||
m_d->m_splitterOrView->restoreState(qSettings);
|
||||
qSettings->endGroup();
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UAVGadgetManager::restoreState(const QByteArray &state)
|
||||
@ -464,35 +485,60 @@ bool UAVGadgetManager::restoreState(const QByteArray &state)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void UAVGadgetManager::saveSettings(QSettings *qs)
|
||||
{
|
||||
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
|
||||
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
|
||||
qs->beginGroup("UAVGadgetManager");
|
||||
qs->beginGroup(m_uavGadgetMode->uniqueModeName());
|
||||
|
||||
QString defaultUAVGadgetManagerKey = "DefaultSettings";
|
||||
QString uavGadgetManagerKey = "Settings";
|
||||
|
||||
// The idea is to have a default setting that is only written once
|
||||
if (!qs->contains(defaultUAVGadgetManagerKey))
|
||||
qs->setValue(defaultUAVGadgetManagerKey, saveState().toBase64());
|
||||
else
|
||||
qs->setValue(uavGadgetManagerKey, saveState().toBase64());
|
||||
// TODO: Currently the default thing doesn't seem to be used,
|
||||
// and is slightly randomly set the first time you close the app (after creating the specific mode?)
|
||||
if (!qs->childGroups().contains(defaultUAVGadgetManagerKey)) {
|
||||
qs->beginGroup(defaultUAVGadgetManagerKey);
|
||||
saveState(qs);
|
||||
qs->endGroup();
|
||||
} else {
|
||||
qs->beginGroup(uavGadgetManagerKey);
|
||||
saveState(qs);
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
qs->endGroup();
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void UAVGadgetManager::readSettings(QSettings *qs)
|
||||
{
|
||||
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
|
||||
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
|
||||
qs->beginGroup("UAVGadgetManager");
|
||||
qs->beginGroup(m_uavGadgetMode->uniqueModeName());
|
||||
|
||||
QString key("");
|
||||
if (qs->contains(uavGadgetManagerKey))
|
||||
key = uavGadgetManagerKey;
|
||||
else if (qs->contains(defaultUAVGadgetManagerKey))
|
||||
key = defaultUAVGadgetManagerKey;
|
||||
else
|
||||
QString defaultUAVGadgetManagerKey = "DefaultSettings";
|
||||
QString uavGadgetManagerKey = "Settings";
|
||||
|
||||
if (qs->childGroups().contains(uavGadgetManagerKey)) {
|
||||
qs->beginGroup(uavGadgetManagerKey);
|
||||
restoreState(qs);
|
||||
qs->endGroup();
|
||||
} else if (qs->childGroups().contains(defaultUAVGadgetManagerKey)) {
|
||||
qs->beginGroup(defaultUAVGadgetManagerKey);
|
||||
restoreState(qs);
|
||||
qs->endGroup();
|
||||
} else if (qs->contains(uavGadgetManagerKey)) {
|
||||
restoreState(QByteArray::fromBase64(qs->value(uavGadgetManagerKey).toByteArray()));
|
||||
} else if (qs->contains(defaultUAVGadgetManagerKey)) {
|
||||
restoreState(QByteArray::fromBase64(qs->value(defaultUAVGadgetManagerKey).toByteArray()));
|
||||
} else {
|
||||
return;
|
||||
const QVariant &managerSettings = qs->value(key);
|
||||
restoreState(QByteArray::fromBase64(managerSettings.toByteArray()));
|
||||
}
|
||||
|
||||
showToolbars(m_showToolbars);
|
||||
updateActions();
|
||||
|
||||
qs->endGroup();
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void UAVGadgetManager::split(Qt::Orientation orientation)
|
||||
|
@ -96,8 +96,9 @@ public:
|
||||
|
||||
IUAVGadget *currentGadget() const;
|
||||
|
||||
QByteArray saveState() const;
|
||||
void saveState(QSettings*) const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
bool restoreState(QSettings* qSettings);
|
||||
|
||||
void saveSettings(QSettings* qs);
|
||||
void readSettings(QSettings* qs);
|
||||
|
@ -576,23 +576,65 @@ void SplitterOrView::unsplit()
|
||||
m_uavGadgetManager->setCurrentGadget(findFirstView()->gadget());
|
||||
}
|
||||
|
||||
|
||||
QByteArray SplitterOrView::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
|
||||
void SplitterOrView::saveState(QSettings* qSettings) const {
|
||||
if (m_splitter) {
|
||||
stream << QByteArray("splitter")
|
||||
<< (qint32)m_splitter->orientation()
|
||||
<< m_splitter->saveState()
|
||||
<< static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState()
|
||||
<< static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState();
|
||||
} else {
|
||||
if (gadget())
|
||||
stream << QByteArray("uavGadget") << gadget()->classId() << gadget()->saveState();
|
||||
qSettings->setValue("type", "splitter");
|
||||
qSettings->setValue("splitterOrientation", (qint32)m_splitter->orientation());
|
||||
// qSettings->setValue("splitterSizes", m_splitter->saveState());
|
||||
// Bit clunky, but makes it more readable in the ini file.
|
||||
QList<QVariant> sizesQVariant;
|
||||
QList<int> sizes = m_splitter->sizes();
|
||||
QList<int>::iterator sizesIterator;
|
||||
for (sizesIterator = sizes.begin(); sizesIterator != sizes.end(); sizesIterator++) {
|
||||
sizesQVariant.append(*sizesIterator);
|
||||
}
|
||||
qSettings->setValue("splitterSizes", sizesQVariant);
|
||||
qSettings->beginGroup("side0");
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
qSettings->beginGroup("side1");
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
} else {
|
||||
qSettings->setValue("type", "uavGadget");
|
||||
qSettings->setValue("classId", gadget()->classId());
|
||||
if (gadget()) {
|
||||
qSettings->beginGroup("gadget");
|
||||
gadget()->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SplitterOrView::restoreState(QSettings* qSettings)
|
||||
{
|
||||
QString mode = qSettings->value("type").toString();
|
||||
if (mode == "splitter") {
|
||||
qint32 orientation = qSettings->value("splitterOrientation").toInt();
|
||||
QList<QVariant> sizesQVariant = qSettings->value("splitterSizes").toList();
|
||||
QList<int> sizes;
|
||||
QList<QVariant>::iterator sizesIterator;
|
||||
for (sizesIterator = sizesQVariant.begin(); sizesIterator != sizesQVariant.end(); sizesIterator++) {
|
||||
sizes.append((*sizesIterator).toInt());
|
||||
}
|
||||
split((Qt::Orientation)orientation);
|
||||
m_splitter->setSizes(sizes);
|
||||
qSettings->beginGroup("side0");
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(qSettings);
|
||||
qSettings->endGroup();
|
||||
qSettings->beginGroup("side1");
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(qSettings);
|
||||
qSettings->endGroup();
|
||||
} else if (mode == "uavGadget") {
|
||||
QString classId = qSettings->value("classId").toString();
|
||||
int index = m_view->indexOfClassId(classId);
|
||||
m_view->listSelectionActivated(index);
|
||||
if(qSettings->childGroups().contains("gadget")) {
|
||||
qSettings->beginGroup("gadget");
|
||||
gadget()->restoreState(qSettings);
|
||||
qSettings->endGroup();
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void SplitterOrView::restoreState(const QByteArray &state)
|
||||
|
@ -121,8 +121,9 @@ public:
|
||||
QSplitter *takeSplitter();
|
||||
UAVGadgetView *takeView();
|
||||
|
||||
QByteArray saveState() const;
|
||||
void saveState(QSettings*) const;
|
||||
void restoreState(const QByteArray &);
|
||||
void restoreState(QSettings*);
|
||||
|
||||
SplitterOrView *findView(Core::IUAVGadget *uavGadget);
|
||||
SplitterOrView *findView(UAVGadgetView *view);
|
||||
|
Loading…
Reference in New Issue
Block a user