mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
Merge branch 'filnet/OP-803_gadget_config_set_twice_on_restore' into next
This commit is contained in:
commit
c47ecd044e
@ -45,8 +45,6 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfi
|
|||||||
foreach (IUAVGadgetConfiguration *config, *m_configurations)
|
foreach (IUAVGadgetConfiguration *config, *m_configurations)
|
||||||
m_toolbar->addItem(config->name());
|
m_toolbar->addItem(config->name());
|
||||||
connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int)));
|
connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int)));
|
||||||
if (m_configurations->count() > 0)
|
|
||||||
loadConfiguration(0);
|
|
||||||
updateToolbar();
|
updateToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,13 +117,14 @@ void UAVGadgetDecorator::saveState(QSettings* qSettings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVGadgetDecorator::restoreState(QSettings* qSetting)
|
void UAVGadgetDecorator::restoreState(QSettings *qSettings)
|
||||||
{
|
{
|
||||||
QString configName = qSetting->value("activeConfiguration").toString();
|
QString configName = qSettings->value("activeConfiguration").toString();
|
||||||
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
|
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
|
||||||
if (config->name() == configName) {
|
if (config->name() == configName) {
|
||||||
m_activeConfiguration = config;
|
m_activeConfiguration = config;
|
||||||
loadConfiguration(config);
|
loadConfiguration(config);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,13 +262,17 @@ void UAVGadgetInstanceManager::createOptionsPages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent)
|
IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent, bool loadDefaultConfiguration)
|
||||||
{
|
{
|
||||||
IUAVGadgetFactory *f = factory(classId);
|
IUAVGadgetFactory *f = factory(classId);
|
||||||
if (f) {
|
if (f) {
|
||||||
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
||||||
IUAVGadget *g = f->createGadget(parent);
|
IUAVGadget *g = f->createGadget(parent);
|
||||||
IUAVGadget *gadget = new UAVGadgetDecorator(g, configs);
|
UAVGadgetDecorator *gadget = new UAVGadgetDecorator(g, configs);
|
||||||
|
if ((loadDefaultConfiguration && configs && configs->count()) > 0) {
|
||||||
|
gadget->loadConfiguration(configs->at(0));
|
||||||
|
}
|
||||||
|
|
||||||
m_gadgetInstances.append(gadget);
|
m_gadgetInstances.append(gadget);
|
||||||
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
|
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
|
||||||
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
|
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
~UAVGadgetInstanceManager();
|
~UAVGadgetInstanceManager();
|
||||||
void readSettings(QSettings *qs);
|
void readSettings(QSettings *qs);
|
||||||
void saveSettings(QSettings *qs);
|
void saveSettings(QSettings *qs);
|
||||||
IUAVGadget *createGadget(QString classId, QWidget *parent);
|
IUAVGadget *createGadget(QString classId, QWidget *parent, bool loadDefaultConfiguration = true);
|
||||||
void removeGadget(IUAVGadget *gadget);
|
void removeGadget(IUAVGadget *gadget);
|
||||||
void removeAllGadgets();
|
void removeAllGadgets();
|
||||||
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
||||||
|
@ -347,11 +347,7 @@ void SplitterOrView::saveState(QSettings* qSettings) const {
|
|||||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(qSettings);
|
static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(qSettings);
|
||||||
qSettings->endGroup();
|
qSettings->endGroup();
|
||||||
} else if (gadget()) {
|
} else if (gadget()) {
|
||||||
qSettings->setValue("type", "uavGadget");
|
m_view->saveState(qSettings);
|
||||||
qSettings->setValue("classId", gadget()->classId());
|
|
||||||
qSettings->beginGroup("gadget");
|
|
||||||
gadget()->saveState(qSettings);
|
|
||||||
qSettings->endGroup();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,13 +370,6 @@ void SplitterOrView::restoreState(QSettings* qSettings)
|
|||||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(qSettings);
|
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(qSettings);
|
||||||
qSettings->endGroup();
|
qSettings->endGroup();
|
||||||
} else if (mode == "uavGadget") {
|
} else if (mode == "uavGadget") {
|
||||||
QString classId = qSettings->value("classId").toString();
|
m_view->restoreState(qSettings);
|
||||||
int index = m_view->indexOfClassId(classId);
|
|
||||||
m_view->listSelectionActivated(index);
|
|
||||||
if(qSettings->childGroups().contains("gadget")) {
|
|
||||||
qSettings->beginGroup("gadget");
|
|
||||||
gadget()->restoreState(qSettings);
|
|
||||||
qSettings->endGroup();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,14 +230,17 @@ void UAVGadgetView::updateToolBar()
|
|||||||
|
|
||||||
void UAVGadgetView::listSelectionActivated(int index)
|
void UAVGadgetView::listSelectionActivated(int index)
|
||||||
{
|
{
|
||||||
if (index < 0) // this could happen when called from SplitterOrView::restoreState()
|
if (index < 0 || index >= m_uavGadgetList->count())
|
||||||
index = m_defaultIndex;
|
index = m_defaultIndex;
|
||||||
|
|
||||||
QString classId = m_uavGadgetList->itemData(index).toString();
|
QString classId = m_uavGadgetList->itemData(index).toString();
|
||||||
if (m_uavGadget && (m_uavGadget->classId() == classId))
|
if (m_uavGadget && (m_uavGadget->classId() == classId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||||
IUAVGadget *gadgetToRemove = m_uavGadget;
|
|
||||||
IUAVGadget *gadget = im->createGadget(classId, this);
|
IUAVGadget *gadget = im->createGadget(classId, this);
|
||||||
|
|
||||||
|
IUAVGadget *gadgetToRemove = m_uavGadget;
|
||||||
setGadget(gadget);
|
setGadget(gadget);
|
||||||
m_uavGadgetManager->setCurrentGadget(gadget);
|
m_uavGadgetManager->setCurrentGadget(gadget);
|
||||||
im->removeGadget(gadgetToRemove);
|
im->removeGadget(gadgetToRemove);
|
||||||
@ -252,3 +255,39 @@ void UAVGadgetView::currentGadgetChanged(IUAVGadget *gadget)
|
|||||||
{
|
{
|
||||||
m_activeLabel->setVisible(m_uavGadget == gadget);
|
m_activeLabel->setVisible(m_uavGadget == gadget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UAVGadgetView::saveState(QSettings* qSettings)
|
||||||
|
{
|
||||||
|
qSettings->setValue("type", "uavGadget");
|
||||||
|
qSettings->setValue("classId", gadget()->classId());
|
||||||
|
qSettings->beginGroup("gadget");
|
||||||
|
gadget()->saveState(qSettings);
|
||||||
|
qSettings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAVGadgetView::restoreState(QSettings* qSettings)
|
||||||
|
{
|
||||||
|
QString classId = qSettings->value("classId").toString();
|
||||||
|
int index = indexOfClassId(classId);
|
||||||
|
if (index < 0) {
|
||||||
|
index = m_defaultIndex;
|
||||||
|
}
|
||||||
|
classId = m_uavGadgetList->itemData(index).toString();
|
||||||
|
|
||||||
|
IUAVGadget *newGadget;
|
||||||
|
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||||
|
if(qSettings->childGroups().contains("gadget")) {
|
||||||
|
newGadget = im->createGadget(classId, this, false);
|
||||||
|
qSettings->beginGroup("gadget");
|
||||||
|
newGadget->restoreState(qSettings);
|
||||||
|
qSettings->endGroup();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newGadget = im->createGadget(classId, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
IUAVGadget *gadgetToRemove = m_uavGadget;
|
||||||
|
setGadget(newGadget);
|
||||||
|
m_uavGadgetManager->setCurrentGadget(newGadget);
|
||||||
|
im->removeGadget(gadgetToRemove);
|
||||||
|
}
|
||||||
|
@ -67,21 +67,25 @@ public:
|
|||||||
UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget = 0, QWidget *parent = 0);
|
UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget = 0, QWidget *parent = 0);
|
||||||
virtual ~UAVGadgetView();
|
virtual ~UAVGadgetView();
|
||||||
|
|
||||||
void removeGadget();
|
|
||||||
IUAVGadget *gadget() const;
|
IUAVGadget *gadget() const;
|
||||||
void setGadget(IUAVGadget *uavGadget);
|
void setGadget(IUAVGadget *uavGadget);
|
||||||
bool hasGadget(IUAVGadget *uavGadget) const;
|
bool hasGadget(IUAVGadget *uavGadget) const;
|
||||||
int indexOfClassId(QString classId);
|
void removeGadget();
|
||||||
|
|
||||||
void showToolbar(bool show);
|
void showToolbar(bool show);
|
||||||
|
|
||||||
|
void saveState(QSettings *qSettings);
|
||||||
|
void restoreState(QSettings *qSettings);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void closeView();
|
void closeView();
|
||||||
void listSelectionActivated(int index);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void listSelectionActivated(int index);
|
||||||
void currentGadgetChanged(IUAVGadget *gadget);
|
void currentGadgetChanged(IUAVGadget *gadget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int indexOfClassId(QString classId);
|
||||||
void updateToolBar();
|
void updateToolBar();
|
||||||
|
|
||||||
QPointer<UAVGadgetManager> m_uavGadgetManager;
|
QPointer<UAVGadgetManager> m_uavGadgetManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user