mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
LocalTaskModel: allow removing of stages
This commit is contained in:
parent
953224eba1
commit
fc9ca1b624
@ -20,6 +20,7 @@ public:
|
|||||||
bool traverseRecursively(const StageCallback &processor) const;
|
bool traverseRecursively(const StageCallback &processor) const;
|
||||||
|
|
||||||
virtual bool insert(Stage::pointer&& stage, int before = -1);
|
virtual bool insert(Stage::pointer&& stage, int before = -1);
|
||||||
|
virtual bool remove(int pos);
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|||||||
@ -96,6 +96,13 @@ bool ContainerBase::insert(Stage::pointer &&stage, int before)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ContainerBase::remove(int pos)
|
||||||
|
{
|
||||||
|
ContainerBasePrivate::const_iterator it = pimpl()->position(pos);
|
||||||
|
pimpl()->children_.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ContainerBase::clear()
|
void ContainerBase::clear()
|
||||||
{
|
{
|
||||||
pimpl()->children_.clear();
|
pimpl()->children_.clear();
|
||||||
|
|||||||
@ -169,6 +169,26 @@ bool LocalTaskModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LocalTaskModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
if (!parent.isValid())
|
||||||
|
return false; // cannot remove top-level container
|
||||||
|
if (flags_ & IS_RUNNING)
|
||||||
|
return false; // cannot modify running task
|
||||||
|
|
||||||
|
Q_ASSERT(dynamic_cast<ContainerBase*>(node(parent)->me()));
|
||||||
|
ContainerBasePrivate *cp = static_cast<ContainerBasePrivate*>(node(parent));
|
||||||
|
ContainerBase *c = static_cast<ContainerBase*>(cp->me());
|
||||||
|
if (row < 0 || (size_t)row + count > cp->children().size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
beginRemoveRows(parent, row, row+count-1);
|
||||||
|
for (; count > 0; --count)
|
||||||
|
c->remove(row);
|
||||||
|
endRemoveRows();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalTaskModel::setStageFactory(const StageFactoryPtr &factory)
|
void LocalTaskModel::setStageFactory(const StageFactoryPtr &factory)
|
||||||
{
|
{
|
||||||
stage_factory_ = factory;
|
stage_factory_ = factory;
|
||||||
|
|||||||
@ -65,6 +65,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;
|
||||||
|
|
||||||
|
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||||
|
|
||||||
/// 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);
|
||||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user