dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
metadata_dialog.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 #include "metadata_dialog.h"
26 #include <QtCore/qglobal.h>
27 
28 #include <QDebug>
29 #include <QScrollBar>
30 #include <QInputDialog>
31 
36 
37 MetadataDialog::MetadataDialog(UAVObject::Metadata mdata, QWidget *parent)
38  : QDialog(parent)
39  , resetDefaults_flag(false)
40  , saveMetadata_flag(false)
41 {
42  m_mdata = &mdata;
43 
44  metadata_editor.setupUi(this);
45 
46  // In case GCS is not in expert mode, hide the apply button
47  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
49  if (!settings->useExpertMode())
50  metadata_editor.bnApplyMetadata->setVisible(false);
51 
52  // Set comboboxes
53  metadata_editor.cmbFlightTelemetryMode->addItem("Periodic", UAVObject::UPDATEMODE_PERIODIC);
54  metadata_editor.cmbFlightTelemetryMode->addItem("Throttled", UAVObject::UPDATEMODE_THROTTLED);
55  metadata_editor.cmbFlightTelemetryMode->addItem("On Change", UAVObject::UPDATEMODE_ONCHANGE);
56  metadata_editor.cmbFlightTelemetryMode->addItem("Manual", UAVObject::UPDATEMODE_MANUAL);
57 
58  metadata_editor.cmbGCSTelemetryMode->addItem("Periodic", UAVObject::UPDATEMODE_PERIODIC);
59  metadata_editor.cmbGCSTelemetryMode->addItem("Throttled", UAVObject::UPDATEMODE_THROTTLED);
60  metadata_editor.cmbGCSTelemetryMode->addItem("On Change", UAVObject::UPDATEMODE_ONCHANGE);
61  metadata_editor.cmbGCSTelemetryMode->addItem("Manual", UAVObject::UPDATEMODE_MANUAL);
62 
63  // Connect the before setting any signals
64  connect(metadata_editor.bnApplyMetadata, &QAbstractButton::clicked, this,
65  &MetadataDialog::saveApplyMetadata);
66  connect(metadata_editor.bnSaveMetadata, &QAbstractButton::clicked, this,
67  &MetadataDialog::saveApplyMetadata);
68  connect(metadata_editor.bnCancel, &QAbstractButton::clicked, this,
69  &MetadataDialog::cancelChanges);
70  connect(metadata_editor.bnResetToDefaults, &QAbstractButton::clicked, this,
71  &MetadataDialog::resetMetadataToDefaults);
72 
73  // Fill buttons and check boxes
74  fillWidgets();
75 }
76 
78 {
79  // Do nothing
80 }
81 
82 void MetadataDialog::saveApplyMetadata()
83 {
84  // Check which button was pressed
85  if (QObject::sender() == metadata_editor.bnSaveMetadata)
86  saveMetadata_flag = true;
87  else if (QObject::sender() == metadata_editor.bnApplyMetadata)
88  saveMetadata_flag = false;
89  else
90  Q_ASSERT(0);
91 
92  // Checkboxes
93  UAVObject::SetFlightAccess(*m_mdata, metadata_editor.cbFlightReadOnly->isChecked()
96  UAVObject::SetGcsAccess(*m_mdata, metadata_editor.cbFlightReadOnly->isChecked()
99  UAVObject::SetFlightTelemetryAcked(*m_mdata, metadata_editor.cbFlightAcked->isChecked());
100  UAVObject::SetGcsTelemetryAcked(*m_mdata, metadata_editor.cbGCSAcked->isChecked());
101 
102  // Comboboxes
103  int currentFlightIdx = metadata_editor.cmbFlightTelemetryMode->currentIndex();
104  int currentGCSIdx = metadata_editor.cmbGCSTelemetryMode->currentIndex();
106  *m_mdata,
107  (UAVObject::UpdateMode)metadata_editor.cmbFlightTelemetryMode->itemData(currentFlightIdx)
108  .toInt());
110  *m_mdata,
111  (UAVObject::UpdateMode)metadata_editor.cmbGCSTelemetryMode->itemData(currentGCSIdx)
112  .toInt());
113 
114  accept();
115 }
116 
117 void MetadataDialog::cancelChanges()
118 {
119  reject();
120 }
121 
122 void MetadataDialog::resetMetadataToDefaults()
123 {
124  resetDefaults_flag = true;
125  accept();
126 }
127 
131 void MetadataDialog::fillWidgets()
132 {
133  // Set checkboxes
134  metadata_editor.cbFlightReadOnly->setChecked(UAVObject::GetFlightAccess(*m_mdata));
135  metadata_editor.cbGCSReadOnly->setChecked(UAVObject::GetGcsAccess(*m_mdata));
136  metadata_editor.cbFlightAcked->setChecked(UAVObject::GetFlightTelemetryAcked(*m_mdata));
137  metadata_editor.cbGCSAcked->setChecked(UAVObject::GetGcsTelemetryAcked(*m_mdata));
138 
139  // Set flight telemetry update mode combo box
140  int accessType = UAVObject::GetFlightTelemetryUpdateMode(*m_mdata);
141  metadata_editor.cmbFlightTelemetryMode->setCurrentIndex(
142  metadata_editor.cmbFlightTelemetryMode->findData(accessType));
143 
144  // Set GCS telemetry update mode combo box
145  accessType = UAVObject::GetGcsTelemetryUpdateMode(*m_mdata);
146  metadata_editor.cmbGCSTelemetryMode->setCurrentIndex(
147  metadata_editor.cmbGCSTelemetryMode->findData(accessType));
148 }
149 
static void SetFlightTelemetryAcked(Metadata &meta, quint8 val)
Definition: uavobject.cpp:427
static UpdateMode GetFlightTelemetryUpdateMode(const Metadata &meta)
Definition: uavobject.cpp:457
static void SetFlightAccess(Metadata &meta, AccessMode mode)
Definition: uavobject.cpp:387
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
static void SetGcsTelemetryAcked(Metadata &meta, quint8 val)
Definition: uavobject.cpp:447
static UpdateMode GetGcsTelemetryUpdateMode(const Metadata &meta)
Definition: uavobject.cpp:479
static quint8 GetFlightTelemetryAcked(const Metadata &meta)
Definition: uavobject.cpp:417
static void SetGcsAccess(Metadata &meta, AccessMode mode)
Definition: uavobject.cpp:407
static void SetFlightTelemetryUpdateMode(Metadata &meta, UpdateMode val)
Definition: uavobject.cpp:468
MetadataDialog(UAVObject::Metadata mdata, QWidget *parent=nullptr)
static AccessMode GetFlightAccess(const Metadata &meta)
Definition: uavobject.cpp:377
static void SetGcsTelemetryUpdateMode(Metadata &meta, UpdateMode val)
Definition: uavobject.cpp:490
static quint8 GetGcsTelemetryAcked(const Metadata &meta)
Definition: uavobject.cpp:437
static AccessMode GetGcsAccess(const Metadata &meta)
Definition: uavobject.cpp:397