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)
|
||||
m_toolbar->addItem(config->name());
|
||||
connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int)));
|
||||
if (m_configurations->count() > 0)
|
||||
loadConfiguration(0);
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
@ -57,7 +55,7 @@ UAVGadgetDecorator::~UAVGadgetDecorator()
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::loadConfiguration(int index) {
|
||||
IUAVGadgetConfiguration* config = m_configurations->at(index);
|
||||
IUAVGadgetConfiguration *config = m_configurations->at(index);
|
||||
loadConfiguration(config);
|
||||
}
|
||||
|
||||
@ -70,13 +68,13 @@ void UAVGadgetDecorator::loadConfiguration(IUAVGadgetConfiguration *config)
|
||||
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration* config)
|
||||
void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (config == m_activeConfiguration)
|
||||
loadConfiguration(config);
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config)
|
||||
void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (config->classId() != classId())
|
||||
return;
|
||||
@ -85,7 +83,7 @@ void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config)
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* config)
|
||||
void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (config->classId() != classId())
|
||||
return;
|
||||
@ -97,7 +95,7 @@ void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* confi
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName)
|
||||
void UAVGadgetDecorator::configurationNameChanged(IUAVGadgetConfiguration *config, QString oldName, QString newName)
|
||||
{
|
||||
if (config->classId() != classId())
|
||||
return;
|
||||
@ -112,20 +110,21 @@ void UAVGadgetDecorator::updateToolbar()
|
||||
m_toolbar->setEnabled(m_toolbar->count() > 1);
|
||||
}
|
||||
|
||||
void UAVGadgetDecorator::saveState(QSettings* qSettings)
|
||||
void UAVGadgetDecorator::saveState(QSettings *qSettings)
|
||||
{
|
||||
if (m_activeConfiguration) {
|
||||
qSettings->setValue("activeConfiguration",m_activeConfiguration->name());
|
||||
qSettings->setValue("activeConfiguration", m_activeConfiguration->name());
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (config->name() == configName) {
|
||||
m_activeConfiguration = 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);
|
||||
if (f) {
|
||||
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
||||
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);
|
||||
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
|
||||
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
~UAVGadgetInstanceManager();
|
||||
void readSettings(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 removeAllGadgets();
|
||||
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
|
@ -347,11 +347,7 @@ void SplitterOrView::saveState(QSettings* qSettings) const {
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
} else if (gadget()) {
|
||||
qSettings->setValue("type", "uavGadget");
|
||||
qSettings->setValue("classId", gadget()->classId());
|
||||
qSettings->beginGroup("gadget");
|
||||
gadget()->saveState(qSettings);
|
||||
qSettings->endGroup();
|
||||
m_view->saveState(qSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,13 +370,6 @@ void SplitterOrView::restoreState(QSettings* qSettings)
|
||||
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();
|
||||
}
|
||||
m_view->restoreState(qSettings);
|
||||
}
|
||||
}
|
||||
|
@ -230,14 +230,17 @@ void UAVGadgetView::updateToolBar()
|
||||
|
||||
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;
|
||||
|
||||
QString classId = m_uavGadgetList->itemData(index).toString();
|
||||
if (m_uavGadget && (m_uavGadget->classId() == classId))
|
||||
return;
|
||||
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
IUAVGadget *gadgetToRemove = m_uavGadget;
|
||||
IUAVGadget *gadget = im->createGadget(classId, this);
|
||||
|
||||
IUAVGadget *gadgetToRemove = m_uavGadget;
|
||||
setGadget(gadget);
|
||||
m_uavGadgetManager->setCurrentGadget(gadget);
|
||||
im->removeGadget(gadgetToRemove);
|
||||
@ -252,3 +255,39 @@ void UAVGadgetView::currentGadgetChanged(IUAVGadget *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);
|
||||
virtual ~UAVGadgetView();
|
||||
|
||||
void removeGadget();
|
||||
IUAVGadget *gadget() const;
|
||||
void setGadget(IUAVGadget *uavGadget);
|
||||
bool hasGadget(IUAVGadget *uavGadget) const;
|
||||
int indexOfClassId(QString classId);
|
||||
void removeGadget();
|
||||
|
||||
void showToolbar(bool show);
|
||||
|
||||
void saveState(QSettings *qSettings);
|
||||
void restoreState(QSettings *qSettings);
|
||||
|
||||
public slots:
|
||||
void closeView();
|
||||
void listSelectionActivated(int index);
|
||||
|
||||
private slots:
|
||||
void listSelectionActivated(int index);
|
||||
void currentGadgetChanged(IUAVGadget *gadget);
|
||||
|
||||
private:
|
||||
int indexOfClassId(QString classId);
|
||||
void updateToolBar();
|
||||
|
||||
QPointer<UAVGadgetManager> m_uavGadgetManager;
|
||||
|
Loading…
Reference in New Issue
Block a user