2 ******************************************************************************
4 * @file opmap_edit_waypoint_dialog.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
10 * @brief The OpenPilot Map 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 "opmap_edit_waypoint_dialog.h"
29 #include "ui_opmap_edit_waypoint_dialog.h"
30 #include "opmapcontrol/opmapcontrol.h"
31 #include "widgetdelegates.h"
32 // *********************************************************************
35 opmap_edit_waypoint_dialog::opmap_edit_waypoint_dialog(QWidget
*parent
, QAbstractItemModel
*model
, QItemSelectionModel
*selection
) :
36 QWidget(parent
, Qt::Window
), model(model
), itemSelection(selection
),
37 ui(new Ui::opmap_edit_waypoint_dialog
)
40 connect(ui
->checkBoxLocked
, SIGNAL(toggled(bool)), this, SLOT(enableEditWidgets(bool)));
41 connect(ui
->cbMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(setupModeWidgets()));
42 connect(ui
->cbCondition
, SIGNAL(currentIndexChanged(int)), this, SLOT(setupConditionWidgets()));
43 connect(ui
->pushButtonCancel
, SIGNAL(clicked()), this, SLOT(pushButtonCancel_clicked()));
44 MapDataDelegate::loadComboBox(ui
->cbMode
, flightDataModel::MODE
);
45 MapDataDelegate::loadComboBox(ui
->cbCondition
, flightDataModel::CONDITION
);
46 MapDataDelegate::loadComboBox(ui
->cbCommand
, flightDataModel::COMMAND
);
47 mapper
= new QDataWidgetMapper(this);
49 mapper
->setItemDelegate(new MapDataDelegate(this));
50 connect(mapper
, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int)));
51 mapper
->setModel(model
);
52 mapper
->setSubmitPolicy(QDataWidgetMapper::AutoSubmit
);
53 mapper
->addMapping(ui
->checkBoxLocked
, flightDataModel::LOCKED
);
54 mapper
->addMapping(ui
->doubleSpinBoxLatitude
, flightDataModel::LATPOSITION
);
55 mapper
->addMapping(ui
->doubleSpinBoxLongitude
, flightDataModel::LNGPOSITION
);
56 mapper
->addMapping(ui
->doubleSpinBoxAltitude
, flightDataModel::ALTITUDE
);
57 mapper
->addMapping(ui
->lineEditDescription
, flightDataModel::WPDESCRITPTION
);
58 mapper
->addMapping(ui
->checkBoxRelative
, flightDataModel::ISRELATIVE
);
59 mapper
->addMapping(ui
->doubleSpinBoxBearing
, flightDataModel::BEARELATIVE
);
60 mapper
->addMapping(ui
->doubleSpinBoxVelocity
, flightDataModel::VELOCITY
);
61 mapper
->addMapping(ui
->doubleSpinBoxDistance
, flightDataModel::DISRELATIVE
);
62 mapper
->addMapping(ui
->doubleSpinBoxRelativeAltitude
, flightDataModel::ALTITUDERELATIVE
);
63 mapper
->addMapping(ui
->cbMode
, flightDataModel::MODE
);
64 mapper
->addMapping(ui
->dsb_modeParam1
, flightDataModel::MODE_PARAMS0
);
65 mapper
->addMapping(ui
->dsb_modeParam2
, flightDataModel::MODE_PARAMS1
);
66 mapper
->addMapping(ui
->dsb_modeParam3
, flightDataModel::MODE_PARAMS2
);
67 mapper
->addMapping(ui
->dsb_modeParam4
, flightDataModel::MODE_PARAMS3
);
69 mapper
->addMapping(ui
->cbCondition
, flightDataModel::CONDITION
);
70 mapper
->addMapping(ui
->dsb_condParam1
, flightDataModel::CONDITION_PARAMS0
);
71 mapper
->addMapping(ui
->dsb_condParam2
, flightDataModel::CONDITION_PARAMS1
);
72 mapper
->addMapping(ui
->dsb_condParam3
, flightDataModel::CONDITION_PARAMS2
);
73 mapper
->addMapping(ui
->dsb_condParam4
, flightDataModel::CONDITION_PARAMS0
);
75 mapper
->addMapping(ui
->cbCommand
, flightDataModel::COMMAND
);
76 mapper
->addMapping(ui
->sbJump
, flightDataModel::JUMPDESTINATION
);
77 mapper
->addMapping(ui
->sbError
, flightDataModel::ERRORDESTINATION
);
78 connect(itemSelection
, SIGNAL(currentRowChanged(QModelIndex
, QModelIndex
)), this, SLOT(currentRowChanged(QModelIndex
, QModelIndex
)));
80 void opmap_edit_waypoint_dialog::currentIndexChanged(int index
)
82 ui
->lbNumber
->setText(QString::number(index
+ 1));
83 QModelIndex idx
= mapper
->model()->index(index
, 0);
84 if (index
== itemSelection
->currentIndex().row()) {
87 itemSelection
->clear();
88 itemSelection
->setCurrentIndex(idx
, QItemSelectionModel::Select
| QItemSelectionModel::Rows
);
91 opmap_edit_waypoint_dialog::~opmap_edit_waypoint_dialog()
96 void opmap_edit_waypoint_dialog::on_pushButtonOK_clicked()
102 void opmap_edit_waypoint_dialog::setupModeWidgets()
104 MapDataDelegate::ModeOptions mode
= (MapDataDelegate::ModeOptions
)ui
->cbMode
->itemData(ui
->cbMode
->currentIndex()).toInt();
107 case MapDataDelegate::MODE_GOTOENDPOINT
:
108 case MapDataDelegate::MODE_FOLLOWVECTOR
:
109 case MapDataDelegate::MODE_CIRCLERIGHT
:
110 case MapDataDelegate::MODE_CIRCLELEFT
:
111 case MapDataDelegate::MODE_DISARMALARM
:
112 case MapDataDelegate::MODE_LAND
:
113 case MapDataDelegate::MODE_BRAKE
:
114 ui
->modeParam1
->setVisible(false);
115 ui
->modeParam2
->setVisible(false);
116 ui
->modeParam3
->setVisible(false);
117 ui
->modeParam4
->setVisible(false);
118 ui
->dsb_modeParam1
->setVisible(false);
119 ui
->dsb_modeParam2
->setVisible(false);
120 ui
->dsb_modeParam3
->setVisible(false);
121 ui
->dsb_modeParam4
->setVisible(false);
123 case MapDataDelegate::MODE_VELOCITY
:
124 ui
->modeParam1
->setVisible(true);
125 ui
->modeParam2
->setVisible(true);
126 ui
->modeParam3
->setVisible(true);
127 ui
->modeParam4
->setVisible(false);
128 ui
->dsb_modeParam1
->setVisible(true);
129 ui
->dsb_modeParam2
->setVisible(true);
130 ui
->dsb_modeParam3
->setVisible(true);
131 ui
->dsb_modeParam4
->setVisible(false);
133 case MapDataDelegate::MODE_FIXEDATTITUDE
:
134 ui
->modeParam1
->setText("pitch");
135 ui
->modeParam2
->setText("roll");
136 ui
->modeParam3
->setText("yaw");
137 ui
->modeParam4
->setText("thrust");
138 ui
->modeParam1
->setVisible(true);
139 ui
->modeParam2
->setVisible(true);
140 ui
->modeParam3
->setVisible(true);
141 ui
->modeParam4
->setVisible(true);
142 ui
->dsb_modeParam1
->setVisible(true);
143 ui
->dsb_modeParam2
->setVisible(true);
144 ui
->dsb_modeParam3
->setVisible(true);
145 ui
->dsb_modeParam4
->setVisible(true);
147 case MapDataDelegate::MODE_SETACCESSORY
:
148 ui
->modeParam1
->setText("Acc.channel");
149 ui
->modeParam2
->setText("Value");
150 ui
->modeParam1
->setVisible(true);
151 ui
->modeParam2
->setVisible(true);
152 ui
->modeParam3
->setVisible(false);
153 ui
->modeParam4
->setVisible(false);
154 ui
->dsb_modeParam1
->setVisible(true);
155 ui
->dsb_modeParam2
->setVisible(true);
156 ui
->dsb_modeParam3
->setVisible(false);
157 ui
->dsb_modeParam4
->setVisible(false);
161 void opmap_edit_waypoint_dialog::setupConditionWidgets()
163 MapDataDelegate::EndConditionOptions mode
= (MapDataDelegate::EndConditionOptions
)ui
->cbCondition
->itemData(ui
->cbCondition
->currentIndex()).toInt();
166 case MapDataDelegate::ENDCONDITION_NONE
:
167 case MapDataDelegate::ENDCONDITION_IMMEDIATE
:
168 case MapDataDelegate::ENDCONDITION_PYTHONSCRIPT
:
169 ui
->condParam1
->setVisible(false);
170 ui
->condParam2
->setVisible(false);
171 ui
->condParam3
->setVisible(false);
172 ui
->condParam4
->setVisible(false);
173 ui
->dsb_condParam1
->setVisible(false);
174 ui
->dsb_condParam2
->setVisible(false);
175 ui
->dsb_condParam3
->setVisible(false);
176 ui
->dsb_condParam4
->setVisible(false);
178 case MapDataDelegate::ENDCONDITION_TIMEOUT
:
179 ui
->condParam1
->setVisible(true);
180 ui
->condParam2
->setVisible(false);
181 ui
->condParam3
->setVisible(false);
182 ui
->condParam4
->setVisible(false);
183 ui
->dsb_condParam1
->setVisible(true);
184 ui
->dsb_condParam2
->setVisible(false);
185 ui
->dsb_condParam3
->setVisible(false);
186 ui
->dsb_condParam4
->setVisible(false);
187 ui
->condParam1
->setText("Timeout(s)");
189 case MapDataDelegate::ENDCONDITION_DISTANCETOTARGET
:
190 ui
->condParam1
->setVisible(true);
191 ui
->condParam2
->setVisible(true);
192 ui
->condParam3
->setVisible(false);
193 ui
->condParam4
->setVisible(false);
194 ui
->dsb_condParam1
->setVisible(true);
195 ui
->dsb_condParam2
->setVisible(true);
196 ui
->dsb_condParam3
->setVisible(false);
197 ui
->dsb_condParam4
->setVisible(false);
198 ui
->condParam1
->setText("Distance(m)");
199 ui
->condParam2
->setText("Flag(0=2D,1=3D)"); // FIXME
201 case MapDataDelegate::ENDCONDITION_LEGREMAINING
:
202 ui
->condParam1
->setVisible(true);
203 ui
->condParam2
->setVisible(false);
204 ui
->condParam3
->setVisible(false);
205 ui
->condParam4
->setVisible(false);
206 ui
->dsb_condParam1
->setVisible(true);
207 ui
->dsb_condParam2
->setVisible(false);
208 ui
->dsb_condParam3
->setVisible(false);
209 ui
->dsb_condParam4
->setVisible(false);
210 ui
->condParam1
->setText("Relative Distance(0=complete,1=just starting)");
212 case MapDataDelegate::ENDCONDITION_BELOWERROR
:
213 ui
->condParam1
->setVisible(true);
214 ui
->condParam2
->setVisible(false);
215 ui
->condParam3
->setVisible(false);
216 ui
->condParam4
->setVisible(false);
217 ui
->dsb_condParam1
->setVisible(true);
218 ui
->dsb_condParam2
->setVisible(false);
219 ui
->dsb_condParam3
->setVisible(false);
220 ui
->dsb_condParam4
->setVisible(false);
221 ui
->condParam1
->setText("error margin (in m)");
223 case MapDataDelegate::ENDCONDITION_ABOVEALTITUDE
:
224 ui
->condParam1
->setVisible(true);
225 ui
->condParam2
->setVisible(false);
226 ui
->condParam3
->setVisible(false);
227 ui
->condParam4
->setVisible(false);
228 ui
->dsb_condParam1
->setVisible(true);
229 ui
->dsb_condParam2
->setVisible(false);
230 ui
->dsb_condParam3
->setVisible(false);
231 ui
->dsb_condParam4
->setVisible(false);
232 ui
->condParam1
->setText("Altitude in meters (negative)");
234 case MapDataDelegate::ENDCONDITION_ABOVESPEED
:
235 ui
->condParam1
->setVisible(true);
236 ui
->condParam2
->setVisible(true);
237 ui
->condParam3
->setVisible(false);
238 ui
->condParam4
->setVisible(false);
239 ui
->dsb_condParam1
->setVisible(true);
240 ui
->dsb_condParam2
->setVisible(true);
241 ui
->dsb_condParam3
->setVisible(false);
242 ui
->dsb_condParam4
->setVisible(false);
243 ui
->condParam1
->setText("Speed in meters/second");
244 ui
->condParam2
->setText("flag: 0=groundspeed 1=airspeed");
246 case MapDataDelegate::ENDCONDITION_POINTINGTOWARDSNEXT
:
247 ui
->condParam1
->setVisible(true);
248 ui
->condParam2
->setVisible(false);
249 ui
->condParam3
->setVisible(false);
250 ui
->condParam4
->setVisible(false);
251 ui
->dsb_condParam1
->setVisible(true);
252 ui
->dsb_condParam2
->setVisible(false);
253 ui
->dsb_condParam3
->setVisible(false);
254 ui
->dsb_condParam4
->setVisible(false);
255 ui
->condParam1
->setText("Degrees variation allowed");
263 void opmap_edit_waypoint_dialog::pushButtonCancel_clicked()
268 void opmap_edit_waypoint_dialog::editWaypoint(mapcontrol::WayPointItem
*waypoint_item
)
270 if (!waypoint_item
) {
279 if (!isActiveWindow()) {
283 setFocus(Qt::OtherFocusReason
);
284 mapper
->setCurrentIndex(waypoint_item
->Number());
287 void opmap_edit_waypoint_dialog::on_pushButton_clicked()
289 mapper
->toPrevious();
292 void opmap_edit_waypoint_dialog::on_pushButton_2_clicked()
297 void opmap_edit_waypoint_dialog::enableEditWidgets(bool value
)
301 foreach(QWidget
* obj
, this->findChildren
<QWidget
*>()) {
302 w
= qobject_cast
<QComboBox
*>(obj
);
304 w
->setEnabled(!value
);
306 w
= qobject_cast
<QLineEdit
*>(obj
);
308 w
->setEnabled(!value
);
310 w
= qobject_cast
<QDoubleSpinBox
*>(obj
);
312 w
->setEnabled(!value
);
314 w
= qobject_cast
<QCheckBox
*>(obj
);
315 if (w
&& w
!= ui
->checkBoxLocked
) {
316 w
->setEnabled(!value
);
318 w
= qobject_cast
<QSpinBox
*>(obj
);
320 w
->setEnabled(!value
);
325 void opmap_edit_waypoint_dialog::currentRowChanged(QModelIndex current
, QModelIndex previous
)
329 mapper
->setCurrentIndex(current
.row());