From ff36e880e918987f756485aaf89b95e38096d238 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 5 Jun 2012 00:53:22 -0500 Subject: [PATCH] Fix for pathcompiler and waypoint table regarding signals and new instances --- .../src/plugins/opmap/pathcompiler.cpp | 39 +++++++++++++++---- .../src/plugins/opmap/pathcompiler.h | 7 +++- .../plugins/waypointeditor/waypointtable.cpp | 29 ++++++++++++-- .../plugins/waypointeditor/waypointtable.h | 2 +- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp index c1c7890a3..3f2a1a2b5 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp @@ -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) diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h index b52ee8e89..5c05b1af1 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h @@ -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 diff --git a/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.cpp b/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.cpp index 46621952b..e0f59c60f 100644 --- a/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.cpp +++ b/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.cpp @@ -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(); diff --git a/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.h b/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.h index a9821e99e..cf2a5a02b 100644 --- a/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.h +++ b/ground/openpilotgcs/src/plugins/waypointeditor/waypointtable.h @@ -54,7 +54,7 @@ signals: protected slots: void waypointsUpdated(UAVObject *); - + void doNewInstance(UAVObject*); public slots: private: