2010-06-29 13:11:35 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file opmap_edit_waypoint_dialog.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
2010-07-16 16:06:09 +02:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
2010-06-29 13:11:35 +02:00
|
|
|
* @{
|
2010-07-16 16:06:09 +02:00
|
|
|
* @addtogroup OPMapPlugin OpenPilot Map Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The OpenPilot Map plugin
|
2010-06-29 13:11:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opmap_edit_waypoint_dialog.h"
|
|
|
|
#include "ui_opmap_edit_waypoint_dialog.h"
|
2012-06-06 21:51:04 +02:00
|
|
|
#include "opmapcontrol/opmapcontrol.h"
|
2012-06-15 00:06:37 +02:00
|
|
|
#include "widgetdelegates.h"
|
2010-07-01 13:00:12 +02:00
|
|
|
// *********************************************************************
|
|
|
|
|
|
|
|
// constructor
|
2012-06-15 00:06:37 +02:00
|
|
|
opmap_edit_waypoint_dialog::opmap_edit_waypoint_dialog(QWidget *parent,QAbstractItemModel * model,QItemSelectionModel * selection) :
|
|
|
|
QWidget(parent),model(model),itemSelection(selection),
|
2010-06-29 13:11:35 +02:00
|
|
|
ui(new Ui::opmap_edit_waypoint_dialog)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
2010-06-29 13:11:35 +02:00
|
|
|
ui->setupUi(this);
|
2012-06-06 21:51:04 +02:00
|
|
|
my_waypoint = NULL;
|
2012-06-15 00:06:37 +02:00
|
|
|
connect(ui->checkBoxLocked,SIGNAL(toggled(bool)),this,SLOT(enableEditWidgets(bool)));
|
2012-06-06 21:51:04 +02:00
|
|
|
connect(ui->cbMode,SIGNAL(currentIndexChanged(int)),this,SLOT(setupModeWidgets()));
|
|
|
|
connect(ui->cbCondition,SIGNAL(currentIndexChanged(int)),this,SLOT(setupConditionWidgets()));
|
|
|
|
|
2012-06-25 20:41:59 +02:00
|
|
|
mapDataDelegate::loadComboBox(ui->cbMode,flightDataModel::MODE);
|
|
|
|
mapDataDelegate::loadComboBox(ui->cbCondition,flightDataModel::CONDITION);
|
|
|
|
mapDataDelegate::loadComboBox(ui->cbCommand,flightDataModel::COMMAND);
|
2012-06-15 00:06:37 +02:00
|
|
|
mapper = new QDataWidgetMapper(this);
|
2012-06-06 21:51:04 +02:00
|
|
|
|
2012-06-25 20:41:59 +02:00
|
|
|
mapper->setItemDelegate(new mapDataDelegate(this));
|
2012-06-15 00:06:37 +02:00
|
|
|
connect(mapper,SIGNAL(currentIndexChanged(int)),this,SLOT(on_currentIndexChanged(int)));
|
2012-06-25 20:41:59 +02:00
|
|
|
mapper->setModel(model);
|
|
|
|
mapper->addMapping(ui->checkBoxLocked,flightDataModel::LOCKED);
|
|
|
|
mapper->addMapping(ui->doubleSpinBoxLatitude,flightDataModel::LATPOSITION);
|
|
|
|
mapper->addMapping(ui->doubleSpinBoxLongitude,flightDataModel::LNGPOSITION);
|
|
|
|
mapper->addMapping(ui->doubleSpinBoxAltitude,flightDataModel::ALTITUDE);
|
|
|
|
mapper->addMapping(ui->lineEditDescription,flightDataModel::WPDESCRITPTION);
|
|
|
|
mapper->addMapping(ui->checkBoxRelative,flightDataModel::ISRELATIVE);
|
|
|
|
mapper->addMapping(ui->doubleSpinBoxBearing,flightDataModel::BEARELATIVE);
|
|
|
|
mapper->addMapping(ui->doubleSpinBoxVelocity,flightDataModel::VELOCITY);
|
|
|
|
mapper->addMapping(ui->spinBoxDistance,flightDataModel::DISRELATIVE);
|
|
|
|
mapper->addMapping(ui->cbMode,flightDataModel::MODE);
|
|
|
|
mapper->addMapping(ui->dsb_modeParam1,flightDataModel::MODE_PARAMS0);
|
|
|
|
mapper->addMapping(ui->dsb_modeParam2,flightDataModel::MODE_PARAMS1);
|
|
|
|
mapper->addMapping(ui->dsb_modeParam3,flightDataModel::MODE_PARAMS2);
|
|
|
|
mapper->addMapping(ui->dsb_modeParam4,flightDataModel::MODE_PARAMS3);
|
2012-06-06 21:51:04 +02:00
|
|
|
|
2012-06-25 20:41:59 +02:00
|
|
|
mapper->addMapping(ui->cbCondition,flightDataModel::CONDITION);
|
|
|
|
mapper->addMapping(ui->dsb_condParam1,flightDataModel::CONDITION_PARAMS0);
|
|
|
|
mapper->addMapping(ui->dsb_condParam2,flightDataModel::CONDITION_PARAMS1);
|
|
|
|
mapper->addMapping(ui->dsb_condParam3,flightDataModel::CONDITION_PARAMS2);
|
|
|
|
mapper->addMapping(ui->dsb_condParam4,flightDataModel::CONDITION_PARAMS0);
|
2012-06-15 00:06:37 +02:00
|
|
|
|
2012-06-25 20:41:59 +02:00
|
|
|
mapper->addMapping(ui->cbCommand,flightDataModel::COMMAND);
|
|
|
|
mapper->addMapping(ui->sbJump,flightDataModel::JUMPDESTINATION);
|
|
|
|
mapper->addMapping(ui->sbError,flightDataModel::ERRORDESTINATION);
|
|
|
|
connect(itemSelection,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(on_currentRowChanged(QModelIndex,QModelIndex)));
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
|
|
|
void opmap_edit_waypoint_dialog::on_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
ui->lbNumber->setText(QString::number(index));
|
|
|
|
QModelIndex idx=mapper->model()->index(index,0);
|
|
|
|
if(index==itemSelection->currentIndex().row())
|
|
|
|
return;
|
|
|
|
itemSelection->clear();
|
|
|
|
itemSelection->setCurrentIndex(idx,QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
2010-06-29 13:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
opmap_edit_waypoint_dialog::~opmap_edit_waypoint_dialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void opmap_edit_waypoint_dialog::on_pushButtonOK_clicked()
|
|
|
|
{
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2012-06-06 21:51:04 +02:00
|
|
|
void opmap_edit_waypoint_dialog::setupModeWidgets()
|
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
mapDataDelegate::ModeOptions mode=(mapDataDelegate::ModeOptions)ui->cbMode->itemData(ui->cbMode->currentIndex()).toInt();
|
2012-06-06 21:51:04 +02:00
|
|
|
switch(mode)
|
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_FLYENDPOINT:
|
|
|
|
case mapDataDelegate::MODE_FLYVECTOR:
|
|
|
|
case mapDataDelegate::MODE_FLYCIRCLERIGHT:
|
|
|
|
case mapDataDelegate::MODE_FLYCIRCLELEFT:
|
|
|
|
case mapDataDelegate::MODE_DRIVEENDPOINT:
|
|
|
|
case mapDataDelegate::MODE_DRIVEVECTOR:
|
|
|
|
case mapDataDelegate::MODE_DRIVECIRCLELEFT:
|
|
|
|
case mapDataDelegate::MODE_DRIVECIRCLERIGHT:
|
|
|
|
case mapDataDelegate::MODE_DISARMALARM:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->modeParam1->setVisible(false);
|
|
|
|
ui->modeParam2->setVisible(false);
|
|
|
|
ui->modeParam3->setVisible(false);
|
|
|
|
ui->modeParam4->setVisible(false);
|
|
|
|
ui->dsb_modeParam1->setVisible(false);
|
|
|
|
ui->dsb_modeParam2->setVisible(false);
|
|
|
|
ui->dsb_modeParam3->setVisible(false);
|
|
|
|
ui->dsb_modeParam4->setVisible(false);
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_FIXEDATTITUDE:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->modeParam1->setText("pitch");
|
|
|
|
ui->modeParam2->setText("roll");
|
|
|
|
ui->modeParam3->setText("yaw");
|
|
|
|
ui->modeParam4->setText("throttle");
|
|
|
|
ui->modeParam1->setVisible(true);
|
|
|
|
ui->modeParam2->setVisible(true);
|
|
|
|
ui->modeParam3->setVisible(true);
|
|
|
|
ui->modeParam4->setVisible(true);
|
|
|
|
ui->dsb_modeParam1->setVisible(true);
|
|
|
|
ui->dsb_modeParam2->setVisible(true);
|
|
|
|
ui->dsb_modeParam3->setVisible(true);
|
|
|
|
ui->dsb_modeParam4->setVisible(true);
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_SETACCESSORY:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->modeParam1->setText("Acc.channel");
|
|
|
|
ui->modeParam2->setText("Value");
|
|
|
|
ui->modeParam1->setVisible(true);
|
|
|
|
ui->modeParam2->setVisible(true);
|
|
|
|
ui->modeParam3->setVisible(false);
|
|
|
|
ui->modeParam4->setVisible(false);
|
|
|
|
ui->dsb_modeParam1->setVisible(true);
|
|
|
|
ui->dsb_modeParam2->setVisible(true);
|
|
|
|
ui->dsb_modeParam3->setVisible(false);
|
|
|
|
ui->dsb_modeParam4->setVisible(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void opmap_edit_waypoint_dialog::setupConditionWidgets()
|
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
mapDataDelegate::EndConditionOptions mode=(mapDataDelegate::EndConditionOptions)ui->cbCondition->itemData(ui->cbCondition->currentIndex()).toInt();
|
2012-06-06 21:51:04 +02:00
|
|
|
switch(mode)
|
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_NONE:
|
|
|
|
case mapDataDelegate::ENDCONDITION_IMMEDIATE:
|
|
|
|
case mapDataDelegate::ENDCONDITION_PYTHONSCRIPT:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(false);
|
|
|
|
ui->condParam2->setVisible(false);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(false);
|
|
|
|
ui->dsb_condParam2->setVisible(false);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_TIMEOUT:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(true);
|
|
|
|
ui->condParam2->setVisible(false);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(true);
|
|
|
|
ui->dsb_condParam2->setVisible(false);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
ui->condParam1->setText("Timeout(ms)");
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_DISTANCETOTARGET:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(true);
|
|
|
|
ui->condParam2->setVisible(true);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(true);
|
|
|
|
ui->dsb_condParam2->setVisible(true);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
ui->condParam1->setText("Distance(m)");
|
|
|
|
ui->condParam2->setText("Flag(0=2D,1=3D)");//FIXME
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_LEGREMAINING:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(true);
|
|
|
|
ui->condParam2->setVisible(false);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(true);
|
|
|
|
ui->dsb_condParam2->setVisible(false);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
ui->condParam1->setText("Relative Distance(0=complete,1=just starting)");
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_ABOVEALTITUDE:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(true);
|
|
|
|
ui->condParam2->setVisible(false);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(true);
|
|
|
|
ui->dsb_condParam2->setVisible(false);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
ui->condParam1->setText("Altitude in meters (negative)");
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::ENDCONDITION_POINTINGTOWARDSNEXT:
|
2012-06-06 21:51:04 +02:00
|
|
|
ui->condParam1->setVisible(true);
|
|
|
|
ui->condParam2->setVisible(false);
|
|
|
|
ui->condParam3->setVisible(false);
|
|
|
|
ui->condParam4->setVisible(false);
|
|
|
|
ui->dsb_condParam1->setVisible(true);
|
|
|
|
ui->dsb_condParam2->setVisible(false);
|
|
|
|
ui->dsb_condParam3->setVisible(false);
|
|
|
|
ui->dsb_condParam4->setVisible(false);
|
|
|
|
ui->condParam1->setText("Degrees variation allowed");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-29 13:11:35 +02:00
|
|
|
void opmap_edit_waypoint_dialog::on_pushButtonCancel_clicked()
|
|
|
|
{
|
2012-06-06 21:51:04 +02:00
|
|
|
my_waypoint = NULL;
|
2010-06-29 13:11:35 +02:00
|
|
|
close();
|
|
|
|
}
|
2010-07-01 13:00:12 +02:00
|
|
|
|
|
|
|
void opmap_edit_waypoint_dialog::editWaypoint(mapcontrol::WayPointItem *waypoint_item)
|
|
|
|
{
|
|
|
|
if (!waypoint_item) return;
|
|
|
|
show();
|
2012-06-15 00:06:37 +02:00
|
|
|
mapper->setCurrentIndex(waypoint_item->Number());
|
2010-07-01 13:00:12 +02:00
|
|
|
}
|
|
|
|
|
2012-06-15 00:06:37 +02:00
|
|
|
void opmap_edit_waypoint_dialog::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
mapper->toPrevious();
|
|
|
|
}
|
|
|
|
|
|
|
|
void opmap_edit_waypoint_dialog::on_pushButton_2_clicked()
|
|
|
|
{
|
|
|
|
mapper->toNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void opmap_edit_waypoint_dialog::enableEditWidgets(bool value)
|
|
|
|
{
|
|
|
|
QWidget * w;
|
|
|
|
foreach(QWidget * obj,this->findChildren<QWidget *>())
|
|
|
|
{
|
|
|
|
w=qobject_cast<QComboBox*>(obj);
|
|
|
|
if(w)
|
|
|
|
w->setEnabled(!value);
|
|
|
|
w=qobject_cast<QLineEdit*>(obj);
|
|
|
|
if(w)
|
|
|
|
w->setEnabled(!value);
|
|
|
|
w=qobject_cast<QDoubleSpinBox*>(obj);
|
|
|
|
if(w)
|
|
|
|
w->setEnabled(!value);
|
|
|
|
w=qobject_cast<QCheckBox*>(obj);
|
|
|
|
if(w && w!=ui->checkBoxLocked)
|
|
|
|
w->setEnabled(!value);
|
|
|
|
w=qobject_cast<QSpinBox*>(obj);
|
|
|
|
if(w)
|
|
|
|
w->setEnabled(!value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void opmap_edit_waypoint_dialog::on_currentRowChanged(QModelIndex current, QModelIndex previous)
|
|
|
|
{
|
|
|
|
mapper->setCurrentIndex(current.row());
|
|
|
|
}
|