1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-03 11:24:10 +01:00

OP-107 Make the waypoint editor have the ability to add new waypoints and edit their

positions.
This commit is contained in:
James Cotton 2012-05-09 17:25:23 -05:00
parent d42bdacc46
commit af63f94da0
4 changed files with 69 additions and 22 deletions

View File

@ -44,17 +44,14 @@ WaypointEditorGadgetWidget::WaypointEditorGadgetWidget(QWidget *parent) : QLabel
waypointTable = new WaypointTable(this); waypointTable = new WaypointTable(this);
m_waypointeditor->waypoints->setModel(waypointTable); m_waypointeditor->waypoints->setModel(waypointTable);
// Get the objects used here
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL); Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL); Q_ASSERT(objManager != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager); waypointObj = Waypoint::GetInstance(objManager);
Q_ASSERT(waypointActiveObj != NULL); Q_ASSERT(waypointObj != NULL);
// Connect the signals // Connect the signals
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointActiveChanged(UAVObject*)));
connect(m_waypointeditor->buttonNewWaypoint, SIGNAL(clicked()), connect(m_waypointeditor->buttonNewWaypoint, SIGNAL(clicked()),
this, SLOT(addInstance())); this, SLOT(addInstance()));
} }
@ -74,6 +71,17 @@ void WaypointEditorGadgetWidget::waypointActiveChanged(UAVObject *)
void WaypointEditorGadgetWidget::addInstance() void WaypointEditorGadgetWidget::addInstance()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
qDebug() << "Instances before: " << objManager->getNumInstances(waypointObj->getObjID());
Waypoint *obj = new Waypoint();
quint32 newInstId = objManager->getNumInstances(waypointObj->getObjID());
obj->initialize(newInstId,obj->getMetaObject());
objManager->registerObject(obj);
qDebug() << "Instances after: " << objManager->getNumInstances(waypointObj->getObjID());
} }
/** /**

View File

@ -51,7 +51,7 @@ protected slots:
private: private:
Ui_WaypointEditor * m_waypointeditor; Ui_WaypointEditor * m_waypointeditor;
WaypointTable *waypointTable; WaypointTable *waypointTable;
WaypointActive *waypointActiveObj; Waypoint *waypointObj;
}; };
#endif /* WaypointEditorGADGETWIDGET_H_ */ #endif /* WaypointEditorGADGETWIDGET_H_ */

View File

@ -34,15 +34,18 @@ WaypointTable::WaypointTable(QObject *parent) :
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL); Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL); Q_ASSERT(objManager != NULL);
waypointObj = Waypoint::GetInstance(objManager); waypointObj = Waypoint::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL); Q_ASSERT(waypointObj != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager); waypointActiveObj = WaypointActive::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL); Q_ASSERT(waypointActiveObj != NULL);
elements = 0; elements = 0;
// Unfortunately there is no per object new instance signal yet
connect(objManager, SIGNAL(newInstance(UAVObject*)),
this, SLOT(waypointsUpdated(UAVObject*)));
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)), connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointsUpdated(UAVObject*))); this, SLOT(waypointsUpdated(UAVObject*)));
connect(waypointObj, SIGNAL(), connect(waypointObj, SIGNAL(),
@ -54,7 +57,7 @@ WaypointTable::WaypointTable(QObject *parent) :
headers.append(QString("Down")); headers.append(QString("Down"));
} }
int WaypointTable::rowCount(const QModelIndex &parent) const int WaypointTable::rowCount(const QModelIndex & /*parent*/) const
{ {
return elements; return elements;
} }
@ -70,11 +73,6 @@ int WaypointTable::columnCount(const QModelIndex &parent) const
QVariant WaypointTable::data(const QModelIndex &index, int role) const QVariant WaypointTable::data(const QModelIndex &index, int role) const
{ {
if(role == Qt::DisplayRole) { if(role == Qt::DisplayRole) {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
Waypoint *obj = Waypoint::GetInstance(objManager, index.row()); Waypoint *obj = Waypoint::GetInstance(objManager, index.row());
Q_ASSERT(obj); Q_ASSERT(obj);
Waypoint::DataFields waypoint = obj->getData(); Waypoint::DataFields waypoint = obj->getData();
@ -120,22 +118,56 @@ QVariant WaypointTable::headerData(int section, Qt::Orientation orientation, int
*/ */
void WaypointTable::waypointsUpdated(UAVObject *) void WaypointTable::waypointsUpdated(UAVObject *)
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
int elementsNow = objManager->getNumInstances(waypointObj->getObjID()); int elementsNow = objManager->getNumInstances(waypointObj->getObjID());
// Currently only support adding instances which is all the UAVO manager // Currently only support adding instances which is all the UAVO manager
// supports // supports
qDebug() << "Elements before " << elementsNow << " and cached " << elements;
if (elementsNow > elements) { if (elementsNow > elements) {
beginInsertRows(QModelIndex(), elements, elementsNow); beginInsertRows(QModelIndex(), elements, elementsNow-1);
elements = elementsNow; elements = elementsNow;
endInsertRows(); endInsertRows();
} }
QModelIndex i1 = index(0,0); QModelIndex i1 = index(0,0);
QModelIndex i2 = index(elements, columnCount(QModelIndex())); QModelIndex i2 = index(elements-1, columnCount(QModelIndex()));
qDebug() << "Waypoints updated. Found " << rowCount(QModelIndex());
emit dataChanged(i1, i2); emit dataChanged(i1, i2);
} }
Qt::ItemFlags WaypointTable::flags(const QModelIndex &index) const
{
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
}
bool WaypointTable::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
{
// if(role != Qt::EditRole)
// return false;
double val = value.toDouble();
qDebug() << "New value " << val << " for column " << index.column();
Waypoint *obj = Waypoint::GetInstance(objManager, index.row());
Q_ASSERT(obj);
Waypoint::DataFields waypoint = obj->getData();
switch(index.column()) {
case 0:
waypoint.Position[Waypoint::POSITION_NORTH] = val;
break;
case 1:
waypoint.Position[Waypoint::POSITION_EAST] = val;
break;
case 2:
waypoint.Position[Waypoint::POSITION_DOWN] = val;
break;
default:
return false;
}
obj->setData(waypoint);
obj->updated();
qDebug() << "Set data for instance " << obj->getInstID();
return true;
}

View File

@ -39,11 +39,17 @@ class WaypointTable : public QAbstractTableModel
public: public:
explicit WaypointTable(QObject *parent = 0); explicit WaypointTable(QObject *parent = 0);
// Get dimensionality of the data
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const;
// Access data
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
// Functions to make the data editable
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData ( const QModelIndex & index, const QVariant & value, int role);
signals: signals:
protected slots: protected slots:
@ -52,6 +58,7 @@ protected slots:
public slots: public slots:
private: private:
UAVObjectManager *objManager;
Waypoint *waypointObj; Waypoint *waypointObj;
WaypointActive *waypointActiveObj; WaypointActive *waypointActiveObj;
QList <QString> headers; QList <QString> headers;