1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +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);
m_waypointeditor->waypoints->setModel(waypointTable);
// Get the objects used here
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager);
Q_ASSERT(waypointActiveObj != NULL);
waypointObj = Waypoint::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL);
// Connect the signals
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointActiveChanged(UAVObject*)));
connect(m_waypointeditor->buttonNewWaypoint, SIGNAL(clicked()),
this, SLOT(addInstance()));
}
@ -74,6 +71,17 @@ void WaypointEditorGadgetWidget::waypointActiveChanged(UAVObject *)
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:
Ui_WaypointEditor * m_waypointeditor;
WaypointTable *waypointTable;
WaypointActive *waypointActiveObj;
Waypoint *waypointObj;
};
#endif /* WaypointEditorGADGETWIDGET_H_ */

View File

@ -34,15 +34,18 @@ WaypointTable::WaypointTable(QObject *parent) :
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
waypointObj = Waypoint::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL);
Q_ASSERT(waypointActiveObj != NULL);
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*)),
this, SLOT(waypointsUpdated(UAVObject*)));
connect(waypointObj, SIGNAL(),
@ -54,7 +57,7 @@ WaypointTable::WaypointTable(QObject *parent) :
headers.append(QString("Down"));
}
int WaypointTable::rowCount(const QModelIndex &parent) const
int WaypointTable::rowCount(const QModelIndex & /*parent*/) const
{
return elements;
}
@ -70,11 +73,6 @@ int WaypointTable::columnCount(const QModelIndex &parent) const
QVariant WaypointTable::data(const QModelIndex &index, int role) const
{
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());
Q_ASSERT(obj);
Waypoint::DataFields waypoint = obj->getData();
@ -120,22 +118,56 @@ QVariant WaypointTable::headerData(int section, Qt::Orientation orientation, int
*/
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
// supports
qDebug() << "Elements before " << elementsNow << " and cached " << elements;
if (elementsNow > elements) {
beginInsertRows(QModelIndex(), elements, elementsNow);
beginInsertRows(QModelIndex(), elements, elementsNow-1);
elements = elementsNow;
endInsertRows();
}
QModelIndex i1 = index(0,0);
QModelIndex i2 = index(elements, columnCount(QModelIndex()));
qDebug() << "Waypoints updated. Found " << rowCount(QModelIndex());
QModelIndex i2 = index(elements-1, columnCount(QModelIndex()));
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:
explicit WaypointTable(QObject *parent = 0);
// Get dimensionality of the data
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
// Access data
QVariant data(const QModelIndex &index, 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:
protected slots:
@ -52,6 +58,7 @@ protected slots:
public slots:
private:
UAVObjectManager *objManager;
Waypoint *waypointObj;
WaypointActive *waypointActiveObj;
QList <QString> headers;