1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/coreplugin: Mostly finished support for uavgadget settings.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@387 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-25 22:31:25 +00:00 committed by ephy
parent 9490bcdb93
commit 4b3bfa361f
5 changed files with 62 additions and 17 deletions

View File

@ -33,8 +33,8 @@ using namespace Core;
IUAVGadget::IUAVGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, QObject *parent) :
IContext(parent),
m_classId(classId),
m_toolbar(new QComboBox),
m_classId(classId),
m_configurations(configurations)
{
m_toolbar->setMinimumContentsLength(15);
@ -85,8 +85,8 @@ QByteArray IUAVGadget::saveState()
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
// if (m_activeConfiguration)
// stream << m_activeConfiguration->name().toLatin1();
if (m_activeConfiguration)
stream << m_activeConfiguration->name().toLatin1();
return bytes;
}

View File

@ -54,7 +54,7 @@ public:
virtual QString contextHelpId() const { return QString(); }
QString classId() const { return m_classId; }
virtual void loadConfiguration(IUAVGadgetConfiguration* /*config*/) {}
virtual void loadConfiguration(IUAVGadgetConfiguration* /*config*/) { }
IUAVGadgetConfiguration *activeConfiguration() { return m_activeConfiguration; }
QComboBox *toolBar() { return m_toolbar; }
virtual QByteArray saveState();
@ -66,10 +66,10 @@ public slots:
void configurationNameChanged(QString oldName, QString newName);
private slots:
void loadConfiguration(int index);
protected:
QComboBox *m_toolbar;
private:
QString m_classId;
QComboBox *m_toolbar;
IUAVGadgetConfiguration *m_activeConfiguration;
QList<IUAVGadgetConfiguration*> *m_configurations;
};

View File

