mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
GCS/coreplugin: Continuation of rev 379: Partially implemented support for uavgadget settings.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@384 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
37a0ce845c
commit
6587eb0524
@ -56,9 +56,9 @@ SOURCES += mainwindow.cpp \
|
||||
eventfilteringmainwindow.cpp \
|
||||
connectionmanager.cpp \
|
||||
iconnection.cpp \
|
||||
uavgadgetoptionspage.cpp \
|
||||
iuavgadgetconfiguration.cpp \
|
||||
uavgadgetinstancemanager.cpp
|
||||
uavgadgetinstancemanager.cpp \
|
||||
uavgadgetoptionspagedecorator.cpp
|
||||
HEADERS += mainwindow.h \
|
||||
tabpositionindicator.h \
|
||||
fancyactionbar.h \
|
||||
@ -111,9 +111,9 @@ HEADERS += mainwindow.h \
|
||||
eventfilteringmainwindow.h \
|
||||
connectionmanager.h \
|
||||
iconnection.h \
|
||||
uavgadgetoptionspage.h \
|
||||
iuavgadgetconfiguration.h \
|
||||
uavgadgetinstancemanager.h
|
||||
uavgadgetinstancemanager.h \
|
||||
uavgadgetoptionspagedecorator.h
|
||||
FORMS += dialogs/settingsdialog.ui \
|
||||
dialogs/shortcutsettings.ui \
|
||||
generalsettings.ui \
|
||||
|
@ -30,7 +30,10 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include "icore.h"
|
||||
#include "coreplugin/uavgadgetinstancemanager.h"
|
||||
//#include "coreimpl.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QPushButton>
|
||||
@ -68,6 +71,11 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
||||
|
||||
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
||||
|
||||
m_instanceManager = Core::ICore::instance()->uavGadgetInstanceManager();
|
||||
|
||||
connect(this, SIGNAL(settingsDialogShown(Core::Internal::SettingsDialog*)), m_instanceManager, SLOT(settingsDialogShown(Core::Internal::SettingsDialog*)));
|
||||
connect(this, SIGNAL(settingsDialogRemoved()), m_instanceManager, SLOT(settingsDialogRemoved()));
|
||||
|
||||
splitter->setCollapsible(1, false);
|
||||
pageTree->header()->setVisible(false);
|
||||
@ -152,11 +160,66 @@ void SettingsDialog::pageSelected()
|
||||
stackedPages->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void SettingsDialog::deletePage()
|
||||
{
|
||||
QTreeWidgetItem *item = pageTree->currentItem();
|
||||
item->parent()->removeChild(item);
|
||||
PageData data = item->data(0, Qt::UserRole).value<PageData>();
|
||||
int index = data.index;
|
||||
m_deletedPageIndices.append(index);
|
||||
pageSelected();
|
||||
}
|
||||
|
||||
void SettingsDialog::insertPage(IOptionsPage* page)
|
||||
{
|
||||
PageData pageData;
|
||||
pageData.index = m_pages.count();
|
||||
pageData.category = page->category();
|
||||
pageData.id = page->id();
|
||||
|
||||
QTreeWidgetItem *categoryItem = 0;
|
||||
for (int i = 0; i < pageTree->topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *tw = pageTree->topLevelItem(i);
|
||||
PageData data = tw->data(0, Qt::UserRole).value<PageData>();
|
||||
if (data.category == page->category()) {
|
||||
categoryItem = tw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!categoryItem)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem;
|
||||
item->setText(0, page->trName());
|
||||
item->setData(0, Qt::UserRole, qVariantFromValue(pageData));
|
||||
|
||||
categoryItem->addChild(item);
|
||||
|
||||
m_pages.append(page);
|
||||
stackedPages->addWidget(page->createPage(stackedPages));
|
||||
|
||||
stackedPages->setCurrentIndex(stackedPages->count());
|
||||
pageTree->setCurrentItem(item);
|
||||
}
|
||||
|
||||
void SettingsDialog::updateText(QString text)
|
||||
{
|
||||
QTreeWidgetItem *item = pageTree->currentItem();
|
||||
item->setText(0, text);
|
||||
}
|
||||
|
||||
void SettingsDialog::disableApplyOk(bool disable)
|
||||
{
|
||||
buttonBox->button(QDialogButtonBox::Apply)->setDisabled(disable);
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable);
|
||||
}
|
||||
|
||||
void SettingsDialog::accept()
|
||||
{
|
||||
m_applied = true;
|
||||
foreach (IOptionsPage *page, m_pages) {
|
||||
page->apply();
|
||||
if (!m_deletedPageIndices.contains(m_pages.indexOf(page)))
|
||||
page->apply();
|
||||
page->finish();
|
||||
}
|
||||
done(QDialog::Accepted);
|
||||
@ -171,15 +234,19 @@ void SettingsDialog::reject()
|
||||
|
||||
void SettingsDialog::apply()
|
||||
{
|
||||
foreach (IOptionsPage *page, m_pages)
|
||||
page->apply();
|
||||
foreach (IOptionsPage *page, m_pages) {
|
||||
if (!m_deletedPageIndices.contains(m_pages.indexOf(page)))
|
||||
page->apply();
|
||||
}
|
||||
m_applied = true;
|
||||
}
|
||||
|
||||
bool SettingsDialog::execDialog()
|
||||
{
|
||||
m_applied = false;
|
||||
emit settingsDialogShown(this);
|
||||
exec();
|
||||
emit settingsDialogRemoved();
|
||||
return m_applied;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,9 @@
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
class UAVGadgetInstanceManager;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class SettingsDialog : public QDialog, public ::Ui::SettingsDialog
|
||||
@ -51,6 +54,14 @@ public:
|
||||
// Run the dialog and return true if 'Ok' was choosen or 'Apply' was invoked
|
||||
// at least once
|
||||
bool execDialog();
|
||||
void insertPage(IOptionsPage* page);
|
||||
void deletePage();
|
||||
void updateText(QString text);
|
||||
void disableApplyOk(bool disable);
|
||||
|
||||
signals:
|
||||
void settingsDialogShown(Core::Internal::SettingsDialog*);
|
||||
void settingsDialogRemoved();
|
||||
|
||||
public slots:
|
||||
void done(int);
|
||||
@ -63,9 +74,11 @@ private slots:
|
||||
|
||||
private:
|
||||
QList<Core::IOptionsPage*> m_pages;
|
||||
UAVGadgetInstanceManager *m_instanceManager;
|
||||
bool m_applied;
|
||||
QString m_currentCategory;
|
||||
QString m_currentPage;
|
||||
QList<int> m_deletedPageIndices;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@ -37,13 +37,17 @@ IUAVGadget::IUAVGadget(QString classId, QList<IUAVGadgetConfiguration*> *configu
|
||||
m_toolbar(new QComboBox),
|
||||
m_configurations(configurations)
|
||||
{
|
||||
foreach (IUAVGadgetConfiguration *config, *configurations)
|
||||
m_toolbar->setMinimumContentsLength(15);
|
||||
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);
|
||||
}
|
||||
|
||||
void IUAVGadget::loadConfiguration(int index) {
|
||||
IUAVGadgetConfiguration* config = m_configurations->at(index);
|
||||
m_activeConfiguration = config;
|
||||
loadConfiguration(config);
|
||||
}
|
||||
|
||||
@ -54,6 +58,21 @@ void IUAVGadget::configurationChanged(IUAVGadgetConfiguration* config)
|
||||
loadConfiguration(config);
|
||||
}
|
||||
|
||||
void IUAVGadget::configurationAdded(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
m_configurations->append(config);
|
||||
m_toolbar->addItem(config->name());
|
||||
}
|
||||
|
||||
void IUAVGadget::configurationToBeDeleted(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
int index = m_configurations->indexOf(config);
|
||||
if (index >= 0) {
|
||||
m_toolbar->removeItem(index);
|
||||
m_configurations->removeAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
void IUAVGadget::configurationNameChanged(QString oldName, QString newName)
|
||||
{
|
||||
for (int i = 0; i < m_toolbar->count(); ++i) {
|
||||
@ -77,7 +96,9 @@ void IUAVGadget::restoreState(QByteArray state)
|
||||
QByteArray configName;
|
||||
stream >> configName;
|
||||
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
|
||||
if (config->name() == configName)
|
||||
if (config->name() == configName) {
|
||||
m_activeConfiguration = config;
|
||||
loadConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,11 +55,14 @@ public:
|
||||
QString classId() const { return m_classId; }
|
||||
|
||||
virtual void loadConfiguration(IUAVGadgetConfiguration* /*config*/) {}
|
||||
IUAVGadgetConfiguration *activeConfiguration() { return m_activeConfiguration; }
|
||||
QComboBox *toolBar() { return m_toolbar; }
|
||||
virtual QByteArray saveState();
|
||||
virtual void restoreState(QByteArray state);
|
||||
public slots:
|
||||
void configurationChanged(IUAVGadgetConfiguration* config);
|
||||
void configurationAdded(IUAVGadgetConfiguration* config);
|
||||
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
|
||||
void configurationNameChanged(QString oldName, QString newName);
|
||||
private slots:
|
||||
void loadConfiguration(int index);
|
||||
|
@ -33,6 +33,7 @@ IUAVGadgetConfiguration::IUAVGadgetConfiguration(bool locked, QString classId, Q
|
||||
QObject(parent),
|
||||
m_locked(locked),
|
||||
m_classId(classId),
|
||||
m_name(name)
|
||||
m_name(name),
|
||||
m_provisionalName(name)
|
||||
{
|
||||
}
|
||||
|
@ -42,8 +42,10 @@ public:
|
||||
QString classId() { return m_classId; }
|
||||
QString name() { return m_name; }
|
||||
void setName(QString name) { m_name = name; }
|
||||
QString provisionalName() { return m_provisionalName; }
|
||||
void setProvisionalName(QString name) { m_provisionalName = name; }
|
||||
bool locked() const { return m_locked; }
|
||||
virtual IUAVGadgetConfiguration *clone() = 0;
|
||||
virtual IUAVGadgetConfiguration *clone(QString name) = 0;
|
||||
|
||||
signals:
|
||||
|
||||
@ -53,6 +55,7 @@ private:
|
||||
bool m_locked;
|
||||
QString m_classId;
|
||||
QString m_name;
|
||||
QString m_provisionalName;
|
||||
|
||||
};
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace Core {
|
||||
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetConfiguration;
|
||||
class UAVGadgetOptionsPage;
|
||||
class IOptionsPage;
|
||||
|
||||
class CORE_EXPORT IUAVGadgetFactory : public QObject
|
||||
{
|
||||
@ -52,11 +52,11 @@ public:
|
||||
m_name(name) {}
|
||||
virtual ~IUAVGadgetFactory() {}
|
||||
|
||||
virtual IUAVGadget *createUAVGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent) = 0;
|
||||
virtual IUAVGadgetConfiguration *createUAVGadgetConfiguration(bool /*locked*/,
|
||||
virtual IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent) = 0;
|
||||
virtual IUAVGadgetConfiguration *createConfiguration(bool /*locked*/,
|
||||
const QString /*configName*/,
|
||||
const QByteArray &/*state*/) { return 0; }
|
||||
virtual UAVGadgetOptionsPage *createUAVGadgetOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
|
||||
virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
|
||||
QString classId() const { return m_classId; }
|
||||
QString name() const { return m_name; }
|
||||
private:
|
||||
|
@ -252,7 +252,7 @@ void MainWindow::extensionsInitialized()
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
|
||||
m_uavGadgetInstanceManager = new UAVGadgetInstanceManager(this);
|
||||
m_uavGadgetInstanceManager->readUAVGadgetConfigurations();
|
||||
m_uavGadgetInstanceManager->readConfigurations();
|
||||
|
||||
// Workspace 1
|
||||
UAVGadgetMode *uavGadgetMode;
|
||||
@ -947,7 +947,7 @@ void MainWindow::writeSettings()
|
||||
m_viewManager->saveSettings(m_settings);
|
||||
m_actionManager->saveSettings(m_settings);
|
||||
|
||||
m_uavGadgetInstanceManager->writeUAVGadgetConfigurations();
|
||||
m_uavGadgetInstanceManager->writeConfigurations();
|
||||
|
||||
foreach (UAVGadgetManager *manager, m_uavGadgetManagers) {
|
||||
manager->saveSettings();
|
||||
|
@ -26,15 +26,18 @@
|
||||
*/
|
||||
|
||||
#include "uavgadgetinstancemanager.h"
|
||||
#include "iuavgadget.h"
|
||||
#include "iuavgadgetfactory.h"
|
||||
#include "iuavgadgetconfiguration.h"
|
||||
#include "uavgadgetoptionspage.h"
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include "coreplugin/dialogs/settingsdialog.h"
|
||||
#include "icore.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
|
||||
using namespace Core;
|
||||
@ -45,22 +48,22 @@ UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
QList<IUAVGadgetFactory*> factories = pm->getObjects<IUAVGadgetFactory>();
|
||||
foreach (IUAVGadgetFactory *f, factories) {
|
||||
if (!m_uavGadgetFactories.contains(f)) {
|
||||
m_uavGadgetFactories.append(f);
|
||||
if (!m_factories.contains(f)) {
|
||||
m_factories.append(f);
|
||||
QString classId = f->classId();
|
||||
QString name = f->name();
|
||||
m_uavGadgetClassIds.insert(classId, name);
|
||||
m_classIds.insert(classId, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::readUAVGadgetConfigurations()
|
||||
void UAVGadgetInstanceManager::readConfigurations()
|
||||
{
|
||||
QSettings *qs = Core::ICore::instance()->settings();
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
foreach (QString classId, m_uavGadgetClassIds.keys())
|
||||
foreach (QString classId, m_classIds.keys())
|
||||
{
|
||||
IUAVGadgetFactory *f = uavGadgetFactory(classId);
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
qs->beginGroup(classId);
|
||||
QStringList configs = qs->childKeys();
|
||||
|
||||
@ -71,29 +74,30 @@ void UAVGadgetInstanceManager::readUAVGadgetConfigurations()
|
||||
stream >> locked;
|
||||
QByteArray state;
|
||||
stream >> state;
|
||||
IUAVGadgetConfiguration *config = f->createUAVGadgetConfiguration(locked, configName, state);
|
||||
m_uavGadgetConfigurations.append(config);
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(locked, configName, state);
|
||||
if (config)
|
||||
m_configurations.append(config);
|
||||
}
|
||||
|
||||
if (configs.count() == 0) {
|
||||
IUAVGadgetConfiguration *config = f->createUAVGadgetConfiguration(false, tr("default"), 0);
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(false, tr("default"), 0);
|
||||
// it is not mandatory for uavgadgets to have any configurations (settings)
|
||||
// and therefore we have to check for that
|
||||
if (config)
|
||||
m_uavGadgetConfigurations.append(config);
|
||||
m_configurations.append(config);
|
||||
}
|
||||
qs->endGroup();
|
||||
}
|
||||
qs->endGroup();
|
||||
createUAVGadgetOptionPages();
|
||||
createOptionsPages();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::writeUAVGadgetConfigurations()
|
||||
void UAVGadgetInstanceManager::writeConfigurations()
|
||||
{
|
||||
QSettings *qs = Core::ICore::instance()->settings();
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
qs->allKeys().clear(); // Remove existing configurations
|
||||
foreach (IUAVGadgetConfiguration *config, m_uavGadgetConfigurations)
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
qs->beginGroup(config->classId());
|
||||
QByteArray ba;
|
||||
@ -106,65 +110,173 @@ void UAVGadgetInstanceManager::writeUAVGadgetConfigurations()
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::createUAVGadgetOptionPages()
|
||||
void UAVGadgetInstanceManager::createOptionsPages()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
foreach (IUAVGadgetConfiguration *config, m_uavGadgetConfigurations)
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
IUAVGadgetFactory *f = uavGadgetFactory(config->classId());
|
||||
UAVGadgetOptionsPage *page = f->createUAVGadgetOptionsPage(config);
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *page = f->createOptionsPage(config);
|
||||
m_optionsPages.append(page);
|
||||
pm->addObject(page);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IUAVGadget *UAVGadgetInstanceManager::createUAVGadget(QString classId, QWidget *parent)
|
||||
IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent)
|
||||
{
|
||||
IUAVGadgetFactory *f = uavGadgetFactory(classId);
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
if (f) {
|
||||
QList<IUAVGadgetConfiguration*> *configs = uavGadgetConfigurations(classId);
|
||||
IUAVGadget *gadget = f->createUAVGadget(configs, parent);
|
||||
m_uavGadgetInstances.append(gadget);
|
||||
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
||||
IUAVGadget *gadget = f->createGadget(configs, parent);
|
||||
m_gadgetInstances.append(gadget);
|
||||
return gadget;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//IUAVGadgetConfiguration *UAVGadgetInstanceManager::createUAVGadgetConfiguration(QString classId,
|
||||
// QString configName)
|
||||
//{
|
||||
// return 0;
|
||||
//}
|
||||
bool UAVGadgetInstanceManager::canDeleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
// to be able to delete a configuration, no instance must be using it
|
||||
foreach (IUAVGadget *gadget, m_gadgetInstances) {
|
||||
if (gadget->activeConfiguration() == config) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// and it cannot be the only configuration
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
if (c != config && c->classId() == config->classId())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//UAVGadgetOptionsPage *UAVGadgetInstanceManager::createUAVGadgetOptionsPage(QString classId)
|
||||
//{
|
||||
// return 0;
|
||||
//}
|
||||
void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (m_provisionalConfigs.contains(config)) {
|
||||
int i = m_provisionalConfigs.indexOf(config);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_provisionalOptionsPages.removeAt(i);
|
||||
int j = m_takenNames[config->classId()].indexOf(config->name());
|
||||
m_takenNames[config->classId()].removeAt(j);
|
||||
m_settingsDialog->deletePage();
|
||||
} else if (m_configurations.contains(config)) {
|
||||
int i = m_configurations.indexOf(config);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_optionsPages.removeAt(i);
|
||||
m_settingsDialog->deletePage();
|
||||
}
|
||||
configNameEdited("", false);
|
||||
}
|
||||
|
||||
QStringList UAVGadgetInstanceManager::uavGadgetConfigurationNames(QString classId) const
|
||||
void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *configToClone)
|
||||
{
|
||||
QString name = suggestName(configToClone->classId(), configToClone->name());
|
||||
|
||||
IUAVGadgetConfiguration *config = configToClone->clone(name);
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *page = f->createOptionsPage(config);
|
||||
m_provisionalConfigs.append(config);
|
||||
m_provisionalOptionsPages.append(page);
|
||||
m_settingsDialog->insertPage(page);
|
||||
}
|
||||
|
||||
// "name" => "name 1", "Name 3" => "Name 4", "Name1" => "Name1 1"
|
||||
QString UAVGadgetInstanceManager::suggestName(QString classId, QString name)
|
||||
{
|
||||
QString suggestedName;
|
||||
|
||||
QString last = name.split(" ").last();
|
||||
bool ok;
|
||||
int num = last.toInt(&ok);
|
||||
int i = 1;
|
||||
if (ok) {
|
||||
QStringList n = name.split(" ");
|
||||
n.removeLast();
|
||||
name = n.join(" ");
|
||||
i = num+1;
|
||||
}
|
||||
do {
|
||||
suggestedName = name + " " + QString::number(i);
|
||||
++i;
|
||||
} while (m_takenNames[classId].contains(suggestedName));
|
||||
|
||||
m_takenNames[classId].append(suggestedName);
|
||||
return suggestedName;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::configNameEdited(QString text, bool hasText)
|
||||
{
|
||||
bool disable = false;
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_configurations) {
|
||||
if (c != d && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *c, m_provisionalConfigs) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
if (hasText && text == "")
|
||||
disable = true;
|
||||
m_settingsDialog->disableApplyOk(disable);
|
||||
if (hasText)
|
||||
m_settingsDialog->updateText(text);
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog)
|
||||
{
|
||||
foreach (QString classId, classIds())
|
||||
m_takenNames.insert(classId, configurationNames(classId));
|
||||
m_settingsDialog = settingsDialog;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogRemoved()
|
||||
{
|
||||
m_takenNames.clear();
|
||||
m_provisionalConfigs.clear();
|
||||
m_provisionalOptionsPages.clear();
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
config->setProvisionalName(config->name());
|
||||
m_settingsDialog = 0;
|
||||
}
|
||||
|
||||
|
||||
QStringList UAVGadgetInstanceManager::configurationNames(QString classId) const
|
||||
{
|
||||
QStringList names;
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
names.append(config->name());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
QString UAVGadgetInstanceManager::uavGadgetName(QString classId) const
|
||||
QString UAVGadgetInstanceManager::gadgetName(QString classId) const
|
||||
{
|
||||
return m_uavGadgetClassIds.value(classId);
|
||||
return m_classIds.value(classId);
|
||||
}
|
||||
|
||||
IUAVGadgetFactory *UAVGadgetInstanceManager::uavGadgetFactory(QString classId) const
|
||||
IUAVGadgetFactory *UAVGadgetInstanceManager::factory(QString classId) const
|
||||
{
|
||||
foreach (IUAVGadgetFactory *f, m_uavGadgetFactories) {
|
||||
foreach (IUAVGadgetFactory *f, m_factories) {
|
||||
if (f->classId() == classId)
|
||||
return f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<IUAVGadgetConfiguration*> *UAVGadgetInstanceManager::uavGadgetConfigurations(QString classId) const
|
||||
QList<IUAVGadgetConfiguration*> *UAVGadgetInstanceManager::configurations(QString classId) const
|
||||
{
|
||||
QList<IUAVGadgetConfiguration*> *configs = new QList<IUAVGadgetConfiguration*>;
|
||||
foreach (IUAVGadgetConfiguration *config, m_uavGadgetConfigurations) {
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
configs->append(config);
|
||||
}
|
||||
|
@ -35,9 +35,13 @@
|
||||
namespace Core
|
||||
{
|
||||
|
||||
namespace Internal {
|
||||
class SettingsDialog;
|
||||
}
|
||||
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetConfiguration;
|
||||
class UAVGadgetOptionsPage;
|
||||
class IOptionsPage;
|
||||
class IUAVGadgetFactory;
|
||||
|
||||
class UAVGadgetInstanceManager : public QObject
|
||||
@ -45,27 +49,37 @@ class UAVGadgetInstanceManager : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVGadgetInstanceManager(QObject *parent = 0);
|
||||
void readUAVGadgetConfigurations();
|
||||
void writeUAVGadgetConfigurations();
|
||||
IUAVGadget *createUAVGadget(QString classId, QWidget *parent);
|
||||
bool deleteUAVGadgetConfiguration(QString classId, QString configName);
|
||||
QStringList uavGadgetClassIds() const { return m_uavGadgetClassIds.keys(); }
|
||||
QStringList uavGadgetConfigurationNames(QString classId) const;
|
||||
QString uavGadgetName(QString classId) const;
|
||||
void readConfigurations();
|
||||
void writeConfigurations();
|
||||
IUAVGadget *createGadget(QString classId, QWidget *parent);
|
||||
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void deleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void cloneConfiguration(IUAVGadgetConfiguration *config);
|
||||
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:
|
||||
|
||||
public slots:
|
||||
void settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog);
|
||||
void settingsDialogRemoved();
|
||||
|
||||
private:
|
||||
IUAVGadgetFactory *uavGadgetFactory(QString classId) const;
|
||||
void createUAVGadgetOptionPages();
|
||||
QList<IUAVGadgetConfiguration*> *uavGadgetConfigurations(QString classId) const;
|
||||
// UAVGadgetOptionsPage *createUAVGadgetOptionsPage(QString classId);
|
||||
QList<IUAVGadget*> m_uavGadgetInstances;
|
||||
QList<IUAVGadgetFactory*> m_uavGadgetFactories;
|
||||
QList<IUAVGadgetConfiguration*> m_uavGadgetConfigurations;
|
||||
QMap<QString, QString> m_uavGadgetClassIds;
|
||||
IUAVGadgetFactory *factory(QString classId) const;
|
||||
void createOptionsPages();
|
||||
QList<IUAVGadgetConfiguration*> *configurations(QString classId) const;
|
||||
QString suggestName(QString classId, QString name);
|
||||
QList<IUAVGadget*> m_gadgetInstances;
|
||||
QList<IUAVGadgetFactory*> m_factories;
|
||||
QList<IUAVGadgetConfiguration*> m_configurations;
|
||||
QList<IOptionsPage*> m_optionsPages;
|
||||
QMap<QString, QString> m_classIds;
|
||||
QMap<QString, QStringList> m_takenNames;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalConfigs;
|
||||
QList<IOptionsPage*> m_provisionalOptionsPages;
|
||||
Core::Internal::SettingsDialog *m_settingsDialog;
|
||||
|
||||
};
|
||||
|
||||
|
@ -128,7 +128,7 @@ struct UAVGadgetManagerPrivate {
|
||||
~UAVGadgetManagerPrivate();
|
||||
Internal::UAVGadgetView *m_view;
|
||||
Internal::SplitterOrView *m_splitterOrView;
|
||||
QPointer<IUAVGadget> m_currentUAVGadget;
|
||||
QPointer<IUAVGadget> m_currentGadget;
|
||||
|
||||
ICore *m_core;
|
||||
|
||||
@ -262,7 +262,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
|
||||
// other setup
|
||||
m_d->m_splitterOrView = new SplitterOrView(this, 0, true);
|
||||
m_d->m_view = m_d->m_splitterOrView->view();
|
||||
setCurrentUAVGadget(m_d->m_view->uavGadget());
|
||||
setCurrentGadget(m_d->m_view->gadget());
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
@ -301,19 +301,19 @@ void UAVGadgetManager::handleContextChange(Core::IContext *context)
|
||||
// qDebug() << Q_FUNC_INFO << context;
|
||||
IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0;
|
||||
if (uavGadget) {
|
||||
setCurrentUAVGadget(uavGadget);
|
||||
setCurrentGadget(uavGadget);
|
||||
} else {
|
||||
updateActions();
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget)
|
||||
void UAVGadgetManager::setCurrentGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
if (m_d->m_currentUAVGadget == uavGadget)
|
||||
if (m_d->m_currentGadget == uavGadget)
|
||||
return;
|
||||
|
||||
SplitterOrView *oldView = currentSplitterOrView();
|
||||
m_d->m_currentUAVGadget = uavGadget;
|
||||
m_d->m_currentGadget = uavGadget;
|
||||
SplitterOrView *view = currentSplitterOrView();
|
||||
if (oldView != view) {
|
||||
if (oldView)
|
||||
@ -322,9 +322,9 @@ void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget)
|
||||
view->update();
|
||||
}
|
||||
uavGadget->widget()->setFocus();
|
||||
emit currentUAVGadgetChanged(uavGadget);
|
||||
emit currentGadgetChanged(uavGadget);
|
||||
updateActions();
|
||||
// emit currentUAVGadgetChanged(uavGadget);
|
||||
// emit currentGadgetChanged(uavGadget);
|
||||
}
|
||||
|
||||
/* Contract: return current SplitterOrView.
|
||||
@ -334,15 +334,15 @@ Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const
|
||||
{
|
||||
if (!m_d->m_splitterOrView) // this is only for startup
|
||||
return 0;
|
||||
SplitterOrView *view = m_d->m_currentUAVGadget ?
|
||||
m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget) :
|
||||
SplitterOrView *view = m_d->m_currentGadget ?
|
||||
m_d->m_splitterOrView->findView(m_d->m_currentGadget) :
|
||||
0;
|
||||
return view;
|
||||
}
|
||||
|
||||
IUAVGadget *UAVGadgetManager::currentUAVGadget() const
|
||||
IUAVGadget *UAVGadgetManager::currentGadget() const
|
||||
{
|
||||
return m_d->m_currentUAVGadget;
|
||||
return m_d->m_currentGadget;
|
||||
}
|
||||
|
||||
void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view)
|
||||
@ -350,10 +350,10 @@ void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view)
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
IUAVGadget *uavGadget = view->uavGadget();
|
||||
IUAVGadget *uavGadget = view->gadget();
|
||||
// emit uavGadgetAboutToClose(uavGadget);
|
||||
removeUAVGadget(uavGadget);
|
||||
view->removeUAVGadget();
|
||||
removeGadget(uavGadget);
|
||||
view->removeGadget();
|
||||
// emit uavGadgetsClosed(uavGadgets);
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view)
|
||||
emptyView(view);
|
||||
|
||||
SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView);
|
||||
Q_ASSERT(splitterOrView->hasUAVGadget() == false);
|
||||
Q_ASSERT(splitterOrView->hasGadget() == false);
|
||||
Q_ASSERT(splitter->isSplitter() == true);
|
||||
splitterOrView->hide();
|
||||
delete splitterOrView;
|
||||
@ -381,11 +381,11 @@ void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view)
|
||||
SplitterOrView *newCurrent = splitter->findFirstView();
|
||||
Q_ASSERT(newCurrent);
|
||||
if (newCurrent)
|
||||
setCurrentUAVGadget(newCurrent->uavGadget());
|
||||
setCurrentGadget(newCurrent->gadget());
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
|
||||
void UAVGadgetManager::addGadgetToContext(IUAVGadget *uavGadget)
|
||||
{
|
||||
if (!uavGadget)
|
||||
return;
|
||||
@ -394,7 +394,7 @@ void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
|
||||
// emit uavGadgetOpened(uavGadget);
|
||||
}
|
||||
|
||||
void UAVGadgetManager::removeUAVGadget(IUAVGadget *uavGadget)
|
||||
void UAVGadgetManager::removeGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
if (!uavGadget)
|
||||
return;
|
||||
@ -496,7 +496,7 @@ void UAVGadgetManager::split(Qt::Orientation orientation)
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
return;
|
||||
|
||||
IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
|
||||
IUAVGadget *uavGadget = m_d->m_currentGadget;
|
||||
Q_ASSERT(uavGadget);
|
||||
SplitterOrView *view = currentSplitterOrView();
|
||||
Q_ASSERT(view);
|
||||
@ -504,7 +504,7 @@ void UAVGadgetManager::split(Qt::Orientation orientation)
|
||||
|
||||
SplitterOrView *sor = m_d->m_splitterOrView->findView(uavGadget);
|
||||
SplitterOrView *next = m_d->m_splitterOrView->findNextView(sor);
|
||||
setCurrentUAVGadget(next->uavGadget());
|
||||
setCurrentGadget(next->gadget());
|
||||
updateActions();
|
||||
}
|
||||
|
||||
@ -537,11 +537,11 @@ void UAVGadgetManager::removeAllSplits()
|
||||
|
||||
if (!m_d->m_splitterOrView->isSplitter())
|
||||
return;
|
||||
IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
|
||||
m_d->m_currentUAVGadget = 0; // trigger update below
|
||||
IUAVGadget *uavGadget = m_d->m_currentGadget;
|
||||
m_d->m_currentGadget = 0; // trigger update below
|
||||
m_d->m_splitterOrView->unsplitAll();
|
||||
m_d->m_splitterOrView->view()->setUAVGadget(uavGadget);
|
||||
setCurrentUAVGadget(uavGadget);
|
||||
m_d->m_splitterOrView->view()->setGadget(uavGadget);
|
||||
setCurrentGadget(uavGadget);
|
||||
}
|
||||
|
||||
void UAVGadgetManager::gotoOtherSplit()
|
||||
@ -555,7 +555,7 @@ void UAVGadgetManager::gotoOtherSplit()
|
||||
if (!view)
|
||||
view = m_d->m_splitterOrView->findFirstView();
|
||||
if (view) {
|
||||
setCurrentUAVGadget(view->uavGadget());
|
||||
setCurrentGadget(view->gadget());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
|
||||
void ensureUAVGadgetManagerVisible();
|
||||
|
||||
IUAVGadget *currentUAVGadget() const;
|
||||
IUAVGadget *currentGadget() const;
|
||||
|
||||
QByteArray saveState() const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
@ -103,7 +103,7 @@ public:
|
||||
bool toolbarsShown() { return m_showToolbars; }
|
||||
|
||||
signals:
|
||||
void currentUAVGadgetChanged(IUAVGadget *gadget);
|
||||
void currentGadgetChanged(IUAVGadget *gadget);
|
||||
|
||||
private slots:
|
||||
void handleContextChange(Core::IContext *context);
|
||||
@ -119,9 +119,9 @@ public slots:
|
||||
void showToolbars(bool show);
|
||||
|
||||
private:
|
||||
void addUAVGadget(IUAVGadget *gadget);
|
||||
void removeUAVGadget(IUAVGadget *gadget);
|
||||
void setCurrentUAVGadget(IUAVGadget *gadget);
|
||||
void addGadgetToContext(IUAVGadget *gadget);
|
||||
void removeGadget(IUAVGadget *gadget);
|
||||
void setCurrentGadget(IUAVGadget *gadget);
|
||||
void closeView(Core::Internal::UAVGadgetView *view);
|
||||
void emptyView(Core::Internal::UAVGadgetView *view);
|
||||
Core::Internal::SplitterOrView *currentSplitterOrView() const;
|
||||
|
@ -72,7 +72,7 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
m_uavGadgetList(new QComboBox),
|
||||
m_closeButton(new QToolButton),
|
||||
m_defaultIndex(0),
|
||||
m_activeLabel(new QLabel(tr("<font color=red><b>Active</b></font>")))
|
||||
m_activeLabel(new QLabel)
|
||||
{
|
||||
|
||||
tl = new QVBoxLayout(this);
|
||||
@ -84,11 +84,11 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
m_uavGadgetList->setMaxVisibleItems(40);
|
||||
m_uavGadgetList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
QStringList sl = im->uavGadgetClassIds();
|
||||
QStringList sl = im->classIds();
|
||||
int index = 0;
|
||||
foreach(QString classId, sl)
|
||||
{
|
||||
m_uavGadgetList->addItem(im->uavGadgetName(classId), classId);
|
||||
m_uavGadgetList->addItem(im->gadgetName(classId), classId);
|
||||
if (classId == QString("EmptyGadget"))
|
||||
m_defaultIndex = index;
|
||||
++index;
|
||||
@ -108,6 +108,7 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
spacerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
m_activeLabel->setTextFormat(Qt::RichText);
|
||||
m_activeLabel->setText("<font color=red><b>" + tr("Active") + "</b></font>");
|
||||
|
||||
m_closeButton->setAutoRaise(true);
|
||||
m_closeButton->setIcon(QIcon(":/core/images/closebutton.png"));
|
||||
@ -127,10 +128,10 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
|
||||
connect(m_uavGadgetList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int)));
|
||||
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
|
||||
connect(m_uavGadgetManager, SIGNAL(currentUAVGadgetChanged(IUAVGadget*)), this, SLOT(currentUAVGadgetChanged(IUAVGadget*)));
|
||||
connect(m_uavGadgetManager, SIGNAL(currentGadgetChanged(IUAVGadget*)), this, SLOT(currentGadgetChanged(IUAVGadget*)));
|
||||
}
|
||||
if (m_uavGadget) {
|
||||
setUAVGadget(m_uavGadget);
|
||||
setGadget(m_uavGadget);
|
||||
} else {
|
||||
listSelectionActivated(m_defaultIndex);
|
||||
}
|
||||
@ -140,7 +141,7 @@ UAVGadgetView::~UAVGadgetView()
|
||||
{
|
||||
}
|
||||
|
||||
bool UAVGadgetView::hasUAVGadget(IUAVGadget *uavGadget) const
|
||||
bool UAVGadgetView::hasGadget(IUAVGadget *uavGadget) const
|
||||
{
|
||||
return (m_uavGadget == uavGadget);
|
||||
}
|
||||
@ -155,7 +156,7 @@ void UAVGadgetView::closeView()
|
||||
m_uavGadgetManager->closeView(this);
|
||||
}
|
||||
|
||||
void UAVGadgetView::removeUAVGadget()
|
||||
void UAVGadgetView::removeGadget()
|
||||
{
|
||||
if (!m_uavGadget)
|
||||
return;
|
||||
@ -175,17 +176,17 @@ void UAVGadgetView::removeUAVGadget()
|
||||
m_uavGadget = 0;
|
||||
}
|
||||
|
||||
IUAVGadget *UAVGadgetView::uavGadget() const
|
||||
IUAVGadget *UAVGadgetView::gadget() const
|
||||
{
|
||||
return m_uavGadget;
|
||||
}
|
||||
|
||||
void UAVGadgetView::setUAVGadget(IUAVGadget *uavGadget)
|
||||
void UAVGadgetView::setGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
if (!uavGadget) {
|
||||
return;
|
||||
}
|
||||
removeUAVGadget();
|
||||
removeGadget();
|
||||
m_uavGadget = uavGadget;
|
||||
tl->addWidget(m_uavGadget->widget());
|
||||
m_uavGadget->widget()->setParent(this);
|
||||
@ -221,9 +222,9 @@ void UAVGadgetView::listSelectionActivated(int index)
|
||||
QString classId = m_uavGadgetList->itemData(index).toString();
|
||||
if (m_uavGadget && (m_uavGadget->classId() == classId))
|
||||
return;
|
||||
IUAVGadget *gadget = fm->createUAVGadget(classId, this);
|
||||
setUAVGadget(gadget);
|
||||
m_uavGadgetManager->setCurrentUAVGadget(gadget);
|
||||
IUAVGadget *gadget = fm->createGadget(classId, this);
|
||||
setGadget(gadget);
|
||||
m_uavGadgetManager->setCurrentGadget(gadget);
|
||||
}
|
||||
|
||||
int UAVGadgetView::indexOfClassId(QString classId)
|
||||
@ -231,10 +232,9 @@ int UAVGadgetView::indexOfClassId(QString classId)
|
||||
return m_uavGadgetList->findData(classId);
|
||||
}
|
||||
|
||||
void UAVGadgetView::currentUAVGadgetChanged(IUAVGadget *gadget)
|
||||
void UAVGadgetView::currentGadgetChanged(IUAVGadget *gadget)
|
||||
{
|
||||
(m_uavGadget == gadget) ? m_activeLabel->show() : m_activeLabel->hide();
|
||||
|
||||
m_activeLabel->setVisible(m_uavGadget == gadget);
|
||||
}
|
||||
|
||||
SplitterOrView::SplitterOrView(Core::UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) :
|
||||
@ -259,9 +259,9 @@ void SplitterOrView::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
if (uavGadget()) {
|
||||
if (gadget()) {
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
m_uavGadgetManager->setCurrentUAVGadget(this->uavGadget());
|
||||
m_uavGadgetManager->setCurrentGadget(this->gadget());
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ void SplitterOrView::paintEvent(QPaintEvent *event)
|
||||
if (!m_view)
|
||||
return;
|
||||
|
||||
if (hasUAVGadget())
|
||||
if (hasGadget())
|
||||
return;
|
||||
|
||||
if (m_uavGadgetManager->toolbarsShown())
|
||||
@ -337,7 +337,7 @@ SplitterOrView *SplitterOrView::findFirstView()
|
||||
*/
|
||||
SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
|
||||
{
|
||||
if (!uavGadget || hasUAVGadget(uavGadget))
|
||||
if (!uavGadget || hasGadget(uavGadget))
|
||||
return this;
|
||||
if (m_splitter) {
|
||||
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||
@ -375,7 +375,7 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IUAVGadget *uavGadget)
|
||||
if (m_splitter) {
|
||||
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
|
||||
if (splitterOrView->hasUAVGadget(uavGadget))
|
||||
if (splitterOrView->hasGadget(uavGadget))
|
||||
return this;
|
||||
if (SplitterOrView *result = splitterOrView->findSplitter(uavGadget))
|
||||
return result;
|
||||
@ -467,12 +467,12 @@ void SplitterOrView::split(Qt::Orientation orientation)
|
||||
m_splitter = new MiniSplitter(this);
|
||||
m_splitter->setOrientation(orientation);
|
||||
m_layout->addWidget(m_splitter);
|
||||
Core::IUAVGadget *e = m_view->uavGadget();
|
||||
Core::IUAVGadget *e = m_view->gadget();
|
||||
|
||||
SplitterOrView *view = 0;
|
||||
SplitterOrView *otherView = 0;
|
||||
if (e) {
|
||||
m_view->removeUAVGadget();
|
||||
m_view->removeGadget();
|
||||
m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager, e)));
|
||||
m_splitter->addWidget((otherView = new SplitterOrView(m_uavGadgetManager)));
|
||||
} else {
|
||||
@ -529,9 +529,9 @@ void SplitterOrView::unsplit()
|
||||
UAVGadgetView *childView = childSplitterOrView->view();
|
||||
Q_ASSERT(childView);
|
||||
if (m_view) {
|
||||
if (IUAVGadget *e = childView->uavGadget()) {
|
||||
childView->removeUAVGadget();
|
||||
m_view->setUAVGadget(e);
|
||||
if (IUAVGadget *e = childView->gadget()) {
|
||||
childView->removeGadget();
|
||||
m_view->setGadget(e);
|
||||
}
|
||||
m_uavGadgetManager->emptyView(childView);
|
||||
} else {
|
||||
@ -541,7 +541,7 @@ void SplitterOrView::unsplit()
|
||||
m_layout->setCurrentWidget(m_view);
|
||||
}
|
||||
delete oldSplitter;
|
||||
m_uavGadgetManager->setCurrentUAVGadget(findFirstView()->uavGadget());
|
||||
m_uavGadgetManager->setCurrentGadget(findFirstView()->gadget());
|
||||
}
|
||||
|
||||
|
||||
@ -557,8 +557,8 @@ QByteArray SplitterOrView::saveState() const
|
||||
<< static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState()
|
||||
<< static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState();
|
||||
} else {
|
||||
if (uavGadget())
|
||||
stream << QByteArray("uavGadget") << uavGadget()->classId() << uavGadget()->saveState();
|
||||
if (gadget())
|
||||
stream << QByteArray("uavGadget") << gadget()->classId() << gadget()->saveState();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
@ -585,6 +585,6 @@ void SplitterOrView::restoreState(const QByteArray &state)
|
||||
m_view->listSelectionActivated(index);
|
||||
m_layout->addWidget(m_view);
|
||||
m_layout->setCurrentWidget(m_view);
|
||||
uavGadget()->restoreState(uavGadgetState);
|
||||
gadget()->restoreState(uavGadgetState);
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ public:
|
||||
UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget = 0, QWidget *parent = 0);
|
||||
virtual ~UAVGadgetView();
|
||||
|
||||
void removeUAVGadget();
|
||||
IUAVGadget *uavGadget() const;
|
||||
void setUAVGadget(IUAVGadget *uavGadget);
|
||||
bool hasUAVGadget(IUAVGadget *uavGadget) const;
|
||||
void removeGadget();
|
||||
IUAVGadget *gadget() const;
|
||||
void setGadget(IUAVGadget *uavGadget);
|
||||
bool hasGadget(IUAVGadget *uavGadget) const;
|
||||
int indexOfClassId(QString classId);
|
||||
void showToolbar(bool show);
|
||||
|
||||
@ -79,7 +79,7 @@ public slots:
|
||||
void listSelectionActivated(int index);
|
||||
|
||||
private slots:
|
||||
void currentUAVGadgetChanged(IUAVGadget *gadget);
|
||||
void currentGadgetChanged(IUAVGadget *gadget);
|
||||
|
||||
private:
|
||||
void updateToolBar();
|
||||
@ -112,9 +112,9 @@ public:
|
||||
inline bool isRoot() const { return m_isRoot; }
|
||||
|
||||
inline bool isSplitter() const { return m_splitter != 0; }
|
||||
inline Core::IUAVGadget *uavGadget() const { return m_view ? m_view->uavGadget() : 0; }
|
||||
inline bool hasUAVGadget(Core::IUAVGadget *uavGadget) const { return m_view && m_view->hasUAVGadget(uavGadget); }
|
||||
inline bool hasUAVGadget() const { return m_view && (m_view->uavGadget() != 0); }
|
||||
inline Core::IUAVGadget *gadget() const { return m_view ? m_view->gadget() : 0; }
|
||||
inline bool hasGadget(Core::IUAVGadget *uavGadget) const { return m_view && m_view->hasGadget(uavGadget); }
|
||||
inline bool hasGadget() const { return m_view && (m_view->gadget() != 0); }
|
||||
inline UAVGadgetView *view() const { return m_view; }
|
||||
inline QSplitter *splitter() const { return m_splitter; }
|
||||
QSplitter *takeSplitter();
|
||||
|
@ -120,6 +120,6 @@ void UAVGadgetMode::grabUAVGadgetManager(Core::IMode *mode)
|
||||
if (mode != this)
|
||||
return;
|
||||
|
||||
if (m_uavGadgetManager->currentUAVGadget())
|
||||
m_uavGadgetManager->currentUAVGadget()->widget()->setFocus();
|
||||
if (m_uavGadgetManager->currentGadget())
|
||||
m_uavGadgetManager->currentGadget()->widget()->setFocus();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetoptionspage.cpp
|
||||
* @file uavgadgetoptionspagedecorator.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup coreplugin
|
||||
* @{
|
||||
@ -25,27 +25,27 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavgadgetoptionspage.h"
|
||||
#include "uavgadgetoptionspagedecorator.h"
|
||||
#include "ui_uavgadgetoptionspage.h"
|
||||
#include "uavgadgetinstancemanager.h"
|
||||
#include "coreimpl.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
|
||||
using namespace Core;
|
||||
|
||||
UAVGadgetOptionsPage::UAVGadgetOptionsPage(IUAVGadgetConfiguration *config, QObject *parent) :
|
||||
UAVGadgetOptionsPageDecorator::UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, QObject *parent) :
|
||||
Core::IOptionsPage(parent),
|
||||
m_optionsPage(page),
|
||||
m_config(config),
|
||||
m_id(config->name()),
|
||||
m_category(config->classId())
|
||||
{
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
m_categoryTr = im->uavGadgetName(m_category);
|
||||
m_instanceManager = ICore::instance()->uavGadgetInstanceManager();
|
||||
m_categoryTr = m_instanceManager->gadgetName(m_category);
|
||||
}
|
||||
|
||||
QWidget *UAVGadgetOptionsPage::createPage(QWidget *parent)
|
||||
QWidget *UAVGadgetOptionsPageDecorator::createPage(QWidget *parent)
|
||||
{
|
||||
m_page = new Ui_TopOptionsPage();
|
||||
QWidget *w = new QWidget(parent);
|
||||
@ -55,14 +55,44 @@ QWidget *UAVGadgetOptionsPage::createPage(QWidget *parent)
|
||||
m_page->lockCheckBox->hide();
|
||||
m_page->nameLineEdit->setDisabled(true);
|
||||
}
|
||||
if (!m_instanceManager->canDeleteConfiguration(m_config))
|
||||
m_page->deleteButton->setDisabled(true);
|
||||
m_page->lockCheckBox->hide(); //
|
||||
m_page->nameLineEdit->setText(m_id);
|
||||
QWidget *wi = widget();
|
||||
|
||||
QWidget *wi = m_optionsPage->createPage(w);
|
||||
m_page->verticalLayout_4->addWidget(wi);
|
||||
|
||||
w->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
connect(m_page->cloneButton, SIGNAL(clicked()), this, SLOT(cloneConfiguration()));
|
||||
connect(m_page->deleteButton, SIGNAL(clicked()), this, SLOT(deleteConfiguration()));
|
||||
connect(m_page->nameLineEdit, SIGNAL(textEdited(QString)), this, SLOT(textEdited(QString)));
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void UAVGadgetOptionsPageDecorator::apply()
|
||||
{
|
||||
m_optionsPage->apply();
|
||||
}
|
||||
|
||||
void UAVGadgetOptionsPageDecorator::finish()
|
||||
{
|
||||
m_optionsPage->finish();
|
||||
}
|
||||
|
||||
void UAVGadgetOptionsPageDecorator::cloneConfiguration()
|
||||
{
|
||||
m_instanceManager->cloneConfiguration(m_config);
|
||||
}
|
||||
|
||||
void UAVGadgetOptionsPageDecorator::deleteConfiguration()
|
||||
{
|
||||
m_instanceManager->deleteConfiguration(m_config);
|
||||
}
|
||||
|
||||
void UAVGadgetOptionsPageDecorator::textEdited(QString name)
|
||||
{
|
||||
m_config->setProvisionalName(name);
|
||||
m_instanceManager->configNameEdited(name);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetoptionspage.h
|
||||
* @file uavgadgetoptionspagedecorator.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup coreplugin
|
||||
* @{
|
||||
@ -25,8 +25,9 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVGADGETOPTIONSPAGE_H
|
||||
#define UAVGADGETOPTIONSPAGE_H
|
||||
#ifndef UAVGADGETOPTIONSPAGEDECORATOR_H
|
||||
#define UAVGADGETOPTIONSPAGEDECORATOR_H
|
||||
|
||||
#include "iuavgadgetconfiguration.h"
|
||||
#include <coreplugin/core_global.h>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
@ -36,29 +37,36 @@ class Ui_TopOptionsPage;
|
||||
namespace Core {
|
||||
|
||||
class IUAVGadgetConfiguration;
|
||||
class UAVGadgetInstanceManager;
|
||||
|
||||
class CORE_EXPORT UAVGadgetOptionsPage : public Core::IOptionsPage
|
||||
class CORE_EXPORT UAVGadgetOptionsPageDecorator : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVGadgetOptionsPage(IUAVGadgetConfiguration *config, QObject *parent = 0);
|
||||
explicit UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QString id() const { return m_id; }
|
||||
QString trName() const { return m_id; }
|
||||
QString category() const { return m_category; }
|
||||
QString trCategory() const { return m_categoryTr; }
|
||||
|
||||
/*final*/ QWidget *createPage(QWidget *parent); // do not override this function in subclasses
|
||||
virtual QWidget *widget() = 0; // implement this instead
|
||||
virtual void apply() = 0;
|
||||
virtual void finish() = 0;
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void cloneConfiguration();
|
||||
void deleteConfiguration();
|
||||
void textEdited(QString);
|
||||
|
||||
private:
|
||||
IOptionsPage *m_optionsPage;
|
||||
IUAVGadgetConfiguration *m_config;
|
||||
UAVGadgetInstanceManager *m_instanceManager;
|
||||
QString m_id;
|
||||
QString m_category;
|
||||
QString m_categoryTr;
|
||||
@ -68,4 +76,4 @@ private:
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // UAVGADGETOPTIONSPAGE_H
|
||||
#endif // UAVGADGETOPTIONSPAGEDECORATOR_H
|
Loading…
x
Reference in New Issue
Block a user