mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
re-enable drag-n-drop to edit task pipeline
This commit is contained in:
parent
e9363919e8
commit
d9be19bbe8
@ -141,6 +141,7 @@ TaskListModel::TaskListModel(QObject *parent)
|
|||||||
: FlatMergeProxyModel(parent)
|
: FlatMergeProxyModel(parent)
|
||||||
{
|
{
|
||||||
ROS_DEBUG_NAMED(LOGNAME, "created TaskListModel: %p", this);
|
ROS_DEBUG_NAMED(LOGNAME, "created TaskListModel: %p", this);
|
||||||
|
setStageFactory(getStageFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskListModel::~TaskListModel() {
|
TaskListModel::~TaskListModel() {
|
||||||
@ -171,28 +172,21 @@ void TaskListModel::setSolutionClient(ros::ServiceClient *client)
|
|||||||
void TaskListModel::setStageFactory(const StageFactoryPtr &factory)
|
void TaskListModel::setStageFactory(const StageFactoryPtr &factory)
|
||||||
{
|
{
|
||||||
stage_factory_ = factory;
|
stage_factory_ = factory;
|
||||||
|
if (stage_factory_)
|
||||||
|
setMimeTypes({ stage_factory_->mimeType() });
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-implemented from base class to allow dropping
|
// re-implemented from base class to allow dropping
|
||||||
Qt::ItemFlags TaskListModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags TaskListModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
auto f = FlatMergeProxyModel::flags(index);
|
||||||
|
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
Qt::ItemFlags f = QAbstractItemModel::flags(index);
|
|
||||||
// dropping at root will create a new local task
|
// dropping at root will create a new local task
|
||||||
if (stage_factory_)
|
if (stage_factory_)
|
||||||
f |= Qt::ItemIsDropEnabled;
|
f |= Qt::ItemIsDropEnabled;
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
|
return f;
|
||||||
return FlatMergeProxyModel::flags(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList TaskListModel::mimeTypes() const
|
|
||||||
{
|
|
||||||
QStringList result;
|
|
||||||
if (stage_factory_)
|
|
||||||
result << stage_factory_->mimeType();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TaskListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant TaskListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
@ -290,7 +284,9 @@ bool TaskListModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a new local task using the given container as root
|
// create a new local task using the given container as root
|
||||||
insertModel(new LocalTaskModel(std::move(container), this), row);
|
auto *m = new LocalTaskModel(std::move(container), this);
|
||||||
|
m->setStageFactory(stage_factory_);
|
||||||
|
insertModel(m, row);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -141,7 +141,6 @@ public:
|
|||||||
|
|
||||||
/// providing a StageFactory makes the model accepting drops
|
/// providing a StageFactory makes the model accepting drops
|
||||||
void setStageFactory(const StageFactoryPtr &factory);
|
void setStageFactory(const StageFactoryPtr &factory);
|
||||||
QStringList mimeTypes() const override;
|
|
||||||
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||||
Qt::DropActions supportedDropActions() const override;
|
Qt::DropActions supportedDropActions() const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|||||||
@ -98,7 +98,11 @@ TaskPanelPrivate::TaskPanelPrivate(TaskPanel *q_ptr)
|
|||||||
{
|
{
|
||||||
setupUi(q_ptr);
|
setupUi(q_ptr);
|
||||||
// init tasks view
|
// init tasks view
|
||||||
tasks_view->setModel(&MetaTaskListModel::instance());
|
MetaTaskListModel *meta_model = &MetaTaskListModel::instance();
|
||||||
|
StageFactoryPtr factory = getStageFactory();
|
||||||
|
if (factory) meta_model->setMimeTypes( { factory->mimeType() } );
|
||||||
|
else button_show_stage_dock_widget->setEnabled(false);
|
||||||
|
tasks_view->setModel(meta_model);
|
||||||
|
|
||||||
tasks_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
tasks_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
tasks_view->setAcceptDrops(true);
|
tasks_view->setAcceptDrops(true);
|
||||||
|
|||||||
@ -97,7 +97,8 @@ TEST(TreeMergeModel, basics) {
|
|||||||
|
|
||||||
EXPECT_EQ(tree.rowCount(), 1);
|
EXPECT_EQ(tree.rowCount(), 1);
|
||||||
EXPECT_EQ(tree.columnCount(), 3);
|
EXPECT_EQ(tree.columnCount(), 3);
|
||||||
EXPECT_TRUE(tree.index(0, 1).flags() & Qt::ItemIsSelectable);
|
EXPECT_TRUE(tree.index(0, 0).flags() & Qt::ItemIsSelectable);
|
||||||
|
EXPECT_FALSE(tree.index(0, 1).flags() & Qt::ItemIsSelectable);
|
||||||
EXPECT_FALSE(tree.index(1, 0).isValid());
|
EXPECT_FALSE(tree.index(1, 0).isValid());
|
||||||
|
|
||||||
QModelIndex idx = tree.index(0, 0);
|
QModelIndex idx = tree.index(0, 0);
|
||||||
|
|||||||
@ -45,6 +45,7 @@ class FlatMergeProxyModelPrivate {
|
|||||||
public:
|
public:
|
||||||
Q_DECLARE_PUBLIC(FlatMergeProxyModel)
|
Q_DECLARE_PUBLIC(FlatMergeProxyModel)
|
||||||
FlatMergeProxyModel* q_ptr;
|
FlatMergeProxyModel* q_ptr;
|
||||||
|
QStringList mime_types_;
|
||||||
|
|
||||||
struct ModelData {
|
struct ModelData {
|
||||||
ModelData(QAbstractItemModel* m) : model_(m) {}
|
ModelData(QAbstractItemModel* m) : model_(m) {}
|
||||||
@ -297,6 +298,16 @@ bool FlatMergeProxyModel::setData(const QModelIndex &index, const QVariant &valu
|
|||||||
return data->model_->setData(src_index, value, role);
|
return data->model_->setData(src_index, value, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatMergeProxyModel::setMimeTypes(const QStringList &mime_types)
|
||||||
|
{
|
||||||
|
d_ptr->mime_types_ = mime_types;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList FlatMergeProxyModel::mimeTypes() const
|
||||||
|
{
|
||||||
|
return d_ptr->mime_types_;
|
||||||
|
}
|
||||||
|
|
||||||
bool FlatMergeProxyModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
bool FlatMergeProxyModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
|
|||||||
@ -78,6 +78,8 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
|
||||||
|
void setMimeTypes(const QStringList& mime_types);
|
||||||
|
QStringList mimeTypes() const override;
|
||||||
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
|
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||||
|
|||||||
@ -44,6 +44,7 @@ class TreeMergeProxyModelPrivate {
|
|||||||
public:
|
public:
|
||||||
Q_DECLARE_PUBLIC(TreeMergeProxyModel)
|
Q_DECLARE_PUBLIC(TreeMergeProxyModel)
|
||||||
TreeMergeProxyModel* q_ptr;
|
TreeMergeProxyModel* q_ptr;
|
||||||
|
QStringList mime_types_;
|
||||||
|
|
||||||
struct ModelData {
|
struct ModelData {
|
||||||
ModelData(const QString& name, QAbstractItemModel* m)
|
ModelData(const QString& name, QAbstractItemModel* m)
|
||||||
@ -248,16 +249,15 @@ Qt::ItemFlags TreeMergeProxyModel::flags(const QModelIndex &index) const
|
|||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QAbstractItemModel::flags(index);
|
return QAbstractItemModel::flags(index);
|
||||||
|
|
||||||
if (isGroupItem(index)) { // top-level item
|
|
||||||
auto f = QAbstractItemModel::flags(index);
|
|
||||||
if (index.column() == 0)
|
|
||||||
f |= Qt::ItemIsEditable | Qt::ItemIsSelectable;
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMergeProxyModelPrivate::ModelData *data = nullptr;
|
TreeMergeProxyModelPrivate::ModelData *data = nullptr;
|
||||||
QModelIndex src_index = d_ptr->mapToSource(index, data);
|
QModelIndex src_index = d_ptr->mapToSource(index, data);
|
||||||
return data->model_ ->flags(src_index);
|
auto f = data->model_ ->flags(src_index);
|
||||||
|
|
||||||
|
if (isGroupItem(index)) { // top-level item
|
||||||
|
if (index.column() == 0)
|
||||||
|
f |= Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
|
||||||
|
}
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TreeMergeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant TreeMergeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
@ -302,6 +302,16 @@ bool TreeMergeProxyModel::setData(const QModelIndex &index, const QVariant &valu
|
|||||||
return data->model_->setData(src_index, value, role);
|
return data->model_->setData(src_index, value, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeMergeProxyModel::setMimeTypes(const QStringList &mime_types)
|
||||||
|
{
|
||||||
|
d_ptr->mime_types_ = mime_types;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TreeMergeProxyModel::mimeTypes() const
|
||||||
|
{
|
||||||
|
return d_ptr->mime_types_;
|
||||||
|
}
|
||||||
|
|
||||||
bool TreeMergeProxyModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
bool TreeMergeProxyModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
|
|||||||
@ -79,6 +79,8 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
|
||||||
|
void setMimeTypes(const QStringList& mime_types);
|
||||||
|
QStringList mimeTypes() const override;
|
||||||
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
bool dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
|
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user