2012-06-15 00:06:37 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2012-06-25 20:41:59 +02:00
|
|
|
* @file modelmapproxy.cpp
|
2012-06-15 00:06:37 +02:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup OPMapPlugin OpenPilot Map Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The OpenPilot Map plugin
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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 "modelmapproxy.h"
|
|
|
|
|
|
|
|
modelMapProxy::modelMapProxy(QObject *parent,OPMapWidget *map,flightDataModel * model,QItemSelectionModel * selectionModel):QObject(parent),myMap(map),model(model),selection(selectionModel)
|
|
|
|
{
|
2012-06-25 22:11:07 +02:00
|
|
|
connect(model,SIGNAL(rowsInserted(const QModelIndex&,int,int)),this,SLOT(rowsInserted(const QModelIndex&,int,int)));
|
|
|
|
connect(model,SIGNAL(rowsRemoved(const QModelIndex&,int,int)),this,SLOT(rowsRemoved(const QModelIndex&,int,int)));
|
|
|
|
connect(selection,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(currentRowChanged(QModelIndex,QModelIndex)));
|
|
|
|
connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChanged(QModelIndex,QModelIndex)));
|
|
|
|
connect(myMap,SIGNAL(selectedWPChanged(QList<WayPointItem*>)),this,SLOT(selectedWPChanged(QList<WayPointItem*>)));
|
|
|
|
connect(myMap,SIGNAL(WPValuesChanged(WayPointItem*)),this,SLOT(WPValuesChanged(WayPointItem*)));
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::WPValuesChanged(WayPointItem * wp)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
QModelIndex index;
|
|
|
|
index=model->index(wp->Number(),flightDataModel::LATPOSITION);
|
|
|
|
if(!index.isValid())
|
|
|
|
return;
|
|
|
|
model->setData(index,wp->Coord().Lat(),Qt::EditRole);
|
|
|
|
index=model->index(wp->Number(),flightDataModel::LNGPOSITION);
|
|
|
|
model->setData(index,wp->Coord().Lng(),Qt::EditRole);
|
2012-06-27 01:25:40 +02:00
|
|
|
|
|
|
|
index=model->index(wp->Number(),flightDataModel::ALTITUDE);
|
|
|
|
model->setData(index,wp->Altitude(),Qt::EditRole);
|
|
|
|
|
2012-06-15 00:06:37 +02:00
|
|
|
index=model->index(wp->Number(),flightDataModel::DISRELATIVE);
|
|
|
|
model->setData(index,wp->getRelativeCoord().distance,Qt::EditRole);
|
|
|
|
index=model->index(wp->Number(),flightDataModel::BEARELATIVE);
|
|
|
|
model->setData(index,wp->getRelativeCoord().bearingToDegrees(),Qt::EditRole);
|
2012-06-20 16:00:15 +02:00
|
|
|
index=model->index(wp->Number(),flightDataModel::ALTITUDERELATIVE);
|
|
|
|
model->setData(index,wp->getRelativeCoord().altitudeRelative,Qt::EditRole);
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::currentRowChanged(QModelIndex current, QModelIndex previous)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
QList<WayPointItem*> list;
|
|
|
|
WayPointItem * wp=findWayPointNumber(current.row());
|
|
|
|
if(!wp)
|
|
|
|
return;
|
|
|
|
list.append(wp);
|
|
|
|
myMap->setSelectedWP(list);
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::selectedWPChanged(QList<WayPointItem *> list)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
selection->clearSelection();
|
|
|
|
foreach(WayPointItem * wp,list)
|
|
|
|
{
|
|
|
|
QModelIndex index=model->index(wp->Number(),0);
|
|
|
|
selection->setCurrentIndex(index,QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
|
|
}
|
|
|
|
}
|
2012-06-17 20:24:02 +02:00
|
|
|
|
|
|
|
modelMapProxy::overlayType modelMapProxy::overlayTranslate(int type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_FLYENDPOINT:
|
|
|
|
case mapDataDelegate::MODE_FLYVECTOR:
|
|
|
|
case mapDataDelegate::MODE_DRIVEENDPOINT:
|
|
|
|
case mapDataDelegate::MODE_DRIVEVECTOR:
|
2012-06-17 20:24:02 +02:00
|
|
|
return OVERLAY_LINE;
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_FLYCIRCLERIGHT:
|
|
|
|
case mapDataDelegate::MODE_DRIVECIRCLERIGHT:
|
2012-06-17 20:24:02 +02:00
|
|
|
return OVERLAY_CIRCLE_RIGHT;
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::MODE_FLYCIRCLELEFT:
|
|
|
|
case mapDataDelegate::MODE_DRIVECIRCLELEFT:
|
2012-06-17 20:24:02 +02:00
|
|
|
return OVERLAY_CIRCLE_LEFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void modelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to, modelMapProxy::overlayType type,QColor color)
|
|
|
|
{
|
|
|
|
if(from==NULL || to==NULL || from==to)
|
|
|
|
return;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case OVERLAY_LINE:
|
|
|
|
myMap->WPLineCreate(from,to,color);
|
|
|
|
break;
|
|
|
|
case OVERLAY_CIRCLE_RIGHT:
|
|
|
|
myMap->WPCircleCreate(to,from,true,color);
|
|
|
|
break;
|
|
|
|
case OVERLAY_CIRCLE_LEFT:
|
|
|
|
myMap->WPCircleCreate(to,from,false,color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-06-24 21:02:45 +02:00
|
|
|
void modelMapProxy::createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type,QColor color)
|
|
|
|
{
|
|
|
|
if(from==NULL || to==NULL)
|
|
|
|
return;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case OVERLAY_LINE:
|
|
|
|
myMap->WPLineCreate(to,from,color);
|
|
|
|
break;
|
|
|
|
case OVERLAY_CIRCLE_RIGHT:
|
|
|
|
myMap->WPCircleCreate(to,from,true,color);
|
|
|
|
break;
|
|
|
|
case OVERLAY_CIRCLE_LEFT:
|
|
|
|
myMap->WPCircleCreate(to,from,false,color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-06-17 20:24:02 +02:00
|
|
|
|
2012-06-24 21:02:45 +02:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 00:06:37 +02:00
|
|
|
void modelMapProxy::refreshOverlays()
|
|
|
|
{
|
|
|
|
myMap->deleteAllOverlays();
|
2012-06-24 21:02:45 +02:00
|
|
|
if(model->rowCount()<1)
|
|
|
|
return;
|
2012-06-17 20:24:02 +02:00
|
|
|
WayPointItem * wp_current=NULL;
|
|
|
|
WayPointItem * wp_next=NULL;
|
|
|
|
int wp_jump;
|
|
|
|
int wp_error;
|
|
|
|
overlayType wp_next_overlay;
|
|
|
|
overlayType wp_jump_overlay;
|
|
|
|
overlayType wp_error_overlay;
|
2012-06-24 21:02:45 +02:00
|
|
|
wp_current=findWayPointNumber(0);
|
|
|
|
overlayType wp_current_overlay=overlayTranslate(model->data(model->index(0,flightDataModel::MODE)).toInt());
|
|
|
|
createOverlay(wp_current,myMap->Home,wp_current_overlay,Qt::green);
|
2012-06-17 20:24:02 +02:00
|
|
|
for(int x=0;x<model->rowCount();++x)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_current=findWayPointNumber(x);
|
|
|
|
wp_jump=model->data(model->index(x,flightDataModel::JUMPDESTINATION)).toInt();
|
|
|
|
wp_error=model->data(model->index(x,flightDataModel::ERRORDESTINATION)).toInt();
|
|
|
|
wp_next_overlay=overlayTranslate(model->data(model->index(x+1,flightDataModel::MODE)).toInt());
|
2012-06-24 21:02:45 +02:00
|
|
|
wp_jump_overlay=overlayTranslate(model->data(model->index(wp_jump,flightDataModel::MODE)).toInt());
|
|
|
|
wp_error_overlay=overlayTranslate(model->data(model->index(wp_error,flightDataModel::MODE)).toInt());
|
|
|
|
createOverlay(wp_current,findWayPointNumber(wp_error),wp_error_overlay,Qt::red);
|
2012-06-17 20:24:02 +02:00
|
|
|
switch(model->data(model->index(x,flightDataModel::COMMAND)).toInt())
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::COMMAND_ONCONDITIONNEXTWAYPOINT:
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_next=findWayPointNumber(x+1);
|
|
|
|
createOverlay(wp_current,wp_next,wp_next_overlay,Qt::green);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::COMMAND_ONCONDITIONJUMPWAYPOINT:
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_next=findWayPointNumber(wp_jump);
|
|
|
|
createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::green);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::COMMAND_ONNOTCONDITIONJUMPWAYPOINT:
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_next=findWayPointNumber(wp_jump);
|
|
|
|
createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::yellow);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::COMMAND_ONNOTCONDITIONNEXTWAYPOINT:
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_next=findWayPointNumber(x+1);
|
|
|
|
createOverlay(wp_current,wp_next,wp_next_overlay,Qt::yellow);
|
|
|
|
break;
|
2012-06-25 20:41:59 +02:00
|
|
|
case mapDataDelegate::COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT:
|
2012-06-17 20:24:02 +02:00
|
|
|
wp_next=findWayPointNumber(wp_jump);
|
|
|
|
createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::green);
|
|
|
|
wp_next=findWayPointNumber(x+1);
|
|
|
|
createOverlay(wp_current,wp_next,wp_next_overlay,Qt::green);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WayPointItem * modelMapProxy::findWayPointNumber(int number)
|
|
|
|
{
|
|
|
|
if(number<0)
|
|
|
|
return NULL;
|
|
|
|
return myMap->WPFind(number);
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::rowsRemoved(const QModelIndex &parent, int first, int last)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
for(int x=last;x>first-1;x--)
|
|
|
|
{
|
|
|
|
myMap->WPDelete(x);
|
|
|
|
}
|
2012-06-17 20:24:02 +02:00
|
|
|
refreshOverlays();
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
WayPointItem * item=findWayPointNumber(topLeft.row());
|
|
|
|
if(!item)
|
|
|
|
return;
|
|
|
|
internals::PointLatLng latlng;
|
|
|
|
int x=topLeft.row();
|
2012-06-20 16:00:15 +02:00
|
|
|
distBearingAltitude distBearing;
|
2012-06-15 00:06:37 +02:00
|
|
|
double altitude;
|
|
|
|
bool relative;
|
|
|
|
QModelIndex index;
|
|
|
|
QString desc;
|
|
|
|
switch(topLeft.column())
|
|
|
|
{
|
2012-06-17 20:24:02 +02:00
|
|
|
case flightDataModel::COMMAND:
|
|
|
|
case flightDataModel::CONDITION:
|
|
|
|
case flightDataModel::JUMPDESTINATION:
|
|
|
|
case flightDataModel::ERRORDESTINATION:
|
|
|
|
case flightDataModel::MODE:
|
|
|
|
refreshOverlays();
|
|
|
|
break;
|
2012-06-15 00:06:37 +02:00
|
|
|
case flightDataModel::WPDESCRITPTION:
|
|
|
|
index=model->index(x,flightDataModel::WPDESCRITPTION);
|
|
|
|
desc=index.data(Qt::DisplayRole).toString();
|
|
|
|
item->SetDescription(desc);
|
|
|
|
break;
|
|
|
|
case flightDataModel::LATPOSITION:
|
|
|
|
latlng=item->Coord();
|
|
|
|
index=model->index(x,flightDataModel::LATPOSITION);
|
|
|
|
latlng.SetLat(index.data(Qt::DisplayRole).toDouble());
|
|
|
|
item->SetCoord(latlng);
|
|
|
|
break;
|
|
|
|
case flightDataModel::LNGPOSITION:
|
|
|
|
latlng=item->Coord();
|
|
|
|
index=model->index(x,flightDataModel::LNGPOSITION);
|
|
|
|
latlng.SetLng(index.data(Qt::DisplayRole).toDouble());
|
|
|
|
item->SetCoord(latlng);
|
|
|
|
break;
|
|
|
|
case flightDataModel::BEARELATIVE:
|
|
|
|
distBearing=item->getRelativeCoord();
|
|
|
|
index=model->index(x,flightDataModel::BEARELATIVE);
|
|
|
|
distBearing.setBearingFromDegrees(index.data(Qt::DisplayRole).toDouble());
|
2012-06-24 21:02:45 +02:00
|
|
|
item->setRelativeCoord(distBearing);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
|
|
|
case flightDataModel::DISRELATIVE:
|
|
|
|
distBearing=item->getRelativeCoord();
|
|
|
|
index=model->index(x,flightDataModel::DISRELATIVE);
|
|
|
|
distBearing.distance=index.data(Qt::DisplayRole).toDouble();
|
2012-06-24 21:02:45 +02:00
|
|
|
item->setRelativeCoord(distBearing);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
2012-06-20 16:00:15 +02:00
|
|
|
case flightDataModel::ALTITUDERELATIVE:
|
|
|
|
distBearing=item->getRelativeCoord();
|
|
|
|
index=model->index(x,flightDataModel::ALTITUDERELATIVE);
|
|
|
|
distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat();
|
2012-06-24 21:02:45 +02:00
|
|
|
item->setRelativeCoord(distBearing);
|
2012-06-20 16:00:15 +02:00
|
|
|
break;
|
2012-06-15 00:06:37 +02:00
|
|
|
case flightDataModel::ISRELATIVE:
|
|
|
|
index=model->index(x,flightDataModel::ISRELATIVE);
|
|
|
|
relative=index.data(Qt::DisplayRole).toBool();
|
|
|
|
if(relative)
|
|
|
|
item->setWPType(mapcontrol::WayPointItem::relative);
|
2012-06-24 21:02:45 +02:00
|
|
|
else
|
|
|
|
item->setWPType(mapcontrol::WayPointItem::absolute);
|
2012-06-15 00:06:37 +02:00
|
|
|
break;
|
|
|
|
case flightDataModel::ALTITUDE:
|
|
|
|
index=model->index(x,flightDataModel::ALTITUDE);
|
|
|
|
altitude=index.data(Qt::DisplayRole).toDouble();
|
|
|
|
item->SetAltitude(altitude);
|
|
|
|
break;
|
|
|
|
case flightDataModel::LOCKED:
|
|
|
|
index=model->index(x,flightDataModel::LOCKED);
|
|
|
|
item->setFlag(QGraphicsItem::ItemIsMovable,!index.data(Qt::DisplayRole).toBool());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:11:07 +02:00
|
|
|
void modelMapProxy::rowsInserted(const QModelIndex &parent, int first, int last)
|
2012-06-15 00:06:37 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
for(int x=first;x<last+1;x++)
|
|
|
|
{
|
|
|
|
QModelIndex index;
|
|
|
|
WayPointItem * item;
|
|
|
|
internals::PointLatLng latlng;
|
2012-06-20 16:00:15 +02:00
|
|
|
distBearingAltitude distBearing;
|
2012-06-15 00:06:37 +02:00
|
|
|
double altitude;
|
|
|
|
bool relative;
|
|
|
|
index=model->index(x,flightDataModel::WPDESCRITPTION);
|
|
|
|
QString desc=index.data(Qt::DisplayRole).toString();
|
|
|
|
index=model->index(x,flightDataModel::LATPOSITION);
|
|
|
|
latlng.SetLat(index.data(Qt::DisplayRole).toDouble());
|
|
|
|
index=model->index(x,flightDataModel::LNGPOSITION);
|
|
|
|
latlng.SetLng(index.data(Qt::DisplayRole).toDouble());
|
|
|
|
index=model->index(x,flightDataModel::DISRELATIVE);
|
|
|
|
distBearing.distance=index.data(Qt::DisplayRole).toDouble();
|
|
|
|
index=model->index(x,flightDataModel::BEARELATIVE);
|
|
|
|
distBearing.setBearingFromDegrees(index.data(Qt::DisplayRole).toDouble());
|
2012-06-20 16:00:15 +02:00
|
|
|
index=model->index(x,flightDataModel::ALTITUDERELATIVE);
|
|
|
|
distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat();
|
2012-06-15 00:06:37 +02:00
|
|
|
index=model->index(x,flightDataModel::ISRELATIVE);
|
|
|
|
relative=index.data(Qt::DisplayRole).toBool();
|
|
|
|
index=model->index(x,flightDataModel::ALTITUDE);
|
|
|
|
altitude=index.data(Qt::DisplayRole).toDouble();
|
|
|
|
if(relative)
|
2012-06-20 16:00:15 +02:00
|
|
|
item=myMap->WPInsert(distBearing,desc,x);
|
|
|
|
else
|
|
|
|
item=myMap->WPInsert(latlng,altitude,desc,x);
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
2012-06-17 20:24:02 +02:00
|
|
|
refreshOverlays();
|
2012-06-15 00:06:37 +02:00
|
|
|
}
|
|
|
|
void modelMapProxy::deleteWayPoint(int number)
|
|
|
|
{
|
|
|
|
model->removeRow(number,QModelIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void modelMapProxy::createWayPoint(internals::PointLatLng coord)
|
|
|
|
{
|
|
|
|
model->insertRow(model->rowCount(),QModelIndex());
|
|
|
|
QModelIndex index=model->index(model->rowCount()-1,flightDataModel::LATPOSITION,QModelIndex());
|
|
|
|
model->setData(index,coord.Lat(),Qt::EditRole);
|
|
|
|
index=model->index(model->rowCount()-1,flightDataModel::LNGPOSITION,QModelIndex());
|
|
|
|
model->setData(index,coord.Lng(),Qt::EditRole);
|
|
|
|
}
|
|
|
|
void modelMapProxy::deleteAll()
|
|
|
|
{
|
|
|
|
model->removeRows(0,model->rowCount(),QModelIndex());
|
|
|
|
}
|