OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / opmap / widgetdelegates.cpp
blobb0ff8bed0cfd9a4ccc9b7a897025ddad4d4ab39d
1 /**
2 ******************************************************************************
4 * @file widgetdelegates.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
9 * @{
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
21 * for more details.
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
27 #include "widgetdelegates.h"
28 #include <QComboBox>
29 #include <QRadioButton>
30 #include <QDebug>
31 QWidget *MapDataDelegate::createEditor(QWidget *parent,
32 const QStyleOptionViewItem & option,
33 const QModelIndex & index) const
35 int column = index.column();
36 QComboBox *box;
38 switch (column) {
39 case flightDataModel::MODE:
40 box = new QComboBox(parent);
41 MapDataDelegate::loadComboBox(box, flightDataModel::MODE);
42 return box;
44 break;
45 case flightDataModel::CONDITION:
46 box = new QComboBox(parent);
47 MapDataDelegate::loadComboBox(box, flightDataModel::CONDITION);
48 return box;
50 break;
52 case flightDataModel::COMMAND:
53 box = new QComboBox(parent);
54 MapDataDelegate::loadComboBox(box, flightDataModel::COMMAND);
55 return box;
57 break;
58 default:
59 return QItemDelegate::createEditor(parent, option, index);
61 break;
64 QComboBox *editor = new QComboBox(parent);
65 return editor;
68 void MapDataDelegate::setEditorData(QWidget *editor,
69 const QModelIndex &index) const
71 if (!index.isValid()) {
72 return;
74 QString className = editor->metaObject()->className();
75 if (className.contains("QComboBox")) {
76 int value = index.model()->data(index, Qt::EditRole).toInt();
77 QComboBox *comboBox = static_cast<QComboBox *>(editor);
78 int x = comboBox->findData(value);
79 comboBox->setCurrentIndex(x);
80 } else {
81 QItemDelegate::setEditorData(editor, index);
85 void MapDataDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
86 const QModelIndex &index) const
88 QString className = editor->metaObject()->className();
90 if (className.contains("QComboBox")) {
91 QComboBox *comboBox = static_cast<QComboBox *>(editor);
92 int value = comboBox->itemData(comboBox->currentIndex()).toInt();
93 model->setData(index, value, Qt::EditRole);
94 } else {
95 QItemDelegate::setModelData(editor, model, index);
99 void MapDataDelegate::updateEditorGeometry(QWidget *editor,
100 const QStyleOptionViewItem &option, const QModelIndex & /* index */) const
102 editor->setGeometry(option.rect);
105 void MapDataDelegate::loadComboBox(QComboBox *combo, flightDataModel::pathPlanDataEnum type)
107 switch (type) {
108 case flightDataModel::MODE:
109 combo->addItem("Goto Endpoint", MODE_GOTOENDPOINT);
110 combo->addItem("Follow Vector", MODE_FOLLOWVECTOR);
111 combo->addItem("Circle Right", MODE_CIRCLERIGHT);
112 combo->addItem("Circle Left", MODE_CIRCLELEFT);
113 combo->addItem("Fixed Attitude", MODE_FIXEDATTITUDE);
114 combo->addItem("Set Accessory", MODE_SETACCESSORY);
115 combo->addItem("Disarm Alarm", MODE_DISARMALARM);
116 combo->addItem("Land", MODE_LAND);
117 combo->addItem("AutoTakeoff", MODE_AUTOTAKEOFF);
118 combo->addItem("Brake", MODE_BRAKE);
119 combo->addItem("Velocity", MODE_VELOCITY);
121 break;
122 case flightDataModel::CONDITION:
123 combo->addItem("None", ENDCONDITION_NONE);
124 combo->addItem("Timeout", ENDCONDITION_TIMEOUT);
125 combo->addItem("Distance to tgt", ENDCONDITION_DISTANCETOTARGET);
126 combo->addItem("Leg remaining", ENDCONDITION_LEGREMAINING);
127 combo->addItem("Below Error", ENDCONDITION_BELOWERROR);
128 combo->addItem("Above Altitude", ENDCONDITION_ABOVEALTITUDE);
129 combo->addItem("Above Speed", ENDCONDITION_ABOVESPEED);
130 combo->addItem("Pointing towards next", ENDCONDITION_POINTINGTOWARDSNEXT);
131 combo->addItem("Python script", ENDCONDITION_PYTHONSCRIPT);
132 combo->addItem("Immediate", ENDCONDITION_IMMEDIATE);
133 break;
134 case flightDataModel::COMMAND:
135 combo->addItem("On conditon next wp", COMMAND_ONCONDITIONNEXTWAYPOINT);
136 combo->addItem("On NOT conditon next wp", COMMAND_ONNOTCONDITIONNEXTWAYPOINT);
137 combo->addItem("On conditon jump wp", COMMAND_ONCONDITIONJUMPWAYPOINT);
138 combo->addItem("On NOT conditon jump wp", COMMAND_ONNOTCONDITIONJUMPWAYPOINT);
139 combo->addItem("On conditon jump wp else next wp", COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT);
140 break;
141 default:
142 break;
146 MapDataDelegate::MapDataDelegate(QObject *parent) : QItemDelegate(parent)