diff --git a/ground/openpilotgcs/src/plugins/pathactioneditor/fieldtreeitem.h b/ground/openpilotgcs/src/plugins/pathactioneditor/fieldtreeitem.h index cb26f0bed..7d33c431f 100644 --- a/ground/openpilotgcs/src/plugins/pathactioneditor/fieldtreeitem.h +++ b/ground/openpilotgcs/src/plugins/pathactioneditor/fieldtreeitem.h @@ -270,4 +270,58 @@ private: UAVObjectField *m_field; }; +class ActionFieldTreeItem : public FieldTreeItem +{ +Q_OBJECT +public: + ActionFieldTreeItem(UAVObjectField *field, int index, const QList &data, QStringList *actions, + TreeItem *parent = 0) : + FieldTreeItem(index, data, parent), m_field(field) { m_enumOptions=actions; } + ActionFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, QStringList *actions, + TreeItem *parent = 0) : + FieldTreeItem(index, data, parent), m_field(field) { m_enumOptions=actions; } + void setData(QVariant value, int column) { + int tmpValIndex = m_field->getValue(m_index).toInt(); + TreeItem::setData(value, column); + setChanged(tmpValIndex != value); + } + QString enumOptions(int index) { + if((index < 0) || (index >= m_enumOptions->length())) { + return QString("Invalid Value (") + QString().setNum(index) + QString(")"); + } + return m_enumOptions->at(index); + } + void apply() { + int value = data(dataColumn).toInt(); + m_field->setValue(value, m_index); + setChanged(false); + } + void update() { + int valIndex = m_field->getValue(m_index).toInt(); + if (data() != valIndex || changed()) { + TreeItem::setData(valIndex); + setHighlight(true); + } + } + QWidget *createEditor(QWidget *parent) { + QComboBox *editor = new QComboBox(parent); + foreach (QString option, *m_enumOptions) + editor->addItem(option); + return editor; + } + + QVariant getEditorValue(QWidget *editor) { + QComboBox *comboBox = static_cast(editor); + return comboBox->currentIndex(); + } + + void setEditorValue(QWidget *editor, QVariant value) { + QComboBox *comboBox = static_cast(editor); + comboBox->setCurrentIndex(value.toInt()); + } +private: + QStringList *m_enumOptions; + UAVObjectField *m_field; +}; + #endif // FIELDTREEITEM_H diff --git a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditor.pro b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditor.pro index 2a5cd1f23..7b1a7bf00 100644 --- a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditor.pro +++ b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditor.pro @@ -23,6 +23,7 @@ SOURCES += treeitem.cpp SOURCES += fieldtreeitem.cpp SOURCES += browseritemdelegate.cpp + OTHER_FILES += pathactioneditor.pluginspec FORMS += pathactioneditor.ui diff --git a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditorgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditorgadgetwidget.cpp index d17cec77d..dde05ba7c 100644 --- a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditorgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditorgadgetwidget.cpp @@ -45,6 +45,7 @@ PathActionEditorGadgetWidget::PathActionEditorGadgetWidget(QWidget *parent) : QL m_model = new PathActionEditorTreeModel(); m_pathactioneditor->pathactions->setModel(m_model); m_pathactioneditor->pathactions->setColumnWidth(0, 300); + m_pathactioneditor->pathactions->setColumnWidth(1, 500); m_pathactioneditor->pathactions->expandAll(); BrowserItemDelegate *m_delegate = new BrowserItemDelegate(); m_pathactioneditor->pathactions->setItemDelegate(m_delegate); diff --git a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.cpp b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.cpp index b8e405bfa..de05b2ce9 100644 --- a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.cpp +++ b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.cpp @@ -48,12 +48,14 @@ PathActionEditorTreeModel::PathActionEditorTreeModel(QObject *parent) : m_manuallyChangedColor(QColor(230, 230, 255)) { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); + m_objManager = pm->getObject(); - connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*))); - connect(objManager->getObject("WaypointActive"),SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objUpdated(UAVObject*))); + connect(m_objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*))); + connect(m_objManager->getObject("WaypointActive"),SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objUpdated(UAVObject*))); + connect(m_objManager->getObject("PathAction"),SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objUpdated(UAVObject*))); + connect(m_objManager->getObject("Waypoint"),SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objUpdated(UAVObject*))); - setupModelData(objManager); + setupModelData(); } PathActionEditorTreeModel::~PathActionEditorTreeModel() @@ -61,8 +63,12 @@ PathActionEditorTreeModel::~PathActionEditorTreeModel() delete m_rootItem; } -void PathActionEditorTreeModel::setupModelData(UAVObjectManager *objManager) +void PathActionEditorTreeModel::setupModelData() { + + m_actions = new QStringList(); + updateActions(); + // root QList rootData; rootData << tr("Property") << tr("Value") << tr("Unit"); @@ -77,19 +83,36 @@ void PathActionEditorTreeModel::setupModelData(UAVObjectManager *objManager) connect(m_waypointsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); { - QList list = objManager->getObjectInstances("PathAction"); + QList list = m_objManager->getObjectInstances("PathAction"); foreach (UAVObject* obj, list) { addInstance(obj,m_pathactionsTree); } } { - QList list = objManager->getObjectInstances("Waypoint"); + QList list = m_objManager->getObjectInstances("Waypoint"); foreach (UAVObject* obj, list) { addInstance(obj,m_waypointsTree); } } } +void PathActionEditorTreeModel::updateActions() { + m_actions->clear(); + QList list = m_objManager->getObjectInstances("PathAction"); + foreach (UAVObject* obj, list) { + QString title; + title.append((QVariant(obj->getInstID()).toString())); + title.append(" "); + title.append((obj->getField("Mode")->getValue().toString())); + title.append(" "); + title.append((obj->getField("Command")->getValue().toString())); + title.append(":"); + title.append((obj->getField("EndCondition")->getValue().toString())); + title.append(" "); + m_actions->append(title); + } +} + void PathActionEditorTreeModel::addInstance(UAVObject *obj, TreeItem *parent) { connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*))); @@ -128,6 +151,12 @@ void PathActionEditorTreeModel::addSingleField(int index, UAVObjectField *field, FieldTreeItem *item; UAVObjectField::FieldType type = field->getType(); + // hack: list available actions in an enum + if (field->getName().compare("Action")==0 && type==UAVObjectField::UINT8) { + data.append( field->getValue(index).toInt()); + data.append( field->getUnits()); + item = new ActionFieldTreeItem(field, index, data, m_actions); + } else { switch (type) { case UAVObjectField::ENUM: { QStringList options = field->getOptions(); @@ -155,6 +184,7 @@ void PathActionEditorTreeModel::addSingleField(int index, UAVObjectField *field, default: Q_ASSERT(false); } + } connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*))); parent->appendChild(item); } @@ -272,7 +302,13 @@ QVariant PathActionEditorTreeModel::data(const QModelIndex &index, int role) con if (fieldItem) { int enumIndex = fieldItem->data(index.column()).toInt(); return fieldItem->enumOptions(enumIndex); - } + } else { + ActionFieldTreeItem *afieldItem = dynamic_cast(item); + if (afieldItem) { + int enumIndex = afieldItem->data(index.column()).toInt(); + return afieldItem->enumOptions(enumIndex); + } + } } return item->data(index.column()); @@ -356,32 +392,32 @@ void PathActionEditorTreeModel::newInstance(UAVObject *obj) addInstance(obj,m_pathactionsTree); m_pathactionsTree->update(); } + updateActions(); emit layoutChanged(); } void PathActionEditorTreeModel::objUpdated(UAVObject *obj) { - if (obj->getName().compare("WaypointActive")==0) { - qint16 index = obj->getField("Index")->getValue().toInt(); - qint16 action; - foreach (TreeItem *child,m_waypointsTree->treeChildren()) { - ObjectTreeItem *objItem = dynamic_cast(child); - if (index == objItem->object()->getInstID()) { - child->setActive(true); - action = objItem->object()->getField("Action")->getValue().toInt(); - } else { - child->setActive(false); - } - } - foreach (TreeItem *child,m_pathactionsTree->treeChildren()) { - ObjectTreeItem *objItem = dynamic_cast(child); - if (action == objItem->object()->getInstID()) { - child->setActive(true); - } else { - child->setActive(false); - } + quint16 index = m_objManager->getObject("WaypointActive")->getField("Index")->getValue().toInt(); + quint16 action; + foreach (TreeItem *child,m_waypointsTree->treeChildren()) { + ObjectTreeItem *objItem = dynamic_cast(child); + if (index == objItem->object()->getInstID()) { + child->setActive(true); + action = objItem->object()->getField("Action")->getValue().toInt(); + } else { + child->setActive(false); } } + foreach (TreeItem *child,m_pathactionsTree->treeChildren()) { + ObjectTreeItem *objItem = dynamic_cast(child); + if (action == objItem->object()->getInstID()) { + child->setActive(true); + } else { + child->setActive(false); + } + } + updateActions(); emit layoutChanged(); } diff --git a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.h b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.h index 9763ba080..71190b86b 100644 --- a/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.h +++ b/ground/openpilotgcs/src/plugins/pathactioneditor/pathactioneditortreemodel.h @@ -82,7 +82,11 @@ private: void addSingleField(int index, UAVObjectField *field, TreeItem *parent); void addInstance(UAVObject *obj, TreeItem *parent); //QString updateMode(quint8 updateMode); - void setupModelData(UAVObjectManager *objManager); + void setupModelData(); + void updateActions(); + + UAVObjectManager *m_objManager; + QStringList *m_actions; TreeItem *m_rootItem; TopTreeItem *m_pathactionsTree;