1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Fix for pathcompiler and waypoint table regarding signals and new instances

This commit is contained in:
James Cotton 2012-06-05 00:53:22 -05:00
parent 0b828fbdd0
commit ff36e880e9
4 changed files with 64 additions and 13 deletions

View File

@ -36,19 +36,25 @@
PathCompiler::PathCompiler(QObject *parent) :
QObject(parent)
{
Waypoint *waypoint = NULL;
HomeLocation *homeLocation = NULL;
/* To catch new waypoint UAVOs */
connect(getObjectManager(), SIGNAL(newInstance(UAVObject*)), this, SLOT(doNewInstance(UAVObject*)));
/* Connect the object updates */
waypoint = Waypoint::GetInstance(getObjectManager());
Q_ASSERT(waypoint);
if(waypoint)
connect(waypoint, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV()));
int numWaypoints = getObjectManager()->getNumInstances(Waypoint::OBJID);
for (int i = 0; i < numWaypoints; i++) {
qDebug() << "Registering waypoint" << i;
Waypoint *waypoint = Waypoint::GetInstance(getObjectManager(), i);
Q_ASSERT(waypoint);
if(waypoint)
connect(waypoint, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV(UAVObject*)));
}
homeLocation = HomeLocation::GetInstance(getObjectManager());
Q_ASSERT(homeLocation);
if(homeLocation)
connect(homeLocation, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV()));
connect(homeLocation, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(doUpdateFromUAV(UAVObject*)));
}
/**
@ -90,6 +96,21 @@ int PathCompiler::loadPath(QString filename)
return -1;
}
/**
* Called whenever a new object instance is created so we can check
* if it's a waypoint and if so connect to it
* @param [in] obj The point to the object being created
*/
void PathCompiler::doNewInstance(UAVObject* obj)
{
Q_ASSERT(obj);
if (!obj)
return;
if (obj->getObjID() == Waypoint::OBJID)
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this,SLOT(doUpdateFromUAV(UAVObject*)));
}
/**
* add a waypoint
* @param waypoint the new waypoint to add
@ -226,12 +247,16 @@ void PathCompiler::doDelAllWaypoints()
* When the UAV waypoints change trigger the pathcompiler to
* get the latest version and then update the visualization
*/
void PathCompiler::doUpdateFromUAV()
void PathCompiler::doUpdateFromUAV(UAVObject *obj)
{
UAVObjectManager *objManager = getObjectManager();
if (!objManager)
return;
if(obj) {
qDebug() << "Update:" << obj->getInstID();
}
Waypoint *waypointObj = Waypoint::GetInstance(getObjectManager());
Q_ASSERT(waypointObj);
if (waypointObj == NULL)

View File

@ -96,6 +96,11 @@ public slots:
* into the view.
*/
/**
* Called when new instances are registered
*/
void doNewInstance(UAVObject*);
/**
* add a waypoint
* @param waypoint the new waypoint to add
@ -128,7 +133,7 @@ public slots:
* When the UAV waypoints change trigger the pathcompiler to
* get the latest version and then update the visualization
*/
void doUpdateFromUAV();
void doUpdateFromUAV(UAVObject *);
};
#endif // PATHCOMPILER_H

View File

@ -45,9 +45,18 @@ WaypointTable::WaypointTable(QObject *parent) :
// Unfortunately there is no per object new instance signal yet
connect(objManager, SIGNAL(newInstance(UAVObject*)),
this, SLOT(waypointsUpdated(UAVObject*)));
this, SLOT(doNewInstance(UAVObject*)));
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointsUpdated(UAVObject*)));
int numWaypoints = objManager->getNumInstances(Waypoint::OBJID);
for (int i = 0; i < numWaypoints; i++) {
Waypoint *waypoint = Waypoint::GetInstance(objManager, i);
Q_ASSERT(waypoint);
if(waypoint)
connect(waypoint, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(waypointsUpdated(UAVObject*)));
}
connect(waypointObj, SIGNAL(),
this, SLOT(waypointsUpdated(UAVObject*)));
@ -112,6 +121,20 @@ QVariant WaypointTable::headerData(int section, Qt::Orientation orientation, int
return QAbstractTableModel::headerData(section, orientation, role);
}
/**
* Called for any new UAVO instance and when that is a Waypoint register
* to update the table
*/
void WaypointTable::doNewInstance(UAVObject*obj)
{
Q_ASSERT(obj);
if (!obj)
return;
if (obj->getObjID() == Waypoint::OBJID)
connect(obj, SIGNAL(objectUpdated(UAVObject*)),this,SLOT(waypointsUpdated(UAVObject*)));
}
/**
* Called whenever the waypoints are updated to inform
* the view
@ -122,7 +145,6 @@ void WaypointTable::waypointsUpdated(UAVObject *)
// Currently only support adding instances which is all the UAVO manager
// supports
qDebug() << "Elements before " << elementsNow << " and cached " << elements;
if (elementsNow > elements) {
beginInsertRows(QModelIndex(), elements, elementsNow-1);
elements = elementsNow;
@ -141,8 +163,7 @@ Qt::ItemFlags WaypointTable::flags(const QModelIndex &index) const
bool WaypointTable::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
{
// if(role != Qt::EditRole)
// return false;
Q_UNUSED(role);
double val = value.toDouble();
qDebug() << "New value " << val << " for column " << index.column();

View File

@ -54,7 +54,7 @@ signals:
protected slots:
void waypointsUpdated(UAVObject *);
void doNewInstance(UAVObject*);
public slots:
private: