mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
GCS - OPMapLib - data model cleaning
This commit is contained in:
parent
1299bbda93
commit
b8b46e90a3
@ -11,25 +11,39 @@ int flightDataModel::rowCount(const QModelIndex &/*parent*/) const
|
||||
return dataStorage.length();
|
||||
}
|
||||
|
||||
int flightDataModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
int flightDataModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 22;
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return 23;
|
||||
}
|
||||
|
||||
QVariant flightDataModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole||role==Qt::EditRole)
|
||||
{
|
||||
int rowNumber=index.row();
|
||||
int columnNumber=index.column();
|
||||
if(rowNumber>dataStorage.length()-1 || rowNumber<0)
|
||||
return QVariant();
|
||||
pathPlanData * myRow=dataStorage.at(rowNumber);
|
||||
QVariant ret=getColumnByIndex(myRow,columnNumber);
|
||||
return ret;
|
||||
}
|
||||
return QVariant();
|
||||
{
|
||||
int rowNumber=index.row();
|
||||
int columnNumber=index.column();
|
||||
if(rowNumber>dataStorage.length()-1 || rowNumber<0)
|
||||
return QVariant::Invalid;
|
||||
pathPlanData * myRow=dataStorage.at(rowNumber);
|
||||
QVariant ret=getColumnByIndex(myRow,columnNumber);
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
else if (role == Qt::BackgroundRole) {
|
||||
// WaypointActive::DataFields waypointActive = waypointActiveObj->getData();
|
||||
|
||||
if(index.row() == waypointActive.Index) {
|
||||
return QBrush(Qt::lightGray);
|
||||
} else
|
||||
return QVariant::Invalid;
|
||||
}*/
|
||||
else {
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
bool flightDataModel::setColumnByIndex(pathPlanData *row,const int index,const QVariant value)
|
||||
{
|
||||
switch(index)
|
||||
@ -54,6 +68,10 @@ bool flightDataModel::setColumnByIndex(pathPlanData *row,const int index,const
|
||||
row->beaRelative=value.toDouble();
|
||||
return true;
|
||||
break;
|
||||
case ALTITUDERELATIVE:
|
||||
row->altitudeRelative=value.toFloat();
|
||||
return true;
|
||||
break;
|
||||
case ISRELATIVE:
|
||||
row->isRelative=value.toDouble();
|
||||
return true;
|
||||
@ -144,6 +162,9 @@ QVariant flightDataModel::getColumnByIndex(const pathPlanData *row,const int ind
|
||||
case BEARELATIVE:
|
||||
return row->beaRelative;
|
||||
break;
|
||||
case ALTITUDERELATIVE:
|
||||
return row->altitudeRelative;
|
||||
break;
|
||||
case ISRELATIVE:
|
||||
return row->isRelative;
|
||||
break;
|
||||
@ -222,6 +243,9 @@ QVariant flightDataModel::headerData(int section, Qt::Orientation orientation, i
|
||||
case BEARELATIVE:
|
||||
return QString("Bearing from home");
|
||||
break;
|
||||
case ALTITUDERELATIVE:
|
||||
return QString("Altitude above home");
|
||||
break;
|
||||
case ISRELATIVE:
|
||||
return QString("Relative to home");
|
||||
break;
|
||||
@ -279,13 +303,13 @@ QVariant flightDataModel::headerData(int section, Qt::Orientation orientation, i
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
else
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
bool flightDataModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (role == Qt::EditRole)
|
||||
{
|
||||
//save value from editor to member m_gridData
|
||||
int columnIndex=index.column();
|
||||
int rowIndex=index.row();
|
||||
if(rowIndex>dataStorage.length()-1)
|
||||
@ -293,7 +317,6 @@ bool flightDataModel::setData(const QModelIndex &index, const QVariant &value, i
|
||||
pathPlanData * myRow=dataStorage.at(rowIndex);
|
||||
setColumnByIndex(myRow,columnIndex,value);
|
||||
emit dataChanged(index,index);
|
||||
//for presentation purposes only: build and emit a joined string
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -314,6 +337,7 @@ bool flightDataModel::insertRows(int row, int count, const QModelIndex &/*parent
|
||||
data->lngPosition=0;
|
||||
data->disRelative=0;
|
||||
data->beaRelative=0;
|
||||
data->altitudeRelative=0;
|
||||
data->isRelative=0;
|
||||
data->altitude=0;
|
||||
data->velocity=0;
|
||||
@ -392,6 +416,11 @@ bool flightDataModel::writeToFile(QString fileName)
|
||||
field.setAttribute("name","bearing_from_home");
|
||||
waypoint.appendChild(field);
|
||||
|
||||
field=doc.createElement("field");
|
||||
field.setAttribute("value",obj->altitudeRelative);
|
||||
field.setAttribute("name","altitude_above_home");
|
||||
waypoint.appendChild(field);
|
||||
|
||||
field=doc.createElement("field");
|
||||
field.setAttribute("value",obj->isRelative);
|
||||
field.setAttribute("name","is_relative_to_home");
|
||||
@ -534,6 +563,8 @@ void flightDataModel::readFromFile(QString fileName)
|
||||
data->disRelative=field.attribute("value").toDouble();
|
||||
else if(field.attribute("name")=="bearing_from_home")
|
||||
data->beaRelative=field.attribute("value").toDouble();
|
||||
else if(field.attribute("name")=="altitude_above_home")
|
||||
data->altitudeRelative=field.attribute("value").toFloat();
|
||||
else if(field.attribute("name")=="is_relative_to_home")
|
||||
data->isRelative=field.attribute("value").toInt();
|
||||
else if(field.attribute("name")=="altitude")
|
||||
|
@ -10,6 +10,7 @@ struct pathPlanData
|
||||
double lngPosition;
|
||||
double disRelative;
|
||||
double beaRelative;
|
||||
double altitudeRelative;
|
||||
bool isRelative;
|
||||
double altitude;
|
||||
float velocity;
|
||||
@ -29,7 +30,7 @@ class flightDataModel:public QAbstractTableModel
|
||||
public:
|
||||
enum pathPlanDataEnum
|
||||
{
|
||||
WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ISRELATIVE,ALTITUDE,
|
||||
WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ALTITUDERELATIVE,ISRELATIVE,ALTITUDE,
|
||||
VELOCITY,MODE,MODE_PARAMS0,MODE_PARAMS1,MODE_PARAMS2,MODE_PARAMS3,
|
||||
CONDITION,CONDITION_PARAMS0,CONDITION_PARAMS1,CONDITION_PARAMS2,CONDITION_PARAMS3,
|
||||
COMMAND,JUMPDESTINATION,ERRORDESTINATION,LOCKED
|
||||
|
@ -59,6 +59,8 @@ void modelMapProxy::on_WPValuesChanged(WayPointItem * wp)
|
||||
model->setData(index,wp->getRelativeCoord().distance,Qt::EditRole);
|
||||
index=model->index(wp->Number(),flightDataModel::BEARELATIVE);
|
||||
model->setData(index,wp->getRelativeCoord().bearingToDegrees(),Qt::EditRole);
|
||||
index=model->index(wp->Number(),flightDataModel::ALTITUDERELATIVE);
|
||||
model->setData(index,wp->getRelativeCoord().altitudeRelative,Qt::EditRole);
|
||||
}
|
||||
|
||||
void modelMapProxy::on_currentRowChanged(QModelIndex current, QModelIndex previous)
|
||||
@ -125,20 +127,8 @@ void modelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to, modelMap
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
typedef enum { MODE_FLYENDPOINT=0, MODE_FLYVECTOR=1, MODE_FLYCIRCLERIGHT=2, MODE_FLYCIRCLELEFT=3,
|
||||
MODE_DRIVEENDPOINT=4, MODE_DRIVEVECTOR=5, MODE_DRIVECIRCLELEFT=6, MODE_DRIVECIRCLERIGHT=7,
|
||||
MODE_FIXEDATTITUDE=8, MODE_SETACCESSORY=9, MODE_DISARMALARM=10 } ModeOptions;
|
||||
typedef enum { ENDCONDITION_NONE=0, ENDCONDITION_TIMEOUT=1, ENDCONDITION_DISTANCETOTARGET=2,
|
||||
ENDCONDITION_LEGREMAINING=3, ENDCONDITION_ABOVEALTITUDE=4, ENDCONDITION_POINTINGTOWARDSNEXT=5,
|
||||
ENDCONDITION_PYTHONSCRIPT=6, ENDCONDITION_IMMEDIATE=7 } EndConditionOptions;
|
||||
typedef enum { COMMAND_ONCONDITIONNEXTWAYPOINT=0, COMMAND_ONNOTCONDITIONNEXTWAYPOINT=1,
|
||||
COMMAND_ONCONDITIONJUMPWAYPOINT=2, COMMAND_ONNOTCONDITIONJUMPWAYPOINT=3,
|
||||
COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT=4 } CommandOptions;
|
||||
*/
|
||||
void modelMapProxy::refreshOverlays()
|
||||
{
|
||||
qDebug()<<"REFRESH OVERLAYS START";
|
||||
myMap->deleteAllOverlays();
|
||||
WayPointItem * wp_current=NULL;
|
||||
WayPointItem * wp_next=NULL;
|
||||
@ -149,7 +139,6 @@ void modelMapProxy::refreshOverlays()
|
||||
overlayType wp_error_overlay;
|
||||
for(int x=0;x<model->rowCount();++x)
|
||||
{
|
||||
qDebug()<<"REFRESH OVERLAYS WP:"<<x;
|
||||
wp_current=findWayPointNumber(x);
|
||||
wp_jump=model->data(model->index(x,flightDataModel::JUMPDESTINATION)).toInt();
|
||||
wp_error=model->data(model->index(x,flightDataModel::ERRORDESTINATION)).toInt();
|
||||
@ -162,50 +151,35 @@ void modelMapProxy::refreshOverlays()
|
||||
case ComboBoxDelegate::COMMAND_ONCONDITIONNEXTWAYPOINT:
|
||||
wp_next=findWayPointNumber(x+1);
|
||||
createOverlay(wp_current,wp_next,wp_next_overlay,Qt::green);
|
||||
qDebug()<<"REFRESH OVERLAYS"<<"AKI0";
|
||||
break;
|
||||
case ComboBoxDelegate::COMMAND_ONCONDITIONJUMPWAYPOINT:
|
||||
wp_next=findWayPointNumber(wp_jump);
|
||||
createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::green);
|
||||
qDebug()<<"REFRESH OVERLAYS"<<"AKI1";
|
||||
break;
|
||||
case ComboBoxDelegate::COMMAND_ONNOTCONDITIONJUMPWAYPOINT:
|
||||
wp_next=findWayPointNumber(wp_jump);
|
||||
createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::yellow);
|
||||
qDebug()<<"REFRESH OVERLAYS"<<"AKI2";
|
||||
break;
|
||||
case ComboBoxDelegate::COMMAND_ONNOTCONDITIONNEXTWAYPOINT:
|
||||
wp_next=findWayPointNumber(x+1);
|
||||
createOverlay(wp_current,wp_next,wp_next_overlay,Qt::yellow);
|
||||
qDebug()<<"REFRESH OVERLAYS"<<"AKI3";
|
||||
break;
|
||||
case ComboBoxDelegate::COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT:
|
||||
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);
|
||||
qDebug()<<"REFRESH OVERLAYS"<<"AKI4";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
WayPointItem * modelMapProxy::findWayPointNumber(int number)
|
||||
{
|
||||
if(number<0)
|
||||
return NULL;
|
||||
return myMap->WPFind(number);
|
||||
}
|
||||
/*
|
||||
WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ISRELATIVE,ALTITUDE,
|
||||
VELOCITY,MODE,MODE_PARAMS0,MODE_PARAMS1,MODE_PARAMS2,MODE_PARAMS3,
|
||||
CONDITION,CONDITION_PARAMS0,CONDITION_PARAMS1,CONDITION_PARAMS2,CONDITION_PARAMS3,
|
||||
COMMAND,JUMPDESTINATION,ERRORDESTINATION
|
||||
*/
|
||||
|
||||
|
||||
void modelMapProxy::on_rowsRemoved(const QModelIndex &parent, int first, int last)
|
||||
{
|
||||
@ -225,7 +199,7 @@ void modelMapProxy::on_dataChanged(const QModelIndex &topLeft, const QModelIndex
|
||||
return;
|
||||
internals::PointLatLng latlng;
|
||||
int x=topLeft.row();
|
||||
distBearing distBearing;
|
||||
distBearingAltitude distBearing;
|
||||
double altitude;
|
||||
bool relative;
|
||||
QModelIndex index;
|
||||
@ -266,7 +240,11 @@ void modelMapProxy::on_dataChanged(const QModelIndex &topLeft, const QModelIndex
|
||||
index=model->index(x,flightDataModel::DISRELATIVE);
|
||||
distBearing.distance=index.data(Qt::DisplayRole).toDouble();
|
||||
break;
|
||||
|
||||
case flightDataModel::ALTITUDERELATIVE:
|
||||
distBearing=item->getRelativeCoord();
|
||||
index=model->index(x,flightDataModel::ALTITUDERELATIVE);
|
||||
distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat();
|
||||
break;
|
||||
case flightDataModel::ISRELATIVE:
|
||||
index=model->index(x,flightDataModel::ISRELATIVE);
|
||||
relative=index.data(Qt::DisplayRole).toBool();
|
||||
@ -293,7 +271,7 @@ void modelMapProxy::on_rowsInserted(const QModelIndex &parent, int first, int la
|
||||
QModelIndex index;
|
||||
WayPointItem * item;
|
||||
internals::PointLatLng latlng;
|
||||
distBearing distBearing;
|
||||
distBearingAltitude distBearing;
|
||||
double altitude;
|
||||
bool relative;
|
||||
index=model->index(x,flightDataModel::WPDESCRITPTION);
|
||||
@ -306,14 +284,16 @@ void modelMapProxy::on_rowsInserted(const QModelIndex &parent, int first, int la
|
||||
distBearing.distance=index.data(Qt::DisplayRole).toDouble();
|
||||
index=model->index(x,flightDataModel::BEARELATIVE);
|
||||
distBearing.setBearingFromDegrees(index.data(Qt::DisplayRole).toDouble());
|
||||
index=model->index(x,flightDataModel::ALTITUDERELATIVE);
|
||||
distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat();
|
||||
index=model->index(x,flightDataModel::ISRELATIVE);
|
||||
relative=index.data(Qt::DisplayRole).toBool();
|
||||
index=model->index(x,flightDataModel::ALTITUDE);
|
||||
altitude=index.data(Qt::DisplayRole).toDouble();
|
||||
item=myMap->WPInsert(latlng,altitude,desc,x);
|
||||
item->setRelativeCoord(distBearing);
|
||||
if(relative)
|
||||
item->setWPType(mapcontrol::WayPointItem::relative);
|
||||
item=myMap->WPInsert(distBearing,desc,x);
|
||||
else
|
||||
item=myMap->WPInsert(latlng,altitude,desc,x);
|
||||
}
|
||||
refreshOverlays();
|
||||
}
|
||||
|
@ -1,4 +1,87 @@
|
||||
#include "modeluavoproxy.h"
|
||||
modelUavoProxy::modelUavoProxy(QObject *parent,flightDataModel * model)
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
|
||||
modelUavoProxy::modelUavoProxy(QObject *parent,flightDataModel * model):QObject(parent),myModel(model)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
Q_ASSERT(pm != NULL);
|
||||
objManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(objManager != NULL);
|
||||
waypointObj = Waypoint::GetInstance(objManager);
|
||||
Q_ASSERT(waypointObj != NULL);
|
||||
pathactionObj=PathAction::GetInstance(objManager);
|
||||
Q_ASSERT(pathactionObj != NULL);
|
||||
}
|
||||
/*WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ISRELATIVE,ALTITUDE,
|
||||
VELOCITY,MODE,MODE_PARAMS0,MODE_PARAMS1,MODE_PARAMS2,MODE_PARAMS3,
|
||||
CONDITION,CONDITION_PARAMS0,CONDITION_PARAMS1,CONDITION_PARAMS2,CONDITION_PARAMS3,
|
||||
COMMAND,JUMPDESTINATION,ERRORDESTINATION,LOCKED
|
||||
*/
|
||||
void modelUavoProxy::modelToObjects()
|
||||
{
|
||||
PathAction * act;
|
||||
act=new PathAction;
|
||||
Waypoint * wp;
|
||||
wp=new Waypoint;
|
||||
Q_ASSERT(act);
|
||||
Q_ASSERT(wp);
|
||||
Waypoint::DataFields waypoint = wp->getData();
|
||||
PathAction::DataFields action = act->getData();
|
||||
QModelIndex index;
|
||||
double distance;
|
||||
double bearing;
|
||||
double altitude;
|
||||
float velocity;
|
||||
int mode;
|
||||
int mode_param[4];
|
||||
int condition;
|
||||
int cond_param[4];
|
||||
int command;
|
||||
int jump;
|
||||
int error;
|
||||
for(int x=0;x<myModel->rowCount();++x)
|
||||
{
|
||||
index=myModel->index(x,flightDataModel::DISRELATIVE);
|
||||
distance=myModel->data(index).toDouble();
|
||||
index=myModel->index(x,flightDataModel::BEARELATIVE);
|
||||
bearing=myModel->data(index).toDouble();
|
||||
index=myModel->index(x,flightDataModel::VELOCITY);
|
||||
velocity=myModel->data(index).toFloat();
|
||||
|
||||
|
||||
index=myModel->index(x,flightDataModel::MODE);
|
||||
mode=myModel->data(index).toInt();
|
||||
index=myModel->index(x,flightDataModel::MODE_PARAMS0);
|
||||
mode_param[0]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::MODE_PARAMS1);
|
||||
mode_param[1]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::MODE_PARAMS2);
|
||||
mode_param[2]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::MODE_PARAMS3);
|
||||
mode_param[3]=myModel->data(index).toFloat();
|
||||
|
||||
index=myModel->index(x,flightDataModel::CONDITION);
|
||||
condition=myModel->data(index).toInt();
|
||||
index=myModel->index(x,flightDataModel::CONDITION_PARAMS0);
|
||||
cond_param[0]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::CONDITION_PARAMS1);
|
||||
cond_param[1]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::CONDITION_PARAMS2);
|
||||
cond_param[2]=myModel->data(index).toFloat();
|
||||
index=myModel->index(x,flightDataModel::CONDITION_PARAMS3);
|
||||
cond_param[3]=myModel->data(index).toFloat();
|
||||
|
||||
index=myModel->index(x,flightDataModel::COMMAND);
|
||||
command=myModel->data(index).toInt();
|
||||
index=myModel->index(x,flightDataModel::JUMPDESTINATION);
|
||||
jump=myModel->data(index).toInt();
|
||||
index=myModel->index(x,flightDataModel::ERRORDESTINATION);
|
||||
error=myModel->data(index).toInt();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void modelUavoProxy::objectsToModel()
|
||||
{
|
||||
}
|
||||
|
@ -14,7 +14,11 @@ public:
|
||||
public slots:
|
||||
void modelToObjects();
|
||||
void objectsToModel();
|
||||
|
||||
private:
|
||||
UAVObjectManager *objManager;
|
||||
Waypoint * waypointObj;
|
||||
PathAction * pathactionObj;
|
||||
flightDataModel * myModel;
|
||||
};
|
||||
|
||||
#endif // MODELUAVOPROXY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user