mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
TaskModel / TaskDisplay: keep names in sync
This commit is contained in:
parent
2bc1b08a00
commit
1ae3793a9d
@ -153,6 +153,7 @@ bool LocalTaskModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||||||
if (name == n->name().c_str())
|
if (name == n->name().c_str())
|
||||||
return false;
|
return false;
|
||||||
n->me()->setName(name.toStdString());
|
n->me()->setName(name.toStdString());
|
||||||
|
dataChanged(index, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,7 @@ namespace moveit_rviz_plugin {
|
|||||||
|
|
||||||
enum NodeFlag {
|
enum NodeFlag {
|
||||||
WAS_VISITED = 0x01, // indicate that model should emit change notifications
|
WAS_VISITED = 0x01, // indicate that model should emit change notifications
|
||||||
|
NAME_CHANGED = 0x02, // indicate that name was manually changed
|
||||||
};
|
};
|
||||||
typedef QFlags<NodeFlag> NodeFlags;
|
typedef QFlags<NodeFlag> NodeFlags;
|
||||||
|
|
||||||
@ -186,7 +187,10 @@ bool RemoteTaskModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||||||
Node *n = node(index);
|
Node *n = node(index);
|
||||||
if (!n || index.column() != 0 || role != Qt::EditRole)
|
if (!n || index.column() != 0 || role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
return n->setName(value.toString());
|
n->setName(value.toString());
|
||||||
|
n->node_flags_ |= NAME_CHANGED;
|
||||||
|
dataChanged(index, index);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef moveit_task_constructor::Stage StageMsg;
|
typedef moveit_task_constructor::Stage StageMsg;
|
||||||
@ -219,7 +223,9 @@ void RemoteTaskModel::processTaskMessage(const moveit_task_constructor::Task &ms
|
|||||||
Q_ASSERT(n->parent_ == parent);
|
Q_ASSERT(n->parent_ == parent);
|
||||||
|
|
||||||
// set content of stage
|
// set content of stage
|
||||||
bool changed = n->setName(QString::fromStdString(s.name));
|
bool changed = false;
|
||||||
|
if (!(n->node_flags_ & NAME_CHANGED)) // avoid overwriting a manually changed name
|
||||||
|
n->setName(QString::fromStdString(s.name));
|
||||||
InterfaceFlags old_flags = n->interface_flags_;
|
InterfaceFlags old_flags = n->interface_flags_;
|
||||||
n->interface_flags_ = InterfaceFlags();
|
n->interface_flags_ = InterfaceFlags();
|
||||||
for (auto f : {READS_START, READS_END, WRITES_NEXT_START, WRITES_PREV_END}) {
|
for (auto f : {READS_START, READS_END, WRITES_NEXT_START, WRITES_PREV_END}) {
|
||||||
|
|||||||
@ -190,6 +190,7 @@ void TaskDisplay::updateTaskListModel()
|
|||||||
onTasksInserted(QModelIndex(), 0, task_list_model_->rowCount()-1);
|
onTasksInserted(QModelIndex(), 0, task_list_model_->rowCount()-1);
|
||||||
connect(task_list_model_.get(), &TaskListModel::rowsInserted, this, &TaskDisplay::onTasksInserted);
|
connect(task_list_model_.get(), &TaskListModel::rowsInserted, this, &TaskDisplay::onTasksInserted);
|
||||||
connect(task_list_model_.get(), &TaskListModel::rowsAboutToBeRemoved, this, &TaskDisplay::onTasksRemoved);
|
connect(task_list_model_.get(), &TaskListModel::rowsAboutToBeRemoved, this, &TaskDisplay::onTasksRemoved);
|
||||||
|
connect(task_list_model_.get(), &TaskListModel::dataChanged, this, &TaskDisplay::onTaskDataChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +208,7 @@ void TaskDisplay::changedTaskSolutionTopic()
|
|||||||
|
|
||||||
void TaskDisplay::onTasksInserted(const QModelIndex &parent, int first, int last)
|
void TaskDisplay::onTasksInserted(const QModelIndex &parent, int first, int last)
|
||||||
{
|
{
|
||||||
if (parent.isValid()) return;
|
if (parent.isValid()) return; // only handle top-level items
|
||||||
|
|
||||||
TaskListModel* m = static_cast<TaskListModel*>(sender());
|
TaskListModel* m = static_cast<TaskListModel*>(sender());
|
||||||
for (; first <= last; ++first) {
|
for (; first <= last; ++first) {
|
||||||
@ -218,7 +219,7 @@ void TaskDisplay::onTasksInserted(const QModelIndex &parent, int first, int last
|
|||||||
|
|
||||||
void TaskDisplay::onTasksRemoved(const QModelIndex &parent, int first, int last)
|
void TaskDisplay::onTasksRemoved(const QModelIndex &parent, int first, int last)
|
||||||
{
|
{
|
||||||
if (parent.isValid()) return;
|
if (parent.isValid()) return; // only handle top-level items
|
||||||
|
|
||||||
for (; first <= last; ++first) {
|
for (; first <= last; ++first) {
|
||||||
rviz::Property *child = tasks_property_->takeChildAt(first);
|
rviz::Property *child = tasks_property_->takeChildAt(first);
|
||||||
@ -226,4 +227,17 @@ void TaskDisplay::onTasksRemoved(const QModelIndex &parent, int first, int last)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TaskDisplay::onTaskDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||||
|
{
|
||||||
|
if (topLeft.parent().isValid()) return; // only handle top-level items
|
||||||
|
|
||||||
|
for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
|
||||||
|
rviz::Property *child = tasks_property_->childAt(row);
|
||||||
|
if (topLeft.column() <= 0 && 0 <= bottomRight.column()) // name changed
|
||||||
|
child->setName(topLeft.sibling(row, 0).data().toString());
|
||||||
|
if (topLeft.column() <= 1 && 1 <= bottomRight.column()) // #solutions changed
|
||||||
|
child->setValue(topLeft.sibling(row, 1).data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace moveit_rviz_plugin
|
} // namespace moveit_rviz_plugin
|
||||||
|
|||||||
@ -88,6 +88,7 @@ private Q_SLOTS:
|
|||||||
void changedTaskSolutionTopic();
|
void changedTaskSolutionTopic();
|
||||||
void onTasksInserted(const QModelIndex& parent, int first, int last);
|
void onTasksInserted(const QModelIndex& parent, int first, int last);
|
||||||
void onTasksRemoved(const QModelIndex& parent, int first, int last);
|
void onTasksRemoved(const QModelIndex& parent, int first, int last);
|
||||||
|
void onTaskDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateTaskListModel();
|
void updateTaskListModel();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user