mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
PathAction editor: make easy selection of actions per waypoint
This commit is contained in:
parent
df67a3e631
commit
a2d6cb8314
@ -270,4 +270,58 @@ private:
|
|||||||
UAVObjectField *m_field;
|
UAVObjectField *m_field;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ActionFieldTreeItem : public FieldTreeItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ActionFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &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<QComboBox*>(editor);
|
||||||
|
return comboBox->currentIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEditorValue(QWidget *editor, QVariant value) {
|
||||||
|
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||||
|
comboBox->setCurrentIndex(value.toInt());
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
QStringList *m_enumOptions;
|
||||||
|
UAVObjectField *m_field;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // FIELDTREEITEM_H
|
#endif // FIELDTREEITEM_H
|
||||||
|
@ -23,6 +23,7 @@ SOURCES += treeitem.cpp
|
|||||||
SOURCES += fieldtreeitem.cpp
|
SOURCES += fieldtreeitem.cpp
|
||||||
SOURCES += browseritemdelegate.cpp
|
SOURCES += browseritemdelegate.cpp
|
||||||
|
|
||||||
|
|
||||||
OTHER_FILES += pathactioneditor.pluginspec
|
OTHER_FILES += pathactioneditor.pluginspec
|
||||||
|
|
||||||
FORMS += pathactioneditor.ui
|
FORMS += pathactioneditor.ui
|
||||||
|
@ -45,6 +45,7 @@ PathActionEditorGadgetWidget::PathActionEditorGadgetWidget(QWidget *parent) : QL
|
|||||||
m_model = new PathActionEditorTreeModel();
|
m_model = new PathActionEditorTreeModel();
|
||||||
m_pathactioneditor->pathactions->setModel(m_model);
|
m_pathactioneditor->pathactions->setModel(m_model);
|
||||||
m_pathactioneditor->pathactions->setColumnWidth(0, 300);
|
m_pathactioneditor->pathactions->setColumnWidth(0, 300);
|
||||||
|
m_pathactioneditor->pathactions->setColumnWidth(1, 500);
|
||||||
m_pathactioneditor->pathactions->expandAll();
|
m_pathactioneditor->pathactions->expandAll();
|
||||||
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
|
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
|
||||||
m_pathactioneditor->pathactions->setItemDelegate(m_delegate);
|
m_pathactioneditor->pathactions->setItemDelegate(m_delegate);
|
||||||
|
@ -48,12 +48,14 @@ PathActionEditorTreeModel::PathActionEditorTreeModel(QObject *parent) :
|
|||||||
m_manuallyChangedColor(QColor(230, 230, 255))
|
m_manuallyChangedColor(QColor(230, 230, 255))
|
||||||
{
|
{
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
m_objManager = pm->getObject<UAVObjectManager>();
|
||||||
|
|
||||||
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
|
connect(m_objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
|
||||||
connect(objManager->getObject("WaypointActive"),SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objUpdated(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()
|
PathActionEditorTreeModel::~PathActionEditorTreeModel()
|
||||||
@ -61,8 +63,12 @@ PathActionEditorTreeModel::~PathActionEditorTreeModel()
|
|||||||
delete m_rootItem;
|
delete m_rootItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathActionEditorTreeModel::setupModelData(UAVObjectManager *objManager)
|
void PathActionEditorTreeModel::setupModelData()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
m_actions = new QStringList();
|
||||||
|
updateActions();
|
||||||
|
|
||||||
// root
|
// root
|
||||||
QList<QVariant> rootData;
|
QList<QVariant> rootData;
|
||||||
rootData << tr("Property") << tr("Value") << tr("Unit");
|
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*)));
|
connect(m_waypointsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||||
|
|
||||||
{
|
{
|
||||||
QList<UAVObject*> list = objManager->getObjectInstances("PathAction");
|
QList<UAVObject*> list = m_objManager->getObjectInstances("PathAction");
|
||||||
foreach (UAVObject* obj, list) {
|
foreach (UAVObject* obj, list) {
|
||||||
addInstance(obj,m_pathactionsTree);
|
addInstance(obj,m_pathactionsTree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
QList<UAVObject*> list = objManager->getObjectInstances("Waypoint");
|
QList<UAVObject*> list = m_objManager->getObjectInstances("Waypoint");
|
||||||
foreach (UAVObject* obj, list) {
|
foreach (UAVObject* obj, list) {
|
||||||
addInstance(obj,m_waypointsTree);
|
addInstance(obj,m_waypointsTree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PathActionEditorTreeModel::updateActions() {
|
||||||
|
m_actions->clear();
|
||||||
|
QList<UAVObject*> 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)
|
void PathActionEditorTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||||
{
|
{
|
||||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||||
@ -128,6 +151,12 @@ void PathActionEditorTreeModel::addSingleField(int index, UAVObjectField *field,
|
|||||||
|
|
||||||
FieldTreeItem *item;
|
FieldTreeItem *item;
|
||||||
UAVObjectField::FieldType type = field->getType();
|
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) {
|
switch (type) {
|
||||||
case UAVObjectField::ENUM: {
|
case UAVObjectField::ENUM: {
|
||||||
QStringList options = field->getOptions();
|
QStringList options = field->getOptions();
|
||||||
@ -155,6 +184,7 @@ void PathActionEditorTreeModel::addSingleField(int index, UAVObjectField *field,
|
|||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||||
parent->appendChild(item);
|
parent->appendChild(item);
|
||||||
}
|
}
|
||||||
@ -272,6 +302,12 @@ QVariant PathActionEditorTreeModel::data(const QModelIndex &index, int role) con
|
|||||||
if (fieldItem) {
|
if (fieldItem) {
|
||||||
int enumIndex = fieldItem->data(index.column()).toInt();
|
int enumIndex = fieldItem->data(index.column()).toInt();
|
||||||
return fieldItem->enumOptions(enumIndex);
|
return fieldItem->enumOptions(enumIndex);
|
||||||
|
} else {
|
||||||
|
ActionFieldTreeItem *afieldItem = dynamic_cast<ActionFieldTreeItem*>(item);
|
||||||
|
if (afieldItem) {
|
||||||
|
int enumIndex = afieldItem->data(index.column()).toInt();
|
||||||
|
return afieldItem->enumOptions(enumIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,14 +392,14 @@ void PathActionEditorTreeModel::newInstance(UAVObject *obj)
|
|||||||
addInstance(obj,m_pathactionsTree);
|
addInstance(obj,m_pathactionsTree);
|
||||||
m_pathactionsTree->update();
|
m_pathactionsTree->update();
|
||||||
}
|
}
|
||||||
|
updateActions();
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathActionEditorTreeModel::objUpdated(UAVObject *obj)
|
void PathActionEditorTreeModel::objUpdated(UAVObject *obj)
|
||||||
{
|
{
|
||||||
if (obj->getName().compare("WaypointActive")==0) {
|
quint16 index = m_objManager->getObject("WaypointActive")->getField("Index")->getValue().toInt();
|
||||||
qint16 index = obj->getField("Index")->getValue().toInt();
|
quint16 action;
|
||||||
qint16 action;
|
|
||||||
foreach (TreeItem *child,m_waypointsTree->treeChildren()) {
|
foreach (TreeItem *child,m_waypointsTree->treeChildren()) {
|
||||||
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(child);
|
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(child);
|
||||||
if (index == objItem->object()->getInstID()) {
|
if (index == objItem->object()->getInstID()) {
|
||||||
@ -381,7 +417,7 @@ void PathActionEditorTreeModel::objUpdated(UAVObject *obj)
|
|||||||
child->setActive(false);
|
child->setActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
updateActions();
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,11 @@ private:
|
|||||||
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
|
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
|
||||||
void addInstance(UAVObject *obj, TreeItem *parent);
|
void addInstance(UAVObject *obj, TreeItem *parent);
|
||||||
//QString updateMode(quint8 updateMode);
|
//QString updateMode(quint8 updateMode);
|
||||||
void setupModelData(UAVObjectManager *objManager);
|
void setupModelData();
|
||||||
|
void updateActions();
|
||||||
|
|
||||||
|
UAVObjectManager *m_objManager;
|
||||||
|
QStringList *m_actions;
|
||||||
|
|
||||||
TreeItem *m_rootItem;
|
TreeItem *m_rootItem;
|
||||||
TopTreeItem *m_pathactionsTree;
|
TopTreeItem *m_pathactionsTree;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user