dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavgadgetoptionspagedecorator.cpp
Go to the documentation of this file.
1 
12 /*
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.
17  *
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
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
28 #include "ui_uavgadgetoptionspage.h"
30 #include "coreimpl.h"
31 
32 #include <QtCore/QDebug>
33 
34 using namespace Core;
35 
38  bool isSingleConfigurationGadget,
39  QObject *parent)
40  : Core::IOptionsPage(parent)
41  , m_optionsPage(page)
42  , m_config(config)
43  , m_isSingleConfigurationGadget(isSingleConfigurationGadget)
44  , m_id(config->name())
45  , m_category(config->classId())
46 {
47  m_optionsPage->setParent(this);
48  m_instanceManager = ICore::instance()->uavGadgetInstanceManager();
49  m_categoryTr = m_instanceManager->gadgetName(m_category);
50 }
51 
53 {
54  m_page = new Ui_TopOptionsPage();
55  QWidget *w = new QWidget(parent);
56  m_page->setupUi(w);
57  if (m_config->locked()) {
58  m_page->deleteButton->hide();
59  m_page->lockCheckBox->hide();
60  m_page->nameLineEdit->setDisabled(true);
61  }
62  if (!m_instanceManager->canDeleteConfiguration(m_config))
63  m_page->deleteButton->setDisabled(true);
64  m_page->lockCheckBox->hide(); //
65  m_page->nameLineEdit->setText(m_id);
66 
67  QWidget *wi = m_optionsPage->createPage(w);
68  wi->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
69  m_page->verticalLayout_4->addWidget(wi);
70 
71  // For some gadgets it might not make sense to have multiple configurations
72  if (m_isSingleConfigurationGadget) {
73  m_page->configurationBox->hide();
74  }
75 
76  connect(m_page->cloneButton, SIGNAL(clicked()), this, SLOT(cloneConfiguration()));
77  connect(m_page->deleteButton, SIGNAL(clicked()), this, SLOT(deleteConfiguration()));
78  connect(m_page->nameLineEdit, SIGNAL(textEdited(QString)), this, SLOT(textEdited(QString)));
79 
80  return w;
81 }
82 
84 {
85  m_id = m_config->provisionalName();
86  m_optionsPage->apply();
87  m_instanceManager->applyChanges(m_config);
88 }
89 
91 {
92  m_optionsPage->finish();
93 }
94 
95 void UAVGadgetOptionsPageDecorator::cloneConfiguration()
96 {
97  m_instanceManager->cloneConfiguration(m_config);
98 }
99 
100 void UAVGadgetOptionsPageDecorator::deleteConfiguration()
101 {
102  m_instanceManager->deleteConfiguration(m_config);
103 }
104 
105 void UAVGadgetOptionsPageDecorator::textEdited(QString name)
106 {
107  m_config->setProvisionalName(name);
108  m_instanceManager->configurationNameEdited(name);
109 }
UAVGadgetOptionsPageDecorator(IOptionsPage *page, IUAVGadgetConfiguration *config, bool isSingleConfigurationGadget=false, QObject *parent=nullptr)
void configurationNameEdited(QString text, bool hasText=true)
void applyChanges(IUAVGadgetConfiguration *config)
static ICore * instance()
Definition: coreimpl.cpp:46
virtual void apply()=0
virtual QWidget * createPage(QWidget *parent)=0
virtual void finish()=0
void deleteConfiguration(IUAVGadgetConfiguration *config)
bool canDeleteConfiguration(IUAVGadgetConfiguration *config)
void cloneConfiguration(IUAVGadgetConfiguration *config)
The IOptionsPage is an interface for providing options pages.
Definition: ioptionspage.h:42
QString gadgetName(QString classId) const
virtual UAVGadgetInstanceManager * uavGadgetInstanceManager() const =0