2 ******************************************************************************
4 * @file uavgadgetoptionspagedecorator.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup CorePlugin Core Plugin
10 * @brief The Core GCS plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "uavgadgetoptionspagedecorator.h"
29 #include "ui_uavgadgetoptionspage.h"
30 #include "uavgadgetinstancemanager.h"
33 #include <QtCore/QDebug>
37 UAVGadgetOptionsPageDecorator::UAVGadgetOptionsPageDecorator(IOptionsPage
*page
, IUAVGadgetConfiguration
*config
,
38 bool isSingleConfigurationGadget
, QObject
*parent
) :
39 Core::IOptionsPage(parent
),
42 m_isSingleConfigurationGadget(isSingleConfigurationGadget
),
44 m_category(config
->classId())
46 m_optionsPage
->setParent(this);
47 m_instanceManager
= ICore::instance()->uavGadgetInstanceManager();
48 m_categoryTr
= m_instanceManager
->gadgetName(m_category
);
51 QWidget
*UAVGadgetOptionsPageDecorator::createPage(QWidget
*parent
)
53 m_page
= new Ui_TopOptionsPage();
54 QWidget
*w
= new QWidget(parent
);
57 QWidget
*wi
= m_optionsPage
->createPage(w
);
58 wi
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
59 m_page
->verticalLayout_4
->addWidget(wi
);
61 // For some gadgets it might not make sense to have multiple configurations
62 if (m_isSingleConfigurationGadget
) {
63 m_page
->configurationBox
->hide();
68 connect(m_page
->cloneButton
, SIGNAL(clicked()), this, SLOT(cloneConfiguration()));
69 connect(m_page
->deleteButton
, SIGNAL(clicked()), this, SLOT(deleteConfiguration()));
70 connect(m_page
->nameLineEdit
, SIGNAL(textEdited(QString
)), this, SLOT(textEdited(QString
)));
75 void UAVGadgetOptionsPageDecorator::apply()
77 m_id
= m_config
->provisionalName();
78 m_optionsPage
->apply();
79 m_instanceManager
->applyChanges(m_config
);
82 void UAVGadgetOptionsPageDecorator::finish()
84 m_optionsPage
->finish();
87 void UAVGadgetOptionsPageDecorator::updateState()
89 if (m_config
->locked()) {
90 m_page
->deleteButton
->hide();
91 m_page
->lockCheckBox
->hide();
92 m_page
->nameLineEdit
->setDisabled(true);
94 switch (m_instanceManager
->canDeleteConfiguration(m_config
)) {
95 case UAVGadgetInstanceManager::OK
:
96 m_page
->deleteButton
->setEnabled(true);
97 m_page
->deleteButton
->setToolTip(tr("Delete this configuration"));
99 case UAVGadgetInstanceManager::KO_ACTIVE
:
100 m_page
->deleteButton
->setEnabled(false);
101 m_page
->deleteButton
->setToolTip(tr("Cannot delete a configuration currently in use"));
103 case UAVGadgetInstanceManager::KO_LONE
:
104 m_page
->deleteButton
->setEnabled(false);
105 m_page
->deleteButton
->setToolTip(tr("Cannot delete the last configuration"));
108 m_page
->deleteButton
->setEnabled(false);
109 m_page
->deleteButton
->setToolTip(tr("DON'T KNOW !"));
112 m_page
->lockCheckBox
->hide();
113 m_page
->nameLineEdit
->setText(m_id
);
116 void UAVGadgetOptionsPageDecorator::cloneConfiguration()
118 m_instanceManager
->cloneConfiguration(m_config
);
121 void UAVGadgetOptionsPageDecorator::deleteConfiguration()
123 m_instanceManager
->deleteConfiguration(m_config
);
126 void UAVGadgetOptionsPageDecorator::textEdited(QString name
)
128 m_config
->setProvisionalName(name
);
129 m_instanceManager
->configurationNameEdited(name
);