@ -45,8 +45,8 @@ using namespace Core;
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
QObject(parent)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QList<IUAVGadgetFactory*> factories = pm->getObjects<IUAVGadgetFactory>();
m_pm = ExtensionSystem::PluginManager::instance();
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
foreach (IUAVGadgetFactory *f, factories) {
if (!m_factories.contains(f)) {
m_factories.append(f);
@ -57,6 +57,13 @@ UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
}
}
UAVGadgetInstanceManager::~UAVGadgetInstanceManager()
{
foreach (IOptionsPage *page, m_optionsPages) {
m_pm->removeObject(page);
}
}
void UAVGadgetInstanceManager::readConfigurations()
{
QSettings *qs = Core::ICore::instance()->settings();
@ -96,7 +103,7 @@ void UAVGadgetInstanceManager::writeConfigurations()
{
QSettings *qs = Core::ICore::instance()->settings();
qs->beginGroup("UAVGadgetConfigurations");
qs->allKeys().clear(); // Remove existing configurations
qs->remove(""); // Remove existing configurations
foreach (IUAVGadgetConfiguration *config, m_configurations)
{
qs->beginGroup(config->classId());
@ -112,13 +119,12 @@ void UAVGadgetInstanceManager::writeConfigurations()
void UAVGadgetInstanceManager::createOptionsPages()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
foreach (IUAVGadgetConfiguration *config, m_configurations)
{
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *page = f->createOptionsPage(config);
m_optionsPages.append(page);
pm->addObject(page);
m_pm->addObject(page);
}
}
@ -130,6 +136,10 @@ IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *par
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
IUAVGadget *gadget = f->createGadget(configs, parent);
m_gadgetInstances.append(gadget);
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
connect(this, SIGNAL(configurationNameChanged(QString,QString)), gadget, SLOT(configurationNameChanged(QString,QString)));
connect(this, SIGNAL(configurationToBeDeleted(IUAVGadgetConfiguration*)), gadget, SLOT(configurationToBeDeleted(IUAVGadgetConfiguration*)));
return gadget;
}
return 0;
@ -161,12 +171,15 @@ void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *con
m_takenNames[config->classId()].removeAt(j);
m_settingsDialog->deletePage();
} else if (m_configurations.contains(config)) {
emit configurationToBeDeleted(config);
int i = m_configurations.indexOf(config);
m_provisionalConfigs.removeAt(i);
m_optionsPages.removeAt(i);
m_pm->removeObject(m_optionsPages.at(i));
m_optionsPages.removeAt(i);//TODO delete
m_settingsDialog->deletePage();
m_configurations.removeAt(i);
}
configNameEdited("", false);
configurationNameEdited("", false);
}
void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *configToClone)
@ -205,7 +218,25 @@ QString UAVGadgetInstanceManager::suggestName(QString classId, QString name)
return suggestedName;
}
void UAVGadgetInstanceManager::configNameEdited(QString text, bool hasText)
void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config)
{
if (config->provisionalName() != config->name()) {
emit configurationNameChanged(config->name(), config->provisionalName());
config->setName(config->provisionalName());
}
if (m_configurations.contains(config)) {
emit configurationChanged(config);
} else if (m_provisionalConfigs.contains(config)) {
emit configurationAdded(config);
m_configurations.append(config);
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *page = f->createOptionsPage(config);
m_optionsPages.append(page);
m_pm->addObject(page);
}
}
void UAVGadgetInstanceManager::configurationNameEdited(QString text, bool hasText)
{
bool disable = false;
foreach (IUAVGadgetConfiguration *c, m_configurations) {
@ -242,7 +273,7 @@ void UAVGadgetInstanceManager::settingsDialogRemoved()
{
m_takenNames.clear();
m_provisionalConfigs.clear();
m_provisionalOptionsPages.clear();
m_provisionalOptionsPages.clear(); //TODO delete
foreach (IUAVGadgetConfiguration *config, m_configurations)
config->setProvisionalName(config->name());
m_settingsDialog = 0;

View File

@ -32,6 +32,10 @@
#include <QtCore/QMap>
#include <QtCore/QStringList>
namespace ExtensionSystem {
class PluginManager;
}
namespace Core
{
@ -49,18 +53,24 @@ class UAVGadgetInstanceManager : public QObject
Q_OBJECT
public:
explicit UAVGadgetInstanceManager(QObject *parent = 0);
~UAVGadgetInstanceManager();
void readConfigurations();
void writeConfigurations();
IUAVGadget *createGadget(QString classId, QWidget *parent);
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
void deleteConfiguration(IUAVGadgetConfiguration *config);
void cloneConfiguration(IUAVGadgetConfiguration *config);
void applyChanges(IUAVGadgetConfiguration *config);
void configurationNameEdited(QString text, bool hasText = true);
QStringList classIds() const { return m_classIds.keys(); }
QStringList configurationNames(QString classId) const;
QString gadgetName(QString classId) const;
void configNameEdited(QString text, bool hasText = true);
signals:
void configurationChanged(IUAVGadgetConfiguration* config);
void configurationAdded(IUAVGadgetConfiguration* config);
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
void configurationNameChanged(QString oldName, QString newName);
public slots:
void settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog);
@ -80,6 +90,7 @@ private:
QList<IUAVGadgetConfiguration*> m_provisionalConfigs;
QList<IOptionsPage*> m_provisionalOptionsPages;
Core::Internal::SettingsDialog *m_settingsDialog;
ExtensionSystem::PluginManager *m_pm;
};

View File

@ -61,6 +61,7 @@ QWidget *UAVGadgetOptionsPageDecorator::createPage(QWidget *parent)
m_page->nameLineEdit->setText(m_id);
QWidget *wi = m_optionsPage->createPage(w);
wi->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_page->verticalLayout_4->addWidget(wi);
connect(m_page->cloneButton, SIGNAL(clicked()), this, SLOT(cloneConfiguration()));
@ -72,6 +73,8 @@ QWidget *UAVGadgetOptionsPageDecorator::createPage(QWidget *parent)
void UAVGadgetOptionsPageDecorator::apply()
{
m_id = m_config->provisionalName();
m_instanceManager->applyChanges(m_config);
m_optionsPage->apply();
}
@ -93,6 +96,6 @@ void UAVGadgetOptionsPageDecorator::deleteConfiguration()
void UAVGadgetOptionsPageDecorator::textEdited(QString name)
{
m_config->setProvisionalName(name);
m_instanceManager->configNameEdited(name);
m_instanceManager->configurationNameEdited(name);
}